mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-21 09:23:00 +00:00
refactor: use standard prettier formatting
This commit is contained in:
@@ -1,37 +1,49 @@
|
||||
import {compressActions, decompressActions} from "./actions"
|
||||
import {fromBase64, toBase64} from "$lib/serialization/base64"
|
||||
import { compressActions, decompressActions } from "./actions";
|
||||
import { fromBase64, toBase64 } from "$lib/serialization/base64";
|
||||
|
||||
export interface NewCharaLayout {
|
||||
charaLayoutVersion: 1
|
||||
device: "one" | "lite" | string
|
||||
charaLayoutVersion: 1;
|
||||
device: "one" | "lite" | string;
|
||||
/**
|
||||
* Layers A1-A3, with numeric action codes on each
|
||||
*/
|
||||
layers: [number[], number[], number[]]
|
||||
layers: [number[], number[], number[]];
|
||||
}
|
||||
|
||||
export type CharaLayout = [number[], number[], number[]]
|
||||
export type CharaLayout = [number[], number[], number[]];
|
||||
|
||||
/**
|
||||
* Serialize a layout into a micro package
|
||||
*/
|
||||
export async function serializeLayout(layout: CharaLayout): Promise<Blob> {
|
||||
const items = compressActions(layout.flat())
|
||||
const stream = new Blob([items]).stream().pipeThrough(new CompressionStream("deflate"))
|
||||
return new Response(stream).blob()
|
||||
const items = compressActions(layout.flat());
|
||||
const stream = new Blob([items])
|
||||
.stream()
|
||||
.pipeThrough(new CompressionStream("deflate"));
|
||||
return new Response(stream).blob();
|
||||
}
|
||||
|
||||
export async function deserializeLayout(layout: Blob): Promise<CharaLayout> {
|
||||
const stream = layout.stream().pipeThrough(new DecompressionStream("deflate"))
|
||||
const raw = await new Response(stream).arrayBuffer()
|
||||
const actions = decompressActions(new Uint8Array(raw))
|
||||
return [actions.slice(0, 90), actions.slice(90, 180), actions.slice(180, 270)]
|
||||
const stream = layout
|
||||
.stream()
|
||||
.pipeThrough(new DecompressionStream("deflate"));
|
||||
const raw = await new Response(stream).arrayBuffer();
|
||||
const actions = decompressActions(new Uint8Array(raw));
|
||||
return [
|
||||
actions.slice(0, 90),
|
||||
actions.slice(90, 180),
|
||||
actions.slice(180, 270),
|
||||
];
|
||||
}
|
||||
|
||||
export async function layoutAsUrlComponent(layout: CharaLayout): Promise<string> {
|
||||
return serializeLayout(layout).then(toBase64)
|
||||
export async function layoutAsUrlComponent(
|
||||
layout: CharaLayout,
|
||||
): Promise<string> {
|
||||
return serializeLayout(layout).then(toBase64);
|
||||
}
|
||||
|
||||
export async function layoutFromUrlComponent(base64: string): Promise<CharaLayout> {
|
||||
return fromBase64(base64).then(deserializeLayout)
|
||||
export async function layoutFromUrlComponent(
|
||||
base64: string,
|
||||
): Promise<CharaLayout> {
|
||||
return fromBase64(base64).then(deserializeLayout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user