mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-05 01:22:50 +00:00
fix: chords can't be deleted
This commit is contained in:
@@ -211,6 +211,7 @@ export class CharaDevice {
|
||||
}
|
||||
|
||||
async deleteChord(chord: Pick<Chord, "actions">) {
|
||||
console.log(`CML C4 ${stringifyChordActions(chord.actions)}`)
|
||||
const status = await this.send(`CML C4 ${stringifyChordActions(chord.actions)}`)
|
||||
if (status.at(-1) !== "0") throw new Error(`Failed with status ${status}`)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<script lang="ts">
|
||||
import LL from "../i18n/i18n-svelte"
|
||||
import {changes, ChangeType, chords, layout, settings} from "$lib/undo-redo"
|
||||
import {changes, ChangeType, chords, layout, overlay, settings} from "$lib/undo-redo"
|
||||
import type {Change} from "$lib/undo-redo"
|
||||
import {fly} from "svelte/transition"
|
||||
import {action} from "$lib/title"
|
||||
import {deviceChords, deviceLayout, deviceSettings, serialPort, syncStatus} from "$lib/serial/connection"
|
||||
import {deserializeActions} from "$lib/serial/chord"
|
||||
|
||||
function undo() {
|
||||
redoQueue = [$changes.pop()!, ...redoQueue]
|
||||
@@ -26,23 +27,26 @@
|
||||
if (!port) return
|
||||
|
||||
$syncStatus = "uploading"
|
||||
for (const change of $changes) {
|
||||
switch (change.type) {
|
||||
case ChangeType.Layout:
|
||||
await port.setLayoutKey(change.layer + 1, change.id, change.action)
|
||||
break
|
||||
case ChangeType.Chord:
|
||||
if (change.phrase.length > 0) {
|
||||
await port.setChord({actions: change.actions, phrase: change.phrase})
|
||||
} else {
|
||||
await port.deleteChord({actions: change.actions})
|
||||
}
|
||||
break
|
||||
case ChangeType.Setting:
|
||||
await port.setSetting(change.id, change.setting)
|
||||
break
|
||||
|
||||
for (const [id, phrase] of $overlay.chords) {
|
||||
const actions = deserializeActions(id)
|
||||
if (actions.length > 0) {
|
||||
await port.setChord({actions, phrase})
|
||||
} else {
|
||||
await port.deleteChord({actions})
|
||||
}
|
||||
}
|
||||
|
||||
for (const [layer, actions] of $overlay.layout.entries()) {
|
||||
for (const [id, action] of actions) {
|
||||
await port.setLayoutKey(layer + 1, id, action)
|
||||
}
|
||||
}
|
||||
|
||||
for (const [id, setting] of $overlay.settings) {
|
||||
await port.setSetting(id, setting)
|
||||
}
|
||||
|
||||
$deviceLayout = $layout.map(layer => layer.map<number>(({action}) => action)) as [
|
||||
number[],
|
||||
number[],
|
||||
|
||||
Reference in New Issue
Block a user