From d266a2d90e58f38d970bbb13b73519d2f685c25f Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 24 Mar 2021 21:35:55 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(viewer)=20show=20recent=20player?= =?UTF-8?q?=20actions=20(#35)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- viewer/src/components/PlayerInfo.vue | 21 +++++++++--- viewer/src/store.ts | 48 ++++++++++++---------------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/viewer/src/components/PlayerInfo.vue b/viewer/src/components/PlayerInfo.vue index 3fe0b193..2102b293 100644 --- a/viewer/src/components/PlayerInfo.vue +++ b/viewer/src/components/PlayerInfo.vue @@ -139,6 +139,7 @@ import Vue from "vue"; import { Component, Prop } from "vue-property-decorator"; -import { Player, factions, Planet } from "@gaia-project/engine"; +import { Command, factions, Planet, Player } from "@gaia-project/engine"; import { factionColor } from "../graphics/utils"; import TechTile from "./TechTile.vue"; import Booster from "./Booster.vue"; @@ -213,7 +214,7 @@ export default class PlayerInfo extends Vue { } get factionColor() { - return factionColor(this.player.faction); + return factionColor(this.faction); } get name() { @@ -224,15 +225,25 @@ export default class PlayerInfo extends Vue { } get tooltip() { - return factionDesc(this.player.faction); + return factionDesc(this.faction); } get planet() { - return factions[this.player.faction].planet; + return factions[this.faction].planet; + } + + get faction() { + return this.player.faction; } get factionName(): string { - return factions[this.player.faction].name; + return factions[this.faction].name; + } + + recentAction(i: number): boolean { + const action = this.player.actions[i]; + const commands = this.$store.getters["gaiaViewer/recentActions"].get(this.faction) ?? []; + return commands.some((c) => c.args[0] === action.rewards); } planetFill(planet: string) { diff --git a/viewer/src/store.ts b/viewer/src/store.ts index 2079296b..0ae25ac1 100644 --- a/viewer/src/store.ts +++ b/viewer/src/store.ts @@ -28,6 +28,20 @@ export type State = { player: { index?: number; auth?: string } | null; }; +function indexCommands(commands, command: Command) { + const map = new Map(); + for (const c of commands as CommandObject[]) { + if (c.command === command) { + if (!map.has(c.faction)) { + map.set(c.faction, []); + } + map.get(c.faction).push(c); + } + } + + return map; +} + const gaiaViewer = { namespaced: true, state: { @@ -165,34 +179,12 @@ const gaiaViewer = { researchClasses: (state: State, getters): Map> => { return researchClasses(getters.recentCommands, getters.currentRoundCommands); }, - recentBuildingCommands: (state: State, getters): Map => { - const map = new Map(); - - for (const command of getters.recentCommands as CommandObject[]) { - if (command.command === Command.Build) { - if (!map.has(command.faction)) { - map.set(command.faction, []); - } - map.get(command.faction).push(command); - } - } - - return map; - }, - currentRoundBuildingCommands: (state: State, getters): Map => { - const map = new Map(); - - for (const command of getters.currentRoundCommands as CommandObject[]) { - if (command.command === Command.Build) { - if (!map.has(command.faction)) { - map.set(command.faction, []); - } - map.get(command.faction).push(command); - } - } - - return map; - }, + recentBuildingCommands: (state: State, getters): Map => + indexCommands(getters.recentCommands, Command.Build), + currentRoundBuildingCommands: (state: State, getters): Map => + indexCommands(getters.currentRoundCommands, Command.Build), + recentActions: (state: State, getters): Map => + indexCommands(getters.recentCommands, Command.Special), }, };