add separated steps for reload (for study purpose)
This commit is contained in:
parent
964994eef9
commit
3581d15621
3 changed files with 45 additions and 10 deletions
|
@ -5,6 +5,8 @@ import { GameData } from "./GameData";
|
||||||
import { Slots } from "./Slots";
|
import { Slots } from "./Slots";
|
||||||
import { VisibleInventory } from "./VisibleInventory";
|
import { VisibleInventory } from "./VisibleInventory";
|
||||||
|
|
||||||
|
export type EReloadStep = 1|2|3;
|
||||||
|
|
||||||
export const createSimulationState = (): SimulationState => {
|
export const createSimulationState = (): SimulationState => {
|
||||||
return new SimulationState(
|
return new SimulationState(
|
||||||
new GameData(new Slots([])),
|
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){
|
||||||
if(name in this.namedSaves){
|
if(name in this.namedSaves){
|
||||||
this.reloadFrom(this.namedSaves[name]);
|
this.reloadFrom(this.namedSaves[name], step);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(this.nextReloadName){
|
if(this.nextReloadName){
|
||||||
if(this.nextReloadName in this.namedSaves){
|
if(this.nextReloadName in this.namedSaves){
|
||||||
this.reloadFrom(this.namedSaves[this.nextReloadName]);
|
this.reloadFrom(this.namedSaves[this.nextReloadName], step);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
const save = this.manualSave;
|
const save = this.manualSave;
|
||||||
if(save){
|
if(save){
|
||||||
this.reloadFrom(save);
|
this.reloadFrom(save, step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private reloadFrom(data: GameData) {
|
private reloadFrom(data: GameData, step?: EReloadStep) {
|
||||||
this.gameData = data.deepClone();
|
if (step == null || step === 1) {
|
||||||
this.pouch.clearForReload();
|
this.gameData = data.deepClone();
|
||||||
this.gameData.addAllToPouchOnReload(this.pouch);
|
this.pouch.clearForReload();
|
||||||
this.pouch.updateEquipmentDurability(this.gameData);
|
}
|
||||||
|
if (step == null || step === 2) {
|
||||||
|
this.gameData.addAllToPouchOnReload(this.pouch);
|
||||||
|
}
|
||||||
|
if (step == null || step === 3) {
|
||||||
|
this.pouch.updateEquipmentDurability(this.gameData);
|
||||||
|
}
|
||||||
this.isOnEventide = false;
|
this.isOnEventide = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Item } from "data/item";
|
import { Item } from "data/item";
|
||||||
import { SimulationState } from "../SimulationState";
|
import { SimulationState, EReloadStep } from "../SimulationState";
|
||||||
import { joinItemStackString, processWrappers } from "./helper";
|
import { joinItemStackString, processWrappers } from "./helper";
|
||||||
import { ItemStackCommandWrapper } from "./ItemStackCommandWrapper";
|
import { ItemStackCommandWrapper } from "./ItemStackCommandWrapper";
|
||||||
import { CommandImpl } from "./type";
|
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{
|
export class CommandUse extends CommandImpl{
|
||||||
private name: string;
|
private name: string;
|
||||||
constructor(name: string){
|
constructor(name: string){
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
CommandInitialize,
|
CommandInitialize,
|
||||||
CommandNop,
|
CommandNop,
|
||||||
CommandReload,
|
CommandReload,
|
||||||
|
CommandReloadStep,
|
||||||
CommandRemove,
|
CommandRemove,
|
||||||
CommandSave,
|
CommandSave,
|
||||||
CommandSaveAs,
|
CommandSaveAs,
|
||||||
|
@ -263,6 +264,15 @@ const parseSimpleCommands = (tokens: string[]): Command | undefined => {
|
||||||
if(tokens.length===2 && keywordMatch(tokens[0],"reload")){
|
if(tokens.length===2 && keywordMatch(tokens[0],"reload")){
|
||||||
return new CommandReload(tokens[1]);
|
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
|
// break
|
||||||
if (tokens.length > 2 && keywordMatch(tokens[0],"break") && keywordMatch(tokens[2],"slots") ){
|
if (tokens.length > 2 && keywordMatch(tokens[0],"break") && keywordMatch(tokens[2],"slots") ){
|
||||||
const slots = parseInt(tokens[1]);
|
const slots = parseInt(tokens[1]);
|
||||||
|
|
Reference in a new issue