Add King Salmonid guesses

This commit is contained in:
Matt Isenhower
2023-03-13 21:25:45 -07:00
parent e17db43e2e
commit 11372de7db
8 changed files with 98 additions and 7 deletions

View File

@@ -1,4 +1,6 @@
import ValueCache from "../../common/ValueCache.mjs";
import DataUpdater from "./DataUpdater.mjs";
import _ from 'lodash';
export default class StageScheduleUpdater extends DataUpdater
{
@@ -40,7 +42,53 @@ export default class StageScheduleUpdater extends DataUpdater
},
];
getData(locale) {
return this.splatnet(locale).getStageScheduleData();
async getData(locale) {
let data = await this.splatnet(locale).getStageScheduleData();
await this.processKingSalmonids(data);
return data;
}
async processKingSalmonids(data) {
let cache = new ValueCache('kingsalmonids');
let guesses = (await cache.getData()) || [];
// Get all known schedule times
let schedules = _.sortBy([
..._.get(data, 'data.coopGroupingSchedule.regularSchedules.nodes'),
..._.get(data, 'data.coopGroupingSchedule.bigRunSchedules.nodes'),
..._.get(data, 'data.coopGroupingSchedule.teamContestSchedules.nodes'),
], 'startTime');
// Remove cached times that don't exist anymore
guesses = guesses.filter(g => schedules.some(s => s.startTime === g.startTime));
// Process each schedule
let king = null;
for (let schedule of schedules) {
// Look for an existing guess
let guess = guesses.find(g => g.startTime === schedule.startTime);
// Determine the king for the current rotation
king = guess ? guess.king : this.nextKingSalmonid(king);
// If we didn't have it cached, add this guess to the cache
if (!guess) {
guesses.push({ startTime: schedule.startTime, king });
}
schedule.__splatoon3ink_king_salmonid_guess = king;
}
await cache.setData(_.sortBy(guesses, 'startTime'));
}
nextKingSalmonid(last = null) {
const sequence = ['Cohozuna', 'Horrorboros'];
let index = sequence.indexOf(last) + 1;
return sequence[index % sequence.length];
}
}

View File

@@ -36,6 +36,12 @@ export default class SalmonRunStatus extends StatusGenerator
lines.push('');
let king = schedule.__splatoon3ink_king_salmonid_guess;
if (king) {
lines.push(`King Salmonid guess: ${king}`);
lines.push('');
}
lines.push('Current weapons:');
lines.push(...schedule.settings.weapons.map(w => ` ${w.name}`));

View File

@@ -35,7 +35,11 @@
"salmonrun": {
"title": "Salmon Run",
"weapons": "Supplied Weapons",
"bigrun": "Big Run"
"bigrun": "Big Run",
"kings": {
"maybe-cohozuna": "Maybe: Cohozuna?",
"maybe-horrorboros": "Maybe: Horrorboros?"
}
},
"festival": {
"title": "Splatfests",

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -8,13 +8,15 @@
</div>
<div class="hidden ss:block text-shadow text-white text-xl">
<template v-if="time.isUpcoming(schedule.startTime)">
<KingSalmonid :schedule="schedule" class="inline-block -mb-1 mr-2" />
<div class="inline-block" v-if="time.isUpcoming(schedule.startTime)">
Shift opens
{{ $t('time.in', { time: formatDurationHoursFromNow(schedule.startTime, true) }) }}
</template>
<template v-else>
</div>
<div class="inline-block" v-else>
{{ $t('time.remaining', { time: formatDurationHoursFromNow(schedule.endTime) }) }}
</template>
</div>
</div>
<div
@@ -26,6 +28,8 @@
</div>
<div class="text-shadow text-zinc-300 ss:hidden">
<KingSalmonid :schedule="schedule" class="inline-block align-middle" />
{{ $t('time.remaining', { time: formatDurationFromNow(schedule.endTime) }) }}
</div>
@@ -52,6 +56,7 @@
import { formatDurationFromNow, formatDurationHoursFromNow } from '@/common/time';
import { useTimeStore } from '../../stores/time.mjs';
import StageImage from '../StageImage.vue';
import KingSalmonid from './KingSalmonid.vue';
import SalmonRunWeapons from './SalmonRunWeapons.vue';
defineProps({

View File

@@ -0,0 +1,25 @@
<template>
<div>
<img
src="@/assets/img/king-cohozuna.png"
:class="size"
:title="$t('salmonrun.kings.maybe-cohozuna')"
v-if="schedule.__splatoon3ink_king_salmonid_guess === 'Cohozuna'"
/>
<img
src="@/assets/img/king-horrorboros.png"
:class="size"
:title="$t('salmonrun.kings.maybe-horrorboros')"
v-if="schedule.__splatoon3ink_king_salmonid_guess === 'Horrorboros'"
/>
</div>
</template>
<script setup>
defineProps({
schedule: Object,
size: {
default: 'w-6',
},
})
</script>

View File

@@ -21,6 +21,8 @@
<StageImage class="w-1/5" imgClass="rounded" :stage="schedule.settings.coopStage" hide-label />
<div class="flex-1 text-sm text-zinc-300 text-shadow">
<KingSalmonid :schedule="schedule" class="inline-block align-middle" size="w-5" />
{{ $t(`splatnet.stages.${schedule.settings.coopStage.id}.name`, schedule.settings.coopStage.name) }}
<span class="text-xs inline-block bg-splatoon-bigRun bg-opacity-80 text-white rounded px-2" v-if="schedule.isBigRun">
@@ -38,6 +40,7 @@
<script setup>
import { formatDurationFromNow } from '@/common/time';
import StageImage from '../StageImage.vue';
import KingSalmonid from './KingSalmonid.vue';
import SalmonRunWeapons from './SalmonRunWeapons.vue';
defineProps({