From ef504fd143bd084805c2b06d450c276d4d3a248e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 28 Jun 2024 16:45:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants.ts | 86 +++++++++++++++++++++++++-------------- src/customDefine/event.ts | 8 ++-- src/env.ts | 14 ++----- 3 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index a492fba..1cfbe12 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -71,9 +71,49 @@ export namespace Table { } as const, } as const; + export const type = { + toLuaType: { + 100000: "number", + 100001: "boolean", + 100002: "integer", + 100003: "string", + 100004: "Point", + 100006: "Unit", + 100010: "UnitKey", + 100011: "table", + 100014: "Ability", + 100025: "Player", + 100026: "UnitGroup", + 100027: "PlayerGroup", + 100031: "Item", + 100032: "ItemKey", + 100039: "AbilityKey", + 100263: "Mover", + } as const, + toName: { + 100000: "实数", + 100001: "布尔", + 100002: "整数", + 100003: "字符串", + 100004: "点", + 100006: "单位", + 100010: "单位类型", + 100011: "表", + 100014: "技能", + 100025: "玩家", + 100026: "单位组", + 100027: "玩家组", + 100031: "物品", + 100032: "物品类型", + 100039: "技能类型", + 100263: "运动器", + } as const, + } as const; + export type Path = keyof typeof path.toCN; export type NameEN = keyof typeof name.toCN; export type NameCN = keyof typeof name.fromCN; + export type TypeID = keyof typeof type.toLuaType; } export namespace CSV { @@ -100,34 +140,18 @@ export namespace CSV { export type Type = keyof typeof type.toPath; } -// 默认情况下各类型物编数据CSV文件的相对路径 (相对于工程项目的script文件) -export const defaultTableTypeToCSVfolderPath = { - unit: "./y3-helper/editor_table/csv/单位", - decoration: "./y3-helper/editor_table/csv/装饰物", - item: "./y3-helper/editor_table/csv/物品", - ability: "./y3-helper/editor_table/csv/技能", - modifier: "./y3-helper/editor_table/csv/魔法效果", - projectile: "./y3-helper/editor_table/csv/投射物", - technology: "./y3-helper/editor_table/csv/科技", - destructible: "./y3-helper/editor_table/csv/可破坏物", - sound: "./y3-helper/editor_table/csv/声音" -} as const; - -export const typeID = { - 100000: ["number", "实数"], - 100001: ["boolean", "布尔"], - 100002: ["integer", "整数"], - 100003: ["string", "字符串"], - 100004: ["Point", "点"], - 100006: ["Unit", "单位"], - 100010: ["UnitKey", "单位类型"], - 100011: ["table", "表"], - 100014: ["Ability", "技能"], - 100025: ["Player", "玩家"], - 100026: ["UnitGroup", "单位组"], - 100027: ["PlayerGroup", "玩家组"], - 100031: ["Item", "物品"], - 100032: ["ItemKey", "物品类型"], - 100039: ["AbilityKey", "技能类型"], - 100263: ["Mover", "运动器"], -} as const; +export namespace Template { + export const path = { + csv: { + unit: "./y3-helper/editor_table/csv/单位", + decoration: "./y3-helper/editor_table/csv/装饰物", + item: "./y3-helper/editor_table/csv/物品", + ability: "./y3-helper/editor_table/csv/技能", + modifier: "./y3-helper/editor_table/csv/魔法效果", + projectile: "./y3-helper/editor_table/csv/投射物", + technology: "./y3-helper/editor_table/csv/科技", + destructible: "./y3-helper/editor_table/csv/可破坏物", + sound: "./y3-helper/editor_table/csv/声音", + } as const, + }; +} diff --git a/src/customDefine/event.ts b/src/customDefine/event.ts index ba28be0..90ef162 100644 --- a/src/customDefine/event.ts +++ b/src/customDefine/event.ts @@ -2,7 +2,7 @@ import { RelativePattern } from "vscode"; import { env } from "../env"; import * as tools from '../tools'; import { BaseDefine } from "./baseDefine"; -import { typeID } from "../constants"; +import { Table } from "../constants"; const filePath = 'customevent.json'; @@ -68,13 +68,13 @@ export class Events extends BaseDefine { } for (let item of conf) { let name = item[0]; - let type: keyof typeof typeID = item[1]; + let type: Table.TypeID = item[1]; if (name && type) { event.args.push({ name, type, - luaType: typeID[type]?.[0] ?? 'any', - desc: typeID[type]?.[1] ?? '不支持的类型', + luaType: Table.type.toLuaType[type]?.[0] ?? 'any', + desc: Table.type.toName[type]?.[1] ?? '不支持的类型', }); } } diff --git a/src/env.ts b/src/env.ts index 7239474..17b3249 100644 --- a/src/env.ts +++ b/src/env.ts @@ -6,7 +6,7 @@ import util from 'util'; import * as tools from './tools'; import { isFileValid, isPathValid, randomInt, toUnicodeIgnoreASCII, hash } from './utility'; import * as fs from 'fs'; -import { defaultTableTypeToCSVfolderPath } from './constants'; +import { Template } from './constants'; type EditorVersion = '1.0' | '2.0' | 'unknown'; @@ -250,16 +250,8 @@ class EnvPath { private initTableTypeToCSVfolderPath(): void { let csvPathConfig: any = vscode.workspace.getConfiguration('Y3-Helper.CSVPath'); //console.log(vscode.workspace.getConfiguration('Y3-Helper.CSVPath').unit); - for (const key in defaultTableTypeToCSVfolderPath) { - this._tableTypeToCSVfolderPath[key] = defaultTableTypeToCSVfolderPath[key as keyof typeof defaultTableTypeToCSVfolderPath]; - // console.log(key + " " + this._tableTypeToCSVfolderPath[key]); - } - - for (const key in csvPathConfig) { - if (key in defaultTableTypeToCSVfolderPath) { - this._tableTypeToCSVfolderPath[key] = csvPathConfig[key]; - // console.log("update:"+key + " " + csvPathConfig[key]); - } + for (const [key, value] of Object.entries(Template.path.csv)) { + this._tableTypeToCSVfolderPath[key] = csvPathConfig[key] ?? value; } }