macro macros
This commit is contained in:
65
config-serializer/config-items/Macro.ts
Normal file
65
config-serializer/config-items/Macro.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
class Macro extends Serializable<Macro> {
|
||||
|
||||
static loopedFlag = 0x80;
|
||||
static privateFlag = 0x08;
|
||||
|
||||
// @assertUInt8
|
||||
id: number;
|
||||
|
||||
isLooped: boolean;
|
||||
|
||||
isPrivate: boolean;
|
||||
|
||||
name: string;
|
||||
|
||||
macroActions: Serializable<MacroActions>;
|
||||
|
||||
_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 `<Macro id="${this.id}" name="${this.name}">`;
|
||||
}
|
||||
|
||||
private getLoopedFlag() {
|
||||
return this.isLooped ? Macro.loopedFlag : 0;
|
||||
}
|
||||
|
||||
private getPrivateFlag() {
|
||||
return this.isPrivate ? Macro.privateFlag : 0;
|
||||
}
|
||||
}
|
||||
11
config-serializer/config-items/Macros.ts
Normal file
11
config-serializer/config-items/Macros.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
class Macros extends ClassArray<Macro> {
|
||||
|
||||
jsObjectToClass(jsObject: any): Serializable<Macro> {
|
||||
return new Macro().fromJsObject(jsObject);
|
||||
}
|
||||
|
||||
binaryToClass(buffer: UhkBuffer): Serializable<Macro> {
|
||||
return new Macro().fromBinary(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
/// <reference path="Layers.ts" />
|
||||
/// <reference path="KeyMap.ts" />
|
||||
/// <reference path="KeyMaps.ts" />
|
||||
/// <reference path="Macro.ts" />
|
||||
/// <reference path="Macros.ts" />
|
||||
/// <reference path="MacroAction.ts" />
|
||||
/// <reference path="MacroActions.ts" />
|
||||
/// <reference path="PressKeyMacroAction.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<MacroActions> = new MacroActions().fromJsObject(config1Js);
|
||||
let config1Js = uhkConfig.macros;
|
||||
let config1Ts: Serializable<Macros> = 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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user