1
0
Fork 0

add separated steps for reload (for study purpose)

This commit is contained in:
sup39 2022-11-07 20:52:22 +09:00
parent 964994eef9
commit 3581d15621
3 changed files with 45 additions and 10 deletions

View file

@ -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;
}

View file

@ -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){

View file

@ -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]);