@@ -3,3 +3,4 @@ uhk-config.bin
|
|||||||
uhk-config-serialized.json
|
uhk-config-serialized.json
|
||||||
uhk-config-serialized.bin
|
uhk-config-serialized.bin
|
||||||
test-serializer.js
|
test-serializer.js
|
||||||
|
*.sw*
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ enum LongPressAction {
|
|||||||
|
|
||||||
class DualRoleKeystrokeAction extends KeyAction {
|
class DualRoleKeystrokeAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
// @assertUInt8
|
||||||
scancode: number;
|
scancode: number;
|
||||||
|
|
||||||
@assertEnum(LongPressAction)
|
// @assertEnum(LongPressAction)
|
||||||
private longPressAction: LongPressAction;
|
private longPressAction: LongPressAction;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): DualRoleKeystrokeAction {
|
_fromJsObject(jsObject: any): DualRoleKeystrokeAction {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class KeystrokeAction extends KeyAction {
|
class KeystrokeAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
// @assertUInt8
|
||||||
scancode: number;
|
scancode: number;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): KeystrokeAction {
|
_fromJsObject(jsObject: any): KeystrokeAction {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ enum KeyModifiers {
|
|||||||
|
|
||||||
class KeystrokeModifiersAction extends KeyAction {
|
class KeystrokeModifiersAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
// @assertUInt8
|
||||||
modifierMask: number;
|
modifierMask: number;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): KeystrokeModifiersAction {
|
_fromJsObject(jsObject: any): KeystrokeModifiersAction {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
class KeystrokeWithModifiersAction extends KeyAction {
|
class KeystrokeWithModifiersAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
// @assertUInt8
|
||||||
modifierMask: number;
|
modifierMask: number;
|
||||||
|
|
||||||
@assertUInt8
|
// @assertUInt8
|
||||||
scancode: number;
|
scancode: number;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): KeystrokeWithModifiersAction {
|
_fromJsObject(jsObject: any): KeystrokeWithModifiersAction {
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
enum PointerRole {
|
||||||
|
none,
|
||||||
|
move,
|
||||||
|
scroll
|
||||||
|
}
|
||||||
|
|
||||||
|
class Module extends Serializable<Module> {
|
||||||
|
|
||||||
|
// @assertUInt8
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
keyActions: Serializable<KeyActions>;
|
||||||
|
|
||||||
|
// @assertEnum(PointerRole)
|
||||||
|
private pointerRole: PointerRole;
|
||||||
|
|
||||||
|
_fromJsObject(jsObject: any): Module {
|
||||||
|
this.id = jsObject.id;
|
||||||
|
this.pointerRole = PointerRole[<string> jsObject.pointerRole];
|
||||||
|
this.keyActions = new KeyActions().fromJsObject(jsObject.keyActions);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
_fromBinary(buffer: UhkBuffer): Module {
|
||||||
|
this.id = buffer.readUInt8();
|
||||||
|
this.pointerRole = buffer.readUInt8();
|
||||||
|
this.keyActions = new KeyActions().fromBinary(buffer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
_toJsObject(): any {
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
pointerRole: PointerRole[this.pointerRole],
|
||||||
|
keyActions: this.keyActions.toJsObject()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
_toBinary(buffer: UhkBuffer): void {
|
||||||
|
buffer.writeUInt8(this.id);
|
||||||
|
buffer.writeUInt8(this.pointerRole);
|
||||||
|
this.keyActions.toBinary(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return `<Module id="${this.id}" pointerRole="${this.pointerRole}">`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ enum MouseActionParam {
|
|||||||
|
|
||||||
class MouseAction extends KeyAction {
|
class MouseAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
// @assertUInt8
|
||||||
mouseAction: MouseActionParam;
|
mouseAction: MouseActionParam;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): MouseAction {
|
_fromJsObject(jsObject: any): MouseAction {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class PlayMacroAction extends KeyAction {
|
class PlayMacroAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
// @assertUInt8
|
||||||
macroId: number;
|
macroId: number;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): PlayMacroAction {
|
_fromJsObject(jsObject: any): PlayMacroAction {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class SwitchKeymapAction extends KeyAction {
|
class SwitchKeymapAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
// @assertUInt8
|
||||||
keymapId: number;
|
keymapId: number;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): SwitchKeymapAction {
|
_fromJsObject(jsObject: any): SwitchKeymapAction {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class SwitchLayerAction extends KeyAction {
|
|||||||
|
|
||||||
isLayerToggleable: boolean;
|
isLayerToggleable: boolean;
|
||||||
|
|
||||||
@assertEnum(Layer)
|
// @assertEnum(Layer)
|
||||||
private layer: Layer;
|
private layer: Layer;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): SwitchLayerAction {
|
_fromJsObject(jsObject: any): SwitchLayerAction {
|
||||||
|
|||||||
@@ -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" />
|
||||||
|
|||||||
@@ -10,31 +10,31 @@ let fs = require('fs');
|
|||||||
|
|
||||||
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
||||||
|
|
||||||
let keyActions1Js = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
let modules1Js = uhkConfig.keymaps[0].layers[0].modules;
|
||||||
let keyActions1Ts: Serializable<KeyActions> = new KeyActions().fromJsObject(keyActions1Js);
|
let modules1Ts: Serializable<Modules> = new Modules().fromJsObject(modules1Js);
|
||||||
let keyActions1Buffer = new UhkBuffer();
|
let modules1Buffer = new UhkBuffer();
|
||||||
keyActions1Ts.toBinary(keyActions1Buffer);
|
modules1Ts.toBinary(modules1Buffer);
|
||||||
let keyActions1BufferContent = keyActions1Buffer.getBufferContent();
|
let modules1BufferContent = modules1Buffer.getBufferContent();
|
||||||
fs.writeFileSync('uhk-config.bin', keyActions1BufferContent);
|
fs.writeFileSync('uhk-config.bin', modules1BufferContent);
|
||||||
|
|
||||||
keyActions1Buffer.offset = 0;
|
modules1Buffer.offset = 0;
|
||||||
console.log();
|
console.log();
|
||||||
let keyActions2Ts = new KeyActions().fromBinary(keyActions1Buffer);
|
let modules2Ts = new Modules().fromBinary(modules1Buffer);
|
||||||
console.log('\n');
|
console.log('\n');
|
||||||
let keyActions2Js = keyActions2Ts.toJsObject();
|
let modules2Js = modules2Ts.toJsObject();
|
||||||
let keyActions2Buffer = new UhkBuffer();
|
let modules2Buffer = new UhkBuffer();
|
||||||
keyActions2Ts.toBinary(keyActions2Buffer);
|
modules2Ts.toBinary(modules2Buffer);
|
||||||
fs.writeFileSync('uhk-config-serialized.json', JSON.stringify(keyActions2Js, undefined, 4));
|
fs.writeFileSync('uhk-config-serialized.json', JSON.stringify(modules2Js, undefined, 4));
|
||||||
let keyActions2BufferContent = keyActions1Buffer.getBufferContent();
|
let modules2BufferContent = modules1Buffer.getBufferContent();
|
||||||
fs.writeFileSync('uhk-config-serialized.bin', keyActions2BufferContent);
|
fs.writeFileSync('uhk-config-serialized.bin', modules2BufferContent);
|
||||||
|
|
||||||
console.log('\n');
|
console.log('\n');
|
||||||
try {
|
try {
|
||||||
assert.deepEqual(keyActions1Js, keyActions2Js);
|
assert.deepEqual(modules1Js, modules2Js);
|
||||||
console.log('JSON configurations are identical.');
|
console.log('JSON configurations are identical.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('JSON configurations differ.');
|
console.log('JSON configurations differ.');
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffersContentsAreEqual = Buffer.compare(keyActions1BufferContent, keyActions2BufferContent) === 0;
|
let buffersContentsAreEqual = Buffer.compare(modules1BufferContent, modules2BufferContent) === 0;
|
||||||
console.log('Binary configurations ' + (buffersContentsAreEqual ? 'are identical' : 'differ') + '.');
|
console.log('Binary configurations ' + (buffersContentsAreEqual ? 'are identical' : 'differ') + '.');
|
||||||
|
|||||||
Reference in New Issue
Block a user