Use references in key actions (#204)

This commit is contained in:
József Farkas
2016-12-13 23:09:39 +01:00
committed by GitHub
parent 3380a9d514
commit e48fdea89d
33 changed files with 266 additions and 255 deletions

View File

@@ -1,6 +1,7 @@
import { Serializable } from '../Serializable';
import { UhkBuffer } from '../UhkBuffer';
import { Layer } from './Layer';
import { Macro } from './Macro';
export class Keymap extends Serializable<Keymap> {
@@ -14,7 +15,7 @@ export class Keymap extends Serializable<Keymap> {
layers: Layer[];
constructor(keymap?: Keymap) {
constructor(keymap?: Keymap, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro) {
super();
if (!keymap) {
return;
@@ -24,40 +25,42 @@ export class Keymap extends Serializable<Keymap> {
this.description = keymap.description;
this.abbreviation = keymap.abbreviation;
this.isDefault = keymap.isDefault;
this.layers = keymap.layers.map(layer => new Layer(layer));
this.layers = keymap.layers.map(layer => new Layer(layer, getKeymap, getMacro));
}
_fromJsObject(jsObject: any): Keymap {
this.isDefault = jsObject.isDefault;
this.abbreviation = jsObject.abbreviation;
this.name = jsObject.name;
this.description = jsObject.description;
this.layers = jsObject.layers.map((layer: any) => new Layer().fromJsObject(layer));
fromJsonObject(jsonObject: any, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro): Keymap {
this.isDefault = jsonObject.isDefault;
this.abbreviation = jsonObject.abbreviation;
this.name = jsonObject.name;
this.description = jsonObject.description;
this.layers = jsonObject.layers.map((layer: any) => new Layer().fromJsonObject(layer, getKeymap, getMacro));
return this;
}
_fromBinary(buffer: UhkBuffer): Keymap {
this.isDefault = buffer.readBoolean();
fromBinary(buffer: UhkBuffer, getKeymap?: (abbrevation: string) => Keymap, getMacro?: (macroId: number) => Macro): Keymap {
this.abbreviation = buffer.readString();
this.isDefault = buffer.readBoolean();
this.name = buffer.readString();
this.description = buffer.readString();
this.layers = buffer.readArray<Layer>(Layer);
this.layers = buffer.readArray<Layer>(uhkBuffer => {
return new Layer().fromBinary(uhkBuffer, getKeymap, getMacro);
});
return this;
}
_toJsObject(): any {
_toJsonObject(): any {
return {
isDefault: this.isDefault,
abbreviation: this.abbreviation,
name: this.name,
description: this.description,
layers: this.layers.map(layer => layer.toJsObject())
layers: this.layers.map(layer => layer.toJsonObject())
};
}
_toBinary(buffer: UhkBuffer): void {
buffer.writeBoolean(this.isDefault);
buffer.writeString(this.abbreviation);
buffer.writeBoolean(this.isDefault);
buffer.writeString(this.name);
buffer.writeString(this.description);
buffer.writeArray(this.layers);