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C NKWFGTCM6HM35MAJAREANFQS76ALYOD7K6FT77X5HQPBCRAPXVRAC NIYF4R7SECNOBIZNKAR627Q5BW7ANIFCKKKPHOM2OZIBVEGYWWZQC 3J7QNHQ4F2VBYCK6SWKPO3AW3YYAJZNWOW6XNSURSRDZOE2ZIGQAC WO2ALETBVNH7N3NXJ6JKWCQ2YIZN6LBO7WEXPHAT3EQQJEUCJITQC L72HFM6IYLNHEFEIFOQQQUAGMY2RN4POCV3Q3SMQERSQBMEZ5J3QC GJGKS2YPL6XOT4CLQ2NVHUU2W7MDHYE2XC77WWRGPBCPSTWZ5GIAC import { GameState } from "../data/GameState";import { UpdaterGeneratorType2 } from "../lib/util/updaterGenerator";
import { GameState, PlayerSaveState, PointNodeRef } from "../data/GameState";import { canAllocate } from "./Neighbors";
// Things that should happen after allocation history is appended to , in order to maintain the game state in a good stateexport function afterAppendAllocationHistory(updaters: UpdaterGeneratorType2<GameState>) {updaters.playerSave.enqueueUpdate((prev, prevGameState) => {let justAllocated = prevGameState.playerSave.justAllocated; // we are assuming that someone verified that this is good2goif (!justAllocated) { return prev; }
export function doTryAllocate(prev: PlayerSaveState, prevGameState: GameState, selfPointNodeRef: PointNodeRef): [PlayerSaveState, boolean] {if (canAllocate(selfPointNodeRef,prevGameState.worldGen,prevGameState.playerSave.allocatedPointNodeSet,prevGameState.playerSave.availableSp) === 'yes') {// do the changeconst nextSet = prev.allocatedPointNodeSet.clone();nextSet.put(selfPointNodeRef);const nextHistory = [...prev.allocatedPointNodeHistory];nextHistory.push(selfPointNodeRef);let availableSp = prev.availableSp - 1;return [{...prev,allocatedPointNodeHistory: nextHistory,allocatedPointNodeSet: nextSet,availableSp}, true];} else {return [prev, false];}}
let prevSet = prev.allocatedPointNodeSet;if (!prevSet.contains(justAllocated)) { // if it's new, add it to history, set, and decrement spconst nextSet = prev.allocatedPointNodeSet.clone();nextSet.put(justAllocated);const nextHistory = [...prev.allocatedPointNodeHistory];nextHistory.push(justAllocated);let availableSp = prev.availableSp - 1;return {...prev,allocatedPointNodeHistory: nextHistory,allocatedPointNodeSet: nextSet,availableSp};}return prev;});
export function afterMaybeSpendingSp(prev: PlayerSaveState, prevGameState: GameState): PlayerSaveState {if (prev.availableSp === 0 && prev.activeQuest) {return {...prev,availableSp: 5,batchesSinceQuestStart: prev.batchesSinceQuestStart + 1};}return prev;
}/*** Same use case and types as [batchify], however, specifically we expect [fn] to be a setState function which takes value-or-callback* as its single argument, and instead of calling [fn] repeatedly for each callback in the batch, we apply the callbacks in the batch* sequentially to get a single state update which we then provide to [fn].*/export function batchifySetState<T>(fn: (arg: T) => void): [((arg: T) => void), () => void] {let batch: T[] = [];return [(arg: T) => {batch.push(arg);console.log({ batchSize: batch.length });}, (() => {if (batch.length === 0) {return;}console.log({ fired: batch.length });let thisBatch = [...batch];batch = [];(fn as any)((prev: any) => {let next = prev;for (let valueOrCallback of thisBatch) {if (typeof valueOrCallback === 'function') {next = valueOrCallback(next);} else {next = valueOrCallback;}}return next;});})]
updaters.playerSave.justAllocated.enqueueUpdate((prev: PointNodeRef | undefined, prevGameState) : PointNodeRef | undefined => {// if we were already selected, but not yet allocated, allocate us and add to the history (maybe this should be managed elsewhere??)if (prevGameState.playerUI.selectedPointNode?.pointNodeId === args.selfPointNodeRef.pointNodeId) {if (canAllocate(args.selfPointNodeRef,prevGameState.worldGen,prevGameState.playerSave.allocatedPointNodeSet,prevGameState.playerSave.availableSp) === 'yes') {return args.selfPointNodeRef;
// update selected to ourselvesupdaters.playerUI.selectedPointNode.enqueueUpdate((prev, gameState) => {if (prev?.pointNodeId === args.selfPointNodeRef.pointNodeId) {this.state.justTriedToAllocate = true;}return args.selfPointNodeRef;});// if we tried to allocate ourselves, see if we canupdaters.playerSave.enqueueUpdate((prev, prevGameState) => {if (this.state.justTriedToAllocate) {this.state.justTriedToAllocate = false;let [next, succeeded] = doTryAllocate(prev, prevGameState, args.selfPointNodeRef);if (succeeded) {this.state.justSpentSp = true;return next;
// whether or not we successfully allocated, run this just in caseafterAppendAllocationHistory(updaters);
// if we spent sp, remember to update quest status and suchupdaters.playerSave.enqueueUpdate((prev, prevGameState) => {if (this.state.justSpentSp) {this.state.justSpentSp = false;return afterMaybeSpendingSp(prev, prevGameState);}return prev;})
// update selected to ourselvesupdaters.playerUI.selectedPointNode.enqueueUpdate((prev, gameState) => {return args.selfPointNodeRef;})
// if we failed to allocate, shift the active tab so the player can see whyupdaters.playerUI.activeTab.enqueueUpdate((prev, prevGameState) => {if (this.state.justFailedToAllocate) {this.state.justFailedToAllocate = false;return 1;}return prev;});