From 1697d673f2e3e5e1db0ebfd62f907c7f0eefbf01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Fri, 1 Apr 2016 03:43:34 +0200 Subject: [PATCH] Use the members of the newly added KeyActionType object because static members were uninitialized. Handle PlayMacroAction in the KeyActionFactory. --- .../config-items/DualRoleKeystrokeAction.ts | 11 +++++------ config-serializer/config-items/KeyAction.ts | 11 +++++++++++ .../config-items/KeyActionFactory.ts | 18 +++++++++++------- .../config-items/KeystrokeAction.ts | 8 +++----- config-serializer/config-items/MouseAction.ts | 12 +++++------- config-serializer/config-items/NoneAction.ts | 5 ++--- .../config-items/PlayMacroAction.ts | 6 ++---- .../config-items/SwitchKeymapAction.ts | 6 ++---- .../config-items/SwitchLayerAction.ts | 7 +++---- config-serializer/serializeConfig.ts | 2 +- 10 files changed, 45 insertions(+), 41 deletions(-) diff --git a/config-serializer/config-items/DualRoleKeystrokeAction.ts b/config-serializer/config-items/DualRoleKeystrokeAction.ts index 43c397be..5579785f 100644 --- a/config-serializer/config-items/DualRoleKeystrokeAction.ts +++ b/config-serializer/config-items/DualRoleKeystrokeAction.ts @@ -13,7 +13,6 @@ enum LongPressAction { } class DualRoleKeystrokeAction extends KeyAction implements Serializable { - static keyActionTypeString = 'dualRoleKeystroke'; public scancode; @@ -24,18 +23,18 @@ class DualRoleKeystrokeAction extends KeyAction implements Serializable { abstract fromJsObject(jsObject: any): KeyAction; abstract fromBinary(buffer: UhkBuffer): KeyAction; diff --git a/config-serializer/config-items/KeyActionFactory.ts b/config-serializer/config-items/KeyActionFactory.ts index 3c536cc8..2461f36f 100644 --- a/config-serializer/config-items/KeyActionFactory.ts +++ b/config-serializer/config-items/KeyActionFactory.ts @@ -2,20 +2,22 @@ class KeyActionFactory { static fromJsObject(jsObject: any): KeyAction { switch (jsObject.keyActionType) { - case NoneAction.keyActionTypeString: + case KeyActionType.NoneAction: return new NoneAction().fromJsObject(jsObject); - case KeystrokeAction.keyActionTypeString: + case KeyActionType.KeystrokeAction: return new KeystrokeAction().fromJsObject(jsObject); - case KeystrokeWithModifiersAction.keyActionTypeString: + case KeyActionType.KeystrokeWithModifiersAction: return new KeystrokeWithModifiersAction().fromJsObject(jsObject); - case DualRoleKeystrokeAction.keyActionTypeString: + case KeyActionType.DualRoleKeystrokeAction: return new DualRoleKeystrokeAction().fromJsObject(jsObject); - case SwitchLayerAction.keyActionTypeString: + case KeyActionType.SwitchLayerAction: return new SwitchLayerAction().fromJsObject(jsObject); - case SwitchKeymapAction.keyActionTypeString: + case KeyActionType.SwitchKeymapAction: return new SwitchKeymapAction().fromJsObject(jsObject); - case MouseAction.keyActionTypeString: + case KeyActionType.MouseAction: return new MouseAction().fromJsObject(jsObject); + case KeyActionType.PlayMacroAction: + return new PlayMacroAction().fromJsObject(jsObject); default: throw `Invalid KeyAction.keyActionType: "${jsObject.actionType}"`; } @@ -40,6 +42,8 @@ class KeyActionFactory { return new SwitchKeymapAction().fromBinary(buffer); case KeyActionId.MouseAction: return new MouseAction().fromBinary(buffer); + case KeyActionId.PlayMacroAction: + return new PlayMacroAction().fromBinary(buffer); default: throw `Invalid KeyAction first byte: ${keyActionFirstByte}`; } diff --git a/config-serializer/config-items/KeystrokeAction.ts b/config-serializer/config-items/KeystrokeAction.ts index ff94de37..d529d239 100644 --- a/config-serializer/config-items/KeystrokeAction.ts +++ b/config-serializer/config-items/KeystrokeAction.ts @@ -1,7 +1,5 @@ class KeystrokeAction extends KeyAction implements Serializable { - static keyActionTypeString = 'keystroke'; - private _scancode: number; get scancode(): number { @@ -16,7 +14,7 @@ class KeystrokeAction extends KeyAction implements Serializable } fromJsObject(jsObject: any): KeystrokeAction { - this.assertKeyActionType(jsObject, KeystrokeAction.keyActionTypeString, 'KeystrokeAction'); + this.assertKeyActionType(jsObject, KeyActionType.KeystrokeAction, 'KeystrokeAction'); this.scancode = jsObject.scancode; return this; } @@ -29,8 +27,8 @@ class KeystrokeAction extends KeyAction implements Serializable toJsObject(): any { return { - keyActionType: KeystrokeAction.keyActionTypeString, - scancode: this.scancode, + keyActionType: KeyActionType.KeystrokeAction, + scancode: this.scancode }; } diff --git a/config-serializer/config-items/MouseAction.ts b/config-serializer/config-items/MouseAction.ts index a8adf982..7689d410 100644 --- a/config-serializer/config-items/MouseAction.ts +++ b/config-serializer/config-items/MouseAction.ts @@ -15,8 +15,6 @@ enum MouseActionParam { } class MouseAction extends KeyAction implements Serializable { - static keyActionTypeString = 'mouse'; - private _mouseAction: MouseActionParam; get mouseAction(): number { @@ -24,18 +22,18 @@ class MouseAction extends KeyAction implements Serializable { } set mouseAction(mouseAction) { - if (!MouseAction.isMouseActionValid(mouseAction)) { + if (!this.isMouseActionValid(mouseAction)) { throw `Invalid MouseAction.mouseAction: ${mouseAction}`; } this._mouseAction = mouseAction; } - static isMouseActionValid(keyActionParam): boolean { + isMouseActionValid(keyActionParam): boolean { return MouseActionParam[keyActionParam] !== undefined; } fromJsObject(jsObject: any): MouseAction { - this.assertKeyActionType(jsObject, MouseAction.keyActionTypeString, 'MouseAction'); + this.assertKeyActionType(jsObject, KeyActionType.MouseAction, 'MouseAction'); this.mouseAction = jsObject.mouseAction; return this; } @@ -44,7 +42,7 @@ class MouseAction extends KeyAction implements Serializable { this.readAndAssertKeyActionId(buffer, KeyActionId.MouseAction, 'MouseAction'); this.mouseAction = buffer.readUInt8(); - if (!MouseAction.isMouseActionValid(this.mouseAction)) { + if (!this.isMouseActionValid(this.mouseAction)) { throw `Invalid MouseAction.param: ${this.mouseAction}`; } @@ -53,7 +51,7 @@ class MouseAction extends KeyAction implements Serializable { toJsObject(): any { return { - keyActionType: MouseAction.keyActionTypeString, + keyActionType: KeyActionType.MouseAction, mouseAction: MouseActionParam[this.mouseAction] }; } diff --git a/config-serializer/config-items/NoneAction.ts b/config-serializer/config-items/NoneAction.ts index ee74b151..be862806 100644 --- a/config-serializer/config-items/NoneAction.ts +++ b/config-serializer/config-items/NoneAction.ts @@ -1,10 +1,9 @@ class NoneAction extends KeyAction implements Serializable { - static keyActionTypeString = 'none'; static noneActionParam = 0; fromJsObject(jsObject: any): NoneAction { - this.assertKeyActionType(jsObject, NoneAction.keyActionTypeString, 'NoneAction'); + this.assertKeyActionType(jsObject, KeyActionType.NoneAction, 'NoneAction'); return this; } @@ -21,7 +20,7 @@ class NoneAction extends KeyAction implements Serializable { toJsObject(): any { return { - keyActionType: NoneAction.keyActionTypeString + keyActionType: KeyActionId.NoneAction }; } diff --git a/config-serializer/config-items/PlayMacroAction.ts b/config-serializer/config-items/PlayMacroAction.ts index 5b3206c2..292eed56 100644 --- a/config-serializer/config-items/PlayMacroAction.ts +++ b/config-serializer/config-items/PlayMacroAction.ts @@ -1,7 +1,5 @@ class PlayMacroAction extends KeyAction implements Serializable { - static keyActionTypeString = 'playMacro'; - private _macroId: number; get macroId(): number { @@ -16,7 +14,7 @@ class PlayMacroAction extends KeyAction implements Serializable } fromJsObject(jsObject: any): PlayMacroAction { - this.assertKeyActionType(jsObject, PlayMacroAction.keyActionTypeString, 'PlayMacroAction'); + this.assertKeyActionType(jsObject, KeyActionType.PlayMacroAction, 'PlayMacroAction'); this.macroId = jsObject.macroId; return this; } @@ -29,7 +27,7 @@ class PlayMacroAction extends KeyAction implements Serializable toJsObject(): any { return { - keyActionType: PlayMacroAction.keyActionTypeString, + keyActionType: KeyActionType.PlayMacroAction, macroId: this.macroId }; } diff --git a/config-serializer/config-items/SwitchKeymapAction.ts b/config-serializer/config-items/SwitchKeymapAction.ts index bce92189..91cf6a02 100644 --- a/config-serializer/config-items/SwitchKeymapAction.ts +++ b/config-serializer/config-items/SwitchKeymapAction.ts @@ -1,7 +1,5 @@ class SwitchKeymapAction extends KeyAction implements Serializable { - static keyActionTypeString = 'switchKeymap'; - private _keymapId: number; get keymapId(): number { @@ -16,7 +14,7 @@ class SwitchKeymapAction extends KeyAction implements Serializable { - static keyActionTypeString = 'switchLayer'; static toggleFlag = 0x80; isLayerToggleable: boolean; @@ -30,8 +29,8 @@ class SwitchLayerAction extends KeyAction implements Serializable