mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
handle nested messages correctly
This commit is contained in:
1 parent
0e637d772e
commit
f95a6e3495
3 files changed
+35
-47
No files matched your search
+2
-2
@@ -4,13 +4,13 @@
|
||||
"license": "BlitzKit License",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"setup": "bun install && bun run build:protos && bun run build:proxyclient && bun run build:catalogitemaccesssor",
|
||||
"setup": "bun install && bun run build:protos && bun run build:proxyclient && bun run build:catalogitemaccessor",
|
||||
"dev": "bun run dev:website",
|
||||
"dev:website": "cd packages/website-ue && bun run dev",
|
||||
"build:game": "cd packages/game && bun run build",
|
||||
"build:website": "cd packages/website-ue && bun run build",
|
||||
"build:proxyclient": "cd packages/scripts && bun run build:proxyclient",
|
||||
"build:catalogitemaccesssor": "cd packages/scripts && bun run build:catalogitemaccesssor",
|
||||
"build:catalogitemaccessor": "cd packages/scripts && bun run build:catalogitemaccessor",
|
||||
"build:protos": "cd packages/scripts && bun run build:protos",
|
||||
"lint": "tsc",
|
||||
"lint:website": "cd packages/website-ue && bun run lint"
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
"build:bot": "bun src/buildBot.ts",
|
||||
"build:ratingleaderboard": "bun src/buildRatingLeaderboard.ts",
|
||||
"build:proxyclient": "bun src/buildProxyClient.ts",
|
||||
"build:catalogitemaccesssor": "bun src/buildCatalogItemAccessor.ts",
|
||||
"build:catalogitemaccessor": "bun src/buildCatalogItemAccessor.ts",
|
||||
"build:protos": "bun src/protos.ts",
|
||||
"patchnotes": "bun src/patchNotes.ts"
|
||||
},
|
||||
|
||||
@@ -1,62 +1,50 @@
|
||||
import { readdir, readFile, writeFile } from "fs/promises";
|
||||
import { lowerFirst } from "lodash-es";
|
||||
|
||||
const SOURCES = "../../packages/closed/protos/blitz";
|
||||
const SOURCES = "../../packages/closed/protos";
|
||||
const TARGET = "../../packages/closed/src/unreal/catalogItemAccessor.ts";
|
||||
|
||||
const componentPattern = /^message (\w+)Component {/gm;
|
||||
const componentPattern = /^export interface (\w+Component) {/gm;
|
||||
const componentSuffixPattern = /Component$/;
|
||||
const tsSuffixPattern = /\.ts$/;
|
||||
|
||||
const files = await readdir(SOURCES).then((files) =>
|
||||
files.filter(
|
||||
(file) =>
|
||||
file.startsWith("blitz_static_") && file.endsWith("_component.proto"),
|
||||
),
|
||||
);
|
||||
let imports = "";
|
||||
let methods = "";
|
||||
|
||||
const imports: { name: string; file: string }[] = [];
|
||||
const files = await readdir(SOURCES);
|
||||
|
||||
for (const file of files) {
|
||||
const content = await readFile(`${SOURCES}/${file}`).then((buffer) =>
|
||||
buffer.toString(),
|
||||
);
|
||||
const components = content.matchAll(componentPattern);
|
||||
if (!file.endsWith("_component.ts")) continue;
|
||||
|
||||
for (const match of components) {
|
||||
const name = match[1];
|
||||
const duplicate = imports.find((_import) => _import.name === name);
|
||||
const buffer = await readFile(`${SOURCES}/${file}`);
|
||||
const content = buffer.toString();
|
||||
const matches = content.matchAll(componentPattern);
|
||||
|
||||
if (duplicate) {
|
||||
console.warn(
|
||||
`Duplicate component ${name} across ${duplicate.file}.proto and ${file}`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
for (const match of matches) {
|
||||
const interfaceName = match[1];
|
||||
const componentName = interfaceName.split("_").at(-1)!;
|
||||
|
||||
const importFile = file.replace(".proto", "");
|
||||
if (componentName.startsWith("BlitzStatic")) continue;
|
||||
|
||||
imports.push({ name, file: importFile });
|
||||
const fieldName = lowerFirst(componentName);
|
||||
const methodName = componentName.replace(componentSuffixPattern, "");
|
||||
const importName = file.replace(tsSuffixPattern, "");
|
||||
|
||||
imports += `import { ${interfaceName} } from "@protos/${importName}";\n`;
|
||||
|
||||
methods += ` ${methodName}(name = "${fieldName}") {\n`;
|
||||
methods += ` return this.component(name, ${interfaceName});`;
|
||||
methods += "\n }\n";
|
||||
}
|
||||
}
|
||||
|
||||
let content = "";
|
||||
let body = "";
|
||||
|
||||
for (const _import of imports) {
|
||||
content += `import { ${_import.name}Component } from "@protos/${_import.file}";\n`;
|
||||
}
|
||||
|
||||
content +=
|
||||
body += imports;
|
||||
body +=
|
||||
'import { BaseCatalogItemAccessor } from "./baseCatalogItemAccessor";\n\n';
|
||||
content +=
|
||||
"export class CatalogItemAccessor extends BaseCatalogItemAccessor {\n";
|
||||
body += `export class CatalogItemAccessor extends BaseCatalogItemAccessor {\n`;
|
||||
body += methods;
|
||||
body += `}\n`;
|
||||
|
||||
for (const _import of imports) {
|
||||
const strippedName = _import.name.replace("BlitzStatic", "");
|
||||
const defaultName = strippedName[0].toLowerCase() + strippedName.slice(1);
|
||||
|
||||
content += ` ${strippedName}(name = "${defaultName}Component") {\n`;
|
||||
content += ` return this.component(name, ${_import.name}Component);\n`;
|
||||
content += " }\n";
|
||||
}
|
||||
|
||||
content += "}\n";
|
||||
|
||||
await writeFile(TARGET, content);
|
||||
await writeFile(TARGET, body);
|
||||
Reference in new issue
Block a user