Commit 03a19480 authored by Chunchi Che's avatar Chunchi Che

fix name

parent 40cc2454
Pipeline #19945 passed with stages
in 5 minutes and 33 seconds
import { ygopro } from "../../idl/ocgcore";
import { YgoProPacket, StocAdapter } from "../packet";
import { UTF16_BUFFER_MAX_LEN } from "../util";
import { UTF16_BUFFER_MAX_LEN, _cutoff_name } from "../util";
const UINT8_PER_UINT16 = 2;
......@@ -24,7 +24,7 @@ export default class HsPlayerEnterAdapter implements StocAdapter {
const decoder = new TextDecoder("utf-16");
const name = decoder.decode(
exData.slice(0, UTF16_BUFFER_MAX_LEN * UINT8_PER_UINT16)
_cutoff_name(exData.slice(0, UTF16_BUFFER_MAX_LEN * UINT8_PER_UINT16))
);
const dataView = new DataView(exData.buffer);
......
......@@ -210,3 +210,22 @@ export function numberToChainFlag(
}
}
}
const chunkItems = <T>(items: T[]) =>
items.reduce((chunks: T[][], item: T, index) => {
const chunk = Math.floor(index / 2);
chunks[chunk] = ([] as T[]).concat(chunks[chunk] || [], item);
return chunks;
}, []);
export function _cutoff_name(data: Uint8Array): Uint8Array {
let res: number[] = [];
for (const char of chunkItems(Array.from(data))) {
if (!char.every((item) => item == 0)) {
res = res.concat(char);
} else {
break;
}
}
return Uint8Array.from(res);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment