Add copy constructors for key actions
This commit is contained in:
@@ -10,12 +10,28 @@ import { SwitchLayerAction } from './SwitchLayerAction';
|
|||||||
|
|
||||||
export class KeyActions extends ClassArray<KeyAction> {
|
export class KeyActions extends ClassArray<KeyAction> {
|
||||||
|
|
||||||
constructor(keyActions?: KeyActions) {
|
constructor(other?: KeyActions) {
|
||||||
super();
|
super();
|
||||||
if (!keyActions) {
|
if (!other) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keyActions.elements.forEach(keyaction => this.elements.push(this.jsObjectToClass(keyaction)));
|
other.elements.forEach(keyAction => {
|
||||||
|
let newKeyAction: KeyAction;
|
||||||
|
if (keyAction instanceof KeystrokeAction) {
|
||||||
|
newKeyAction = new KeystrokeAction(keyAction);
|
||||||
|
} else if (keyAction instanceof SwitchLayerAction) {
|
||||||
|
newKeyAction = new SwitchLayerAction(keyAction);
|
||||||
|
} else if (keyAction instanceof SwitchKeymapAction) {
|
||||||
|
newKeyAction = new SwitchKeymapAction(keyAction);
|
||||||
|
} else if (keyAction instanceof MouseAction) {
|
||||||
|
newKeyAction = new MouseAction(keyAction);
|
||||||
|
} else if (keyAction instanceof PlayMacroAction) {
|
||||||
|
newKeyAction = new PlayMacroAction(keyAction);
|
||||||
|
} else {
|
||||||
|
newKeyAction = new NoneAction();
|
||||||
|
}
|
||||||
|
this.elements.push(newKeyAction);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
jsObjectToClass(jsObject: any): KeyAction {
|
jsObjectToClass(jsObject: any): KeyAction {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {assertEnum, assertUInt8} from '../../assert';
|
import { assertEnum, assertUInt8 } from '../../assert';
|
||||||
import {UhkBuffer} from '../../UhkBuffer';
|
import { UhkBuffer } from '../../UhkBuffer';
|
||||||
import {KeyModifiers} from '../KeyModifiers';
|
import { KeyModifiers } from '../KeyModifiers';
|
||||||
import {LongPressAction} from '../LongPressAction';
|
import { LongPressAction } from '../LongPressAction';
|
||||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||||
|
|
||||||
export enum KeystrokeActionFlag {
|
export enum KeystrokeActionFlag {
|
||||||
scancode = 1 << 0,
|
scancode = 1 << 0,
|
||||||
@@ -28,6 +28,16 @@ export class KeystrokeAction extends KeyAction {
|
|||||||
@assertEnum(LongPressAction)
|
@assertEnum(LongPressAction)
|
||||||
longPressAction: LongPressAction;
|
longPressAction: LongPressAction;
|
||||||
|
|
||||||
|
constructor(other?: KeystrokeAction) {
|
||||||
|
super();
|
||||||
|
if (!other) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.scancode = other.scancode;
|
||||||
|
this.modifierMask = other.modifierMask;
|
||||||
|
this.longPressAction = other.longPressAction;
|
||||||
|
}
|
||||||
|
|
||||||
_fromJsObject(jsObject: JsObjectKeystrokeAction): KeystrokeAction {
|
_fromJsObject(jsObject: JsObjectKeystrokeAction): KeystrokeAction {
|
||||||
this.assertKeyActionType(jsObject);
|
this.assertKeyActionType(jsObject);
|
||||||
this.scancode = jsObject.scancode;
|
this.scancode = jsObject.scancode;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {assertEnum} from '../../assert';
|
import { assertEnum } from '../../assert';
|
||||||
import {UhkBuffer} from '../../UhkBuffer';
|
import { UhkBuffer } from '../../UhkBuffer';
|
||||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||||
|
|
||||||
export enum MouseActionParam {
|
export enum MouseActionParam {
|
||||||
leftClick,
|
leftClick,
|
||||||
@@ -23,9 +23,17 @@ export class MouseAction extends KeyAction {
|
|||||||
@assertEnum(MouseActionParam)
|
@assertEnum(MouseActionParam)
|
||||||
mouseAction: MouseActionParam;
|
mouseAction: MouseActionParam;
|
||||||
|
|
||||||
|
constructor(other?: MouseAction) {
|
||||||
|
super();
|
||||||
|
if (!other) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.mouseAction = other.mouseAction;
|
||||||
|
}
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): MouseAction {
|
_fromJsObject(jsObject: any): MouseAction {
|
||||||
this.assertKeyActionType(jsObject);
|
this.assertKeyActionType(jsObject);
|
||||||
this.mouseAction = MouseActionParam[<string> jsObject.mouseAction];
|
this.mouseAction = MouseActionParam[<string>jsObject.mouseAction];
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
import {assertUInt8} from '../../assert';
|
import { assertUInt8 } from '../../assert';
|
||||||
import {UhkBuffer} from '../../UhkBuffer';
|
import { UhkBuffer } from '../../UhkBuffer';
|
||||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||||
|
|
||||||
export class PlayMacroAction extends KeyAction {
|
export class PlayMacroAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
@assertUInt8
|
||||||
macroId: number;
|
macroId: number;
|
||||||
|
|
||||||
|
constructor(other?: PlayMacroAction) {
|
||||||
|
super();
|
||||||
|
if (!other) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.macroId = other.macroId;
|
||||||
|
}
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): PlayMacroAction {
|
_fromJsObject(jsObject: any): PlayMacroAction {
|
||||||
this.assertKeyActionType(jsObject);
|
this.assertKeyActionType(jsObject);
|
||||||
this.macroId = jsObject.macroId;
|
this.macroId = jsObject.macroId;
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
import {assertUInt8} from '../../assert';
|
import { assertUInt8 } from '../../assert';
|
||||||
import {UhkBuffer} from '../../UhkBuffer';
|
import { UhkBuffer } from '../../UhkBuffer';
|
||||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||||
|
|
||||||
export class SwitchKeymapAction extends KeyAction {
|
export class SwitchKeymapAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
@assertUInt8
|
||||||
keymapId: number;
|
keymapId: number;
|
||||||
|
|
||||||
|
constructor(other?: SwitchKeymapAction) {
|
||||||
|
super();
|
||||||
|
if (!other) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.keymapId = other.keymapId;
|
||||||
|
}
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): SwitchKeymapAction {
|
_fromJsObject(jsObject: any): SwitchKeymapAction {
|
||||||
this.assertKeyActionType(jsObject);
|
this.assertKeyActionType(jsObject);
|
||||||
this.keymapId = jsObject.keymapId;
|
this.keymapId = jsObject.keymapId;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {assertEnum} from '../../assert';
|
import { assertEnum } from '../../assert';
|
||||||
import {UhkBuffer} from '../../UhkBuffer';
|
import { UhkBuffer } from '../../UhkBuffer';
|
||||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||||
|
|
||||||
export enum LayerName {
|
export enum LayerName {
|
||||||
mod,
|
mod,
|
||||||
@@ -15,9 +15,18 @@ export class SwitchLayerAction extends KeyAction {
|
|||||||
@assertEnum(LayerName)
|
@assertEnum(LayerName)
|
||||||
layer: LayerName;
|
layer: LayerName;
|
||||||
|
|
||||||
|
constructor(other?: SwitchLayerAction) {
|
||||||
|
super();
|
||||||
|
if (!other) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.isLayerToggleable = other.isLayerToggleable;
|
||||||
|
this.layer = other.layer;
|
||||||
|
}
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): SwitchLayerAction {
|
_fromJsObject(jsObject: any): SwitchLayerAction {
|
||||||
this.assertKeyActionType(jsObject);
|
this.assertKeyActionType(jsObject);
|
||||||
this.layer = LayerName[<string> jsObject.layer];
|
this.layer = LayerName[<string>jsObject.layer];
|
||||||
this.isLayerToggleable = jsObject.toggle;
|
this.isLayerToggleable = jsObject.toggle;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user