From e2b049273692e619af9982926a9c9ed1d7b969f7 Mon Sep 17 00:00:00 2001 From: Sam Rang Date: Sun, 17 Apr 2016 23:48:17 -0500 Subject: [PATCH] macro macros --- config-serializer/config-items/Macro.ts | 65 +++++++++++++++++++ config-serializer/config-items/Macros.ts | 11 ++++ .../config-items/config-items.ts | 2 + config-serializer/test-serializer.ts | 6 +- config-serializer/uhk-config.json | 29 +++++++++ 5 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 config-serializer/config-items/Macro.ts create mode 100644 config-serializer/config-items/Macros.ts diff --git a/config-serializer/config-items/Macro.ts b/config-serializer/config-items/Macro.ts new file mode 100644 index 00000000..11a08a32 --- /dev/null +++ b/config-serializer/config-items/Macro.ts @@ -0,0 +1,65 @@ +class Macro extends Serializable { + + static loopedFlag = 0x80; + static privateFlag = 0x08; + + // @assertUInt8 + id: number; + + isLooped: boolean; + + isPrivate: boolean; + + name: string; + + macroActions: Serializable; + + _fromJsObject(jsObject: any): Macro { + this.id = jsObject.id; + this.isLooped = jsObject.isLooped; + this.isPrivate = jsObject.isPrivate; + this.name = jsObject.name; + this.macroActions = new MacroActions().fromJsObject(jsObject.macroActions); + return this; + } + + _fromBinary(buffer: UhkBuffer): Macro { + this.id = buffer.readUInt8(); + let bools = buffer.readUInt8(); + /* saves almost a byte but limits number of keymaps... */ + this.isLooped = (bools & Macro.loopedFlag) !== 0; + this.isPrivate = (bools & Macro.privateFlag) !== 0; + this.name = buffer.readString(); + this.macroActions = new MacroActions().fromBinary(buffer); + return this; + } + + _toJsObject(): any { + return { + id: this.id, + isLooped: this.isLooped, + isPrivate: this.isPrivate, + name: this.name, + macroActions: this.macroActions.toJsObject() + }; + } + + _toBinary(buffer: UhkBuffer): void { + buffer.writeUInt8(this.id); + buffer.writeUInt8(this.getLoopedFlag() | this.getPrivateFlag()); + buffer.writeString(this.name); + this.macroActions.toBinary(buffer); + } + + toString(): string { + return ``; + } + + private getLoopedFlag() { + return this.isLooped ? Macro.loopedFlag : 0; + } + + private getPrivateFlag() { + return this.isPrivate ? Macro.privateFlag : 0; + } +} diff --git a/config-serializer/config-items/Macros.ts b/config-serializer/config-items/Macros.ts new file mode 100644 index 00000000..49fd6d4b --- /dev/null +++ b/config-serializer/config-items/Macros.ts @@ -0,0 +1,11 @@ +class Macros extends ClassArray { + + jsObjectToClass(jsObject: any): Serializable { + return new Macro().fromJsObject(jsObject); + } + + binaryToClass(buffer: UhkBuffer): Serializable { + return new Macro().fromBinary(buffer); + } + +} diff --git a/config-serializer/config-items/config-items.ts b/config-serializer/config-items/config-items.ts index a84a4312..597ddb7e 100644 --- a/config-serializer/config-items/config-items.ts +++ b/config-serializer/config-items/config-items.ts @@ -15,6 +15,8 @@ /// /// /// +/// +/// /// /// /// diff --git a/config-serializer/test-serializer.ts b/config-serializer/test-serializer.ts index cc4c97ab..8cae059c 100644 --- a/config-serializer/test-serializer.ts +++ b/config-serializer/test-serializer.ts @@ -10,8 +10,8 @@ let fs = require('fs'); let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json')); -let config1Js = uhkConfig.macros[0].macroActions; -let config1Ts: Serializable = new MacroActions().fromJsObject(config1Js); +let config1Js = uhkConfig.macros; +let config1Ts: Serializable = new Macros().fromJsObject(config1Js); let config1Buffer = new UhkBuffer(); config1Ts.toBinary(config1Buffer); let config1BufferContent = config1Buffer.getBufferContent(); @@ -19,7 +19,7 @@ fs.writeFileSync('uhk-config.bin', config1BufferContent); config1Buffer.offset = 0; console.log(); -let config2Ts = new MacroActions().fromBinary(config1Buffer); +let config2Ts = new Macros().fromBinary(config1Buffer); console.log('\n'); let config2Js = config2Ts.toJsObject(); let config2Buffer = new UhkBuffer(); diff --git a/config-serializer/uhk-config.json b/config-serializer/uhk-config.json index 778e9354..f780192b 100644 --- a/config-serializer/uhk-config.json +++ b/config-serializer/uhk-config.json @@ -254,6 +254,35 @@ "text": "this is a text" } ] + }, + { + "id": 1, + "isLooped": true, + "isPrivate": true, + "name": "Blah Blah blah", + "macroActions": [ + { + "macroActionType": "pressKey", + "scancode": 111 + }, + { + "macroActionType": "releaseMouseButtons", + "mouseButtonsMask": 104 + }, + { + "macroActionType": "scrollMouse", + "x": 0, + "y": -20000 + }, + { + "macroActionType": "delay", + "delay": 40000 + }, + { + "macroActionType": "text", + "text": "blahhhhhhh" + } + ] } ], "epilogue": 1234678