Skip to content

Commit

Permalink
更新物编
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Mar 27, 2024
1 parent 6b36e8f commit ab05ebb
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 79 deletions.
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
{
"command": "y3-helper.downloadPresetUI",
"title": "Y3:下载预设资源(UI)"
},
{
"command": "y3-helper.addNewDataInCSV",
"title": "Y3:在CSV表格中添加新物编数据"
},
{
"command": "y3-helper.modifyUIDandNameInCSV",
"title": "Y3:修改CSV表格中的物编数据UID和名称"
},
{
"command": "y3-helper.",
"title": "Y3:修改CSV表格中的物编数据UID和名称"
}
],
"configuration": {
Expand Down
63 changes: 63 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@


export const enum EditorTableType {
Unit = "unit",
Decoration = "decoration",
Item = "item",
Ability = "ability",
Modifier = "modifier",
Projectile = "projectile",
Technology = "technology",
Destructible = "destructible",
Sound = "sound"
}


export const englishPathToChinese: Readonly<{ [key: string]: string } >= {
"editorunit": "单位",
"soundall": "声音",
"abilityall": "技能",
"editordecoration": "装饰物",
"editordestructible": "可破坏物",
"editoritem": "物品",
"modifierall": "魔法效果",
"projectileall": "投射物",
"technologyall": "科技"
};
export const englishToChinese: Readonly<{ [key: string]: string } >= {
"unit": "单位",
"decoration": "装饰物",
"item": "物品",
"ability": "技能",
"modifier": "魔法效果",
"projectile": "投射物",
"technology": "科技",
"destructible": "可破坏物",
"sound": "声音"
};
export const chineseToEnglish:Readonly< { [key: string]: string } >= {
"单位": "unit",
"装饰物": "decoration",
"物品": "item",
"技能": "ability",
"魔法效果": "modifier",
"投射物": "projectile",
"科技": "technology",
"可破坏物": "destructible",
"声音": "sound"
};

/**
* 物编数据类型与其在Y3项目中存放的文件夹名的对应关系
*/
export const editorTableTypeToFolderName: Readonly<{ [key: string]: string }> = {
"unit": "editorunit",
"decoration": "editordecoration",
"item": "editoritem",
"ability": "abilityall",
"modifier": "modifierall",
"projectile": "projectileall",
"technology": "technologyall",
"destructible": "editordestructible",
"sound":"soundall"
};
4 changes: 2 additions & 2 deletions src/CSVeditor.ts → src/editorTable/CSVeditor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Env } from "./env";

import { Env } from "../env";
import csvParser from 'csv-parser';
/**
* 物编数据CSV表格的编辑器
*/
Expand Down
4 changes: 2 additions & 2 deletions src/CSVimporter.ts → src/editorTable/CSVimporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import * as vscode from 'vscode';
import csvParser from 'csv-parser';
import * as fs from 'fs';

import { Env } from "./env";
import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII, getFileNameByVscodeUri, hash } from './utility';
import { Env } from "../env";
import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII, getFileNameByVscodeUri, hash } from '../utility';

import * as path from 'path';
import { v4 as uuidv4 } from 'uuid';
Expand Down
19 changes: 11 additions & 8 deletions src/editorTable.ts → src/editorTable/editorTable.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { Env } from './env';
import { isPathValid, isJson, getFileNameByVscodeUri } from './utility';
import { Env } from '../env';
import { isPathValid, isJson, getFileNameByVscodeUri } from '../utility';
import { encode } from 'punycode';
import { englishPathToChinese } from '../constants';



export class Y3HelperDataProvider implements vscode.TreeDataProvider<FileNode> {
export class EditorTableDataProvider 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 };
private editorTablePath: string = "";
private zhlanguageJson: any = undefined;

