✨ (viewer) show recent player actions (#35)
This commit is contained in:
parent
a2eb09a0dc
commit
d266a2d90e
2 changed files with 36 additions and 33 deletions
|
|
@ -139,6 +139,7 @@
|
|||
<SpecialAction
|
||||
v-for="(action, i) in player.actions"
|
||||
:action="['>' + action.rewards]"
|
||||
:recent="recentAction(i)"
|
||||
:disabled="!action.enabled || passed"
|
||||
:key="action.action + '-' + i"
|
||||
y="17.5"
|
||||
|
|
@ -178,7 +179,7 @@
|
|||
<script lang="ts">
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,20 @@ export type State = {
|
|||
player: { index?: number; auth?: string } | null;
|
||||
};
|
||||
|
||||
function indexCommands(commands, command: Command) {
|
||||
const map = new Map<Faction, CommandObject[]>();
|
||||
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<Faction, Map<ResearchField, "recent" | "current-round">> => {
|
||||
return researchClasses(getters.recentCommands, getters.currentRoundCommands);
|
||||
},
|
||||
recentBuildingCommands: (state: State, getters): Map<Faction, CommandObject[]> => {
|
||||
const map = new Map<Faction, CommandObject[]>();
|
||||
|
||||
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<Faction, CommandObject[]> => {
|
||||
const map = new Map<Faction, CommandObject[]>();
|
||||
|
||||
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<Faction, CommandObject[]> =>
|
||||
indexCommands(getters.recentCommands, Command.Build),
|
||||
currentRoundBuildingCommands: (state: State, getters): Map<Faction, CommandObject[]> =>
|
||||
indexCommands(getters.currentRoundCommands, Command.Build),
|
||||
recentActions: (state: State, getters): Map<Faction, CommandObject[]> =>
|
||||
indexCommands(getters.recentCommands, Command.Special),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue