Fix the rest of serialization problems and make test-serialize.ts compare the original and resulting JSON.
This commit is contained in:
@@ -36,7 +36,7 @@ class DualRoleKeystrokeAction extends KeyAction implements Serializable<DualRole
|
||||
fromJsObject(jsObject: any): DualRoleKeystrokeAction {
|
||||
this.assertKeyActionType(jsObject, KeyActionType.DualRoleKeystrokeAction, 'DualRoleKeystrokeAction');
|
||||
this.scancode = jsObject.scancode;
|
||||
this.longPressAction = jsObject.longPressAction;
|
||||
this.longPressAction = LongPressAction[<string>jsObject.longPressAction];
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class DualRoleKeystrokeAction extends KeyAction implements Serializable<DualRole
|
||||
return {
|
||||
keyActionType: KeyActionType.DualRoleKeystrokeAction,
|
||||
scancode: this.scancode,
|
||||
longPressAction: KeyActionId[this.longPressAction]
|
||||
longPressAction: LongPressAction[this.longPressAction]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ class MouseAction extends KeyAction implements Serializable<MouseAction> {
|
||||
|
||||
fromJsObject(jsObject: any): MouseAction {
|
||||
this.assertKeyActionType(jsObject, KeyActionType.MouseAction, 'MouseAction');
|
||||
console.log(jsObject.mouseAction)
|
||||
this.mouseAction = MouseActionParam[<string>jsObject.mouseAction];
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class NoneAction extends KeyAction implements Serializable<NoneAction> {
|
||||
|
||||
toJsObject(): any {
|
||||
return {
|
||||
keyActionType: KeyActionId.NoneAction
|
||||
keyActionType: KeyActionType.NoneAction
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,20 @@
|
||||
/// <reference path="UhkBuffer.ts" />
|
||||
/// <reference path="config-items/config-items.ts" />
|
||||
|
||||
let assert = require('assert');
|
||||
let fs = require('fs');
|
||||
|
||||
let buffer = new UhkBuffer();
|
||||
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
||||
let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
||||
let keyActionObjects: KeyActions = new KeyActions().fromJsObject(keyActions);
|
||||
|
||||
keyActionObjects.toBinary(buffer);
|
||||
fs.writeFileSync('uhk-config.bin', buffer.getBufferContent());
|
||||
|
||||
buffer.offset = 0;
|
||||
let serializedKeyActions = JSON.stringify(new KeyActions().fromBinary(buffer).toJsObject(), undefined, 4);
|
||||
fs.writeFileSync('uhk-config-serialized.json', serializedKeyActions);
|
||||
let serializedKeyActions = new KeyActions().fromBinary(buffer).toJsObject();
|
||||
fs.writeFileSync('uhk-config-serialized.json', JSON.stringify(serializedKeyActions, undefined, 4));
|
||||
|
||||
assert.deepEqual(keyActions, serializedKeyActions);
|
||||
console.log('JSON configurations are identical.');
|
||||
|
||||
Reference in New Issue
Block a user