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