From 3a6483aa61e71e7734319f67320fac6536137a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Wed, 29 Nov 2023 01:06:24 +0100 Subject: [PATCH] feat: combine save/apply resolves #45 --- src/i18n/de/index.ts | 6 +- src/i18n/en/index.ts | 6 +- .../backup/compat/legacy-chords.sample.csv | 26 ++++ .../backup/compat/legacy-chords.sample.json | 26 ++++ src/lib/backup/compat/legacy-chords.ts | 21 +++ src/routes/EditActions.svelte | 145 +++--------------- src/routes/SyncOverlay.svelte | 1 - 7 files changed, 97 insertions(+), 134 deletions(-) create mode 100644 src/lib/backup/compat/legacy-chords.sample.csv create mode 100644 src/lib/backup/compat/legacy-chords.sample.json create mode 100644 src/lib/backup/compat/legacy-chords.ts diff --git a/src/i18n/de/index.ts b/src/i18n/de/index.ts index 46c6f5e5..85ccf73f 100644 --- a/src/i18n/de/index.ts +++ b/src/i18n/de/index.ts @@ -1,4 +1,4 @@ -import type {Translation} from "../i18n-types" +import type { Translation } from "../i18n-types" const de = { TITLE: "CharaChorder Gerätemanager", @@ -11,9 +11,7 @@ const de = { }, sync: { TITLE_READ: "Neueste Änderungen werden abgerufen", - TITLE_WRITE: "Änderungen werden gebrannt", - DISCLAIMER_WRITE: - "Das Brennen von Änderungen ist nur für Layouts und Einstellungen erforderlich wenn diese Neustarts überdauern sollen. Bei Akkorden passiert das brennen automatisch beim anwenden.", + TITLE_WRITE: "Änderungen werden gespeichert", }, backup: { TITLE: "Sicherungskopie", diff --git a/src/i18n/en/index.ts b/src/i18n/en/index.ts index cee960be..c3b8a160 100644 --- a/src/i18n/en/index.ts +++ b/src/i18n/en/index.ts @@ -1,4 +1,4 @@ -import type {BaseTranslation} from "../i18n-types" +import type { BaseTranslation } from "../i18n-types" const en = { TITLE: "CharaChorder Device Manager", @@ -18,9 +18,7 @@ const en = { }, sync: { TITLE_READ: "Reading latest changes", - TITLE_WRITE: "Burning changes to device", - DISCLAIMER_WRITE: - "Burning is only necessary if you want your layout or settings to persist across reboots. Chords always persist automatically on apply.", + TITLE_WRITE: "Saving changes to device", }, modal: { CLOSE: "Close", diff --git a/src/lib/backup/compat/legacy-chords.sample.csv b/src/lib/backup/compat/legacy-chords.sample.csv new file mode 100644 index 00000000..93c0ef49 --- /dev/null +++ b/src/lib/backup/compat/legacy-chords.sample.csv @@ -0,0 +1,26 @@ +e + b + a,babe +e + c + b,because +f + e + c + a,face +h + e + c + a,each +i + d + ',I'd +i + g + b,big +i + g + e,give +k + b + a,back +k + e + a,take +l + e + a,late +l + e + d + a,lead +l + f + e,feel +l + g + e + a,large +l + h + e,help +l + i + a,Lia +l + i + f,fill +l + i + f + e,life +l + i + g + b + a,gitlab +l + k + i + e,like +m + e + a,make +m + i + ',I'm +n + c + a,can +n + d + a,and +n + e + b,been +n + e + b + a,enable +n + e + d,end diff --git a/src/lib/backup/compat/legacy-chords.sample.json b/src/lib/backup/compat/legacy-chords.sample.json new file mode 100644 index 00000000..93c0ef49 --- /dev/null +++ b/src/lib/backup/compat/legacy-chords.sample.json @@ -0,0 +1,26 @@ +e + b + a,babe +e + c + b,because +f + e + c + a,face +h + e + c + a,each +i + d + ',I'd +i + g + b,big +i + g + e,give +k + b + a,back +k + e + a,take +l + e + a,late +l + e + d + a,lead +l + f + e,feel +l + g + e + a,large +l + h + e,help +l + i + a,Lia +l + i + f,fill +l + i + f + e,life +l + i + g + b + a,gitlab +l + k + i + e,like +m + e + a,make +m + i + ',I'm +n + c + a,can +n + d + a,and +n + e + b,been +n + e + b + a,enable +n + e + d,end diff --git a/src/lib/backup/compat/legacy-chords.ts b/src/lib/backup/compat/legacy-chords.ts new file mode 100644 index 00000000..653e3396 --- /dev/null +++ b/src/lib/backup/compat/legacy-chords.ts @@ -0,0 +1,21 @@ +import { KEYMAP_IDS } from "$lib/serial/keymap-codes" +import type { CharaChordFile } from "$lib/share/chara-file" + + +export function csvChordsToJson(csv: string): CharaChordFile { + return { + charaVersion: 1, + type: 'chords', + chords: csv.split('\n').map(line => { + const [input, output] = line.split(',', 2) + return [ + input.split('+').map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0), + output.split('').map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0), + ] + }) + } +} + +export function isCsvLayout(csv: string): boolean { + return /^((\s*\w+\s*+?),\s*\w+\n?)+$/.test(csv) +} diff --git a/src/routes/EditActions.svelte b/src/routes/EditActions.svelte index 664274b5..32250fee 100644 --- a/src/routes/EditActions.svelte +++ b/src/routes/EditActions.svelte @@ -2,7 +2,7 @@ import LL from "../i18n/i18n-svelte" import {changes, ChangeType, chords, layout, overlay, settings} from "$lib/undo-redo" import type {Change} from "$lib/undo-redo" - import {fly} from "svelte/transition" + import {fly, slide} from "svelte/transition" import {action} from "$lib/title" import { deviceChords, @@ -34,10 +34,9 @@ } let redoQueue: Change[] = [] - async function apply() { + async function save() { const port = $serialPort if (!port) return - $syncStatus = "uploading" for (const [id, {actions, phrase}] of $overlay.chords) { @@ -79,21 +78,7 @@ await port.setSetting(id, setting) } - $deviceLayout = $layout.map(layer => layer.map(({action}) => action)) as [ - number[], - number[], - number[], - ] - $deviceChords = $chords - .map(({actions, phrase}) => ({actions, phrase})) - .filter(({phrase}) => phrase.length > 1) - $deviceSettings = $settings.map(({value}) => value) - $changes = [] - $syncStatus = "done" - } - async function flashChanges() { - $syncStatus = "uploading" // Yes, this is a completely arbitrary and unnecessary delay. // The only purpose of it is to create a sense of weight, // aka make it more "energy intensive" to click. @@ -101,7 +86,7 @@ // would be if they click it every time they change a setting. // Because of that, we don't need to show a fearmongering message such as // "Your device will break after you click this 10,000 times!" - const virtualWriteTime = 6000 + const virtualWriteTime = 1000 const startStamp = performance.now() await new Promise(resolve => { function animate() { @@ -118,83 +103,22 @@ } requestAnimationFrame(animate) }) - if ($serialPort) { - await $serialPort.commit() - $changes = [] - } + await port.commit() + + $deviceLayout = $layout.map(layer => layer.map(({action}) => action)) as [ + number[], + number[], + number[], + ] + $deviceChords = $chords + .map(({actions, phrase}) => ({actions, phrase})) + .filter(({phrase}) => phrase.length > 1) + $deviceSettings = $settings.map(({value}) => value) + $changes = [] $syncStatus = "done" } - - -
- {#if $changes.length !== 0} +
save {/if}