chore: commit investigation state
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m25s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m25s
This commit is contained in:
@@ -105,7 +105,13 @@ export const useManaStore = create<ManaStore>()(
|
||||
if (state.elements[element]?.unlocked) return fail(ErrorCode.INVALID_INPUT, `Element ${element} is already unlocked`);
|
||||
if (state.rawMana < cost) return fail(ErrorCode.INSUFFICIENT_MANA, `Need ${cost} raw mana, have ${state.rawMana}`);
|
||||
|
||||
set({ rawMana: state.rawMana - cost, elements: { ...state.elements, [element]: { ...state.elements[element], unlocked: true } } });
|
||||
// If the element doesn't exist in the store (e.g. from an old save), create it
|
||||
const existing = state.elements[element];
|
||||
const newElement = existing
|
||||
? { ...existing, unlocked: true }
|
||||
: { current: 0, max: 10, baseMax: 10, unlocked: true };
|
||||
|
||||
set({ rawMana: state.rawMana - cost, elements: { ...state.elements, [element]: newElement } });
|
||||
return okVoid();
|
||||
},
|
||||
|
||||
@@ -174,6 +180,18 @@ export const useManaStore = create<ManaStore>()(
|
||||
persistedState.elements[k].baseMax = persistedState.elements[k].max ?? 10;
|
||||
}
|
||||
}
|
||||
// Add any missing elements that exist in ELEMENTS but not in the save
|
||||
for (const k of Object.keys(ELEMENTS)) {
|
||||
if (!persistedState.elements[k]) {
|
||||
const isUnlocked = BASE_UNLOCKED_ELEMENTS.includes(k);
|
||||
persistedState.elements[k] = {
|
||||
current: isUnlocked ? 0 : 0,
|
||||
max: 10,
|
||||
baseMax: 10,
|
||||
unlocked: isUnlocked,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return persistedState;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user