From 96e280bcca9011472664e4f13c5cbca19fd0c61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 26 Mar 2024 14:40:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20CSV=20=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CSVeditor.ts | 11 +++ src/CSVimporter.ts | 4 + src/Y3HelperEditorTable.ts | 45 ++--------- src/env.ts | 76 +++++++++++++++++++ src/extension.ts | 42 ++++++++-- src/templateGenerator.ts | 27 +------ template/csv_template/ability/battle_attr.csv | 2 +- template/csv_template/ability/cast_state.csv | 2 +- template/csv_template/ability/custom_key.csv | 2 +- 9 files changed, 141 insertions(+), 70 deletions(-) create mode 100644 src/CSVeditor.ts diff --git a/src/CSVeditor.ts b/src/CSVeditor.ts new file mode 100644 index 0000000..7a94114 --- /dev/null +++ b/src/CSVeditor.ts @@ -0,0 +1,11 @@ +import { Env } from "./env"; + +/** + * 物编数据CSV表格的编辑器 + */ +export class CSVeditor{ + constructor(private readonly env:Env){ + + } + +} \ No newline at end of file diff --git a/src/CSVimporter.ts b/src/CSVimporter.ts index f91eb71..2bf2aa4 100644 --- a/src/CSVimporter.ts +++ b/src/CSVimporter.ts @@ -1,3 +1,7 @@ +/** + * 从CSV表格中导入物编数据 + */ + import * as vscode from 'vscode'; import csvParser from 'csv-parser'; import * as fs from 'fs'; diff --git a/src/Y3HelperEditorTable.ts b/src/Y3HelperEditorTable.ts index 7b184b0..21bc604 100644 --- a/src/Y3HelperEditorTable.ts +++ b/src/Y3HelperEditorTable.ts @@ -10,59 +10,28 @@ import { encode } from 'punycode'; export class Y3HelperDataProvider implements vscode.TreeDataProvider { private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); readonly onDidChangeTreeData: vscode.Event = 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; } diff --git a/src/env.ts b/src/env.ts index 8f5f9ae..05ef137 100644 --- a/src/env.ts +++ b/src/env.ts @@ -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'; @@ -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文件保存地址 */ diff --git a/src/extension.ts b/src/extension.ts index 6809736..59b5fe1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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'; @@ -274,6 +274,7 @@ class Helper { { label: '投射物', description: 'projectile' }, { label: '科技', description: 'technology' }, { label: '可破坏物', description: 'destructible' }, + { label: '声音', description: 'sound' } ]; vscode.window.showQuickPick(items, { @@ -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"); @@ -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/"); @@ -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)); @@ -417,6 +445,8 @@ class Helper { this.checkNewProject(); this.reloadEnvWhenConfigChange(); + + this.registerCommandOfCSVeditor(); } } diff --git a/src/templateGenerator.ts b/src/templateGenerator.ts index 4e42abe..d6060e3 100644 --- a/src/templateGenerator.ts +++ b/src/templateGenerator.ts @@ -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; } @@ -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插件的发布打包程序不支持中文路径 只能被迫转换一下 完后又改回原名 */ diff --git a/template/csv_template/ability/battle_attr.csv b/template/csv_template/ability/battle_attr.csv index e989aa5..e95f06f 100644 --- a/template/csv_template/ability/battle_attr.csv +++ b/template/csv_template/ability/battle_attr.csv @@ -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,[] diff --git a/template/csv_template/ability/cast_state.csv b/template/csv_template/ability/cast_state.csv index bb4482e..b6733ee 100644 --- a/template/csv_template/ability/cast_state.csv +++ b/template/csv_template/ability/cast_state.csv @@ -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 diff --git a/template/csv_template/ability/custom_key.csv b/template/csv_template/ability/custom_key.csv index 02e60d3..6b3e6b4 100644 --- a/template/csv_template/ability/custom_key.csv +++ b/template/csv_template/ability/custom_key.csv @@ -1,3 +1,3 @@ key,uid,name,kv ID,UID,名称,玩家自定义 -134265579,134265579,这是一个技能,{} \ No newline at end of file +134265579,134265579,这是一个技能,{}