diff --git a/src/core/index.ts b/src/core/index.ts index 60856fe..c40ae27 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -3,7 +3,9 @@ import { SoundController } from './audio/sound'; import { EventEmitter } from './common/eventEmitter'; import { loading, readyAllResource } from './loader/load'; import { ResourceStore, ResourceType } from './loader/resource'; +import { UiController } from './main/custom/ui'; import { GameEvent, hook } from './main/game'; +import { fixedUi, mainUi } from './main/init/ui'; import { GameStorage } from './main/storage'; import { resolvePlugin } from './plugin'; @@ -44,6 +46,10 @@ export interface AncTe { hook: EventEmitter; storage: GameStorage[]; }; + ui: { + main: UiController; + fixed: UiController; + }; } function ready() { @@ -57,6 +63,10 @@ function ready() { game: { hook, storage: GameStorage.list + }, + ui: { + main: mainUi, + fixed: fixedUi } }; diff --git a/src/core/main/custom/hotkey.ts b/src/core/main/custom/hotkey.ts index 12ccdd5..408c6c2 100644 --- a/src/core/main/custom/hotkey.ts +++ b/src/core/main/custom/hotkey.ts @@ -31,12 +31,14 @@ type RegisterData = Omit; export class Hotkey extends EventEmitter { keyMap: Map = new Map(); list: Record = {}; - storage: GameStorage>; + storage?: GameStorage>; groups: Record = {}; - constructor(id: string) { + constructor(id: string, storage: boolean = true) { super(); - this.storage = new GameStorage(GameStorage.fromAncTe(id)); + if (storage) { + this.storage = new GameStorage(GameStorage.fromAuthor('AncTe', id)); + } } /** @@ -47,7 +49,7 @@ export class Hotkey extends EventEmitter { const key = { id, name, - key: this.storage.getValue(id, data.defaults), + key: this.storage?.getValue(id, data.defaults) ?? data.defaults, ...data }; this.ensureKey(key.key).push(key); diff --git a/src/core/main/custom/ui.ts b/src/core/main/custom/ui.ts index 02ee36b..73b1cfc 100644 --- a/src/core/main/custom/ui.ts +++ b/src/core/main/custom/ui.ts @@ -185,6 +185,7 @@ export class GameUi extends EventEmitter { export class UiController extends Focus { static list: UiController[] = []; + list: Record = {}; constructor(equal?: boolean) { super(true, equal); @@ -219,7 +220,7 @@ export class UiController extends Focus { * @param id ui的id */ get(id: string) { - return [...this.targets.values()].find(v => v.id === id); + return this.list[id]; } /** @@ -227,8 +228,36 @@ export class UiController extends Focus { * @param id 要关闭的ui的id */ close(id: string) { - const ui = this.stack.find(v => v.id === id); + const ui = this.get(id); if (!ui) return; this.splice(ui); } + + /** + * 打开一个新的ui + * @param id 要打开的ui的id + */ + open(id: string) { + const ui = this.get(id); + if (!ui) return; + this.add(ui); + } + + override register(...item: GameUi[]): this { + super.register(...item); + item.forEach(v => { + this.list[v.id] = v; + }); + + return this; + } + + override unregister(...item: GameUi[]): this { + super.unregister(...item); + item.forEach(v => { + delete this.list[v.id]; + }); + + return this; + } } diff --git a/src/core/main/init/ui.ts b/src/core/main/init/ui.ts index 3df84d7..9a76be2 100644 --- a/src/core/main/init/ui.ts +++ b/src/core/main/init/ui.ts @@ -61,3 +61,5 @@ fixedUi.register( new GameUi('chapter', Chapter), new GameUi('completeAchi', CompleteAchi) ); + +mainUi.focus(mainUi.get('start'), true); diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 8a93a7d..6efcd05 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -403,7 +403,7 @@ interface SettingStorage { } const storage = new GameStorage( - GameStorage.fromAncTe('setting') + GameStorage.fromAuthor('AncTe', 'setting') ); loading.once('coreInit', () => { diff --git a/src/core/main/storage.ts b/src/core/main/storage.ts index c1b0119..227191f 100644 --- a/src/core/main/storage.ts +++ b/src/core/main/storage.ts @@ -55,8 +55,8 @@ export class GameStorage { return `HumanBreak_${key}`; } - static fromAncTe(key: string) { - return `AncTe@${key}`; + static fromAuthor(author: string, key: string) { + return `${author}@${key}`; } }