Add some copy constructors

This commit is contained in:
Farkas József
2016-09-17 16:39:45 +02:00
parent 7464948f1c
commit 813714073e
6 changed files with 82 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
import {assertUInt8} from '../assert';
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
import {Layers} from './Layers';
import { assertUInt8 } from '../assert';
import { Serializable } from '../Serializable';
import { UhkBuffer } from '../UhkBuffer';
import { Layers } from './Layers';
export class Keymap extends Serializable<Keymap> {
@@ -18,6 +18,19 @@ export class Keymap extends Serializable<Keymap> {
layers: Layers;
constructor(keymap?: Keymap) {
super();
if (!keymap) {
return;
}
this.id = keymap.id;
this.name = keymap.name;
this.description = keymap.description;
this.abbreviation = keymap.abbreviation;
this.isDefault = keymap.isDefault;
this.layers = new Layers(keymap.layers);
}
_fromJsObject(jsObject: any): Keymap {
this.id = jsObject.id;
this.isDefault = jsObject.isDefault;

View File

@@ -6,7 +6,17 @@ import { Modules } from './Modules';
export class Layer extends Serializable<Layer> {
modules: Modules;
animation: AnimationKeyboard = 'none';
animation: AnimationKeyboard;
constructor(layers?: Layer) {
super();
if (!layers) {
this.animation = 'none';
return;
}
this.modules = new Modules(layers.modules);
this.animation = layers.animation;
}
_fromJsObject(jsObject: any): Layer {
this.modules = new Modules().fromJsObject(jsObject.modules);

View File

@@ -1,9 +1,17 @@
import {ClassArray} from '../ClassArray';
import {UhkBuffer} from '../UhkBuffer';
import {Layer} from './Layer';
import { ClassArray } from '../ClassArray';
import { UhkBuffer } from '../UhkBuffer';
import { Layer } from './Layer';
export class Layers extends ClassArray<Layer> {
constructor(layers?: Layers) {
super();
if (!layers) {
return;
}
layers.elements.forEach(layer => this.elements.push(new Layer(layer)));
}
jsObjectToClass(jsObject: any): Layer {
return new Layer().fromJsObject(jsObject);
}

View File

@@ -1,7 +1,7 @@
import {assertEnum, assertUInt8} from '../assert';
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
import {KeyActions} from './key-action';
import { assertEnum, assertUInt8 } from '../assert';
import { Serializable } from '../Serializable';
import { UhkBuffer } from '../UhkBuffer';
import { KeyActions } from './key-action';
enum PointerRole {
none,
@@ -19,9 +19,19 @@ export class Module extends Serializable<Module> {
@assertEnum(PointerRole)
private pointerRole: PointerRole;
constructor(moduleI?: Module) {
super();
if (!moduleI) {
return;
}
this.id = moduleI.id;
this.keyActions = new KeyActions(moduleI.keyActions);
this.pointerRole = moduleI.pointerRole;
}
_fromJsObject(jsObject: any): Module {
this.id = jsObject.id;
this.pointerRole = PointerRole[<string> jsObject.pointerRole];
this.pointerRole = PointerRole[<string>jsObject.pointerRole];
this.keyActions = new KeyActions().fromJsObject(jsObject.keyActions);
return this;
}

View File

@@ -1,9 +1,17 @@
import {ClassArray} from '../ClassArray';
import {UhkBuffer} from '../UhkBuffer';
import {Module} from './Module';
import { ClassArray } from '../ClassArray';
import { UhkBuffer } from '../UhkBuffer';
import { Module } from './Module';
export class Modules extends ClassArray<Module> {
constructor(modules?: Modules) {
super();
if (!modules) {
return;
}
modules.elements.forEach(module => this.elements.push(new Module(module)));
}
jsObjectToClass(jsObject: any): Module {
return new Module().fromJsObject(jsObject);
}

View File

@@ -1,15 +1,23 @@
import {ClassArray} from '../../ClassArray';
import {UhkBuffer} from '../../UhkBuffer';
import {KeyAction, KeyActionId, keyActionType} from './KeyAction';
import {KeystrokeAction} from './KeystrokeAction';
import {MouseAction} from './MouseAction';
import {NoneAction} from './NoneAction';
import {PlayMacroAction} from './PlayMacroAction';
import {SwitchKeymapAction} from './SwitchKeymapAction';
import {SwitchLayerAction} from './SwitchLayerAction';
import { ClassArray } from '../../ClassArray';
import { UhkBuffer } from '../../UhkBuffer';
import { KeyAction, KeyActionId, keyActionType } from './KeyAction';
import { KeystrokeAction } from './KeystrokeAction';
import { MouseAction } from './MouseAction';
import { NoneAction } from './NoneAction';
import { PlayMacroAction } from './PlayMacroAction';
import { SwitchKeymapAction } from './SwitchKeymapAction';
import { SwitchLayerAction } from './SwitchLayerAction';
export class KeyActions extends ClassArray<KeyAction> {
constructor(keyActions?: KeyActions) {
super();
if (!keyActions) {
return;
}
keyActions.elements.forEach(keyaction => this.elements.push(this.jsObjectToClass(keyaction)));
}
jsObjectToClass(jsObject: any): KeyAction {
switch (jsObject.keyActionType) {
case keyActionType.NoneAction: