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> {
|
||||
|
||||
constructor(keyActions?: KeyActions) {
|
||||
constructor(other?: KeyActions) {
|
||||
super();
|
||||
if (!keyActions) {
|
||||
if (!other) {
|
||||
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 {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {assertEnum, assertUInt8} from '../../assert';
|
||||
import {UhkBuffer} from '../../UhkBuffer';
|
||||
import {KeyModifiers} from '../KeyModifiers';
|
||||
import {LongPressAction} from '../LongPressAction';
|
||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
||||
import { assertEnum, assertUInt8 } from '../../assert';
|
||||
import { UhkBuffer } from '../../UhkBuffer';
|
||||
import { KeyModifiers } from '../KeyModifiers';
|
||||
import { LongPressAction } from '../LongPressAction';
|
||||
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||
|
||||
export enum KeystrokeActionFlag {
|
||||
scancode = 1 << 0,
|
||||
@@ -28,6 +28,16 @@ export class KeystrokeAction extends KeyAction {
|
||||
@assertEnum(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 {
|
||||
this.assertKeyActionType(jsObject);
|
||||
this.scancode = jsObject.scancode;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {assertEnum} from '../../assert';
|
||||
import {UhkBuffer} from '../../UhkBuffer';
|
||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
||||
import { assertEnum } from '../../assert';
|
||||
import { UhkBuffer } from '../../UhkBuffer';
|
||||
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||
|
||||
export enum MouseActionParam {
|
||||
leftClick,
|
||||
@@ -23,9 +23,17 @@ export class MouseAction extends KeyAction {
|
||||
@assertEnum(MouseActionParam)
|
||||
mouseAction: MouseActionParam;
|
||||
|
||||
constructor(other?: MouseAction) {
|
||||
super();
|
||||
if (!other) {
|
||||
return;
|
||||
}
|
||||
this.mouseAction = other.mouseAction;
|
||||
}
|
||||
|
||||
_fromJsObject(jsObject: any): MouseAction {
|
||||
this.assertKeyActionType(jsObject);
|
||||
this.mouseAction = MouseActionParam[<string> jsObject.mouseAction];
|
||||
this.mouseAction = MouseActionParam[<string>jsObject.mouseAction];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import {assertUInt8} from '../../assert';
|
||||
import {UhkBuffer} from '../../UhkBuffer';
|
||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
||||
import { assertUInt8 } from '../../assert';
|
||||
import { UhkBuffer } from '../../UhkBuffer';
|
||||
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||
|
||||
export class PlayMacroAction extends KeyAction {
|
||||
|
||||
@assertUInt8
|
||||
macroId: number;
|
||||
|
||||
constructor(other?: PlayMacroAction) {
|
||||
super();
|
||||
if (!other) {
|
||||
return;
|
||||
}
|
||||
this.macroId = other.macroId;
|
||||
}
|
||||
|
||||
_fromJsObject(jsObject: any): PlayMacroAction {
|
||||
this.assertKeyActionType(jsObject);
|
||||
this.macroId = jsObject.macroId;
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import {assertUInt8} from '../../assert';
|
||||
import {UhkBuffer} from '../../UhkBuffer';
|
||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
||||
import { assertUInt8 } from '../../assert';
|
||||
import { UhkBuffer } from '../../UhkBuffer';
|
||||
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||
|
||||
export class SwitchKeymapAction extends KeyAction {
|
||||
|
||||
@assertUInt8
|
||||
keymapId: number;
|
||||
|
||||
constructor(other?: SwitchKeymapAction) {
|
||||
super();
|
||||
if (!other) {
|
||||
return;
|
||||
}
|
||||
this.keymapId = other.keymapId;
|
||||
}
|
||||
|
||||
_fromJsObject(jsObject: any): SwitchKeymapAction {
|
||||
this.assertKeyActionType(jsObject);
|
||||
this.keymapId = jsObject.keymapId;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {assertEnum} from '../../assert';
|
||||
import {UhkBuffer} from '../../UhkBuffer';
|
||||
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
|
||||
import { assertEnum } from '../../assert';
|
||||
import { UhkBuffer } from '../../UhkBuffer';
|
||||
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
|
||||
|
||||
export enum LayerName {
|
||||
mod,
|
||||
@@ -15,9 +15,18 @@ export class SwitchLayerAction extends KeyAction {
|
||||
@assertEnum(LayerName)
|
||||
layer: LayerName;
|
||||
|
||||
constructor(other?: SwitchLayerAction) {
|
||||
super();
|
||||
if (!other) {
|
||||
return;
|
||||
}
|
||||
this.isLayerToggleable = other.isLayerToggleable;
|
||||
this.layer = other.layer;
|
||||
}
|
||||
|
||||
_fromJsObject(jsObject: any): SwitchLayerAction {
|
||||
this.assertKeyActionType(jsObject);
|
||||
this.layer = LayerName[<string> jsObject.layer];
|
||||
this.layer = LayerName[<string>jsObject.layer];
|
||||
this.isLayerToggleable = jsObject.toggle;
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user