From 3f85b6a39f06900f29840b2010b583f59a5d5301 Mon Sep 17 00:00:00 2001 From: Yoichiro Tanaka Date: Fri, 22 Sep 2023 12:00:33 +0900 Subject: [PATCH 1/3] Fix the encoder rendering issue. --- src/assets/keymaps/FrogNpKeymap.ts | 12 ++++++++---- src/models/KeyModel.ts | 12 +++++++++--- src/models/KeyboardModel.ts | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/assets/keymaps/FrogNpKeymap.ts b/src/assets/keymaps/FrogNpKeymap.ts index 56a8dff7..1e252790 100644 --- a/src/assets/keymaps/FrogNpKeymap.ts +++ b/src/assets/keymaps/FrogNpKeymap.ts @@ -22,10 +22,14 @@ export const FrogNpKeymap = [ y: 0.25, x: 4.5, }, - '1,0', - '1,1', - '1,2', - '1,3', + '1,0\n\n\n\n\n\n\n\n\ne2', + { a: 3 }, + 'e3', + { a: 4 }, + { a: 7 }, + 'e4', + { a: 4 }, + '\n\n\n\n\n\n\n\n\ne5', ], [ { diff --git a/src/models/KeyModel.ts b/src/models/KeyModel.ts index 5f31e716..ccbea4d9 100644 --- a/src/models/KeyModel.ts +++ b/src/models/KeyModel.ts @@ -55,14 +55,20 @@ export default class KeyModel { this.encoderId = encoderId; this.location = location; const locs = location.split('\n'); - this.pos = locs[0]; + if (this.location.match(/^e[0-9]+$/i)) { + this.pos = ''; + } else { + this.pos = locs[0]; + } if (!this.includePosition(this.pos) && this.encoderId === null) { // If there is no position label and this is not an encoder, // this Key should be "Decal". this.keyOp = { ...(this.keyOp || {}), ...{ d: true } }; } - this.optionLabel = - 4 <= locs.length ? locs[3] : `${OPTION_DEFAULT},${OPTION_DEFAULT}`; + this.optionLabel = `${OPTION_DEFAULT},${OPTION_DEFAULT}`; + if (4 <= locs.length && 0 < locs[3].length) { + this.optionLabel = locs[3]; + } const options = this.optionLabel.split(','); this.option = options[0]; this.optionChoice = options[1]; diff --git a/src/models/KeyboardModel.ts b/src/models/KeyboardModel.ts index 0daf61da..5b4f947d 100644 --- a/src/models/KeyboardModel.ts +++ b/src/models/KeyboardModel.ts @@ -272,7 +272,7 @@ export default class KeyboardModel { curr.nextRow(keyRow[0]); for (let col = 0; col < keyRow.length; col++) { - const item: string | KeyOp = keyRow[col]; // KeyMapOp or string('rwo,col') + const item: string | KeyOp = keyRow[col]; // KeyMapOp or string('row,col') let keymapItem: KeymapItem; if (typeof item === 'string') { From 62602cdd115860ddd4a069c3bf760035c214c7de Mon Sep 17 00:00:00 2001 From: Yoichiro Tanaka Date: Fri, 22 Sep 2023 12:02:34 +0900 Subject: [PATCH 2/3] Fix the test case. --- src/models/KeyboardModel.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/models/KeyboardModel.test.ts b/src/models/KeyboardModel.test.ts index e30e3dd1..12653ad1 100644 --- a/src/models/KeyboardModel.test.ts +++ b/src/models/KeyboardModel.test.ts @@ -27,7 +27,7 @@ describe('KeyboardModel', () => { expect(actual[0].x).toEqual(0); expect(actual[0].y).toEqual(0); expect(actual[1].location).toEqual('e0'); - expect(actual[1].pos).toEqual('e0'); + expect(actual[1].pos).toEqual(''); expect(actual[1].optionLabel).toEqual('-,-'); expect(actual[1].option).toEqual('-'); expect(actual[1].optionChoice).toEqual('-'); @@ -36,9 +36,9 @@ describe('KeyboardModel', () => { expect(actual[1].y).toEqual(0); expect(actual[2].location).toEqual('0,1\n\n\n\n\n\n\n\n\ne1'); expect(actual[2].pos).toEqual('0,1'); - expect(actual[2].optionLabel).toEqual(''); - expect(actual[2].option).toEqual(''); - expect(actual[2].optionChoice).toBeUndefined(); + expect(actual[2].optionLabel).toEqual('-,-'); + expect(actual[2].option).toEqual('-'); + expect(actual[2].optionChoice).toEqual('-'); expect(actual[2].encoderId).toEqual(1); expect(actual[2].x).toEqual(2); expect(actual[2].y).toEqual(0); From 7d58c295a75b7361cfeb6a8643cb0299ec086576 Mon Sep 17 00:00:00 2001 From: Yoichiro Tanaka Date: Fri, 22 Sep 2023 12:08:12 +0900 Subject: [PATCH 3/3] Add a comment. --- src/models/KeyModel.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/models/KeyModel.ts b/src/models/KeyModel.ts index ccbea4d9..07e6bb4e 100644 --- a/src/models/KeyModel.ts +++ b/src/models/KeyModel.ts @@ -55,6 +55,9 @@ export default class KeyModel { this.encoderId = encoderId; this.location = location; const locs = location.split('\n'); + // If the location is only encoder ID like 'e0', the pos is empty. + // This is for the case that the encoder is defined as like + // "{a:3},"e0",{a:4}" or "{a:7},"e0",{a:4}". if (this.location.match(/^e[0-9]+$/i)) { this.pos = ''; } else {