mirror of
https://github.com/motajs/template.git
synced 2026-11-10 04:24:30 +08:00
refactor: 按键系统
This commit is contained in:
1 parent
d5b2a820d8
commit
564f53d82a
15 files changed
+569
-419
No files matched your search
@@ -6,17 +6,20 @@ import {
|
||||
IClientPluginDefine
|
||||
} from '@user/client-modules';
|
||||
import { ICoreStateCoreConfig } from '@user/data-state';
|
||||
import {
|
||||
DEBUG_DIVIDER,
|
||||
DEBUG_VARIATOR,
|
||||
DIVIDER_DEBUG_DIVIDER,
|
||||
VARIATOR_DEBUG_SPEED
|
||||
} from '../constant';
|
||||
import { ExcitationVariator } from '@motajs/animate';
|
||||
import { SaveCompression } from '@user/data-common';
|
||||
import { IClientHotkeySave } from '@user/client-base';
|
||||
import {
|
||||
DEBUG_VARIATOR,
|
||||
VARIATOR_DEBUG_SPEED,
|
||||
DEBUG_DIVIDER,
|
||||
DIVIDER_DEBUG_DIVIDER
|
||||
} from './constant';
|
||||
|
||||
export class MainClientPlugin implements IClientPluginDefine {
|
||||
id: string = 'main-client-plugin';
|
||||
clientDeps: readonly string[] = [];
|
||||
dataDeps: readonly string[] = [];
|
||||
|
||||
awake(state: IClientCore): void {
|
||||
// 渲染调试配置
|
||||
@@ -50,5 +53,12 @@ export class MainClientPlugin implements IClientPluginDefine {
|
||||
|
||||
// 存档初始化
|
||||
state.save.init(`@game/${core.name}`);
|
||||
|
||||
// 按键不是跟随存档的,而是跟随游戏的,所以不进 state 的 addSaveableContent,而是单独调用 global
|
||||
const hotkey =
|
||||
await state.save.getGlobal<IClientHotkeySave>('@system/hotkey');
|
||||
if (hotkey) {
|
||||
state.hotkey.loadState(hotkey, SaveCompression.NoCompression);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { KeyCode } from '@motajs/system';
|
||||
import { IClientCore } from '@user/client-modules';
|
||||
|
||||
export function initializeHotkey(state: IClientCore) {
|
||||
const hotkey = state.hotkey;
|
||||
const system = hotkey.system;
|
||||
|
||||
//#region 通用按键
|
||||
|
||||
hotkey.setGroup('@system/common', [
|
||||
system.addCommand('ok', {
|
||||
priority: 0,
|
||||
defaults: [[KeyCode.Enter], [KeyCode.Space], [KeyCode.KeyC]]
|
||||
}),
|
||||
system.addCommand('exit', {
|
||||
priority: 0,
|
||||
defaults: [[KeyCode.Escape], [KeyCode.KeyX]]
|
||||
})
|
||||
]);
|
||||
|
||||
//#endregion
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user