mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2025-12-24 03:36:20 +00:00
fix: legacy chords with commas and spaces
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import {KEYMAP_IDS} from "$lib/serial/keymap-codes"
|
import {KEYMAP_IDS} from "$lib/serial/keymap-codes"
|
||||||
import type {CharaChordFile} from "$lib/share/chara-file"
|
import type {CharaChordFile} from "$lib/share/chara-file"
|
||||||
|
|
||||||
|
const SPECIAL_KEYS = new Map<string, string>([[" ", "SPACE"]])
|
||||||
|
|
||||||
export function csvChordsToJson(csv: string): CharaChordFile {
|
export function csvChordsToJson(csv: string): CharaChordFile {
|
||||||
return {
|
return {
|
||||||
charaVersion: 1,
|
charaVersion: 1,
|
||||||
@@ -9,18 +11,18 @@ export function csvChordsToJson(csv: string): CharaChordFile {
|
|||||||
.trim()
|
.trim()
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map(line => {
|
.map(line => {
|
||||||
const [input, output] = line.split(",", 2)
|
const [input, output] = line.split(/,(?=[^,]*$)/, 2)
|
||||||
return [
|
return [
|
||||||
input.split("+").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0),
|
input.split("+").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0),
|
||||||
output
|
output
|
||||||
.trim()
|
.trim()
|
||||||
.split("")
|
.split("")
|
||||||
.map(it => KEYMAP_IDS.get(it)?.code ?? 0),
|
.map(it => KEYMAP_IDS.get(SPECIAL_KEYS.get(it) ?? it)?.code ?? 0),
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isCsvChords(csv: string): boolean {
|
export function isCsvChords(csv: string): boolean {
|
||||||
return /^([^+, ]+( *\+ *[^+, ]+)* *, *[^+, ]+ *(\n|(?=$)))+$/.test(csv)
|
return /^([^+]+( *\+ *[^+]+)* *, *[^+, ]+ *(\n|(?=$)))+$/.test(csv)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user