]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/tracker.js
simple tracker config dialog
[alttp.git] / resources / js / helpers / tracker.js
index bc18847fcc10e47ad7f0a8c8405b64ce0323a37b..e4b0ebe9f765a33d497ff2d994537a64168860ae 100644 (file)
@@ -68,6 +68,10 @@ export const BOSSES = [
 ];
 
 export const CONFIG = {
+       showMap: 'situational',
+       showCompass: 'situational',
+       showSmall: 'always',
+       showBig: 'always',
        wildMap: false,
        wildCompass: false,
        wildSmall: false,
@@ -1552,6 +1556,20 @@ export const UNDERWORLD_LOCATIONS = [
        },
 ];
 
+export const shouldShowDungeonItem = (config, which) => {
+       const show = config[`show${which}`] || 'always';
+       const wild = config[`wild${which}`] || false;
+       switch (show) {
+               default:
+               case 'always':
+                       return true;
+               case 'situational':
+                       return wild;
+               case 'never':
+                       return false;
+       }
+};
+
 export const toggleBoolean = name => state => ({
        ...state,
        [name]: !state[name],
@@ -1765,11 +1783,15 @@ const collectUnderworld = (state, data) => {
        });
 };
 
-export const computeState = (data, prizeMap) => {
+export const computeState = (config, data, prizeMap) => {
        const state = {};
        collectInventory(state, data.slice(SRAM_ADDR.INV_START), prizeMap);
        collectOverworld(state, data);
        collectUnderworld(state, data.slice(SRAM_ADDR.ROOM_DATA_START));
+       const amounts = getDungeonAmounts(config, state);
+       DUNGEONS.forEach(dungeon => {
+               state[`${dungeon.id}-checks`] = amounts[dungeon.id];
+       });
        return state;
 };
 
@@ -1804,12 +1826,54 @@ const getDungeonAmounts = (config, state) => {
        return amounts;
 };
 
-export const mergeStates = (config, cur, inc) => {
-       const next = { ...cur, ...inc };
-       const amounts = getDungeonAmounts(config, inc);
+export const mergeStates = (autoState, manualState) => {
+       const next = { ...autoState };
+       BOOLEAN_STATES.forEach(name => {
+               if (manualState[name]) {
+                       next[name] = true;
+               }
+       });
+       INTEGER_STATES.forEach(name => {
+               next[name] = Math.max(autoState[name] || 0, manualState[name] || 0);
+       });
        DUNGEONS.forEach(dungeon => {
-               next[`${dungeon.id}-checks`] = amounts[dungeon.id];
+               next[`${dungeon.id}-small-key`] += manualState[`${dungeon.id}-small-key`] || 0;
+               next[`${dungeon.id}-checks`] += manualState[`${dungeon.id}-checks`] || 0;
+               if (manualState[`${dungeon.id}-big-key`]) {
+                       next[`${dungeon.id}-big-key`] = true;
+               }
+               if (manualState[`${dungeon.id}-compass`]) {
+                       next[`${dungeon.id}-compass`] = true;
+               }
+               if (manualState[`${dungeon.id}-map`]) {
+                       next[`${dungeon.id}-map`] = true;
+               }
+               if (manualState[`${dungeon.id}-boss-defeated`]) {
+                       next[`${dungeon.id}-boss-defeated`] = true;
+               }
+               if (manualState[`${dungeon.id}-prize`] &&
+                       manualState[`${dungeon.id}-prize`] !== 'crystal'
+               ) {
+                       next[`${dungeon.id}-prize`] = manualState[`${dungeon.id}-prize`];
+               } else if (!next[`${dungeon.id}-prize`]) {
+                       next[`${dungeon.id}-prize`] = 'crystal';
+               }
+               if (manualState[`${dungeon.id}-prize-acquired`]) {
+                       next[`${dungeon.id}-prize-acquired`] = true;
+               }
+       });
+       OVERWORLD_LOCATIONS.forEach(loc => {
+               if (manualState[loc.id]) {
+                       next[loc.id] = true;
+               }
+       });
+       UNDERWORLD_LOCATIONS.forEach(loc => {
+               if (manualState[loc.id]) {
+                       next[loc.id] = true;
+               }
        });
+       next['mm-medallion'] = manualState['mm-medallion'];
+       next['tr-medallion'] = manualState['tr-medallion'];
        //console.log(next);
        return next;
 };