successfully serializing 1 module, still problem with serializing multiple
This commit is contained in:
49
config-serializer/config-items/Module.ts
Normal file
49
config-serializer/config-items/Module.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
enum PointerRole {
|
||||||
|
none,
|
||||||
|
move,
|
||||||
|
scroll
|
||||||
|
}
|
||||||
|
|
||||||
|
class Module extends Serializable<Module> {
|
||||||
|
|
||||||
|
@assertEnum(PointerRole)
|
||||||
|
private role: PointerRole;
|
||||||
|
|
||||||
|
@assertUInt8
|
||||||
|
moduleId: number;
|
||||||
|
|
||||||
|
keyActions: Serializable<KeyActions>;
|
||||||
|
|
||||||
|
_fromJsObject(jsObject: any): Module {
|
||||||
|
this.moduleId = jsObject.id;
|
||||||
|
this.role = PointerRole[<string> jsObject.pointerRole];
|
||||||
|
this.keyActions = new KeyActions().fromJsObject(jsObject.keyActions);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
_fromBinary(buffer: UhkBuffer): Module {
|
||||||
|
this.moduleId = buffer.readUInt8();
|
||||||
|
this.role = buffer.readUInt8();
|
||||||
|
this.keyActions = new KeyActions().fromBinary(buffer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
_toJsObject(): any {
|
||||||
|
return {
|
||||||
|
id: this.moduleId,
|
||||||
|
pointerRole: PointerRole[this.role],
|
||||||
|
keyActions: this.keyActions.toJsObject()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_toBinary(buffer: UhkBuffer): void {
|
||||||
|
buffer.writeUInt8(this.moduleId);
|
||||||
|
buffer.writeUInt8(this.role);
|
||||||
|
this.keyActions.toBinary(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return `<Module id="${this.moduleId}">`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
11
config-serializer/config-items/Modules.ts
Normal file
11
config-serializer/config-items/Modules.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class Modules extends ClassArray<Module> {
|
||||||
|
|
||||||
|
jsObjectToClass(jsObject: any): Serializable<Module> {
|
||||||
|
return new Module().fromJsObject(jsObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
binaryToClass(buffer: UhkBuffer): Serializable<Module> {
|
||||||
|
return new Module().fromBinary(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,3 +9,5 @@
|
|||||||
/// <reference path="SwitchLayerAction.ts" />
|
/// <reference path="SwitchLayerAction.ts" />
|
||||||
/// <reference path="SwitchKeymapAction.ts" />
|
/// <reference path="SwitchKeymapAction.ts" />
|
||||||
/// <reference path="NoneAction.ts" />
|
/// <reference path="NoneAction.ts" />
|
||||||
|
/// <reference path="Module.ts" />
|
||||||
|
/// <reference path="Modules.ts" />
|
||||||
|
|||||||
Reference in New Issue
Block a user