Use the members of the newly added KeyActionType object because static members were uninitialized. Handle PlayMacroAction in the KeyActionFactory.
This commit is contained in:
@@ -13,7 +13,6 @@ enum LongPressAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DualRoleKeystrokeAction extends KeyAction implements Serializable<DualRoleKeystrokeAction> {
|
class DualRoleKeystrokeAction extends KeyAction implements Serializable<DualRoleKeystrokeAction> {
|
||||||
static keyActionTypeString = 'dualRoleKeystroke';
|
|
||||||
|
|
||||||
public scancode;
|
public scancode;
|
||||||
|
|
||||||
@@ -24,18 +23,18 @@ class DualRoleKeystrokeAction extends KeyAction implements Serializable<DualRole
|
|||||||
}
|
}
|
||||||
|
|
||||||
set longPressAction(value) {
|
set longPressAction(value) {
|
||||||
if (!DualRoleKeystrokeAction.isDualRoleKeystrokeActionValid(value)) {
|
if (!this.isDualRoleKeystrokeActionValid(value)) {
|
||||||
throw `Invalid DualRoleKeystrokeAction.longPressAction: ${value}`;
|
throw `Invalid DualRoleKeystrokeAction.longPressAction: ${value}`;
|
||||||
}
|
}
|
||||||
this._longPressAction = value;
|
this._longPressAction = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static isDualRoleKeystrokeActionValid(keyActionIdParam): boolean {
|
isDualRoleKeystrokeActionValid(keyActionIdParam): boolean {
|
||||||
return MouseActionParam[keyActionIdParam] !== undefined;
|
return LongPressAction[keyActionIdParam] !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): DualRoleKeystrokeAction {
|
fromJsObject(jsObject: any): DualRoleKeystrokeAction {
|
||||||
this.assertKeyActionType(jsObject, DualRoleKeystrokeAction.keyActionTypeString, 'DualRoleKeystrokeAction');
|
this.assertKeyActionType(jsObject, KeyActionType.DualRoleKeystrokeAction, 'DualRoleKeystrokeAction');
|
||||||
this.scancode = jsObject.scancode;
|
this.scancode = jsObject.scancode;
|
||||||
this.longPressAction = jsObject.longPressAction;
|
this.longPressAction = jsObject.longPressAction;
|
||||||
return this;
|
return this;
|
||||||
@@ -50,7 +49,7 @@ class DualRoleKeystrokeAction extends KeyAction implements Serializable<DualRole
|
|||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: DualRoleKeystrokeAction.keyActionTypeString,
|
keyActionType: KeyActionType.DualRoleKeystrokeAction,
|
||||||
scancode: this.scancode,
|
scancode: this.scancode,
|
||||||
longPressAction: KeyActionId[this.longPressAction]
|
longPressAction: KeyActionId[this.longPressAction]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,17 @@ enum KeyActionId {
|
|||||||
PlayMacroAction = 7
|
PlayMacroAction = 7
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let KeyActionType = {
|
||||||
|
NoneAction : 'none',
|
||||||
|
KeystrokeAction : 'keystroke',
|
||||||
|
KeystrokeWithModifiersAction : 'keystrokeWithModifiers',
|
||||||
|
DualRoleKeystrokeAction : 'dualRoleKeystroke',
|
||||||
|
SwitchLayerAction : 'switchLayer',
|
||||||
|
SwitchKeymapAction : 'switchKeymap',
|
||||||
|
MouseAction : 'mouse',
|
||||||
|
PlayMacroAction : 'playMacro'
|
||||||
|
}
|
||||||
|
|
||||||
abstract class KeyAction implements Serializable<KeyAction> {
|
abstract class KeyAction implements Serializable<KeyAction> {
|
||||||
abstract fromJsObject(jsObject: any): KeyAction;
|
abstract fromJsObject(jsObject: any): KeyAction;
|
||||||
abstract fromBinary(buffer: UhkBuffer): KeyAction;
|
abstract fromBinary(buffer: UhkBuffer): KeyAction;
|
||||||
|
|||||||
@@ -2,20 +2,22 @@ class KeyActionFactory {
|
|||||||
|
|
||||||
static fromJsObject(jsObject: any): KeyAction {
|
static fromJsObject(jsObject: any): KeyAction {
|
||||||
switch (jsObject.keyActionType) {
|
switch (jsObject.keyActionType) {
|
||||||
case NoneAction.keyActionTypeString:
|
case KeyActionType.NoneAction:
|
||||||
return new NoneAction().fromJsObject(jsObject);
|
return new NoneAction().fromJsObject(jsObject);
|
||||||
case KeystrokeAction.keyActionTypeString:
|
case KeyActionType.KeystrokeAction:
|
||||||
return new KeystrokeAction().fromJsObject(jsObject);
|
return new KeystrokeAction().fromJsObject(jsObject);
|
||||||
case KeystrokeWithModifiersAction.keyActionTypeString:
|
case KeyActionType.KeystrokeWithModifiersAction:
|
||||||
return new KeystrokeWithModifiersAction().fromJsObject(jsObject);
|
return new KeystrokeWithModifiersAction().fromJsObject(jsObject);
|
||||||
case DualRoleKeystrokeAction.keyActionTypeString:
|
case KeyActionType.DualRoleKeystrokeAction:
|
||||||
return new DualRoleKeystrokeAction().fromJsObject(jsObject);
|
return new DualRoleKeystrokeAction().fromJsObject(jsObject);
|
||||||
case SwitchLayerAction.keyActionTypeString:
|
case KeyActionType.SwitchLayerAction:
|
||||||
return new SwitchLayerAction().fromJsObject(jsObject);
|
return new SwitchLayerAction().fromJsObject(jsObject);
|
||||||
case SwitchKeymapAction.keyActionTypeString:
|
case KeyActionType.SwitchKeymapAction:
|
||||||
return new SwitchKeymapAction().fromJsObject(jsObject);
|
return new SwitchKeymapAction().fromJsObject(jsObject);
|
||||||
case MouseAction.keyActionTypeString:
|
case KeyActionType.MouseAction:
|
||||||
return new MouseAction().fromJsObject(jsObject);
|
return new MouseAction().fromJsObject(jsObject);
|
||||||
|
case KeyActionType.PlayMacroAction:
|
||||||
|
return new PlayMacroAction().fromJsObject(jsObject);
|
||||||
default:
|
default:
|
||||||
throw `Invalid KeyAction.keyActionType: "${jsObject.actionType}"`;
|
throw `Invalid KeyAction.keyActionType: "${jsObject.actionType}"`;
|
||||||
}
|
}
|
||||||
@@ -40,6 +42,8 @@ class KeyActionFactory {
|
|||||||
return new SwitchKeymapAction().fromBinary(buffer);
|
return new SwitchKeymapAction().fromBinary(buffer);
|
||||||
case KeyActionId.MouseAction:
|
case KeyActionId.MouseAction:
|
||||||
return new MouseAction().fromBinary(buffer);
|
return new MouseAction().fromBinary(buffer);
|
||||||
|
case KeyActionId.PlayMacroAction:
|
||||||
|
return new PlayMacroAction().fromBinary(buffer);
|
||||||
default:
|
default:
|
||||||
throw `Invalid KeyAction first byte: ${keyActionFirstByte}`;
|
throw `Invalid KeyAction first byte: ${keyActionFirstByte}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction> {
|
class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction> {
|
||||||
|
|
||||||
static keyActionTypeString = 'keystroke';
|
|
||||||
|
|
||||||
private _scancode: number;
|
private _scancode: number;
|
||||||
|
|
||||||
get scancode(): number {
|
get scancode(): number {
|
||||||
@@ -16,7 +14,7 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): KeystrokeAction {
|
fromJsObject(jsObject: any): KeystrokeAction {
|
||||||
this.assertKeyActionType(jsObject, KeystrokeAction.keyActionTypeString, 'KeystrokeAction');
|
this.assertKeyActionType(jsObject, KeyActionType.KeystrokeAction, 'KeystrokeAction');
|
||||||
this.scancode = jsObject.scancode;
|
this.scancode = jsObject.scancode;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -29,8 +27,8 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
|
|||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: KeystrokeAction.keyActionTypeString,
|
keyActionType: KeyActionType.KeystrokeAction,
|
||||||
scancode: this.scancode,
|
scancode: this.scancode
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ enum MouseActionParam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
||||||
static keyActionTypeString = 'mouse';
|
|
||||||
|
|
||||||
private _mouseAction: MouseActionParam;
|
private _mouseAction: MouseActionParam;
|
||||||
|
|
||||||
get mouseAction(): number {
|
get mouseAction(): number {
|
||||||
@@ -24,18 +22,18 @@ class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set mouseAction(mouseAction) {
|
set mouseAction(mouseAction) {
|
||||||
if (!MouseAction.isMouseActionValid(mouseAction)) {
|
if (!this.isMouseActionValid(mouseAction)) {
|
||||||
throw `Invalid MouseAction.mouseAction: ${mouseAction}`;
|
throw `Invalid MouseAction.mouseAction: ${mouseAction}`;
|
||||||
}
|
}
|
||||||
this._mouseAction = mouseAction;
|
this._mouseAction = mouseAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
static isMouseActionValid(keyActionParam): boolean {
|
isMouseActionValid(keyActionParam): boolean {
|
||||||
return MouseActionParam[keyActionParam] !== undefined;
|
return MouseActionParam[keyActionParam] !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): MouseAction {
|
fromJsObject(jsObject: any): MouseAction {
|
||||||
this.assertKeyActionType(jsObject, MouseAction.keyActionTypeString, 'MouseAction');
|
this.assertKeyActionType(jsObject, KeyActionType.MouseAction, 'MouseAction');
|
||||||
this.mouseAction = jsObject.mouseAction;
|
this.mouseAction = jsObject.mouseAction;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -44,7 +42,7 @@ class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
|||||||
this.readAndAssertKeyActionId(buffer, KeyActionId.MouseAction, 'MouseAction');
|
this.readAndAssertKeyActionId(buffer, KeyActionId.MouseAction, 'MouseAction');
|
||||||
|
|
||||||
this.mouseAction = buffer.readUInt8();
|
this.mouseAction = buffer.readUInt8();
|
||||||
if (!MouseAction.isMouseActionValid(this.mouseAction)) {
|
if (!this.isMouseActionValid(this.mouseAction)) {
|
||||||
throw `Invalid MouseAction.param: ${this.mouseAction}`;
|
throw `Invalid MouseAction.param: ${this.mouseAction}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +51,7 @@ class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
|||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: MouseAction.keyActionTypeString,
|
keyActionType: KeyActionType.MouseAction,
|
||||||
mouseAction: MouseActionParam[this.mouseAction]
|
mouseAction: MouseActionParam[this.mouseAction]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
||||||
|
|
||||||
static keyActionTypeString = 'none';
|
|
||||||
static noneActionParam = 0;
|
static noneActionParam = 0;
|
||||||
|
|
||||||
fromJsObject(jsObject: any): NoneAction {
|
fromJsObject(jsObject: any): NoneAction {
|
||||||
this.assertKeyActionType(jsObject, NoneAction.keyActionTypeString, 'NoneAction');
|
this.assertKeyActionType(jsObject, KeyActionType.NoneAction, 'NoneAction');
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
|||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: NoneAction.keyActionTypeString
|
keyActionType: KeyActionId.NoneAction
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class PlayMacroAction extends KeyAction implements Serializable<PlayMacroAction> {
|
class PlayMacroAction extends KeyAction implements Serializable<PlayMacroAction> {
|
||||||
|
|
||||||
static keyActionTypeString = 'playMacro';
|
|
||||||
|
|
||||||
private _macroId: number;
|
private _macroId: number;
|
||||||
|
|
||||||
get macroId(): number {
|
get macroId(): number {
|
||||||
@@ -16,7 +14,7 @@ class PlayMacroAction extends KeyAction implements Serializable<PlayMacroAction>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): PlayMacroAction {
|
fromJsObject(jsObject: any): PlayMacroAction {
|
||||||
this.assertKeyActionType(jsObject, PlayMacroAction.keyActionTypeString, 'PlayMacroAction');
|
this.assertKeyActionType(jsObject, KeyActionType.PlayMacroAction, 'PlayMacroAction');
|
||||||
this.macroId = jsObject.macroId;
|
this.macroId = jsObject.macroId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -29,7 +27,7 @@ class PlayMacroAction extends KeyAction implements Serializable<PlayMacroAction>
|
|||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: PlayMacroAction.keyActionTypeString,
|
keyActionType: KeyActionType.PlayMacroAction,
|
||||||
macroId: this.macroId
|
macroId: this.macroId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapAction> {
|
class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapAction> {
|
||||||
|
|
||||||
static keyActionTypeString = 'switchKeymap';
|
|
||||||
|
|
||||||
private _keymapId: number;
|
private _keymapId: number;
|
||||||
|
|
||||||
get keymapId(): number {
|
get keymapId(): number {
|
||||||
@@ -16,7 +14,7 @@ class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapA
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): SwitchKeymapAction {
|
fromJsObject(jsObject: any): SwitchKeymapAction {
|
||||||
this.assertKeyActionType(jsObject, SwitchKeymapAction.keyActionTypeString, 'SwitchKeymapAction');
|
this.assertKeyActionType(jsObject, KeyActionType.SwitchKeymapAction, 'SwitchKeymapAction');
|
||||||
this.keymapId = jsObject.keymapId;
|
this.keymapId = jsObject.keymapId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -29,7 +27,7 @@ class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapA
|
|||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: SwitchKeymapAction.keyActionTypeString,
|
keyActionType: KeyActionType.SwitchKeymapAction,
|
||||||
keymapId: this.keymapId
|
keymapId: this.keymapId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ enum Layer {
|
|||||||
|
|
||||||
class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAction> {
|
class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAction> {
|
||||||
|
|
||||||
static keyActionTypeString = 'switchLayer';
|
|
||||||
static toggleFlag = 0x80;
|
static toggleFlag = 0x80;
|
||||||
|
|
||||||
isLayerToggleable: boolean;
|
isLayerToggleable: boolean;
|
||||||
@@ -30,8 +29,8 @@ class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAct
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): SwitchLayerAction {
|
fromJsObject(jsObject: any): SwitchLayerAction {
|
||||||
this.assertKeyActionType(jsObject, SwitchLayerAction.keyActionTypeString, 'SwitchLayerAction');
|
this.assertKeyActionType(jsObject, KeyActionType.SwitchLayerAction, 'SwitchLayerAction');
|
||||||
this.layer = jsObject.layerId;
|
this.layer = jsObject.layer;
|
||||||
this.isLayerToggleable = jsObject.toggle;
|
this.isLayerToggleable = jsObject.toggle;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -46,7 +45,7 @@ class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAct
|
|||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: SwitchLayerAction.keyActionTypeString,
|
keyActionType: KeyActionType.SwitchLayerAction,
|
||||||
layer: this.layer,
|
layer: this.layer,
|
||||||
toggle: this.isLayerToggleable
|
toggle: this.isLayerToggleable
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ let writer = new UhkBuffer();
|
|||||||
|
|
||||||
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
||||||
let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
||||||
|
console.log(keyActions);
|
||||||
let keyActionObjects: KeyActions = new KeyActions().fromJsObject(keyActions);
|
let keyActionObjects: KeyActions = new KeyActions().fromJsObject(keyActions);
|
||||||
|
|
||||||
fs.writeFileSync('uhk-config.bin', writer.buffer);
|
fs.writeFileSync('uhk-config.bin', writer.buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user