feat: sequencing
This commit is contained in:
@@ -7,9 +7,10 @@ import {
|
||||
type MissionStep,
|
||||
type RepairMissionId,
|
||||
} from "@/types/gameplay/repairMission";
|
||||
import { type PyloneStep } from "@/types/gameplay/pylone";
|
||||
|
||||
export type MainGameState = "intro" | "bike" | "pylone" | "ferme" | "outro";
|
||||
export type { MissionStep, RepairMissionId };
|
||||
export type { MissionStep, RepairMissionId, PyloneStep };
|
||||
|
||||
interface IntroState {
|
||||
currentStep: GameStep;
|
||||
@@ -38,7 +39,9 @@ interface GameState {
|
||||
bike: MissionState & {
|
||||
isRepaired: boolean;
|
||||
};
|
||||
pylone: MissionState & {
|
||||
pylone: {
|
||||
currentStep: PyloneStep;
|
||||
dialogueAudio: string | null;
|
||||
isPowered: boolean;
|
||||
};
|
||||
ferme: MissionState & {
|
||||
@@ -66,7 +69,6 @@ interface GameActions {
|
||||
setMissionStep: (mission: RepairMissionId, step: MissionStep) => void;
|
||||
completeIntro: () => void;
|
||||
completeBike: () => void;
|
||||
completePylone: () => void;
|
||||
completeFerme: () => void;
|
||||
completeMission: (mission: RepairMissionId) => void;
|
||||
startOutro: () => void;
|
||||
@@ -104,22 +106,7 @@ function completeBikeState(state: GameState): GameStateUpdate {
|
||||
},
|
||||
pylone: {
|
||||
...state.pylone,
|
||||
currentStep: "waiting",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function completePyloneState(state: GameState): GameStateUpdate {
|
||||
return {
|
||||
mainState: "ferme",
|
||||
pylone: {
|
||||
...state.pylone,
|
||||
currentStep: "done",
|
||||
isPowered: true,
|
||||
},
|
||||
ferme: {
|
||||
...state.ferme,
|
||||
currentStep: "waiting",
|
||||
currentStep: "locked",
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -159,13 +146,42 @@ function completeMissionState(
|
||||
switch (mission) {
|
||||
case "bike":
|
||||
return completeBikeState(state);
|
||||
case "pylone":
|
||||
return completePyloneState(state);
|
||||
case "ferme":
|
||||
return completeFermeState(state);
|
||||
}
|
||||
}
|
||||
|
||||
function getNextPyloneStep(step: PyloneStep): PyloneStep {
|
||||
switch (step) {
|
||||
case "locked":
|
||||
return "alert";
|
||||
case "alert":
|
||||
return "searching";
|
||||
case "searching":
|
||||
return "helped";
|
||||
case "helped":
|
||||
return "manipulation";
|
||||
case "manipulation":
|
||||
return "manipulation";
|
||||
}
|
||||
}
|
||||
|
||||
function advancePyloneStep(state: GameState): GameStateUpdate {
|
||||
const nextStep = getNextPyloneStep(state.pylone.currentStep);
|
||||
if (
|
||||
nextStep === "manipulation" &&
|
||||
state.pylone.currentStep === "manipulation"
|
||||
) {
|
||||
return {
|
||||
mainState: "outro",
|
||||
pylone: { ...state.pylone, currentStep: "manipulation" },
|
||||
};
|
||||
}
|
||||
return {
|
||||
pylone: { ...state.pylone, currentStep: nextStep },
|
||||
};
|
||||
}
|
||||
|
||||
function advanceRepairMissionState(
|
||||
state: GameState,
|
||||
mission: RepairMissionId,
|
||||
@@ -273,7 +289,6 @@ export const useGameStore = create<GameStore>()((set) => ({
|
||||
set((state) => setMissionStepState(state, mission, step)),
|
||||
completeIntro: () => set(completeIntroState),
|
||||
completeBike: () => set((state) => completeMissionState(state, "bike")),
|
||||
completePylone: () => set((state) => completeMissionState(state, "pylone")),
|
||||
completeFerme: () => set((state) => completeMissionState(state, "ferme")),
|
||||
completeMission: (mission) =>
|
||||
set((state) => completeMissionState(state, mission)),
|
||||
@@ -281,9 +296,19 @@ export const useGameStore = create<GameStore>()((set) => ({
|
||||
advanceGameState: () =>
|
||||
set((state) => {
|
||||
if (state.mainState === "intro") {
|
||||
if (state.intro.currentStep === "bike") {
|
||||
return {
|
||||
mainState: "bike",
|
||||
intro: { ...state.intro, hasCompleted: true },
|
||||
};
|
||||
}
|
||||
return completeIntroState(state);
|
||||
}
|
||||
|
||||
if (state.mainState === "pylone") {
|
||||
return advancePyloneStep(state);
|
||||
}
|
||||
|
||||
if (isRepairMissionId(state.mainState)) {
|
||||
return advanceRepairMissionState(state, state.mainState);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user