Skip to content

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jun 28, 2024
1 parent e9f7caa commit ef504fd
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 46 deletions.
86 changes: 55 additions & 31 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
};
}
8 changes: 4 additions & 4 deletions src/customDefine/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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] ?? '不支持的类型',
});
}
}
Expand Down
14 changes: 3 additions & 11 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit ef504fd

Please sign in to comment.