Add assertion decorations for various numeric types.
This commit is contained in:
@@ -14,24 +14,11 @@ enum LongPressAction {
|
||||
|
||||
class DualRoleKeystrokeAction extends KeyAction {
|
||||
|
||||
public scancode;
|
||||
@assertUInt8
|
||||
scancode: number;
|
||||
|
||||
private _longPressAction: LongPressAction;
|
||||
|
||||
get longPressAction(): number {
|
||||
return this._longPressAction;
|
||||
}
|
||||
|
||||
set longPressAction(value) {
|
||||
if (!this.isDualRoleKeystrokeActionValid(value)) {
|
||||
throw `Invalid DualRoleKeystrokeAction.longPressAction: ${value}`;
|
||||
}
|
||||
this._longPressAction = value;
|
||||
}
|
||||
|
||||
isDualRoleKeystrokeActionValid(keyActionIdParam): boolean {
|
||||
return LongPressAction[keyActionIdParam] !== undefined;
|
||||
}
|
||||
@assertEnum(LongPressAction)
|
||||
private longPressAction: LongPressAction;
|
||||
|
||||
_fromJsObject(jsObject: any): DualRoleKeystrokeAction {
|
||||
this.assertKeyActionType(jsObject, KeyActionType.DualRoleKeystrokeAction, 'DualRoleKeystrokeAction');
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
class KeystrokeAction extends KeyAction {
|
||||
|
||||
private _scancode: number;
|
||||
|
||||
get scancode(): number {
|
||||
return this._scancode;
|
||||
}
|
||||
|
||||
set scancode(value) {
|
||||
this._scancode = value;
|
||||
}
|
||||
@assertUInt8
|
||||
scancode: number;
|
||||
|
||||
_fromJsObject(jsObject: any): KeystrokeAction {
|
||||
this.assertKeyActionType(jsObject, KeyActionType.KeystrokeAction, 'KeystrokeAction');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class KeystrokeModifiersAction extends KeyAction {
|
||||
|
||||
@assertUInt8
|
||||
modifierMask: number;
|
||||
|
||||
_fromJsObject(jsObject: any): KeystrokeModifiersAction {
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
class KeystrokeWithModifiersAction extends KeyAction {
|
||||
|
||||
@assertUInt8
|
||||
modifierMask: number;
|
||||
|
||||
private _scancode: number;
|
||||
|
||||
get scancode(): number {
|
||||
return this._scancode;
|
||||
}
|
||||
|
||||
set scancode(value) {
|
||||
this._scancode = value;
|
||||
}
|
||||
@assertUInt8
|
||||
scancode: number;
|
||||
|
||||
_fromJsObject(jsObject: any): KeystrokeWithModifiersAction {
|
||||
this.assertKeyActionType(
|
||||
|
||||
@@ -15,22 +15,9 @@ enum MouseActionParam {
|
||||
}
|
||||
|
||||
class MouseAction extends KeyAction {
|
||||
private _mouseAction: MouseActionParam;
|
||||
|
||||
get mouseAction(): MouseActionParam {
|
||||
return this._mouseAction;
|
||||
}
|
||||
|
||||
set mouseAction(mouseAction) {
|
||||
// if (!this.isMouseActionValid(mouseAction)) {
|
||||
// throw `Invalid MouseAction.mouseAction: ${mouseAction}`;
|
||||
// }
|
||||
this._mouseAction = mouseAction;
|
||||
}
|
||||
|
||||
// isMouseActionValid(keyActionParam): boolean {
|
||||
// return MouseActionParam[<string>keyActionParam] !== undefined;
|
||||
// }
|
||||
@assertUInt8
|
||||
mouseAction: MouseActionParam;
|
||||
|
||||
_fromJsObject(jsObject: any): MouseAction {
|
||||
this.assertKeyActionType(jsObject, KeyActionType.MouseAction, 'MouseAction');
|
||||
@@ -40,12 +27,7 @@ class MouseAction extends KeyAction {
|
||||
|
||||
_fromBinary(buffer: UhkBuffer): MouseAction {
|
||||
this.readAndAssertKeyActionId(buffer, KeyActionId.MouseAction, 'MouseAction');
|
||||
|
||||
this.mouseAction = buffer.readUInt8();
|
||||
// if (!this.isMouseActionValid(this.mouseAction)) {
|
||||
// throw `Invalid MouseAction.param: ${this.mouseAction}`;
|
||||
// }
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
class PlayMacroAction extends KeyAction {
|
||||
|
||||
private _macroId: number;
|
||||
|
||||
get macroId(): number {
|
||||
return this._macroId;
|
||||
}
|
||||
|
||||
set macroId(value) {
|
||||
this._macroId = value;
|
||||
}
|
||||
@assertUInt8
|
||||
macroId: number;
|
||||
|
||||
_fromJsObject(jsObject: any): PlayMacroAction {
|
||||
this.assertKeyActionType(jsObject, KeyActionType.PlayMacroAction, 'PlayMacroAction');
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
class SwitchKeymapAction extends KeyAction {
|
||||
|
||||
private _keymapId: number;
|
||||
|
||||
get keymapId(): number {
|
||||
return this._keymapId;
|
||||
}
|
||||
|
||||
set keymapId(value) {
|
||||
this._keymapId = value;
|
||||
}
|
||||
@assertUInt8
|
||||
keymapId: number;
|
||||
|
||||
_fromJsObject(jsObject: any): SwitchKeymapAction {
|
||||
this.assertKeyActionType(jsObject, KeyActionType.SwitchKeymapAction, 'SwitchKeymapAction');
|
||||
|
||||
@@ -12,18 +12,7 @@ class SwitchLayerAction extends KeyAction {
|
||||
|
||||
@assertEnum(Layer)
|
||||
private layer: Layer;
|
||||
/*
|
||||
get layer(): number {
|
||||
return this._layer;
|
||||
}
|
||||
|
||||
set layer(value) {
|
||||
if (!TypeChecker.isUInt8Valid(value)) {
|
||||
throw 'Invalid SwitchLayerAction.layerId: ${value}';
|
||||
}
|
||||
this._layer = value;
|
||||
}
|
||||
*/
|
||||
getToggleFlag() {
|
||||
return this.isLayerToggleable ? SwitchLayerAction.toggleFlag : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user