Use KeyActionId values wherever possible. Add some further value checks. Assign this.mouseAction properly.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
enum LongPressActionId {
|
||||
leftCtrl = 233,
|
||||
leftCtrl = 236, // KeyActionId.DualRoleActionLeftCtrl
|
||||
leftShift,
|
||||
leftAlt,
|
||||
leftSuper,
|
||||
|
||||
@@ -45,9 +45,9 @@ class KeyAction {
|
||||
|
||||
if (TypeChecker.isScancodeValid(keyActionFirstByte)) {
|
||||
return new KeystrokeAction().fromBinary(buffer);
|
||||
} else if (keyActionFirstByte === MouseAction.keyActionId) {
|
||||
} else if (keyActionFirstByte === KeyActionId.MouseAction) {
|
||||
return new MouseAction().fromBinary(buffer);
|
||||
} else if (keyActionFirstByte === NoneAction.keyActionId) {
|
||||
} else if (keyActionFirstByte === KeyActionId.NoneAction) {
|
||||
return new NoneAction().fromBinary(buffer);
|
||||
} else {
|
||||
throw 'Invalid KeyAction first byte "${keyActionFirstByte}"';
|
||||
|
||||
@@ -16,7 +16,6 @@ enum MouseActionParam {
|
||||
|
||||
class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
||||
static keyActionTypeString = 'mouse';
|
||||
static keyActionId = 244;
|
||||
|
||||
private _mouseAction: MouseActionParam;
|
||||
|
||||
@@ -42,12 +41,12 @@ class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
||||
|
||||
fromBinary(buffer: UhkBuffer): MouseAction {
|
||||
let keyActionId = buffer.readUInt8();
|
||||
if (keyActionId !== MouseAction.keyActionId) {
|
||||
if (keyActionId !== KeyActionId.MouseAction) {
|
||||
throw 'Invalid MouseAction.id: ${keyActionId}';
|
||||
}
|
||||
|
||||
let keyActionParam = buffer.readUInt8();
|
||||
if (!MouseAction.isMouseActionValid(keyActionParam)) {
|
||||
this.mouseAction = buffer.readUInt8();
|
||||
if (!MouseAction.isMouseActionValid(this.mouseAction)) {
|
||||
throw 'Invalid MouseAction.param: ${keyActionParam}';
|
||||
}
|
||||
|
||||
@@ -62,7 +61,7 @@ class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
||||
}
|
||||
|
||||
toBinary(buffer: UhkBuffer) {
|
||||
buffer.writeUInt8(MouseAction.keyActionId);
|
||||
buffer.writeUInt8(KeyActionId.MouseAction);
|
||||
buffer.writeUInt8(this.mouseAction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
||||
|
||||
static keyActionTypeString = 'none';
|
||||
static keyActionId = 0;
|
||||
static keyActionNoneParam = 0;
|
||||
static noneActionParam = 0;
|
||||
|
||||
fromJsObject(jsObject: any): NoneAction {
|
||||
if (jsObject.keyActionType !== NoneAction.keyActionTypeString) {
|
||||
throw 'Invalid KeyActionNone.keyActionType: "${jsObject.keyActionType}"';
|
||||
throw 'Invalid NoneAction.keyActionType: "${jsObject.keyActionType}"';
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
fromBinary(buffer: UhkBuffer): NoneAction {
|
||||
let keyActionId = buffer.readUInt8();
|
||||
if (keyActionId !== NoneAction.keyActionId) {
|
||||
throw 'Invalid KeyActionNone.id: ${keyActionId}';
|
||||
if (keyActionId !== KeyActionId.NoneAction) {
|
||||
throw 'Invalid NoneAction.id: ${keyActionId}';
|
||||
}
|
||||
|
||||
let keyActionParam = buffer.readUInt8();
|
||||
if (keyActionParam !== NoneAction.keyActionNoneParam) {
|
||||
throw 'Invalid KeyActionNone.param: ${keyActionParam}';
|
||||
if (keyActionParam !== NoneAction.noneActionParam) {
|
||||
throw 'Invalid NoneAction.param: ${keyActionParam}';
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -32,7 +31,7 @@ class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
||||
}
|
||||
|
||||
toBinary(buffer: UhkBuffer) {
|
||||
buffer.writeUInt8(NoneAction.keyActionId);
|
||||
buffer.writeUInt8(NoneAction.keyActionNoneParam);
|
||||
buffer.writeUInt8(KeyActionId.NoneAction);
|
||||
buffer.writeUInt8(NoneAction.noneActionParam);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class PlayMacroAction extends KeyAction implements Serializable<PlayMacroAction> {
|
||||
|
||||
static keyActionTypeString = 'playMacro';
|
||||
static keyActionId = 245;
|
||||
|
||||
private _macroId: number;
|
||||
|
||||
@@ -17,11 +16,20 @@ class PlayMacroAction extends KeyAction implements Serializable<PlayMacroAction>
|
||||
}
|
||||
|
||||
fromJsObject(jsObject: any): PlayMacroAction {
|
||||
if (jsObject.keyActionType !== PlayMacroAction.keyActionTypeString) {
|
||||
throw 'Invalid PlayMacroAction.keyActionType: "${jsObject.keyActionType}"';
|
||||
}
|
||||
|
||||
this.macroId = jsObject.macroId;
|
||||
return this;
|
||||
}
|
||||
|
||||
fromBinary(buffer: UhkBuffer): PlayMacroAction {
|
||||
let keyActionId = buffer.readUInt8();
|
||||
if (keyActionId !== KeyActionId.PlayMacroAction) {
|
||||
throw 'Invalid PlayMacroAction.keyActionId: ${keyActionId}';
|
||||
}
|
||||
|
||||
this.macroId = buffer.readUInt8();
|
||||
return this;
|
||||
}
|
||||
@@ -34,7 +42,7 @@ class PlayMacroAction extends KeyAction implements Serializable<PlayMacroAction>
|
||||
}
|
||||
|
||||
toBinary(buffer: UhkBuffer) {
|
||||
buffer.writeUInt8(PlayMacroAction.keyActionId);
|
||||
buffer.writeUInt8(KeyActionId.PlayMacroAction);
|
||||
buffer.writeUInt8(this.macroId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapAction> {
|
||||
|
||||
static keyActionTypeString = 'switchKeymap';
|
||||
static keyActionId = 246;
|
||||
|
||||
private _keymapId: number;
|
||||
|
||||
@@ -34,7 +33,7 @@ class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapA
|
||||
}
|
||||
|
||||
toBinary(buffer: UhkBuffer) {
|
||||
buffer.writeUInt8(SwitchKeymapAction.keyActionId);
|
||||
buffer.writeUInt8(KeyActionId.SwitchKeymapAction);
|
||||
buffer.writeUInt8(this.keymapId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user