constructor(private env: Env) {
this.englishPathToChinese = this.env.englishPathToChinese;
this.englishPathToChinese = englishPathToChinese;
if (!vscode.workspace.workspaceFolders) {
vscode.window.showErrorMessage("当前未打开工作目录");
return;
Expand Down Expand Up @@ -79,7 +79,7 @@ export class Y3HelperDataProvider implements vscode.TreeDataProvider<FileNode> {
}
else if (stat.isDirectory()) {
if (label in this.englishPathToChinese) {
label = this.englishPathToChinese[label];
label = this.englishPathToChinese[label] + '(' + label + ')';
}
else {
return Promise.resolve(fileNodes);
Expand Down Expand Up @@ -211,7 +211,7 @@ export class GoEditorTableSymbolProvider implements vscode.WorkspaceSymbolProvid
export class GoEditorTableDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
private englishKeyToChineseKey: any;
constructor(private zhlanguageJson: any = undefined ) {
let englishKeyToChineseKeyJsonPath = path.join(__dirname, "../config/englishKeyToChineseKey.json");
let englishKeyToChineseKeyJsonPath = path.join(__dirname, "../../config/englishKeyToChineseKey.json");
if (isPathValid(englishKeyToChineseKeyJsonPath)) {
try {
this.englishKeyToChineseKey = JSON.parse(fs.readFileSync(englishKeyToChineseKeyJsonPath, 'utf8'));
Expand All @@ -220,6 +220,9 @@ export class GoEditorTableDocumentSymbolProvider implements vscode.DocumentSymbo
vscode.window.showErrorMessage("读取和解析" + englishKeyToChineseKeyJsonPath + "时失败,错误为:" + error);
}
}
else {
vscode.window.showErrorMessage("在以下路径找不到englishKeyToChineseKey.json:\n"+englishKeyToChineseKeyJsonPath);
}
}
public provideDocumentSymbols(
document: vscode.TextDocument, token: vscode.CancellationToken):
Expand Down Expand Up @@ -313,4 +316,4 @@ function getChineseName(editorTableJsonName:string,editorTableJson: any, zhlangu
res = name + "(" + editorTableJsonName.substring(0, editorTableJsonName.length - 5) + ")";//显示为"这是一个单位(134219828)"的格式
}
return res;
}
}
21 changes: 11 additions & 10 deletions src/templateGenerator.ts → src/editorTable/templateGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as vscode from 'vscode';
import * as fs from 'fs-extra';
import { Env } from './env';
import { Env } from '../env';
import * as path from 'path';
import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII } from './utility';
import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII } from '../utility';
import { chineseToEnglish,englishToChinese } from '../constants';
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;
this.chineseToEnglish = chineseToEnglish;
this.englishToChinese = englishToChinese;
}


