Skip to content

Commit

Permalink
支持所有界面
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed May 21, 2024
1 parent 28518a4 commit 976127e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
52 changes: 42 additions & 10 deletions src/customDefine/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class UI extends BaseDefine {
};
}

private async loadUIFile(fileUri: vscode.Uri): Promise<Node|undefined> {
private async loadUI(fileUri: vscode.Uri): Promise<Node|undefined> {
let jsonText = (await tools.readFile(fileUri))?.string;
if (!jsonText) {
return;
Expand All @@ -71,28 +71,56 @@ export class UI extends BaseDefine {
}
}

private async loadPrefeb(fileUri: vscode.Uri) {
let nodes: Node[] = [];

private async loadSceneUI(fileUri: vscode.Uri) {
let jsonText = (await tools.readFile(fileUri))?.string;
if (!jsonText) {
return undefined;
}
try {
let json = JSON.parse(jsonText);
if (typeof json !== 'object') {
return undefined;
}

if (!Array.isArray(json['children'])) {
return undefined;
}

let nodes: Node[] = [];
for (const child of json['children']) {
let node = this.makeNode(child);
if (node) {
nodes.push(node);
}
}
return nodes;
} catch(e) {
tools.log.error(e as Error);
}
}

private async loadPrefeb(fileUri: vscode.Uri) {
let jsonText = (await tools.readFile(fileUri))?.string;
if (!jsonText) {
return undefined;
}
try {
let json = JSON.parse(jsonText);
if (typeof json !== 'object') {
return nodes;
return undefined;
}

let prefab_data = json['prefab_data'];
if (!prefab_data || typeof prefab_data !== 'object') {
return nodes;
return undefined;
}

let nodes: Node[] = [];
for (const key in prefab_data) {
let prefeb = prefab_data[key];
let node = this.makeNode(prefeb['data']);
if (node) {
node.name = prefeb['name'];
nodes.push(node);
}
}
Expand All @@ -102,7 +130,7 @@ export class UI extends BaseDefine {
}
}

private async loadUI() {
private async loadUIPackage() {
let uiPackage: UIPackage = {
画板: [],
场景UI: [],
Expand All @@ -124,6 +152,10 @@ export class UI extends BaseDefine {
let uri = vscode.Uri.joinPath(dir, fileName);
switch (fileName) {
case 'SceneUI.json': {
let nodes = await this.loadSceneUI(uri);
if (nodes) {
uiPackage.场景UI = nodes;
}
continue;
}
case 'ui_config.json': {
Expand All @@ -134,7 +166,7 @@ export class UI extends BaseDefine {
continue;
}
default: {
let node = await this.loadUIFile(uri);
let node = await this.loadUI(uri);
if (node) {
uiPackage.画板.push(node);
}
Expand All @@ -146,9 +178,9 @@ export class UI extends BaseDefine {
}
}

public async getUI() {
public async getUIPackage() {
if (!this._uiCache) {
this._uiCache = await this.loadUI();
this._uiCache = await this.loadUIPackage();
}
return this._uiCache;
}
Expand Down
21 changes: 19 additions & 2 deletions src/mainMenu/pages/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,28 @@ export class 界面 extends TreeNode {
return;
}

node.childs = (await define.界面.getUI())
node.childs = (await define.界面.getUIPackage())
.画板
.map(ui => new UINode(ui));
}
}),
new TreeNode('场景UI', {
iconPath: new vscode.ThemeIcon('smiley'),

show: async () => {
return env.mapUri !== undefined;
},

update: async (node) => {
if (env.mapUri === undefined) {
return;
}

node.childs = (await define.界面.getUIPackage())
.场景UI
.map(ui => new UINode(ui));
}
}),
new TreeNode('元件', {
iconPath: new vscode.ThemeIcon('extensions'),

Expand All @@ -75,7 +92,7 @@ export class 界面 extends TreeNode {
return;
}

node.childs = (await define.界面.getUI())
node.childs = (await define.界面.getUIPackage())
.元件
.map(ui => new UINode(ui));
}
Expand Down

0 comments on commit 976127e

Please sign in to comment.