-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
187 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { RelativePattern } from "vscode"; | ||
import { env } from "../env"; | ||
import * as tools from '../tools'; | ||
import { BaseDefine } from "./baseDefine"; | ||
import { typeID } from "../constants"; | ||
|
||
const filePath = 'customevent.json'; | ||
|
||
type Event = { | ||
name: string; | ||
id: number; | ||
args: EventArg[]; | ||
}; | ||
|
||
type EventArg = { | ||
name: string; | ||
type: number; | ||
luaType: string; | ||
desc: string; | ||
}; | ||
|
||
export class Events extends BaseDefine { | ||
constructor() { | ||
super(); | ||
|
||
this.onDidChange(() => { | ||
this._eventsCache = undefined; | ||
}); | ||
} | ||
|
||
private _eventsCache?: Event[]; | ||
|
||
get watchPattern() { | ||
if (!env.mapUri) { | ||
return; | ||
} | ||
return new RelativePattern(env.mapUri, filePath); | ||
} | ||
|
||
private async loadEvents() { | ||
let events: Event[] = []; | ||
try { | ||
if (!env.mapUri) { | ||
return events; | ||
} | ||
let jsonFile = await tools.readFile(env.mapUri, filePath); | ||
if (!jsonFile) { | ||
return events; | ||
} | ||
let json = JSON.parse(jsonFile.string); | ||
if (typeof json !== 'object') { | ||
return events; | ||
} | ||
// 自定义单位属性 | ||
if (Array.isArray(json.group_info)) { | ||
for (let item of json.group_info) { | ||
let id = item.items?.[0]; | ||
let name = decodeURI(item.items?.[1]); | ||
if (id && name) { | ||
events.push({name, id: id, args: []}); | ||
} | ||
} | ||
} | ||
for (const event of events) { | ||
let conf = json.conf?.[event.id.toString()]; | ||
if (!conf) { | ||
continue; | ||
} | ||
for (let item of conf) { | ||
let name = decodeURI(item[0]); | ||
let type = item[1]; | ||
if (name && type) { | ||
event.args.push({ | ||
name, | ||
type, | ||
luaType: typeID[type]?.[0] ?? '不支持的类型', | ||
desc: typeID[type]?.[1] ?? '不支持的类型', | ||
}); | ||
} | ||
} | ||
} | ||
} finally { | ||
return events; | ||
} | ||
} | ||
|
||
public async getEvents() { | ||
if (!this._eventsCache) { | ||
this._eventsCache = await this.loadEvents(); | ||
} | ||
return this._eventsCache; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { PlayerAttrs } from "./playerAttrs"; | ||
import { UnitAttrs } from "./unitAttrs"; | ||
import { Events } from "./event"; | ||
|
||
export let define = { | ||
export const define = { | ||
单位属性: new UnitAttrs, | ||
玩家属性: new PlayerAttrs, | ||
自定义事件: new Events, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { TreeNode } from "../treeNode"; | ||
import * as vscode from 'vscode'; | ||
import { define } from "../../customDefine"; | ||
import { env } from "../../env"; | ||
|
||
export class 自定义事件 extends TreeNode { | ||
constructor() { | ||
super('自定义事件', { | ||
iconPath: new vscode.ThemeIcon('group-by-ref-type'), | ||
show: async () => { | ||
await env.mapReady(); | ||
return env.projectUri !== undefined; | ||
}, | ||
|
||
update: async (node) => { | ||
node.childs = (await define.自定义事件.getEvents()).map(event => { | ||
let args = event.args.map(arg => arg.name); | ||
return new TreeNode(event.name, { | ||
description: `${event.id.toString()}(${args.join(',')})`, | ||
contextValue: '自定义事件', | ||
data: event.id, | ||
}); | ||
}); | ||
}, | ||
}); | ||
|
||
define.自定义事件.onDidChange(() => { | ||
this.refresh(); | ||
}); | ||
} | ||
}; | ||
|
||
vscode.commands.registerCommand('y3-helper.copyEventName', (node: TreeNode) => { | ||
if (typeof node.label !== 'string') { | ||
return; | ||
} | ||
vscode.env.clipboard.writeText(node.label); | ||
}); | ||
|
||
vscode.commands.registerCommand('y3-helper.copyEventID', (node: TreeNode) => { | ||
if (typeof node.data !== 'number') { | ||
return; | ||
} | ||
vscode.env.clipboard.writeText(node.data.toString()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters