|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed, Ref, ref, watchEffect } from "vue"; |
| 3 | +import { Unit } from "../types"; |
| 4 | +import { fetchData } from "../utils"; |
| 5 | +import AwardTable from "./AwardTable.vue"; |
| 6 | +
|
| 7 | +const props = defineProps({ |
| 8 | + code: { type: String, required: true }, |
| 9 | + presetMapNames: { type: Object, required: true }, |
| 10 | +}); |
| 11 | +
|
| 12 | +const units: Ref<Unit[]> = ref([]); |
| 13 | +function unitCounts(counts: Unit[], unit_ids: number[]) { |
| 14 | + return Object.entries( |
| 15 | + counts |
| 16 | + .filter((unit) => unit_ids.includes(unit.unit_id)) |
| 17 | + .reduce( |
| 18 | + (playerTotals, unitCount) => { |
| 19 | + return { |
| 20 | + ...playerTotals, |
| 21 | + [unitCount.player]: |
| 22 | + (playerTotals[unitCount.player] ?? 0) + unitCount.amount, |
| 23 | + }; |
| 24 | + }, |
| 25 | + {} as Record<string, number>, |
| 26 | + ), |
| 27 | + ) |
| 28 | + .map(([player, total]) => ({ name: player, total })) |
| 29 | + .toSorted((a, b) => b.total - a.total) |
| 30 | + .slice(0, 3); |
| 31 | +} |
| 32 | +
|
| 33 | +const monkCounts = computed(() => { |
| 34 | + return unitCounts(units.value, [125, 775, 1023]); |
| 35 | +}); |
| 36 | +
|
| 37 | +const militiaCounts = computed(() => { |
| 38 | + return unitCounts(units.value, [74]); |
| 39 | +}); |
| 40 | +
|
| 41 | +const ramsCounts = computed(() => { |
| 42 | + return unitCounts(units.value, [35, 422, 548, 1258]); |
| 43 | +}); |
| 44 | +
|
| 45 | +const xolotlCounts = computed(() => { |
| 46 | + return unitCounts(units.value, [1570]); |
| 47 | +}); |
| 48 | +
|
| 49 | +const tradeCounts = computed(() => { |
| 50 | + return unitCounts(units.value, [17, 128]); |
| 51 | +}); |
| 52 | +
|
| 53 | +const battleElephantCounts = computed(() => { |
| 54 | + return unitCounts(units.value, [1132, 1134]); |
| 55 | +}); |
| 56 | +
|
| 57 | +const elephantsCounts = computed(() => { |
| 58 | + return unitCounts( |
| 59 | + units.value, |
| 60 | + [1132, 1134, 239, 558, 873, 875, 1120, 1122, 1744, 1746], |
| 61 | + ); |
| 62 | +}); |
| 63 | +
|
| 64 | +const phosphoruCounts = computed(() => { |
| 65 | + return unitCounts( |
| 66 | + units.value, |
| 67 | + [ |
| 68 | + 1962, 1980, 1704, 1706, 869, 871, 1001, 1003, 1738, 1739, 1740, 1759, |
| 69 | + 1760, 1761, 1126, 1127, 1128, |
| 70 | + ], |
| 71 | + ); |
| 72 | +}); |
| 73 | +
|
| 74 | +const teutonicCounts = computed(() => { |
| 75 | + return unitCounts(units.value, [25, 554]); |
| 76 | +}); |
| 77 | +
|
| 78 | +watchEffect(async () => { |
| 79 | + units.value = await fetchData(props.code, "units"); |
| 80 | +}); |
| 81 | +</script> |
| 82 | + |
| 83 | +<template> |
| 84 | + <div :class="$style.container"> |
| 85 | + <AwardTable |
| 86 | + :winners="monkCounts" |
| 87 | + title="Holy Clown" |
| 88 | + description="Who created the most monks, missionaries and priests." |
| 89 | + /> |
| 90 | + <AwardTable |
| 91 | + :winners="militiaCounts" |
| 92 | + title="Bullyboi" |
| 93 | + description="Who is addicted to Militia?" |
| 94 | + /> |
| 95 | + <AwardTable |
| 96 | + :winners="ramsCounts" |
| 97 | + title="Choo Choo" |
| 98 | + description="Who created the most rams." |
| 99 | + /> |
| 100 | + <AwardTable |
| 101 | + :winners="xolotlCounts" |
| 102 | + title="Wololo Guru" |
| 103 | + description="Who created the most Xolotl Warriors." |
| 104 | + /> |
| 105 | + <AwardTable |
| 106 | + :winners="tradeCounts" |
| 107 | + title="The Trader" |
| 108 | + description="Who created the most Trade Carts and Trade Cogs." |
| 109 | + /> |
| 110 | + <AwardTable |
| 111 | + :winners="battleElephantCounts" |
| 112 | + title="The legend of Liar" |
| 113 | + description="Who created the most Battle Elephants." |
| 114 | + /> |
| 115 | + <AwardTable |
| 116 | + :winners="elephantsCounts" |
| 117 | + title="The Chonker" |
| 118 | + description="Who created the most Elephants (of any kind!)." |
| 119 | + /> |
| 120 | + <AwardTable |
| 121 | + :winners="phosphoruCounts" |
| 122 | + title="Phosphoru Disciple" |
| 123 | + description="Who created the most Phosphoru-esque units (War Chariots, Hussite Wagons, Magyar Huszar, Organ Guns, Ratha, Arambai)." |
| 124 | + /> |
| 125 | + <AwardTable |
| 126 | + :winners="teutonicCounts" |
| 127 | + title="Grand Master of the Teutonic Order" |
| 128 | + description="Who created the most Teutonic Knights." |
| 129 | + /> |
| 130 | + </div> |
| 131 | +</template> |
| 132 | + |
| 133 | +<style lang="css" module> |
| 134 | +.container { |
| 135 | + display: grid; |
| 136 | + grid-template-columns: 1fr 1fr; |
| 137 | +} |
| 138 | +</style> |
0 commit comments