csv form format

This commit is contained in:
2026-01-20 16:56:27 +08:00
parent b6331e206b
commit 41cd99fa36
3 changed files with 131 additions and 41 deletions
+1 -1
View File
@@ -1 +1 @@
g_game.bcm_tool.queryPlayerInfo(g_game.bcm_tool.listPlayers()); g_game.bcm_tool.queryPlayerInfo(g_game.bcm_tool.getPlayerIds());
+42 -11
View File
@@ -2,7 +2,6 @@
class BcmTool { class BcmTool {
constructor() { constructor() {
this.mgrTeamInfo = g_game.mgr.mgr_team_player_team_info; this.mgrTeamInfo = g_game.mgr.mgr_team_player_team_info;
this.logger = new Logger();
} }
queryPlayerInfo(playersToQuery) { queryPlayerInfo(playersToQuery) {
const attributes = [ const attributes = [
@@ -51,21 +50,24 @@ class BcmTool {
['防守技能', 48], ['防守技能', 48],
['身体素质', 50], ['身体素质', 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)) { if (!this.checkInfo(playerId)) {
console.log('找不到id', playerId); console.log('找不到id', playerId);
continue; continue;
} }
this.logger.Info(this.queryName(playerId)); form.SetCell(0, i + 1, this.queryName(playerId));
for (const info of attributes) { for (let j = 0; j != attributes.length; ++j) {
const name = info[0]; const record = this.queryInfo(playerId, attributes[j][1]);
const id = info[1]; form.SetCell(j + 1, i + 1, record.toString());
const record = this.queryInfo(playerId, id);
this.logger.Info(name, record);
} }
g_game.tools.CopyStrToClipboard(this.logger.GetOutput());
this.logger.Clear();
} }
console.log(form);
g_game.tools.CopyStrToClipboard(form.ToString());
} }
checkInfo(playerId) { checkInfo(playerId) {
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
@@ -97,15 +99,44 @@ class Logger {
for (const msg of msgs) { for (const msg of msgs) {
this.msgs += String(msg); this.msgs += String(msg);
} }
}
NextLine() {
this.msgs += '\n'; this.msgs += '\n';
} }
GetOutput() { GetContent() {
return this.msgs; return this.msgs;
} }
Clear() { Clear() {
this.msgs = ''; 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(); g_game.bcm_tool = new BcmTool();
})(); })();
+84 -25
View File
@@ -1,9 +1,10 @@
class BcmTool { class BcmTool
{
private mgrTeamInfo = g_game.mgr.mgr_team_player_team_info; private mgrTeamInfo = g_game.mgr.mgr_team_player_team_info;
private logger = new Logger();
public queryPlayerInfo(playersToQuery:string[]) { public queryPlayerInfo(playersToQuery: string[])
{
const attributes = [ const attributes = [
['速度', 1], ['速度', 1],
['力量', 2], ['力量', 2],
@@ -51,70 +52,128 @@ class BcmTool {
['身体素质', 50], ['身体素质', 50],
]; ];
for (const playerId of playersToQuery) { var form = new Form();
if (!this.checkInfo(playerId)) { 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); console.log('找不到id', playerId);
continue; continue;
} }
this.logger.Info(this.queryName(playerId)); form.SetCell(0, i + 1, this.queryName(playerId));
for (const info of attributes) { for (let j = 0; j != attributes.length; ++j)
const name = info[0]; {
const id = info[1]; const record = this.queryInfo(playerId, attributes[j][1] as number);
const record = this.queryInfo(playerId, id as number); form.SetCell(j + 1, i + 1, record.toString());
this.logger.Info(name, record);
} }
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); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data != null; return data != null;
} }
public queryName(playerId:string) { public queryName(playerId: string)
{
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data.playerName; return data.playerName;
} }
public queryInfo(playerId:string, attri:number) { public queryInfo(playerId: string, attri: number)
{
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data.GetSingleAttribute(attri).toFixed(2); return data.GetSingleAttribute(attri).toFixed(2);
} }
public getPlayerIds() { public getPlayerIds()
{
return Object.keys(this.mgrTeamInfo._map_player_detail); return Object.keys(this.mgrTeamInfo._map_player_detail);
} }
public listPlayers() { public listPlayers()
{
const ids = Object.keys(this.mgrTeamInfo._map_player_detail); 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); console.log(this.queryName(id), id);
} }
} }
} }
class Logger { class Logger
{
private msgs = ''; private msgs = '';
public Info(...msgs:any[]) { public Info(...msgs: any[])
for (const msg of msgs) { {
for (const msg of msgs)
{
this.msgs += String(msg); this.msgs += String(msg);
} }
}
public NextLine()
{
this.msgs += '\n'; this.msgs += '\n';
} }
public GetOutput() { public GetContent()
{
return this.msgs; return this.msgs;
} }
public Clear() { public Clear()
{
this.msgs = ''; 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(); g_game.bcm_tool = new BcmTool();
})(); })();