Expand All @@ -22,7 +23,7 @@ export class TemplateGenerator{
*/
public generateTemplateCSVToTargetPath(templateType: string, targetPath: vscode.Uri): boolean{
try {
fs.copy(path.join(path.join(__dirname, "../template/csv_template"), templateType), targetPath.fsPath,{ overwrite: false });
fs.copy(path.join(path.join(__dirname, "../../template/csv_template"), templateType), targetPath.fsPath,{ overwrite: false });
}
catch (error) {
vscode.window.showErrorMessage("模板生成异常:"+error);
Expand All @@ -35,7 +36,7 @@ export class TemplateGenerator{

try {
await this.renameTemplateCSVtoChinese();
await fs.copySync(path.join(__dirname, "../template/csv_template"), targetPath.fsPath, { overwrite: false });
await fs.copySync(path.join(__dirname, "../../template/csv_template"), targetPath.fsPath, { overwrite: false });
await this.renameTemplateCSVtoEnglish();
}
catch (error) {
Expand All @@ -53,8 +54,8 @@ export class TemplateGenerator{
for (let key in this.englishToChinese) {
let oldFileName: string = key;
let newFileName: string = this.englishToChinese[key];
oldFileName = path.join(__dirname, "../template/csv_template/" + oldFileName);
newFileName = path.join(__dirname, "../template/csv_template/" + newFileName);
oldFileName = path.join(__dirname, "../../template/csv_template/" + oldFileName);
newFileName = path.join(__dirname, "../../template/csv_template/" + newFileName);
await fs.renameSync(oldFileName, newFileName);
}
}
Expand All @@ -63,8 +64,8 @@ export class TemplateGenerator{
for (let key in this.chineseToEnglish) {
let oldFileName: string = key;
let newFileName: string = this.chineseToEnglish[key];
oldFileName = path.join(__dirname, "../template/csv_template/" + oldFileName);
newFileName = path.join(__dirname, "../template/csv_template/" + newFileName);
oldFileName = path.join(__dirname, "../../template/csv_template/" + oldFileName);
newFileName = path.join(__dirname, "../../template/csv_template/" + newFileName);
await fs.renameSync(oldFileName, newFileName);
}
}
Expand Down
54 changes: 17 additions & 37 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import path from 'path';
import * as tools from './tools';
import { isPathValid } from './utility';
import * as fs from 'fs';
import { EditorTableType } from './constants';

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

export class Env {

constructor() {
this.updateTableTypeToCSVfolderPath();// 初始化时从插件配置更新物编数据对应存放文件夹路径的关系
this.initTableTypeToCSVfolderPath();// 初始化时从插件配置更新物编数据对应存放文件夹路径的关系
}

private async searchEditorUriByReg(): Promise<vscode.Uri | undefined> {
Expand Down Expand Up @@ -186,9 +187,10 @@ export class Env {
public y3Uri?: vscode.Uri;
public projectUri?: vscode.Uri;
public editorTableUri?: vscode.Uri;// 物编数据
public csvTableUri?: vscode.Uri;// CSV表格路径

// 默认情况下各类型物编数据CSV文件的相对路径 (相对于工程项目的script文件)
public defaultTableTypeToCSVfolderPath: Readonly<{ [key: string]: string }> = {
private readonly defaultTableTypeToCSVfolderPath: Readonly<{ [key: string]: string }> = {
unit: "./resource/editor_table/单位",
decoration: "./resource/editor_table/装饰物",
item: "./resource/editor_table/物品",
Expand All @@ -201,7 +203,7 @@ export class Env {
};

// 实际情况下各类型物编数据CSV文件的相对路径 (相对于工程项目的script文件)
public tableTypeToCSVfolderPath: { [key: string]: string } = {
public readonly tableTypeToCSVfolderPath: { [key: string]: string } = {
unit: "./resource/editor_table/单位",
decoration: "./resource/editor_table/装饰物",
item: "./resource/editor_table/物品",
Expand All @@ -212,39 +214,7 @@ 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 {
Expand Down Expand Up @@ -291,7 +261,7 @@ export class Env {
/**
* 从插件配置中更新物编数据类型对应的CSV文件保存地址
*/
public updateTableTypeToCSVfolderPath(): void {
public initTableTypeToCSVfolderPath(): void {
let csvPathConfig: any = vscode.workspace.getConfiguration('Y3-Helper.CSVPath');
//console.log(vscode.workspace.getConfiguration('Y3-Helper.CSVPath').unit);
for (const key in this.defaultTableTypeToCSVfolderPath) {
Expand Down Expand Up @@ -322,6 +292,7 @@ export class Env {
this.scriptUri = vscode.Uri.joinPath(this.mapUri, 'script');
this.y3Uri = vscode.Uri.joinPath(this.scriptUri, 'y3');
this.editorTableUri = vscode.Uri.joinPath(this.mapUri, "editor_table");
this.csvTableUri = vscode.Uri.joinPath(this.scriptUri, "./resource/editor_table/");
}
})(),
]);
Expand Down Expand Up @@ -351,4 +322,13 @@ export class Env {
await this.init();
this.status = 'ready';
}

public allocateEditorTableObjectUID(editorTableType:EditorTableType): number{
let res: number = 0;
// todo:分配物编对象数据的UID

return res;
}
}


Loading

0 comments on commit ab05ebb

Please sign in to comment.