mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-15 17:33:03 +00:00
fix: header transformation plugin not properly handling utf-8 characters
This commit is contained in:
@@ -12,6 +12,8 @@ interface PublicDirFile {
|
||||
relativePath: string;
|
||||
}
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
function getPublicDirFiles(publicDir?: string): PublicDirFile[] {
|
||||
if (!publicDir) return [];
|
||||
|
||||
@@ -41,20 +43,23 @@ function createVarName(fileName: string) {
|
||||
function transformAsset(asset: MinimalOutputAsset) {
|
||||
const varName = createVarName(asset.fileName);
|
||||
|
||||
let bytes: string;
|
||||
let buffer: Uint8Array;
|
||||
if (typeof asset.source === "string") {
|
||||
bytes = [...asset.source].map((v) => String(v.charCodeAt(0))).join(",");
|
||||
buffer = textEncoder.encode(asset.source);
|
||||
} else {
|
||||
bytes = [...asset.source].map((v) => String(v)).join(",");
|
||||
buffer = asset.source;
|
||||
}
|
||||
|
||||
const bytes = [...buffer].map((v) => String(v)).join(",");
|
||||
|
||||
return `constexpr const unsigned char ${varName}[] {${bytes}};
|
||||
`;
|
||||
}
|
||||
|
||||
function transformChunk(chunk: MinimalOutputChunk) {
|
||||
const varName = createVarName(chunk.fileName);
|
||||
const bytes = [...chunk.code].map((v) => String(v.charCodeAt(0))).join(",");
|
||||
const buffer = textEncoder.encode(chunk.code);
|
||||
const bytes = [...buffer].map((v) => String(v)).join(",");
|
||||
|
||||
return `constexpr const unsigned char ${varName}[] {${bytes}};
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user