feat: 根据存储键获取存储实例

This commit is contained in:
unanmed 2023-09-29 17:48:05 +08:00
parent 5338a5d6de
commit 02e2934b9a
2 changed files with 16 additions and 2 deletions

View File

@ -44,7 +44,7 @@ export interface Mota {
plugin: AncTePlugin; plugin: AncTePlugin;
game: { game: {
hook: EventEmitter<GameEvent>; hook: EventEmitter<GameEvent>;
storage: GameStorage<any>[]; storage: typeof GameStorage;
}; };
ui: { ui: {
main: UiController; main: UiController;
@ -62,7 +62,7 @@ function ready() {
plugin: {}, plugin: {},
game: { game: {
hook, hook,
storage: GameStorage.list storage: GameStorage
}, },
ui: { ui: {
main: mainUi, main: mainUi,

View File

@ -55,9 +55,23 @@ export class GameStorage<T> {
return `HumanBreak_${key}`; return `HumanBreak_${key}`;
} }
/**
*
* @param author
* @param key
*/
static fromAuthor(author: string, key: string) { static fromAuthor(author: string, key: string) {
return `${author}@${key}`; return `${author}@${key}`;
} }
/**
*
* @param key
* @example Storage.get(Storage.fromAuthor('AncTe', 'setting'));
*/
static get(key: string) {
return this.list.find(v => v.key === key);
}
} }
window.addEventListener('unload', () => { window.addEventListener('unload', () => {