From 3581d156212bad16d3a8b95863249e824ebed857 Mon Sep 17 00:00:00 2001 From: sup39 Date: Mon, 7 Nov 2022 20:52:22 +0900 Subject: [PATCH] add separated steps for reload (for study purpose) --- src/core/SimulationState.ts | 26 +++++++++++++++++--------- src/core/command/Commands.ts | 19 ++++++++++++++++++- src/core/command/Parser.ts | 10 ++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/core/SimulationState.ts b/src/core/SimulationState.ts index 98d7adc..10e4d12 100644 --- a/src/core/SimulationState.ts +++ b/src/core/SimulationState.ts @@ -5,6 +5,8 @@ import { GameData } from "./GameData"; import { Slots } from "./Slots"; import { VisibleInventory } from "./VisibleInventory"; +export type EReloadStep = 1|2|3; + export const createSimulationState = (): SimulationState => { return new SimulationState( new GameData(new Slots([])), @@ -78,30 +80,36 @@ export class SimulationState { } } - public reload(name?: string) { + public reload(name?: string, step?: EReloadStep) { if(name){ if(name in this.namedSaves){ - this.reloadFrom(this.namedSaves[name]); + this.reloadFrom(this.namedSaves[name], step); } }else{ if(this.nextReloadName){ if(this.nextReloadName in this.namedSaves){ - this.reloadFrom(this.namedSaves[this.nextReloadName]); + this.reloadFrom(this.namedSaves[this.nextReloadName], step); } }else{ const save = this.manualSave; if(save){ - this.reloadFrom(save); + this.reloadFrom(save, step); } } } } - private reloadFrom(data: GameData) { - this.gameData = data.deepClone(); - this.pouch.clearForReload(); - this.gameData.addAllToPouchOnReload(this.pouch); - this.pouch.updateEquipmentDurability(this.gameData); + private reloadFrom(data: GameData, step?: EReloadStep) { + if (step == null || step === 1) { + this.gameData = data.deepClone(); + this.pouch.clearForReload(); + } + if (step == null || step === 2) { + this.gameData.addAllToPouchOnReload(this.pouch); + } + if (step == null || step === 3) { + this.pouch.updateEquipmentDurability(this.gameData); + } this.isOnEventide = false; } diff --git a/src/core/command/Commands.ts b/src/core/command/Commands.ts index 56cffff..14c0f04 100644 --- a/src/core/command/Commands.ts +++ b/src/core/command/Commands.ts @@ -1,5 +1,5 @@ import { Item } from "data/item"; -import { SimulationState } from "../SimulationState"; +import { SimulationState, EReloadStep } from "../SimulationState"; import { joinItemStackString, processWrappers } from "./helper"; import { ItemStackCommandWrapper } from "./ItemStackCommandWrapper"; import { CommandImpl } from "./type"; @@ -59,6 +59,23 @@ export class CommandReload extends CommandImpl { } } +export class CommandReloadStep extends CommandImpl { + static stepLabels = { + 1: "[Step 1] Clear Visible Inventory", + 2: "[Step 2] Add All Items in GameData to Visible Inventory", + 3: "[Step 3] Update Equipment Durability", + }; + constructor(private step: EReloadStep, private name?: string){ + super(); + } + public execute(state: SimulationState): void { + state.reload(this.name, this.step); + } + public getDisplayString(): string { + return `Reload${this.name?` ${this.name}`:""} ${CommandReloadStep.stepLabels[this.step]}`; + } +} + export class CommandUse extends CommandImpl{ private name: string; constructor(name: string){ diff --git a/src/core/command/Parser.ts b/src/core/command/Parser.ts index 86a3440..cab6cf8 100644 --- a/src/core/command/Parser.ts +++ b/src/core/command/Parser.ts @@ -12,6 +12,7 @@ import { CommandInitialize, CommandNop, CommandReload, + CommandReloadStep, CommandRemove, CommandSave, CommandSaveAs, @@ -263,6 +264,15 @@ const parseSimpleCommands = (tokens: string[]): Command | undefined => { if(tokens.length===2 && keywordMatch(tokens[0],"reload")){ return new CommandReload(tokens[1]); } + for (const step of [1, 2, 3] as const) { + const kw = "reload"+step; + if(tokens.length===1 && keywordMatch(tokens[0],kw)){ + return new CommandReloadStep(step); + } + if(tokens.length===2 && keywordMatch(tokens[0],kw)){ + return new CommandReloadStep(step, tokens[1]); + } + } // break if (tokens.length > 2 && keywordMatch(tokens[0],"break") && keywordMatch(tokens[2],"slots") ){ const slots = parseInt(tokens[1]);