Skip to content

Commit

Permalink
场景UI的meta
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed May 21, 2024
1 parent 199c768 commit d81782a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/metaBuilder/initBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BaseBuilder } from './baseBuilder';
import { env } from '../env';
import { PlayerAttrs } from './playerAttrs';
import { CustomEvents } from './customEvents';
import { UI } from './ui';

let path = 'y3-helper/meta';

Expand Down Expand Up @@ -38,10 +39,12 @@ export function init() {
let unitAttrs = new UnitAttrs(path + '/unitAttrs.lua');
let playerAttrs = new PlayerAttrs(path + '/playerAttrs.lua');
let customEvents = new CustomEvents(path + '/customEvents.lua');
let ui = new UI(path + '/ui.lua');

initBuilder.addFile(unitAttrs);
initBuilder.addFile(playerAttrs);
initBuilder.addFile(customEvents);
initBuilder.addFile(ui);

unitAttrs.onDidChange(() => {
initBuilder.update();
Expand All @@ -52,4 +55,7 @@ export function init() {
customEvents.onDidChange(() => {
initBuilder.update();
});
ui.onDidChange(() => {
initBuilder.update();
});
}
2 changes: 1 addition & 1 deletion src/metaBuilder/playerAttrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local PlayerAttr = {
%{ATTR_ENUMS}
}
y3.util.tableMerge(y3.const.PlayerAttr, PlayerAttr)
y3.util.tableMerge(y3.const.PlayerAttr or {}, PlayerAttr)
`;

export class PlayerAttrs extends BaseBuilder {
Expand Down
33 changes: 33 additions & 0 deletions src/metaBuilder/ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { define } from '../customDefine';
import { BaseBuilder } from './baseBuilder';

const template =
`---@enum(key, partial) y3.Const.SceneUI
local SceneUI = {
%{UI_ENUMS}
}
y3.util.tableMerge(y3.const.SceneUI or {}, SceneUI)
`;

export class UI extends BaseBuilder {
constructor(path: string) {
super(path);
this.update();
define.界面.onDidChange(() => {
this.update();
});
}

async make() {
let uiPackage = await define.界面.getUIPackage();
let sceneUIs = uiPackage.场景UI;
if (sceneUIs.length === 0) {
return;
}
return template.replace('%{UI_ENUMS}', sceneUIs.map(sceneUI => {
return ` ["${sceneUI.name}"] = "${sceneUI.uid}",`;
}).join('\r\n'));
}

}
2 changes: 1 addition & 1 deletion src/metaBuilder/unitAttrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local UnitAttr = {
%{ATTR_ENUMS}
}
y3.util.tableMerge(y3.const.UnitAttr, UnitAttr)
y3.util.tableMerge(y3.const.UnitAttr or {}, UnitAttr)
`;

export class UnitAttrs extends BaseBuilder {
Expand Down

0 comments on commit d81782a

Please sign in to comment.