Add copy constructors for macro related classes

This commit is contained in:
Farkas József
2016-09-21 22:02:46 +02:00
parent 93bfb43051
commit 591c240605
8 changed files with 91 additions and 1 deletions

View File

@@ -16,6 +16,18 @@ export class Macro extends Serializable<Macro> {
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;

View File

@@ -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;

View File

@@ -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];

View File

@@ -10,6 +10,31 @@ import { TextMacroAction } from './TextMacroAction';
export class MacroActions extends ClassArray<MacroAction> {
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:

View File

@@ -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];

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;