Commit 57ab45b7 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/name' into 'main'

fix name

See merge request mycard/Neos!97
parents 4bb4fe41 03a19480
Pipeline #19946 passed with stages
in 5 minutes and 42 seconds
import { ygopro } from "../../idl/ocgcore"; import { ygopro } from "../../idl/ocgcore";
import { YgoProPacket, StocAdapter } from "../packet"; 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; const UINT8_PER_UINT16 = 2;
...@@ -24,7 +24,7 @@ export default class HsPlayerEnterAdapter implements StocAdapter { ...@@ -24,7 +24,7 @@ export default class HsPlayerEnterAdapter implements StocAdapter {
const decoder = new TextDecoder("utf-16"); const decoder = new TextDecoder("utf-16");
const name = decoder.decode( 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); const dataView = new DataView(exData.buffer);
......
...@@ -210,3 +210,22 @@ export function numberToChainFlag( ...@@ -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