diff --git a/src/shared/files/config.file.ts b/src/shared/files/config.file.ts index f10d74d..806bf3d 100644 --- a/src/shared/files/config.file.ts +++ b/src/shared/files/config.file.ts @@ -9,6 +9,7 @@ features: # Plugins are loaded in order plugins: + player-party: true player-agent: true player-name: true player-skins: diff --git a/src/table/plugin.manager.ts b/src/table/plugin.manager.ts index c5f6f74..10f1c30 100644 --- a/src/table/plugin.manager.ts +++ b/src/table/plugin.manager.ts @@ -8,6 +8,7 @@ import { PlayerAgentPlugin } from "./plugins/player-agent.plugin"; import { PlayerLevelPlugin } from "./plugins/player-level.plugin"; import { PlayerMatchesPlugin } from "./plugins/player-matches.plugin"; import { PlayerNamePlugin } from "./plugins/player-name.plugin"; +import { PlayerPartyPlugin } from "./plugins/player-party.plugin"; import { PlayerPeakRankPlugin } from "./plugins/player-peak-rank.plugin"; import { PlayerRankPlugin } from "./plugins/player-rank.plugin"; import { PlayerRRPlugin } from "./plugins/player-rr.plugin"; @@ -24,6 +25,7 @@ export const STATE_HOOK_MAP = { } as const; const INBUILT_PLUGINS: PluginDefinition[] = [ + PlayerPartyPlugin, PlayerAgentPlugin, PlayerNamePlugin, PlayerRankPlugin, diff --git a/src/table/plugins/player-party.plugin.ts b/src/table/plugins/player-party.plugin.ts new file mode 100644 index 0000000..0f29b96 --- /dev/null +++ b/src/table/plugins/player-party.plugin.ts @@ -0,0 +1,77 @@ +import chalk from "chalk"; + +import { inject } from "~/shared/dependencies"; +import { PartyService } from "~/shared/services/party.service"; + +import { definePlugin } from "../types/plugin.interface"; + +const PLUGIN_ID = "player-party"; +const COLUMN_NAME = "Party"; +export const PlayerPartyPlugin = definePlugin({ + id: PLUGIN_ID, + type: "post", + hooks: { + onState: async ({ data, table }) => { + const partyService = inject(PartyService); + + const parties = partyService.getParties(); + + if (parties.length <= 0) { + return; + } + + data.prefetched.uuids.forEach((puuid, index) => { + const party = parties.find(p => p.players.includes(puuid)); + + if (party) { + table.grid.setCell({ + rowId: puuid, + colId: PLUGIN_ID, + value: formatParty({ + index, + isMyParty: partyService.isInMyParty(puuid), + isCaptain: party.captain === puuid, + }), + }); + } + }); + + table.headers.set(PLUGIN_ID, COLUMN_NAME); + }, + }, +}); + +/* Formatter */ + +function formatParty(opts: { + index: number; + isMyParty: boolean; + isCaptain: boolean; +}): string { + let icon: string; + + if (opts.isMyParty) { + icon = selfPartyIcon; + } else { + icon = partyIcons[opts.index]!; + } + + if (opts.isCaptain) { + icon = chalk.bold(">>") + " " + icon; + } + + return icon; +} + +const selfPartySymbol = "*"; +const selfPartyIcon = chalk.rgb(221, 224, 41)(selfPartySymbol); +const partySymbol = "■"; +const partyIcons = [ + chalk.rgb(227, 67, 67)(partySymbol), + chalk.rgb(216, 67, 227)(partySymbol), + chalk.rgb(67, 70, 227)(partySymbol), + chalk.rgb(67, 227, 208)(partySymbol), + chalk.rgb(94, 227, 67)(partySymbol), + chalk.rgb(226, 237, 57)(partySymbol), + chalk.rgb(212, 82, 207)(partySymbol), +];