Skip to content

Commit

Permalink
自动更新定义文件
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Dec 26, 2024
1 parent 81c15d7 commit 0f8d99f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/editorTable/editorTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class EditorObject<N extends Table.NameCN = Table.NameCN> {
if (!this.text) {
return undefined;
}
this._json = new EditorJson(this.text, this.manager.fixedFloat);
this._json = new EditorJson(this.text, fixedFloat);
}
return this._json;
}
Expand Down Expand Up @@ -466,7 +466,7 @@ export class EditorTable<N extends Table.NameCN = Table.NameCN> extends vscode.D
templateJson = template.string;
}

let json = new EditorJson(templateJson, this.manager.fixedFloat);
let json = new EditorJson(templateJson, fixedFloat);
json.set('uid', key.toString());
json.set('key', BigInt(key));
json.set('_ref_', BigInt(key));
Expand Down Expand Up @@ -688,12 +688,6 @@ export class EditorManager {
return this.editorTables.get(tableName) as EditorTable<N>;
}

/**
* 是否强制浮点数保留一位小数。默认为false。
* 启用后如果想表示整数,需要使用 `123n` 或 `BigInt(123)`。
*/
fixedFloat = false;

private _allObjects?: EditorObject[];
private _allObjectsMap?: Record<number, EditorObject[]>;
private _cacheVersion = 0;
Expand Down Expand Up @@ -792,3 +786,9 @@ export async function getObjectsByKey(key: number): Promise<EditorObject[]> {
}
return await map.editorTable.getObjectsByKey(key);
}

/**
* 是否强制浮点数保留一位小数。默认为false。
* 启用后如果想表示整数,需要使用 `123n` 或 `BigInt(123)`。
*/
export let fixedFloat = false;
2 changes: 1 addition & 1 deletion src/metaBuilder/baseBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export abstract class BaseBuilder {
return;
}
let code = await this.make();
if (code) {
if (code && code !== (await tools.fs.readFile(env.scriptUri))?.string) {
await tools.fs.writeFile(env.scriptUri, this.path, code);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/metaBuilder/tsMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class TS extends BaseBuilder {
this.update();
});
}

async make(): Promise<string> {
let attrs = await define().单位属性.getAttrs();
return template.replace('%{UNIT_ATTRS}', attrs.map(attr => {
Expand Down
8 changes: 5 additions & 3 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function initPlugin() {
mainMenu.refresh('插件');
}

async function updatePlugin() {
async function updatePluginDTS(showme = false) {
await y3.env.mapReady();
if (!y3.env.pluginUri) {
return;
Expand All @@ -78,7 +78,7 @@ async function updatePlugin() {
let suc = await y3.fs.copy(templateUri, targetUri, {
overwrite: true,
});
if (suc) {
if (suc && showme) {
vscode.window.showInformationMessage('插件定义文件更新成功');
y3.open(targetUri);
mainMenu.refresh('插件');
Expand Down Expand Up @@ -157,13 +157,15 @@ export async function init() {

updatePluginManager();
updateMapSaveWatcher();
updatePluginDTS();
y3.env.onDidChange(() => {
updatePluginManager();
updateMapSaveWatcher();
updatePluginDTS();
});

vscode.commands.registerCommand('y3-helper.initPlugin', initPlugin);
vscode.commands.registerCommand('y3-helper.updatePlugin', updatePlugin);
vscode.commands.registerCommand('y3-helper.updatePlugin', () => updatePluginDTS(true));

vscode.commands.registerCommand('y3-helper.runPlugin', async (uri?: vscode.Uri, funcName?: string) => {
if (!uri) {
Expand Down
8 changes: 2 additions & 6 deletions template/plugin/y3-helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4861,11 +4861,6 @@ declare class EditorManager {
* @returns 表对象
*/
openTable<N extends Table$2.NameCN>(tableName: N): EditorTable<N>;
/**
* 是否强制浮点数保留一位小数。默认为false。
* 启用后如果想表示整数,需要使用 `123n` 或 `BigInt(123)`。
*/
fixedFloat: boolean;
private _allObjects?;
private _allObjectsMap?;
private _cacheVersion;
Expand All @@ -4877,6 +4872,7 @@ declare class EditorManager {
declare function openTable<N extends Table$2.NameCN>(tableName: N): EditorTable<N>;
declare function getAllObjects(): Promise<y3.table.EditorObject<"\u5355\u4F4D" | "\u58F0\u97F3" | "\u6280\u80FD" | "\u88C5\u9970\u7269" | "\u53EF\u7834\u574F\u7269" | "\u7269\u54C1" | "\u9B54\u6CD5\u6548\u679C" | "\u6295\u5C04\u7269" | "\u79D1\u6280">[]>;
declare function getObjectsByKey(key: number): Promise<EditorObject[]>;
declare let fixedFloat: boolean;
declare function init$1(): void;
declare function ready$1(): Promise<void>;
declare function get(key: string | number | bigint): string | undefined;
Expand Down Expand Up @@ -5135,7 +5131,7 @@ declare namespace excel {
export { CellTable, Excel, MultiCellTable, MultiTable, Sheet, Table$1 as Table, init, loadFile, loadFileWithAllSheets, rule, setBaseDir };
}
declare namespace table {
export { EditorData, EditorManager, EditorObject, EditorTable, FieldInfo, getAllObjects, getObject, getObjectsByKey, openTable, ready };
export { EditorData, EditorManager, EditorObject, EditorTable, FieldInfo, fixedFloat, getAllObjects, getObject, getObjectsByKey, openTable, ready };
}
declare namespace language {
export { get, init$1 as init, keyOf, onDidChange, ready$1 as ready, set };
Expand Down

0 comments on commit 0f8d99f

Please sign in to comment.