diff --git a/src/config-serializer/config-items/key-action/KeyActions.ts b/src/config-serializer/config-items/key-action/KeyActions.ts index 1bbcfa74..e11f4075 100644 --- a/src/config-serializer/config-items/key-action/KeyActions.ts +++ b/src/config-serializer/config-items/key-action/KeyActions.ts @@ -10,12 +10,28 @@ import { SwitchLayerAction } from './SwitchLayerAction'; export class KeyActions extends ClassArray { - 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 { diff --git a/src/config-serializer/config-items/key-action/KeystrokeAction.ts b/src/config-serializer/config-items/key-action/KeystrokeAction.ts index 9ad171b5..a59fd890 100644 --- a/src/config-serializer/config-items/key-action/KeystrokeAction.ts +++ b/src/config-serializer/config-items/key-action/KeystrokeAction.ts @@ -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; diff --git a/src/config-serializer/config-items/key-action/MouseAction.ts b/src/config-serializer/config-items/key-action/MouseAction.ts index 9b802d2e..3e9e76dd 100644 --- a/src/config-serializer/config-items/key-action/MouseAction.ts +++ b/src/config-serializer/config-items/key-action/MouseAction.ts @@ -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[ jsObject.mouseAction]; + this.mouseAction = MouseActionParam[jsObject.mouseAction]; return this; } diff --git a/src/config-serializer/config-items/key-action/PlayMacroAction.ts b/src/config-serializer/config-items/key-action/PlayMacroAction.ts index da12714b..72411078 100644 --- a/src/config-serializer/config-items/key-action/PlayMacroAction.ts +++ b/src/config-serializer/config-items/key-action/PlayMacroAction.ts @@ -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; diff --git a/src/config-serializer/config-items/key-action/SwitchKeymapAction.ts b/src/config-serializer/config-items/key-action/SwitchKeymapAction.ts index 99660de9..c6125e1a 100644 --- a/src/config-serializer/config-items/key-action/SwitchKeymapAction.ts +++ b/src/config-serializer/config-items/key-action/SwitchKeymapAction.ts @@ -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; diff --git a/src/config-serializer/config-items/key-action/SwitchLayerAction.ts b/src/config-serializer/config-items/key-action/SwitchLayerAction.ts index 0b0c8b12..832abad8 100644 --- a/src/config-serializer/config-items/key-action/SwitchLayerAction.ts +++ b/src/config-serializer/config-items/key-action/SwitchLayerAction.ts @@ -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[ jsObject.layer]; + this.layer = LayerName[jsObject.layer]; this.isLayerToggleable = jsObject.toggle; return this; }