From 591c2406059067620ae64aae21c830883823be16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Farkas=20J=C3=B3zsef?= Date: Wed, 21 Sep 2016 22:02:46 +0200 Subject: [PATCH] Add copy constructors for macro related classes --- src/config-serializer/config-items/Macro.ts | 12 +++++++++ .../macro-action/DelayMacroAction.ts | 8 ++++++ .../macro-action/KeyMacroAction.ts | 10 ++++++++ .../config-items/macro-action/MacroActions.ts | 25 +++++++++++++++++++ .../macro-action/MouseButtonMacroAction.ts | 9 +++++++ .../macro-action/MoveMouseMacroAction.ts | 11 +++++++- .../macro-action/ScrollMouseMacroAction.ts | 9 +++++++ .../macro-action/TextMacroAction.ts | 8 ++++++ 8 files changed, 91 insertions(+), 1 deletion(-) diff --git a/src/config-serializer/config-items/Macro.ts b/src/config-serializer/config-items/Macro.ts index 9ee71d0e..b6f7b1e0 100644 --- a/src/config-serializer/config-items/Macro.ts +++ b/src/config-serializer/config-items/Macro.ts @@ -16,6 +16,18 @@ export class Macro extends Serializable { macroActions: MacroActions; + constructor(other?: Macro) { + super(); + if (!other) { + return; + } + this.id = other.id; + this.isLooped = other.isLooped; + this.isPrivate = other.isPrivate; + this.name = other.name; + this.macroActions = new MacroActions(other.macroActions); + } + _fromJsObject(jsObject: any): Macro { this.id = jsObject.id; this.isLooped = jsObject.isLooped; diff --git a/src/config-serializer/config-items/macro-action/DelayMacroAction.ts b/src/config-serializer/config-items/macro-action/DelayMacroAction.ts index 2b59a788..e0ca5e5c 100644 --- a/src/config-serializer/config-items/macro-action/DelayMacroAction.ts +++ b/src/config-serializer/config-items/macro-action/DelayMacroAction.ts @@ -7,6 +7,14 @@ export class DelayMacroAction extends MacroAction { @assertUInt16 delay: number; + constructor(other?: DelayMacroAction) { + super(); + if (!other) { + return; + } + this.delay = other.delay; + } + _fromJsObject(jsObject: any): DelayMacroAction { this.assertMacroActionType(jsObject); this.delay = jsObject.delay; diff --git a/src/config-serializer/config-items/macro-action/KeyMacroAction.ts b/src/config-serializer/config-items/macro-action/KeyMacroAction.ts index 5c1de7d1..c8b999d7 100644 --- a/src/config-serializer/config-items/macro-action/KeyMacroAction.ts +++ b/src/config-serializer/config-items/macro-action/KeyMacroAction.ts @@ -23,6 +23,16 @@ export class KeyMacroAction extends MacroAction { @assertUInt8 modifierMask: number; + constructor(other?: KeyMacroAction) { + super(); + if (!other) { + return; + } + this.action = other.action; + this.scancode = other.scancode; + this.modifierMask = other.modifierMask; + } + _fromJsObject(jsObject: JsObjectKeyMacroAction): KeyMacroAction { this.assertMacroActionType(jsObject); this.action = MacroSubAction[jsObject.action]; diff --git a/src/config-serializer/config-items/macro-action/MacroActions.ts b/src/config-serializer/config-items/macro-action/MacroActions.ts index 91c52f8a..981b9af9 100644 --- a/src/config-serializer/config-items/macro-action/MacroActions.ts +++ b/src/config-serializer/config-items/macro-action/MacroActions.ts @@ -10,6 +10,31 @@ import { TextMacroAction } from './TextMacroAction'; export class MacroActions extends ClassArray { + constructor(other?: MacroActions) { + super(); + if (!other) { + return; + } + other.elements.forEach(macroAction => { + let newMacroAction: MacroAction; + if (macroAction instanceof KeyMacroAction) { + newMacroAction = new KeyMacroAction(macroAction); + } else if (macroAction instanceof MouseButtonMacroAction) { + newMacroAction = new MouseButtonMacroAction(macroAction); + } else if (macroAction instanceof MoveMouseMacroAction) { + newMacroAction = new MoveMouseMacroAction(macroAction); + } else if (macroAction instanceof ScrollMouseMacroAction) { + newMacroAction = new ScrollMouseMacroAction(macroAction); + } else if (macroAction instanceof DelayMacroAction) { + newMacroAction = new DelayMacroAction(macroAction); + } else if (macroAction instanceof TextMacroAction) { + newMacroAction = new TextMacroAction(macroAction); + } + + this.elements.push(newMacroAction); + }); + } + jsObjectToClass(jsObject: any): MacroAction { switch (jsObject.macroActionType) { case macroActionType.KeyMacroAction: diff --git a/src/config-serializer/config-items/macro-action/MouseButtonMacroAction.ts b/src/config-serializer/config-items/macro-action/MouseButtonMacroAction.ts index d7acabe4..e087eb92 100644 --- a/src/config-serializer/config-items/macro-action/MouseButtonMacroAction.ts +++ b/src/config-serializer/config-items/macro-action/MouseButtonMacroAction.ts @@ -21,6 +21,15 @@ export class MouseButtonMacroAction extends MacroAction { @assertUInt8 mouseButtonsMask: number; + constructor(other?: MouseButtonMacroAction) { + super(); + if (!other) { + return; + } + this.action = other.action; + this.mouseButtonsMask = other.mouseButtonsMask; + } + _fromJsObject(jsObject: JsObjectMouseButtonMacroAction): MouseButtonMacroAction { this.assertMacroActionType(jsObject); this.action = MacroSubAction[jsObject.action]; diff --git a/src/config-serializer/config-items/macro-action/MoveMouseMacroAction.ts b/src/config-serializer/config-items/macro-action/MoveMouseMacroAction.ts index d64100cd..c42bbb22 100644 --- a/src/config-serializer/config-items/macro-action/MoveMouseMacroAction.ts +++ b/src/config-serializer/config-items/macro-action/MoveMouseMacroAction.ts @@ -1,6 +1,6 @@ import { assertInt16 } from '../../assert'; import { UhkBuffer } from '../../UhkBuffer'; -import { MacroAction, MacroActionId, macroActionType } from './MacroAction'; +import { MacroAction, MacroActionId, macroActionType } from './MacroAction'; export class MoveMouseMacroAction extends MacroAction { @@ -10,6 +10,15 @@ export class MoveMouseMacroAction extends MacroAction { @assertInt16 y: number; + constructor(other?: MoveMouseMacroAction) { + super(); + if (!other) { + return; + } + this.x = other.x; + this.y = other.y; + } + _fromJsObject(jsObject: any): MoveMouseMacroAction { this.assertMacroActionType(jsObject); this.x = jsObject.x; diff --git a/src/config-serializer/config-items/macro-action/ScrollMouseMacroAction.ts b/src/config-serializer/config-items/macro-action/ScrollMouseMacroAction.ts index e5ff7a8e..8780f701 100644 --- a/src/config-serializer/config-items/macro-action/ScrollMouseMacroAction.ts +++ b/src/config-serializer/config-items/macro-action/ScrollMouseMacroAction.ts @@ -10,6 +10,15 @@ export class ScrollMouseMacroAction extends MacroAction { @assertInt16 y: number; + constructor(other?: ScrollMouseMacroAction) { + super(); + if (!other) { + return; + } + this.x = other.x; + this.y = other.y; + } + _fromJsObject(jsObject: any): ScrollMouseMacroAction { this.assertMacroActionType(jsObject); this.x = jsObject.x; diff --git a/src/config-serializer/config-items/macro-action/TextMacroAction.ts b/src/config-serializer/config-items/macro-action/TextMacroAction.ts index 1b3df2cf..c6d25cef 100644 --- a/src/config-serializer/config-items/macro-action/TextMacroAction.ts +++ b/src/config-serializer/config-items/macro-action/TextMacroAction.ts @@ -5,6 +5,14 @@ export class TextMacroAction extends MacroAction { text: string; + constructor(other?: TextMacroAction) { + super(); + if (!other) { + return; + } + this.text = other.text; + } + _fromJsObject(jsObject: any): TextMacroAction { this.assertMacroActionType(jsObject); this.text = jsObject.text;