@@ -4,7 +4,7 @@ import { useData } from "vitepress";
44import MapPicksChart from " ./MapPicksChart.vue" ;
55import MapBansChart from " ./MapBansChart.vue" ;
66import CivPickChart from " ./CivPickChart.vue" ;
7- import { allCivs , Draft , Drafts , Game , Player } from " ../types" ;
7+ import { allCivs , Draft , Drafts , Game , Player , Unit } from " ../types" ;
88import CivBansChart from " ./CivBansChart.vue" ;
99import CivPlayedChart , { type GameStats } from " ./CivPlayedChart.vue" ;
1010import CivWinrateChart from " ./CivWinrateChart.vue" ;
@@ -13,6 +13,7 @@ import { fetchData, normalizeCivs } from "../utils";
1313import EApmChart from " ./EApmChart.vue" ;
1414import VilCountChart from " ./VilCountChart.vue" ;
1515import MostCreatedChart from " ./MostCreatedChart.vue" ;
16+ import UnitAmountChart from " ./UnitAmountChart.vue" ;
1617
1718const props = defineProps ({
1819 code: { type: String , required: true },
@@ -23,6 +24,7 @@ const { params } = useData();
2324const drafts: Ref <Drafts > = ref ({ civDrafts: [], mapDrafts: [] });
2425const games: Ref <Game []> = ref ([]);
2526const players: Ref <Player []> = ref ([]);
27+ const units: Ref <Unit []> = ref ([]);
2628const selectedBrackets = ref ([... (params .value ?.brackets ?? [])]);
2729const selectedMaps: Ref <string []> = ref ([]);
2830
@@ -31,10 +33,12 @@ watchEffect(async () => {
3133 fetchData (props .code , " drafts" ),
3234 fetchData (props .code , " games" ),
3335 fetchData (props .code , " players" ),
36+ fetchData (props .code , " units" ),
3437 ];
3538 drafts .value = await promises [0 ];
3639 games .value = await promises [1 ];
3740 players .value = await promises [2 ];
41+ units .value = await promises [3 ];
3842});
3943
4044function mapName(map_id : string ) {
@@ -169,6 +173,20 @@ const filteredPlayers = computed(
169173 // .filter((player) => selectedMaps.value.includes(mapName(player.map))),
170174);
171175
176+ const unitCounts = computed (() => {
177+ return units .value .reduce (
178+ (totals , playerData ) => {
179+ if (playerData .unit_name == " Villager" ) return totals ;
180+ return {
181+ ... totals ,
182+ [playerData .unit_name ]:
183+ (totals [playerData .unit_name ] ?? 0 ) + playerData .amount ,
184+ };
185+ },
186+ {} as Record <string , number >,
187+ );
188+ });
189+
172190const allMaps = computed (() => {
173191 return [... new Set (games .value .map ((game ) => game .map ))].toSorted ();
174192});
@@ -294,6 +312,7 @@ watch(allMaps, () => {
294312 <EApmChart :players =" filteredPlayers " />
295313 <VilCountChart :players =" filteredPlayers " />
296314 <MostCreatedChart :players =" filteredPlayers " />
315+ <UnitAmountChart v-if =" units .length " :units =" unitCounts " />
297316</template >
298317
299318<style lang="css" module>
0 commit comments