Skip to content

Commit

Permalink
生成物编的meta
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Nov 18, 2024
1 parent 28f4d6a commit 923004b
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 117 deletions.
71 changes: 0 additions & 71 deletions src/customDefine/editorTables.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/customDefine/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PlayerAttrs } from "./playerAttrs";
import { UnitAttrs } from "./unitAttrs";
import { EditorTables } from "./editorTables";
import { Events } from "./event";
import { UI } from "./ui";
import { UIAnim } from "./uiAnim";
Expand All @@ -11,11 +10,6 @@ export const define = {
单位属性: new UnitAttrs,
玩家属性: new PlayerAttrs,
自定义事件: new Events,
单位类型: new EditorTables("editorunit"),
技能类型: new EditorTables("abilityall"),
物品类型: new EditorTables("editoritem"),
魔法效果类型: new EditorTables("modifierall"),
投射物类型: new EditorTables("projectileall"),
界面: new UI,
时间轴动画: new UIAnim,
跳字: new JumpWord,
Expand Down
2 changes: 1 addition & 1 deletion src/editorTable/editorTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ interface CreateOptions<N extends Table.NameCN> {
overwrite?: boolean,
}

export class EditorTable<N extends Table.NameCN> extends vscode.Disposable {
export class EditorTable<N extends Table.NameCN = Table.NameCN> extends vscode.Disposable {
public uri;
public nameEN;
private _objectCache: { [key: number]: EditorObject<N> | null | undefined } = {};
Expand Down
2 changes: 1 addition & 1 deletion src/luaLanguage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LanguageServer {
vscode.languages.registerHoverProvider('lua', new HoverProvider());
vscode.languages.registerInlayHintsProvider('lua', new InlayHintProvider());
vscode.languages.registerDefinitionProvider('lua', new DefinitionProvider());
vscode.languages.registerCompletionItemProvider('lua', new CompletionProvider(), ...'0123456789');
//vscode.languages.registerCompletionItemProvider('lua', new CompletionProvider(), ...'0123456789');
}
}

Expand Down
38 changes: 0 additions & 38 deletions src/metaBuilder/editorTables.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/metaBuilder/initBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { UI } from './ui';
import { UIAnim } from './uiAnim';
import { JumpWord } from './jumpword';
import { Font } from './font';
import { Objects } from './objects';

let path = 'y3-helper/meta';

Expand Down Expand Up @@ -55,4 +56,5 @@ export function init() {
initBuilder.addChild(UIAnim, 'uiAnim.lua');
initBuilder.addChild(JumpWord, 'jumpword.lua');
initBuilder.addChild(Font, 'font.lua');
//initBuilder.addChild(Objects, 'objects.lua');
}
55 changes: 55 additions & 0 deletions src/metaBuilder/objects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { BaseBuilder } from './baseBuilder';
import * as y3 from 'y3-helper';

const template =
`---@alias py.%{NAME}KeyEnum integer
%{KEYS}
`;

export class Objects extends BaseBuilder {
constructor(path: string) {
super(path);
this.update();
y3.env.onDidChange(() => {
this.update();
this.updateTables();
});
}

private tables: Map<y3.consts.Table.NameCN, y3.table.EditorTable> = new Map();
private updateTables() {
for (let key in y3.consts.Table.name.fromCN) {
let name = key as y3.consts.Table.NameCN;
let current = this.tables.get(name);
if (!current) {
let table = y3.table.openTable(name);
this.tables.set(name, table);
table.onDidChange(() => {
this.update();
this.updateTables();
});
}
}
}

private async makeOne(table: y3.table.EditorTable) {
let keyList = await table.getList();
let enName = y3.consts.Table.name.fromCN[table.name];
let text = template
. replace('%{NAME}', enName[0].toUpperCase() + enName.slice(1))
. replace('%{KEYS}', keyList.map((key) => {
return `---| ${key}`;
}).join('\r\n'));
return text;
}

async make() {
let texts = await Promise.all(
Array.from(this.tables.values()).map((table) => {
return this.makeOne(table);
})
);
return texts.join('\r\n');
}

}

0 comments on commit 923004b

Please sign in to comment.