fix: break circular dependency between combat-descent and non-combat-room actions
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m2s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m2s
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
|
||||
import type { GameAction, SpellState, FloorState, GolemancyState, ActivityLogEntry, AchievementState, EquipmentSpellState, ActivityEventType, ActiveGolem, EnemyState, EquipmentInstance } from '../types';
|
||||
|
||||
/** Signature for the advanceRoomOrFloor callback to break circular dependency */
|
||||
export type AdvanceRoomFn = (get: () => CombatStore, set: (s: Partial<CombatState>) => void) => void;
|
||||
|
||||
// ─── Combat State (data only) ─────────────────────────────────────────────────
|
||||
|
||||
export interface CombatState {
|
||||
@@ -118,9 +121,9 @@ export interface CombatActions {
|
||||
/** Grant discipline XP scaled by floor, then advance */
|
||||
onEnterLibraryRoom: () => void;
|
||||
/** Tick non-combat room progress (called from game tick pipeline) */
|
||||
tickNonCombatRoom: (hours: number) => void;
|
||||
tickNonCombatRoom: (hours: number, advance: AdvanceRoomFn) => void;
|
||||
/** Skip current non-combat room (library, recovery, treasure) */
|
||||
skipNonCombatRoom: () => void;
|
||||
skipNonCombatRoom: (advance: AdvanceRoomFn) => void;
|
||||
/** Stay 1 hour longer in library or recovery room */
|
||||
stayLongerInRoom: () => void;
|
||||
|
||||
|
||||
@@ -220,8 +220,8 @@ export const useCombatStore = create<CombatStore>()(
|
||||
advanceRoomOrFloor: () => advanceRoomOrFloor(get, set),
|
||||
onEnterRoomDescend: () => onEnterRoomDescend(get, set),
|
||||
onEnterLibraryRoom: () => onEnterLibraryRoom(get, set),
|
||||
tickNonCombatRoom: (hours: number) => tickNonCombatRoom(get, set, hours),
|
||||
skipNonCombatRoom: () => skipNonCombatRoom(get, set),
|
||||
tickNonCombatRoom: (hours: number) => tickNonCombatRoom(get, set, hours, advanceRoomOrFloor),
|
||||
skipNonCombatRoom: () => skipNonCombatRoom(get, set, advanceRoomOrFloor),
|
||||
stayLongerInRoom: () => stayLongerInRoom(get, set),
|
||||
|
||||
// Golemancy
|
||||
|
||||
@@ -7,10 +7,10 @@ import { useDisciplineStore } from './discipline-slice';
|
||||
import { useManaStore } from './manaStore';
|
||||
import { useAttunementStore } from './attunementStore';
|
||||
import { PUZZLE_ROOMS } from '../constants';
|
||||
import { advanceRoomOrFloor } from './combat-descent-actions';
|
||||
|
||||
type GetFn = () => CombatStore;
|
||||
type SetFn = (state: Partial<CombatState>) => void;
|
||||
type AdvanceFn = (get: GetFn, set: SetFn) => void;
|
||||
|
||||
// ─── Room Entry Handlers ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -105,22 +105,22 @@ export function onEnterPuzzleRoom(get: GetFn, set: SetFn): void {
|
||||
|
||||
// ─── Tick Handlers ────────────────────────────────────────────────────────────
|
||||
|
||||
export function tickNonCombatRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
export function tickNonCombatRoom(get: GetFn, set: SetFn, hours: number, advance: AdvanceFn): void {
|
||||
const s = get();
|
||||
const rt = s.currentRoom.roomType as string;
|
||||
|
||||
if (rt === 'library') {
|
||||
tickLibraryRoom(get, set, hours);
|
||||
tickLibraryRoom(get, set, hours, advance);
|
||||
} else if (rt === 'recovery') {
|
||||
tickRecoveryRoom(get, set, hours);
|
||||
tickRecoveryRoom(get, set, hours, advance);
|
||||
} else if (rt === 'treasure') {
|
||||
tickTreasureRoom(get, set, hours);
|
||||
tickTreasureRoom(get, set, hours, advance);
|
||||
} else if (rt === 'puzzle') {
|
||||
tickPuzzleRoom(get, set, hours);
|
||||
tickPuzzleRoom(get, set, hours, advance);
|
||||
}
|
||||
}
|
||||
|
||||
function tickLibraryRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
function tickLibraryRoom(get: GetFn, set: SetFn, hours: number, advance: AdvanceFn): void {
|
||||
const s = get();
|
||||
const room = s.currentRoom;
|
||||
const progress = (room.libraryProgress || 0) + hours;
|
||||
@@ -150,13 +150,13 @@ function tickLibraryRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
|
||||
if (progress >= required) {
|
||||
set({ currentRoom: { ...room, libraryProgress: progress } });
|
||||
advanceRoomOrFloor(get, set);
|
||||
advance(get, set);
|
||||
} else {
|
||||
set({ currentRoom: { ...room, libraryProgress: progress } });
|
||||
}
|
||||
}
|
||||
|
||||
function tickRecoveryRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
function tickRecoveryRoom(get: GetFn, set: SetFn, hours: number, advance: AdvanceFn): void {
|
||||
const s = get();
|
||||
const room = s.currentRoom;
|
||||
const progress = (room.recoveryProgress || 0) + hours;
|
||||
@@ -164,13 +164,13 @@ function tickRecoveryRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
|
||||
if (progress >= required) {
|
||||
set({ currentRoom: { ...room, recoveryProgress: progress } });
|
||||
advanceRoomOrFloor(get, set);
|
||||
advance(get, set);
|
||||
} else {
|
||||
set({ currentRoom: { ...room, recoveryProgress: progress } });
|
||||
}
|
||||
}
|
||||
|
||||
function tickTreasureRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
function tickTreasureRoom(get: GetFn, set: SetFn, hours: number, advance: AdvanceFn): void {
|
||||
const s = get();
|
||||
const room = s.currentRoom;
|
||||
const progress = (room.treasureProgress || 0) + hours;
|
||||
@@ -228,13 +228,13 @@ function tickTreasureRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
|
||||
if (progress >= required) {
|
||||
set({ currentRoom: { ...room, treasureProgress: progress, treasureLootClaimed: Array.from(claimedSet) } });
|
||||
advanceRoomOrFloor(get, set);
|
||||
advance(get, set);
|
||||
} else {
|
||||
set({ currentRoom: { ...room, treasureProgress: progress, treasureLootClaimed: Array.from(claimedSet) } });
|
||||
}
|
||||
}
|
||||
|
||||
function tickPuzzleRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
function tickPuzzleRoom(get: GetFn, set: SetFn, hours: number, advance: AdvanceFn): void {
|
||||
const s = get();
|
||||
const room = s.currentRoom;
|
||||
const progress = (room.puzzleProgress || 0) + hours;
|
||||
@@ -243,7 +243,7 @@ function tickPuzzleRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
if (progress >= required) {
|
||||
set({ currentRoom: { ...room, puzzleProgress: progress } });
|
||||
get().addActivityLog('puzzle_solved', `Puzzle solved on Floor ${s.currentFloor}!`);
|
||||
advanceRoomOrFloor(get, set);
|
||||
advance(get, set);
|
||||
} else {
|
||||
set({ currentRoom: { ...room, puzzleProgress: progress } });
|
||||
}
|
||||
@@ -251,12 +251,12 @@ function tickPuzzleRoom(get: GetFn, set: SetFn, hours: number): void {
|
||||
|
||||
// ─── Player Actions ───────────────────────────────────────────────────────────
|
||||
|
||||
export function skipNonCombatRoom(get: GetFn, set: SetFn): void {
|
||||
export function skipNonCombatRoom(get: GetFn, set: SetFn, advance: AdvanceFn): void {
|
||||
const s = get();
|
||||
const rt = s.currentRoom.roomType as string;
|
||||
if (rt === 'library' || rt === 'recovery' || rt === 'treasure') {
|
||||
get().addActivityLog('floor_transition', `Skipped ${rt} room on Floor ${s.currentFloor}`);
|
||||
advanceRoomOrFloor(get, set);
|
||||
advance(get, set);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user