Merge pull request #33 from srang/feature/keymap_keymaps
Feature/keymap keymaps
This commit is contained in:
@@ -122,7 +122,7 @@ class UhkBuffer {
|
|||||||
|
|
||||||
readString(): string {
|
readString(): string {
|
||||||
let stringByteLength = this.readCompactLength();
|
let stringByteLength = this.readCompactLength();
|
||||||
let str = this.buffer.toString(UhkBuffer.stringEncoding, this.offset, stringByteLength);
|
let str = this.buffer.toString(UhkBuffer.stringEncoding, this.offset, this.offset + stringByteLength);
|
||||||
this.dump(`${UhkBuffer.stringEncoding}(${str})`);
|
this.dump(`${UhkBuffer.stringEncoding}(${str})`);
|
||||||
this.bytesToBacktrack = stringByteLength;
|
this.bytesToBacktrack = stringByteLength;
|
||||||
this.offset += stringByteLength;
|
this.offset += stringByteLength;
|
||||||
|
|||||||
60
config-serializer/config-items/KeyMap.ts
Normal file
60
config-serializer/config-items/KeyMap.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
class KeyMap extends Serializable<KeyMap> {
|
||||||
|
|
||||||
|
static defaultFlag = 0x80;
|
||||||
|
|
||||||
|
// @assertUInt8
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
abbreviation: string;
|
||||||
|
|
||||||
|
isDefault: boolean;
|
||||||
|
|
||||||
|
layers: Serializable<Layers>;
|
||||||
|
|
||||||
|
_fromJsObject(jsObject: any): KeyMap {
|
||||||
|
this.id = jsObject.id;
|
||||||
|
this.isDefault = jsObject.isDefault;
|
||||||
|
this.abbreviation = jsObject.abbreviation;
|
||||||
|
this.name = jsObject.name;
|
||||||
|
this.layers = new Layers().fromJsObject(jsObject.layers);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
_fromBinary(buffer: UhkBuffer): KeyMap {
|
||||||
|
let map = buffer.readUInt8();
|
||||||
|
/* saves almost a byte but limits number of keymaps... */
|
||||||
|
this.isDefault = (map & KeyMap.defaultFlag) !== 0;
|
||||||
|
this.id = map & ~KeyMap.defaultFlag; // Clear isDefault bit.;
|
||||||
|
this.abbreviation = buffer.readString();
|
||||||
|
this.name = buffer.readString();
|
||||||
|
this.layers = new Layers().fromBinary(buffer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
_toJsObject(): any {
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
isDefault: this.isDefault,
|
||||||
|
abbreviation: this.abbreviation,
|
||||||
|
name: this.name,
|
||||||
|
layers: this.layers.toJsObject()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
_toBinary(buffer: UhkBuffer): void {
|
||||||
|
buffer.writeUInt8(this.id | this.getDefaultFlag());
|
||||||
|
buffer.writeString(this.abbreviation);
|
||||||
|
buffer.writeString(this.name);
|
||||||
|
this.layers.toBinary(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return `<KeyMap id="${this.id}" name="${this.name}">`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getDefaultFlag() {
|
||||||
|
return this.isDefault ? KeyMap.defaultFlag : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
config-serializer/config-items/KeyMaps.ts
Normal file
11
config-serializer/config-items/KeyMaps.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class KeyMaps extends ClassArray<KeyMap> {
|
||||||
|
|
||||||
|
jsObjectToClass(jsObject: any): Serializable<KeyMap> {
|
||||||
|
return new KeyMap().fromJsObject(jsObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
binaryToClass(buffer: UhkBuffer): Serializable<KeyMap> {
|
||||||
|
return new KeyMap().fromBinary(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,4 +22,8 @@ class Layer extends Serializable<Layer> {
|
|||||||
this.modules.toBinary(buffer);
|
this.modules.toBinary(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return `<Layer>`;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,3 +13,5 @@
|
|||||||
/// <reference path="Modules.ts" />
|
/// <reference path="Modules.ts" />
|
||||||
/// <reference path="Layer.ts" />
|
/// <reference path="Layer.ts" />
|
||||||
/// <reference path="Layers.ts" />
|
/// <reference path="Layers.ts" />
|
||||||
|
/// <reference path="KeyMap.ts" />
|
||||||
|
/// <reference path="KeyMaps.ts" />
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ let fs = require('fs');
|
|||||||
|
|
||||||
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
||||||
|
|
||||||
let config1Js = uhkConfig.keymaps[0].layers;
|
let config1Js = uhkConfig.keymaps;
|
||||||
let config1Ts: Serializable<Layers> = new Layers().fromJsObject(config1Js);
|
let config1Ts: Serializable<KeyMaps> = new KeyMaps().fromJsObject(config1Js);
|
||||||
let config1Buffer = new UhkBuffer();
|
let config1Buffer = new UhkBuffer();
|
||||||
config1Ts.toBinary(config1Buffer);
|
config1Ts.toBinary(config1Buffer);
|
||||||
let config1BufferContent = config1Buffer.getBufferContent();
|
let config1BufferContent = config1Buffer.getBufferContent();
|
||||||
@@ -19,7 +19,7 @@ fs.writeFileSync('uhk-config.bin', config1BufferContent);
|
|||||||
|
|
||||||
config1Buffer.offset = 0;
|
config1Buffer.offset = 0;
|
||||||
console.log();
|
console.log();
|
||||||
let config2Ts = new Layers().fromBinary(config1Buffer);
|
let config2Ts = new KeyMaps().fromBinary(config1Buffer);
|
||||||
console.log('\n');
|
console.log('\n');
|
||||||
let config2Js = config2Ts.toJsObject();
|
let config2Js = config2Ts.toJsObject();
|
||||||
let config2Buffer = new UhkBuffer();
|
let config2Buffer = new UhkBuffer();
|
||||||
|
|||||||
@@ -134,7 +134,7 @@
|
|||||||
"modules": [
|
"modules": [
|
||||||
{
|
{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"pointerRole": "none",
|
"pointerRole": "move",
|
||||||
"keyActions": []
|
"keyActions": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -148,7 +148,48 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "Dvorak"
|
"isDefault": false,
|
||||||
|
"abbreviation": "VIM",
|
||||||
|
"name": "VIM",
|
||||||
|
"layers": [
|
||||||
|
{
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"pointerRole": "move",
|
||||||
|
"keyActions": [
|
||||||
|
{
|
||||||
|
"keyActionType": "mouse",
|
||||||
|
"mouseAction": "scrollDown"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"keyActionType": "playMacro",
|
||||||
|
"macroId": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"keyActionType": "switchKeymap",
|
||||||
|
"keymapId": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"pointerRole": "scroll",
|
||||||
|
"keyActions": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"pointerRole": "move",
|
||||||
|
"keyActions": [
|
||||||
|
{
|
||||||
|
"keyActionType": "keystroke",
|
||||||
|
"scancode": 111
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"macros": [
|
"macros": [
|
||||||
|
|||||||
Reference in New Issue
Block a user