Skip to content

Commit

Permalink
更新 CSV 工具
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Mar 26, 2024
1 parent 506a1c2 commit 96e280b
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 70 deletions.
11 changes: 11 additions & 0 deletions src/CSVeditor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Env } from "./env";

/**
* 物编数据CSV表格的编辑器
*/
export class CSVeditor{
constructor(private readonly env:Env){

}

}
4 changes: 4 additions & 0 deletions src/CSVimporter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* 从CSV表格中导入物编数据
*/

import * as vscode from 'vscode';
import csvParser from 'csv-parser';
import * as fs from 'fs';
Expand Down
45 changes: 7 additions & 38 deletions src/Y3HelperEditorTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,28 @@ import { encode } from 'punycode';
export class Y3HelperDataProvider implements vscode.TreeDataProvider<FileNode> {
private _onDidChangeTreeData: vscode.EventEmitter<FileNode | undefined> = new vscode.EventEmitter<FileNode | undefined>();
readonly onDidChangeTreeData: vscode.Event<FileNode | undefined> = this._onDidChangeTreeData.event;
public readonly englishPathToChinese: { [key: string]: string } = {
"editorunit": "单位",
"soundall": "声音",
"abilityall": "技能",
"editordecoration": "装饰物",
"editordestructible": "可破坏物",
"editoritem": "物品",
"modifierall": "魔法效果",
"projectileall": "投射物",
"technologyall": "科技"
};
public readonly englishPathToChinese: { [key: string]: string };
private editorTablePath: string = "";
private zhlanguageJson: any = undefined;
public getZhlanguageJson(): any{
return this.zhlanguageJson;
}

constructor(private env: Env) {

this.englishPathToChinese = this.env.englishPathToChinese;
if (!vscode.workspace.workspaceFolders) {
vscode.window.showErrorMessage("当前未打开工作目录");
return;
}

this.editorTablePath = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, "../editor_table");


if (!isPathValid(this.editorTablePath)) {
this.editorTablePath = "";
}
this.editorTablePath = this.env.editorTablePath;

// 载入中文名称
let zhlanguagePath = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, "../zhlanguage.json");
if (isPathValid(zhlanguagePath)) {
try {
this.zhlanguageJson = JSON.parse(fs.readFileSync(zhlanguagePath, 'utf8'));
}
catch (error) {
vscode.window.showErrorMessage("读取和解析" + zhlanguagePath + "时失败,错误为:" + error);
}
}
else {
return;
}
this.zhlanguageJson = this.env.zhlanguageJson;
}

refresh(): void {
this._onDidChangeTreeData.fire(undefined);
}

private editorTablePath: string = "";
public getEditorTablePath():string
{
return this.editorTablePath;
}

getTreeItem(element: FileNode): vscode.TreeItem {
return element;
}
Expand Down
76 changes: 76 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as os from 'os';
import winreg from 'winreg';
import path from 'path';
import * as tools from './tools';
import { isPathValid } from './utility';
import * as fs from 'fs';

type EditorVersion = '1.0' | '2.0' | 'unknown';

Expand Down Expand Up @@ -210,8 +212,82 @@ export class Env {
destructible: "./resource/editor_table/可破坏物",
sound: "./resource/editor_table/声音"
};
public readonly englishPathToChinese: { [key: string]: string } = {
"editorunit": "单位",
"soundall": "声音",
"abilityall": "技能",
"editordecoration": "装饰物",
"editordestructible": "可破坏物",
"editoritem": "物品",
"modifierall": "魔法效果",
"projectileall": "投射物",
"technologyall": "科技"
};
public readonly englishToChinese: { [key: string]: string } = {
"unit": "单位",
"decoration": "装饰物",
"item": "物品",
"ability": "技能",
"modifier": "魔法效果",
"projectile": "投射物",
"technology": "科技",
"destructible": "可破坏物",
"sound": "声音"
};
public readonly chineseToEnglish: { [key: string]: string } = {
"单位": "unit",
"装饰物": "decoration",
"物品": "item",
"技能": "ability",
"魔法效果": "modifier",
"投射物": "projectile",
"科技": "technology",
"可破坏物": "destructible",
"声音": "sound"
};
private _zhlanguageJson: any = undefined;

