From 41cd99fa36bdf1edd2c38323775a4019318edab7 Mon Sep 17 00:00:00 2001 From: lingdar77 Date: Tue, 20 Jan 2026 16:56:27 +0800 Subject: [PATCH] csv form format --- README.md | 2 +- dist/bcm_tool.js | 53 ++++++++++++++++----- src/bcm_tool.ts | 117 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 131 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 7c7424d..9a942b1 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -g_game.bcm_tool.queryPlayerInfo(g_game.bcm_tool.listPlayers()); \ No newline at end of file +g_game.bcm_tool.queryPlayerInfo(g_game.bcm_tool.getPlayerIds()); \ No newline at end of file diff --git a/dist/bcm_tool.js b/dist/bcm_tool.js index 4eda485..979da99 100644 --- a/dist/bcm_tool.js +++ b/dist/bcm_tool.js @@ -2,7 +2,6 @@ class BcmTool { constructor() { this.mgrTeamInfo = g_game.mgr.mgr_team_player_team_info; - this.logger = new Logger(); } queryPlayerInfo(playersToQuery) { const attributes = [ @@ -51,21 +50,24 @@ class BcmTool { ['防守技能', 48], ['身体素质', 50], ]; - for (const playerId of playersToQuery) { + var form = new Form(); + for (let i = 0; i != attributes.length; ++i) { + form.SetCell(i + 1, 0, attributes[i][0]); + } + for (let i = 0; i != playersToQuery.length; ++i) { + const playerId = playersToQuery[i]; if (!this.checkInfo(playerId)) { console.log('找不到id', playerId); continue; } - this.logger.Info(this.queryName(playerId)); - for (const info of attributes) { - const name = info[0]; - const id = info[1]; - const record = this.queryInfo(playerId, id); - this.logger.Info(name, record); + form.SetCell(0, i + 1, this.queryName(playerId)); + for (let j = 0; j != attributes.length; ++j) { + const record = this.queryInfo(playerId, attributes[j][1]); + form.SetCell(j + 1, i + 1, record.toString()); } - g_game.tools.CopyStrToClipboard(this.logger.GetOutput()); - this.logger.Clear(); } + console.log(form); + g_game.tools.CopyStrToClipboard(form.ToString()); } checkInfo(playerId) { const data = this.mgrTeamInfo.GetPlayerData(playerId); @@ -97,15 +99,44 @@ class Logger { for (const msg of msgs) { this.msgs += String(msg); } + } + NextLine() { this.msgs += '\n'; } - GetOutput() { + GetContent() { return this.msgs; } Clear() { this.msgs = ''; } } +class Form { + constructor() { + this.records = []; + } + SetCell(col, row, data) { + if (this.records[col] == null) { + this.records[col] = []; + } + this.records[col][row] = data; + } + ToString() { + var _a; + var logger = new Logger(); + for (let col = 0; col != this.records.length; ++col) { + for (let row = 0; row != this.records[col].length; ++row) { + logger.Info((_a = this.records[col][row]) !== null && _a !== void 0 ? _a : ''); + if (row < this.records[col].length - 1) { + logger.Info(','); + } + } + if (col < this.records.length - 1) { + logger.NextLine(); + } + } + return logger.GetContent(); + } +} (() => { g_game.bcm_tool = new BcmTool(); })(); diff --git a/src/bcm_tool.ts b/src/bcm_tool.ts index 149c745..121fe46 100644 --- a/src/bcm_tool.ts +++ b/src/bcm_tool.ts @@ -1,9 +1,10 @@ -class BcmTool { +class BcmTool +{ private mgrTeamInfo = g_game.mgr.mgr_team_player_team_info; - private logger = new Logger(); - public queryPlayerInfo(playersToQuery:string[]) { + public queryPlayerInfo(playersToQuery: string[]) + { const attributes = [ ['速度', 1], ['力量', 2], @@ -50,71 +51,129 @@ class BcmTool { ['防守技能', 48], ['身体素质', 50], ]; - - for (const playerId of playersToQuery) { - if (!this.checkInfo(playerId)) { + + var form = new Form(); + for (let i = 0; i != attributes.length; ++i) + { + form.SetCell(i + 1, 0, attributes[i][0] as string); + } + for (let i = 0; i != playersToQuery.length; ++i) + { + const playerId = playersToQuery[i]; + if (!this.checkInfo(playerId)) + { console.log('找不到id', playerId); continue; } - this.logger.Info(this.queryName(playerId)); - for (const info of attributes) { - const name = info[0]; - const id = info[1]; - const record = this.queryInfo(playerId, id as number); - this.logger.Info(name, record); + form.SetCell(0, i + 1, this.queryName(playerId)); + for (let j = 0; j != attributes.length; ++j) + { + const record = this.queryInfo(playerId, attributes[j][1] as number); + form.SetCell(j + 1, i + 1, record.toString()); } - g_game.tools.CopyStrToClipboard(this.logger.GetOutput()); - this.logger.Clear(); } + console.log(form); + g_game.tools.CopyStrToClipboard(form.ToString()); } - - public checkInfo(playerId:string) { + + public checkInfo(playerId: string) + { const data = this.mgrTeamInfo.GetPlayerData(playerId); return data != null; } - - public queryName(playerId:string) { + + public queryName(playerId: string) + { const data = this.mgrTeamInfo.GetPlayerData(playerId); return data.playerName; } - - public queryInfo(playerId:string, attri:number) { + + public queryInfo(playerId: string, attri: number) + { const data = this.mgrTeamInfo.GetPlayerData(playerId); return data.GetSingleAttribute(attri).toFixed(2); } - public getPlayerIds() { + public getPlayerIds() + { return Object.keys(this.mgrTeamInfo._map_player_detail); } - public listPlayers() { + public listPlayers() + { const ids = Object.keys(this.mgrTeamInfo._map_player_detail); - for (const id of ids) { + for (const id of ids) + { console.log(this.queryName(id), id); } } } -class Logger { +class Logger +{ private msgs = ''; - public Info(...msgs:any[]) { - for (const msg of msgs) { + public Info(...msgs: any[]) + { + for (const msg of msgs) + { this.msgs += String(msg); } + } + + public NextLine() + { this.msgs += '\n'; } - public GetOutput() { + public GetContent() + { return this.msgs; } - public Clear() { + public Clear() + { this.msgs = ''; } } -(()=>{ +class Form +{ + private records: string[][] = []; + + public SetCell(col: number, row: number, data: string) + { + if (this.records[col] == null) + { + this.records[col] = []; + } + this.records[col][row] = data; + } + + public ToString() + { + var logger = new Logger(); + for (let col = 0; col != this.records.length; ++col) + { + for (let row = 0; row != this.records[col].length; ++row) + { + logger.Info(this.records[col][row] ?? ''); + if (row < this.records[col].length - 1) + { + logger.Info(','); + } + } + if (col < this.records.length - 1) + { + logger.NextLine(); + } + } + return logger.GetContent(); + } +} + +(() => +{ g_game.bcm_tool = new BcmTool(); })(); \ No newline at end of file