feat: auto keyMap
This commit is contained in:
parent
45630998e1
commit
3d45055640
|
@ -14,6 +14,12 @@ export default class ActionRegistry extends decorate(Class) {
|
|||
this._actionIds = {};
|
||||
this._stream = [];
|
||||
this._actionTransformers = {};
|
||||
const entries = Object.entries(this.constructor.keyMap);
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const [action, key] = entries[i];
|
||||
this.keyActions[key] = action;
|
||||
this.actionKeys[action] = key;
|
||||
}
|
||||
}
|
||||
|
||||
actionForKey(key) {
|
||||
|
@ -40,13 +46,8 @@ export default class ActionRegistry extends decorate(Class) {
|
|||
return this.actionKeys[action];
|
||||
}
|
||||
|
||||
mapKeysToActions(map) {
|
||||
const entries = Object.entries(map);
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const [action, key] = entries[i];
|
||||
this.keyActions[key] = action;
|
||||
this.actionKeys[action] = key;
|
||||
}
|
||||
static setKeyMap(keyMap) {
|
||||
this.keyMap = keyMap;
|
||||
}
|
||||
|
||||
onKeyDown(key) {
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
import D from 'debug';
|
||||
|
||||
import ActionRegistry from './action-registry';
|
||||
import InputPacket from './packets/input';
|
||||
|
||||
export {default as ActionRegistry} from './action-registry';
|
||||
export {default as InputNormalizer} from './normalizer';
|
||||
export {InputPacket};
|
||||
export {ActionRegistry, InputPacket};
|
||||
|
||||
const debug = D('@avocado/input');
|
||||
|
||||
export default {
|
||||
hooks: {
|
||||
'@latus/core/config': () => ({
|
||||
keyMap: {},
|
||||
}),
|
||||
'@latus/core/starting': (latus) => {
|
||||
const {keyMap} = latus.get('@avocado/input');
|
||||
const ids = Object.fromEntries(Object.keys(keyMap).map((action, i) => [action, i]));
|
||||
debug('got key map: %O, generated IDs: %O', keyMap, ids);
|
||||
InputPacket.setActionIds(ids);
|
||||
ActionRegistry.setKeyMap(keyMap);
|
||||
},
|
||||
'@latus/socket/packets': () => ({
|
||||
Input: InputPacket,
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue
Block a user