public get zhlanguageJson(): any {

if (this._zhlanguageJson) {
return this._zhlanguageJson;
}
if (!vscode.workspace.workspaceFolders || !vscode.workspace.workspaceFolders[0]) {
return undefined;
}
// 载入中文名称
let zhlanguagePath = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, "../zhlanguage.json");
if (isPathValid(zhlanguagePath)) {
try {
this._zhlanguageJson = JSON.parse(fs.readFileSync(zhlanguagePath, 'utf8'));
}
catch (error) {
vscode.window.showErrorMessage("读取和解析" + zhlanguagePath + "时失败,错误为:" + error);
}
}
else {
return undefined;
}
return this._zhlanguageJson;
}

private _editorTablePath: string = "";

public get editorTablePath(): string{
if (!vscode.workspace.workspaceFolders || !vscode.workspace.workspaceFolders[0]) {
return "";
}
this._editorTablePath = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, "../editor_table");


if (!isPathValid(this._editorTablePath)) {
this._editorTablePath = "";
}
return this._editorTablePath;
}



/**
* 从插件配置中更新物编数据类型对应的CSV文件保存地址
*/
Expand Down
42 changes: 36 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GameLauncher } from './launchGame';
import { CSVimporter } from './CSVimporter';
import * as utility from './utility';
import { TemplateGenerator } from './templateGenerator';
import { Y3HelperDataProvider, GoEditorTableSymbolProvider, GoEditorTableDocumentSymbolProvider } from './Y3HelperEditorTable';
import { Y3HelperDataProvider, GoEditorTableSymbolProvider, GoEditorTableDocumentSymbolProvider } from './y3HelperEditorTable';
import * as tools from "./tools";
import * as preset from './preset';

Expand Down Expand Up @@ -274,6 +274,7 @@ class Helper {
{ label: '投射物', description: 'projectile' },
{ label: '科技', description: 'technology' },
{ label: '可破坏物', description: 'destructible' },
{ label: '声音', description: 'sound' }
];

vscode.window.showQuickPick(items, {
Expand All @@ -296,6 +297,33 @@ class Helper {
});
}

/**
* 注册CSVeditor相关的命令
*/
private registerCommandOfCSVeditor() {
vscode.commands.registerCommand('y3-helper.addNewDataInCSV', async () => {
const items: vscode.QuickPickItem[] = [
{ label: '单位', description: 'unit' },
{ label: '装饰物', description: 'decoration' },
{ label: '物品', description: 'item' },
{ label: '技能', description: 'ability' },
{ label: '魔法效果', description: 'modifier' },
{ label: '投射物', description: 'projectile' },
{ label: '科技', description: 'technology' },
{ label: '可破坏物', description: 'destructible' },
{ label: '声音', description: 'sound' }
];
vscode.window.showQuickPick(items, {
placeHolder: '选择你要添加的物编数据类型(CSV)'
}).then(selection => {
if (selection) {
vscode.window.showInformationMessage(`你选择了: ${selection.label}`);
}
vscode.window.showInputBox();
});
});
}

