diff --git a/config-serializer/ClassArray.ts b/config-serializer/ClassArray.ts index 8e6b0ec3..06266af1 100644 --- a/config-serializer/ClassArray.ts +++ b/config-serializer/ClassArray.ts @@ -14,7 +14,6 @@ abstract class ClassArray extends Serializable { let arrayLength = buffer.readCompactLength(); if (buffer.enableDump) { - process.stdout.write(']\n'); buffer.enableDump = false; } @@ -36,7 +35,6 @@ abstract class ClassArray extends Serializable { buffer.writeCompactLength(this.elements.length); if (buffer.enableDump) { - process.stdout.write(']\n'); buffer.enableDump = false; } diff --git a/config-serializer/Serializable.ts b/config-serializer/Serializable.ts index c7b0b50a..f108db94 100644 --- a/config-serializer/Serializable.ts +++ b/config-serializer/Serializable.ts @@ -5,58 +5,43 @@ abstract class Serializable { private static enableDump = true; fromJsObject(jsObject: any): Serializable { - let isArray = this instanceof ClassArray; - this.dumpMethodName('fromJsObject'); - this.dump(`${this.strintifyJsObject(jsObject)}` + (isArray ? '\n' : ` => `)); + this.dump(`${this.getIndentation()}${this.constructor.name}.fromJsObject: ` + + `${this.strintifyJsObject(jsObject)}\n`); Serializable.depth++; let value = this._fromJsObject(jsObject); Serializable.depth--; - if (!isArray) { - this.dump(`${value}\n`); - } + this.dump(`${this.getIndentation()}=> ${value}\n`); return value; } fromBinary(buffer: UhkBuffer): Serializable { - let isArray = this instanceof ClassArray; - this.dumpMethodName('fromBinary'); - this.dump('['); + this.dump(`\n${this.getIndentation()}${this.constructor.name}.fromBinary: [`); Serializable.depth++; buffer.enableDump = Serializable.enableDump; let value = this._fromBinary(buffer); buffer.enableDump = false; Serializable.depth--; - if (!isArray) { - this.dump(`] => ${value}\n`); - } + this.dump(`]\n${this.getIndentation()}=> ${value}`); return value; } toJsObject(): any { - let isArray = this instanceof ClassArray; - this.dumpMethodName('toJsObject'); - this.dump(`${this}` + (isArray ? '\n' : ` => `)); + this.dump(`${this.getIndentation()}${this.constructor.name}.toJsObject: ${this}\n`); Serializable.depth++; let value = this._toJsObject(); Serializable.depth--; - if (!isArray) { - this.dump(`${this.strintifyJsObject(value)}\n`); - } + this.dump(`${this.getIndentation()}=> ${this.strintifyJsObject(value)}\n`); return value; } toBinary(buffer: UhkBuffer): void { - let isArray = this instanceof ClassArray; - this.dumpMethodName('toBinary'); - this.dump(`${this} => ['`); + this.dump(`\n${this.getIndentation()}${this.constructor.name}.toBinary: ${this} [`); Serializable.depth++; buffer.enableDump = Serializable.enableDump; let value = this._toBinary(buffer); buffer.enableDump = false; Serializable.depth--; - if (!isArray) { - this.dump(`]\n`); - } + this.dump(`]`); return value; } @@ -71,9 +56,8 @@ abstract class Serializable { } } - private dumpMethodName(methodName: string) { - let indentation = new Array(Serializable.depth + 1).join(' '); - this.dump(`${indentation}${this.constructor.name}.${methodName}: `); + private getIndentation() { + return new Array(Serializable.depth + 1).join(' '); } private strintifyJsObject(jsObject: any): string { diff --git a/config-serializer/UhkBuffer.ts b/config-serializer/UhkBuffer.ts index d7e66db3..85f1204f 100644 --- a/config-serializer/UhkBuffer.ts +++ b/config-serializer/UhkBuffer.ts @@ -1,4 +1,5 @@ class UhkBuffer { + private static eepromSize = 32 * 1024; private static maxCompactLength = 0xFFFF; private static longCompactLengthPrefix = 0xFF; @@ -156,21 +157,25 @@ class UhkBuffer { } set enableDump(value) { - UhkBuffer.isFirstElementToDump = true; + if (value) { + UhkBuffer.isFirstElementToDump = true; + } this._enableDump = value; } dump(value) { - if (this.enableDump) { - if (!UhkBuffer.isFirstElementToDump) { - process.stdout.write(', '); - } - process.stdout.write(value); - if (UhkBuffer.isFirstElementToDump) { - UhkBuffer.isFirstElementToDump = false; - } - } else { - UhkBuffer.isFirstElementToDump = true; + if (!this.enableDump) { + return; + } + + if (!UhkBuffer.isFirstElementToDump) { + process.stdout.write(', '); + } + + process.stdout.write(value); + + if (UhkBuffer.isFirstElementToDump) { + UhkBuffer.isFirstElementToDump = false; } } } diff --git a/config-serializer/test-serializer.ts b/config-serializer/test-serializer.ts index a075c17f..0765ffc6 100644 --- a/config-serializer/test-serializer.ts +++ b/config-serializer/test-serializer.ts @@ -18,7 +18,9 @@ let keyActions1BufferContent = keyActions1Buffer.getBufferContent(); fs.writeFileSync('uhk-config.bin', keyActions1BufferContent); keyActions1Buffer.offset = 0; +console.log(); let keyActions2Ts = new KeyActions().fromBinary(keyActions1Buffer); +console.log('\n'); let keyActions2Js = keyActions2Ts.toJsObject(); let keyActions2Buffer = new UhkBuffer(); keyActions2Ts.toBinary(keyActions2Buffer); @@ -45,6 +47,7 @@ fs.writeFileSync('uhk-config-serialized.json', JSON.stringify(modules2Js, undefi let modules2BufferContent = modules1Buffer.getBufferContent(); fs.writeFileSync('uhk-config-serialized.bin', modules2BufferContent); +console.log('\n'); try { /* wanted to also compare class->json & class->binary->class->json with original json */ assert.deepEqual(modulesbaseJs, modules1Js); diff --git a/examples/uhk.key-design.mouse-layer.svg b/examples/uhk.key-design.mouse-layer.svg index d4ec77cd..4e902ec3 100644 --- a/examples/uhk.key-design.mouse-layer.svg +++ b/examples/uhk.key-design.mouse-layer.svg @@ -51,7 +51,7 @@ showgrid="false" inkscape:zoom="1.4585257" inkscape:cx="512.161" - inkscape:cy="290.51895" + inkscape:cy="235.66905" inkscape:window-x="0" inkscape:window-y="0" inkscape:window-maximized="1" @@ -618,8 +618,8 @@ style="fill:#333333;stroke:none" rx="3.5433071" ry="3.5433071" - x="395.1778" - y="160.27048" + x="395.80423" + y="159.85286" height="63.779526" width="63.779526" id="b6" /> @@ -863,154 +863,30 @@ x="340.14719" y="133.07333" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:19px;font-family:Helvetica;-inkscape-font-specification:Helvetica;text-align:center;text-anchor:middle;fill:#ffffff;fill-opacity:1" /> - - - - - Move - - - - - - - - Move - - - - - - - - Move - - - - - - - - Move - - - - - - - - Scroll - - - - - - - - Scroll - - - - - - - - Scroll - - - - - - - - Scroll - - - - - - - - Click - - - Right - - - - - Click - - - Middle - - - - - Click - - - Left - - - - - Click - - - Button 4 - - - - - Click - - - + x="250.27643" + y="341.86749">Button 4 Btn 5 + sodipodi:linespacing="125%" + id="text4768-32" + y="341.4451" + x="393.08392" + style="font-style:normal;font-weight:normal;font-size:14.79448128px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + xml:space="preserve"> - - - - Click - - + id="g4555" + transform="translate(1.7599488,0.08481185)"> + + Scroll + + - Btn 6 + y="339.72635" /> + + + Scroll + + + + + + Move + + + + + + Click + + + + + + Click + + + + + + Click + + + + + + Scroll + + + + + + Scroll + + + + + + Move + + + + + + Move + + + + + + Move + + + + + + Click + + + + + + Click + + + + + + Click + + + + Button 5 + Button 6 diff --git a/examples/uhk.key-design.mouse-layer.with_alignments.svg b/examples/uhk.key-design.mouse-layer.with_alignments.svg index 847917ed..e769f8cf 100644 --- a/examples/uhk.key-design.mouse-layer.with_alignments.svg +++ b/examples/uhk.key-design.mouse-layer.with_alignments.svg @@ -23,7 +23,7 @@ image/svg+xml - + @@ -51,11 +51,11 @@ showgrid="false" inkscape:zoom="1.4585257" inkscape:cx="512.161" - inkscape:cy="290.51895" + inkscape:cy="235.66905" inkscape:window-x="0" inkscape:window-y="0" inkscape:window-maximized="1" - inkscape:current-layer="g4336-9-1-6" + inkscape:current-layer="g4471" units="mm" inkscape:document-units="mm" inkscape:snap-bbox="true" @@ -184,7 +184,7 @@ width="63.779526" height="21.259842" x="613.95819" - y="238.22409" + y="238.22406" rx="3.5433099" ry="3.5433097" /> @@ -1060,154 +1060,30 @@ x="340.14719" y="133.07333" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:19px;font-family:Helvetica;-inkscape-font-specification:Helvetica;text-align:center;text-anchor:middle;fill:#ffffff;fill-opacity:1" /> - - - - - Move - - - - - - - - Move - - - - - - - - Move - - - - - - - - Move - - - - - - - - Scroll - - - - - - - - Scroll - - - - - - - - Scroll - - - - - - - - Scroll - - - - - - - - Click - - - - - - - - Click - - - - - - - - Click - - - - - - - - Click - - - Button 4 + x="250.27643" + y="341.86749">Button 4 - - - - Click - - - - Btn 5 - + id="g4471"> - - - - - - - Click - - Btn 6 + sodipodi:linespacing="125%" + id="text4768-32" + y="341.4451" + x="393.08392" + style="font-style:normal;font-weight:normal;font-size:14.79448128px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + xml:space="preserve"> + + + Scroll + + + + y="339.72635" /> + + + Scroll + + + + + + Move + + + + + + Click + + + + + + Click + + + + + + Click + + + + + + Scroll + + + + + + Scroll + + + + + + Move + + + + + + Move + + + + + + Move + + + + + + Click + + + + + + Click + + + + + + Click + + + + Button 5 + Button 6