mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-22 01:42:47 +00:00
refactor: use standard prettier formatting
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
import {compressActions, decompressActions} from "../serialization/actions"
|
||||
import { compressActions, decompressActions } from "../serialization/actions";
|
||||
|
||||
export interface Chord {
|
||||
actions: number[]
|
||||
phrase: number[]
|
||||
actions: number[];
|
||||
phrase: number[];
|
||||
}
|
||||
|
||||
export function parsePhrase(phrase: string): number[] {
|
||||
return decompressActions(
|
||||
Uint8Array.from({length: phrase.length / 2}).map((_, i) =>
|
||||
Uint8Array.from({ length: phrase.length / 2 }).map((_, i) =>
|
||||
Number.parseInt(phrase.slice(i * 2, i * 2 + 2), 16),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function stringifyPhrase(phrase: number[]): string {
|
||||
return [...compressActions(phrase)]
|
||||
.map(it => it.toString(16).padStart(2, "0"))
|
||||
.map((it) => it.toString(16).padStart(2, "0"))
|
||||
.join("")
|
||||
.toUpperCase()
|
||||
.toUpperCase();
|
||||
}
|
||||
|
||||
export function parseChordActions(actions: string): number[] {
|
||||
return deserializeActions(BigInt(`0x${actions}`))
|
||||
return deserializeActions(BigInt(`0x${actions}`));
|
||||
}
|
||||
|
||||
export function stringifyChordActions(actions: number[]): string {
|
||||
return serializeActions(actions).toString(16).padStart(32, "0").toUpperCase()
|
||||
return serializeActions(actions).toString(16).padStart(32, "0").toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,23 +34,24 @@ export function stringifyChordActions(actions: number[]): string {
|
||||
* Actions are represented as 10-bit codes, for a maximum of 12 actions
|
||||
*/
|
||||
export function serializeActions(actions: number[]): bigint {
|
||||
let native = 0n
|
||||
let native = 0n;
|
||||
for (let i = 1; i <= actions.length; i++) {
|
||||
native |= BigInt(actions[actions.length - i] & 0x3ff) << BigInt((12 - i) * 10)
|
||||
native |=
|
||||
BigInt(actions[actions.length - i] & 0x3ff) << BigInt((12 - i) * 10);
|
||||
}
|
||||
return native
|
||||
return native;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {serializeActions}
|
||||
*/
|
||||
export function deserializeActions(native: bigint): number[] {
|
||||
const actions = []
|
||||
const actions = [];
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const action = Number(native & 0x3ffn)
|
||||
actions.push(action)
|
||||
native >>= 10n
|
||||
const action = Number(native & 0x3ffn);
|
||||
actions.push(action);
|
||||
native >>= 10n;
|
||||
}
|
||||
|
||||
return actions
|
||||
return actions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user