private registerCommandOfGenerateAllTemplateCSV() {
vscode.commands.registerCommand('y3-helper.generateAllTemplateCSV', async () => {
console.log("y3-helper.generateTemplateCSV");
Expand All @@ -314,7 +342,7 @@ class Helper {
vscode.window.showErrorMessage("未找到script文件夹");
return false;
}
// todo: 生成csv模板
// 生成csv模板
let templateGenerator = new TemplateGenerator(this.env);

let targetUri: vscode.Uri = vscode.Uri.joinPath(this.env.scriptUri,"./resource/editor_table/");
Expand Down Expand Up @@ -366,14 +394,14 @@ class Helper {
vscode.commands.registerCommand('y3-Helper.editorTableView.refresh', () => y3HelperDataProvider.refresh());

const goEditorTableSymbolProvider = new GoEditorTableSymbolProvider(
y3HelperDataProvider.getEditorTablePath(),
y3HelperDataProvider.getZhlanguageJson(),
y3HelperDataProvider.englishPathToChinese
this.env.editorTablePath,
this.env.zhlanguageJson,
this.env.englishPathToChinese
);

this.context.subscriptions.push(vscode.languages.registerWorkspaceSymbolProvider(goEditorTableSymbolProvider));

const goEditorTableDocumentSymbolProvider = new GoEditorTableDocumentSymbolProvider(y3HelperDataProvider.getZhlanguageJson());
const goEditorTableDocumentSymbolProvider = new GoEditorTableDocumentSymbolProvider(this.env.zhlanguageJson);
let sel: vscode.DocumentSelector = { scheme: 'file', language: 'json' };
this.context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider(sel,goEditorTableDocumentSymbolProvider));

Expand Down Expand Up @@ -417,6 +445,8 @@ class Helper {

this.checkNewProject();
this.reloadEnvWhenConfigChange();

this.registerCommandOfCSVeditor();
}
}

Expand Down
27 changes: 4 additions & 23 deletions src/templateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import * as path from 'path';
import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII } from './utility';
export class TemplateGenerator{
private env: Env;
private readonly englishToChinese;
private readonly chineseToEnglish;
public constructor(env: Env) {
this.env = env;
this.chineseToEnglish = this.env.chineseToEnglish;
this.englishToChinese = this.env.englishToChinese;
}


Expand Down Expand Up @@ -42,29 +46,6 @@ export class TemplateGenerator{
}


private readonly englishToChinese: { [key: string]: string } = {
"unit":"单位",
"decoration":"装饰物",
"item":"物品",
"ability":"技能",
"modifier":"魔法效果",
"projectile":"投射物",
"technology":"科技" ,
"destructible":"可破坏物" ,
"sound":"声音"
};
private readonly chineseToEnglish: { [key: string]: string } = {
"单位": "unit",
"装饰物": "decoration",
"物品": "item",
"技能": "ability",
"魔法效果": "modifier",
"投射物": "projectile",
"科技": "technology",
"可破坏物": "destructible",
"声音": "sound"
};

/**
* vsocde插件的发布打包程序不支持中文路径 只能被迫转换一下 完后又改回原名
*/
Expand Down
2 changes: 1 addition & 1 deletion template/csv_template/ability/battle_attr.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
key,uid,name,ability_cast_range,ability_cost,ability_damage,ability_damage_range,ability_hp_cost,ability_max_stack_count,ability_stack_cd,build_list,build_rotate,can_autocast_when_attack_target,can_cast_when_hp_insufficient,can_cost_hp,cold_down_time,cost_hp_can_die,influenced_by_cd_reduce,is_autocast,player_props_cost
ID,UID,名称,释放范围,技能消耗,技能伤害值,技能影响范围,生命值消耗,最大充能数,充能时间,建造单位,建造角度,攻击命令触发自动施法,生命不足能否施放,消耗生命值施放,冷却时间,消耗生命是否致死,技能受冷却影响,自动施法,玩家属性消耗
134265579,134265579,这是一个技能,"("14.114514")","("5")","("5")","("0.0")","("0")","("0")","("0")",(),0.0,False,False,False,"("5")",False,True,False,[]
134265579,134265579,这是一个技能,"(""14.114514"")","(""5"")","(""5"")","(""0.0"")","(""0"")","(""0"")","(""0"")",(),0,False,False,False,"(""5"")",False,True,False,[]
2 changes: 1 addition & 1 deletion template/csv_template/ability/cast_state.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
key,uid,name,ability_break_cast_range,ability_bw_point,ability_cast_point,ability_channel_time,ability_prepare_time,can_bs_interrupt,can_cast_interrupt,can_interrupt_others,can_prepare_interrupt,can_ps_interrupt,influenced_by_move
ID,UID,名称,施法打断范围,施法完成,施法开始,施法出手,施法引导,施法完成可以被打断,施法出手可以被打断,技能可以打断其他技能,施法引导可以被打断,施法开始可以被打断,移动会对技能产生影响
134265579,134265579,这是一个技能,"("50")",0.5,0.2,0.0,0.0,True,False,True,False,True,True
134265579,134265579,这是一个技能,"(""50"")",0.5,0.2,0,0,True,False,True,False,True,True
2 changes: 1 addition & 1 deletion template/csv_template/ability/custom_key.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
key,uid,name,kv
ID,UID,名称,玩家自定义
134265579,134265579,这是一个技能,{}
134265579,134265579,这是一个技能,{}

0 comments on commit 96e280b

Please sign in to comment.