mirror of
https://github.com/FullScreenShenanigans/FullScreenPokemon.git
synced 2026-08-12 02:18:13 -07:00
Used ItemsHoldr with item generics (#609)
* Used ItemsHoldr with item generics * itemsholdr@0.7.6
This commit is contained in:
+2
-1
@@ -13,6 +13,7 @@
|
||||
"changelinr": "^0.7.2",
|
||||
"flagswappr": "^0.7.2",
|
||||
"gamestartr": "^0.7.13",
|
||||
"itemsholdr": "^0.7.6",
|
||||
"menugraphr": "^0.7.4",
|
||||
"stateholdr": "^0.7.3",
|
||||
"stringfilr": "^0.7.2",
|
||||
@@ -144,4 +145,4 @@
|
||||
},
|
||||
"types": "./src/index.d.ts",
|
||||
"version": "0.7.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import { Mods } from "./components/Mods";
|
||||
import { Physics } from "./components/Physics";
|
||||
import { Saves } from "./components/Saves";
|
||||
import { Scrolling } from "./components/Scrolling";
|
||||
import { Storage } from "./components/Storage";
|
||||
import { IStorageItems, Storage } from "./components/Storage";
|
||||
import { IPlayer, IThing, Things } from "./components/Things";
|
||||
import { Utilities } from "./components/Utilities";
|
||||
import { createAreaSpawner } from "./creators/createAreaSpawner";
|
||||
@@ -152,7 +152,7 @@ export class FullScreenPokemon extends GameStartr {
|
||||
* Cache-based wrapper around localStorage.
|
||||
*/
|
||||
@component(createItemsHolder)
|
||||
public readonly itemsHolder: ItemsHoldr;
|
||||
public readonly itemsHolder: ItemsHoldr<IStorageItems>;
|
||||
|
||||
/**
|
||||
* Storage container and lazy loader for GameStartr maps.
|
||||
|
||||
@@ -275,12 +275,12 @@ export class Inputs<TGameStartr extends FullScreenPokemon> extends GeneralCompon
|
||||
|
||||
this.gameStarter.modAttacher.fireEvent(this.gameStarter.mods.eventNames.onKeyDownSelect);
|
||||
|
||||
const selectItem: string = this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.selectItem);
|
||||
const selectItem = this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.selectItem);
|
||||
if (!selectItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
const itemSchema: IItemSchema = this.gameStarter.constants.items.byName[selectItem];
|
||||
const itemSchema: IItemSchema = this.gameStarter.constants.items.byName[selectItem.join("")];
|
||||
if (!itemSchema.bagActivate) {
|
||||
throw new Error("Currently selected item does not have a .bagActivate.");
|
||||
}
|
||||
|
||||
+17
-15
@@ -1,9 +1,9 @@
|
||||
import { GeneralComponent } from "gamestartr";
|
||||
import { IExportedItems } from "itemsholdr";
|
||||
|
||||
import { FullScreenPokemon } from "../FullScreenPokemon";
|
||||
import { PokedexListingStatus } from "./Constants";
|
||||
import { IPokedex, IPokedexInformation, IPokemonListing } from "./constants/Pokemon";
|
||||
import { IStorageItems } from "./Storage";
|
||||
import { ICharacter } from "./Things";
|
||||
|
||||
/**
|
||||
@@ -39,17 +39,17 @@ export class Saves<TGameStartr extends FullScreenPokemon> extends GeneralCompone
|
||||
* upon a new game being started.
|
||||
*/
|
||||
public clearSavedData(): void {
|
||||
const oldLocalStorage: IExportedItems = this.gameStarter.itemsHolder.exportItems();
|
||||
const oldLocalStorage: IStorageItems & { [i: string]: any } = this.gameStarter.itemsHolder.exportItems();
|
||||
|
||||
const collectionKeys: string[] = this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.stateCollectionKeys);
|
||||
if (collectionKeys) {
|
||||
for (const collection of collectionKeys) {
|
||||
oldLocalStorage[collection] = this.gameStarter.itemsHolder.getItem(collection);
|
||||
oldLocalStorage[collection] = this.gameStarter.itemsHolder.getItem(collection as keyof IStorageItems);
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of Object.keys(oldLocalStorage)) {
|
||||
this.gameStarter.itemsHolder.removeItem(key);
|
||||
this.gameStarter.itemsHolder.removeItem(key as keyof IStorageItems);
|
||||
}
|
||||
|
||||
this.gameStarter.itemsHolder.clear();
|
||||
@@ -68,18 +68,20 @@ export class Saves<TGameStartr extends FullScreenPokemon> extends GeneralCompone
|
||||
return;
|
||||
}
|
||||
|
||||
const oldLocalStorage: IExportedItems = this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.oldLocalStorage);
|
||||
for (const key in oldLocalStorage) {
|
||||
if (!oldLocalStorage.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
const oldLocalStorage = this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.oldLocalStorage);
|
||||
if (oldLocalStorage !== undefined) {
|
||||
for (const key in oldLocalStorage) {
|
||||
if (!oldLocalStorage.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const prefix = this.gameStarter.stateHolder.getPrefix();
|
||||
const prefix = this.gameStarter.stateHolder.getPrefix();
|
||||
|
||||
if (key.slice(0, prefix.length) === prefix) {
|
||||
this.gameStarter.stateHolder.setCollection(key.slice(prefix.length), oldLocalStorage[key]);
|
||||
} else {
|
||||
this.gameStarter.itemsHolder.setItem(key, oldLocalStorage[key]);
|
||||
if (key.slice(0, prefix.length) === prefix) {
|
||||
this.gameStarter.stateHolder.setCollection(key.slice(prefix.length), oldLocalStorage[key as keyof IStorageItems]);
|
||||
} else {
|
||||
this.gameStarter.itemsHolder.setItem(key as keyof IStorageItems, oldLocalStorage[key as keyof IStorageItems]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +175,7 @@ export class Saves<TGameStartr extends FullScreenPokemon> extends GeneralCompone
|
||||
const split: string[] = key.split("::");
|
||||
this.gameStarter.stateHolder.setCollection(split[1] + "::" + split[2], data[key]);
|
||||
} else {
|
||||
this.gameStarter.itemsHolder.setItem(key, data[key]);
|
||||
this.gameStarter.itemsHolder.setItem(key as keyof IStorageItems, data[key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,46 @@
|
||||
import { component } from "babyioc";
|
||||
import { GeneralComponent } from "gamestartr";
|
||||
|
||||
import { component } from "babyioc";
|
||||
import { FullScreenPokemon } from "../FullScreenPokemon";
|
||||
import { IPokemon } from "./Battles";
|
||||
import { IPokedex, IPokedexListing } from "./constants/Pokemon";
|
||||
import { IInventoryListing } from "./menus/Items";
|
||||
import { ItemNames } from "./storage/ItemNames";
|
||||
|
||||
export interface ILastPokecenter {
|
||||
location: string | undefined;
|
||||
map: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Items to be held in storage.
|
||||
*/
|
||||
export interface IStorageItems {
|
||||
area: string;
|
||||
autoSave: boolean;
|
||||
badges: {
|
||||
[i: string]: boolean;
|
||||
};
|
||||
gameStarted: boolean;
|
||||
hasPokedex: boolean;
|
||||
items: IInventoryListing[];
|
||||
lastPokecenter: ILastPokecenter;
|
||||
location: string | undefined;
|
||||
map: string;
|
||||
money: number;
|
||||
name: string[];
|
||||
nameRival: string[];
|
||||
oldLocalStorage?: IStorageItems;
|
||||
pokedex: IPokedex;
|
||||
pokemonInParty: IPokemon[];
|
||||
pokemonInPC: IPokemon[];
|
||||
selectItem: string[] | undefined;
|
||||
stateCollectionKeys: string[];
|
||||
starter: string[];
|
||||
starterRival: string[];
|
||||
time: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings for storing items in ItemsHoldrs.
|
||||
*/
|
||||
|
||||
@@ -56,8 +56,9 @@ export class Ending<TGameStartr extends FullScreenPokemon> extends GeneralCompon
|
||||
queue.run((): void => this.finalize(battleInfo, outcome, onBattleComplete));
|
||||
|
||||
if (this.gameStarter.battles.isPartyWiped()) {
|
||||
const { map, location } = this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.lastPokecenter);
|
||||
this.gameStarter.battles.healParty();
|
||||
this.gameStarter.maps.setMap(this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.lastPokecenter));
|
||||
this.gameStarter.maps.setMap(map, location);
|
||||
this.gameStarter.mapScreener.blockInputs = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export class Pause<TGameStartr extends FullScreenPokemon> extends GeneralCompone
|
||||
},
|
||||
];
|
||||
|
||||
if (this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.hasPokedex) === true) {
|
||||
if (this.gameStarter.itemsHolder.getItem(this.gameStarter.storage.names.hasPokedex)) {
|
||||
options.unshift({
|
||||
text: "%%%%%%%POKEDEX%%%%%%%",
|
||||
callback: this.open,
|
||||
|
||||
@@ -84,7 +84,7 @@ export class ItemNames<TGameStartr extends FullScreenPokemon> extends GeneralCom
|
||||
/**
|
||||
* Pokemon in the player's PC storage.
|
||||
*/
|
||||
public readonly pokemonInPC = "pokemonInPc";
|
||||
public readonly pokemonInPC = "pokemonInPC";
|
||||
|
||||
/**
|
||||
* Item name the player has listed under select.
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
MenuGraphr,
|
||||
} from "menugraphr";
|
||||
|
||||
import { IPokedexInformation, IPokedexListing } from "../components/constants/Pokemon";
|
||||
import { IPokedex, IPokedexInformation, IPokedexListing } from "../components/constants/Pokemon";
|
||||
import { IDialog, IMenuBase, IMenuSchema } from "../components/Menus";
|
||||
import { FullScreenPokemon } from "../FullScreenPokemon";
|
||||
|
||||
@@ -66,16 +66,14 @@ export const createMenuGrapher = (fsp: FullScreenPokemon): MenuGraphr =>
|
||||
return total.toString().split("");
|
||||
},
|
||||
"POKEDEX.LENGTH": (): string[] => {
|
||||
const pokedex: IPokedexListing[] = fsp.itemsHolder.getItem(fsp.storage.names.pokedex);
|
||||
if (!pokedex || !pokedex.length) {
|
||||
const pokedex: IPokedex = fsp.itemsHolder.getItem(fsp.storage.names.pokedex);
|
||||
if (!pokedex) {
|
||||
return ["0"];
|
||||
}
|
||||
|
||||
return pokedex
|
||||
.map((listing: IPokedexListing): number =>
|
||||
Number(listing.seen))
|
||||
.reduce((a: number, b: number): number =>
|
||||
a + b)
|
||||
return Object.keys(pokedex)
|
||||
.map((listing): number => Number(pokedex[listing].seen))
|
||||
.reduce((a: number, b: number): number => a + b)
|
||||
.toString()
|
||||
.split("");
|
||||
},
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { IItemsHoldr } from "itemsholdr";
|
||||
import { ModAttachr } from "modattachr";
|
||||
|
||||
import { FullScreenPokemon } from "../FullScreenPokemon";
|
||||
|
||||
export const createModAttacher = (fsp: FullScreenPokemon): ModAttachr =>
|
||||
new ModAttachr({
|
||||
itemsHolder: fsp.itemsHolder,
|
||||
itemsHolder: fsp.itemsHolder as IItemsHoldr,
|
||||
transformModName: (name: string): string => `Mods::${name}`,
|
||||
mods: fsp.mods.mods,
|
||||
});
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { IItemsHoldr } from "itemsholdr";
|
||||
import { StateHoldr } from "stateholdr";
|
||||
|
||||
import { FullScreenPokemon } from "../FullScreenPokemon";
|
||||
|
||||
export const createStateHolder = (fsp: FullScreenPokemon): StateHoldr =>
|
||||
new StateHoldr({
|
||||
itemsHolder: fsp.itemsHolder,
|
||||
itemsHolder: fsp.itemsHolder as IItemsHoldr,
|
||||
prefix: "StateHolder::",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user