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