From c9a270033dc5c6ca0fd3241b44800313623e9a8f Mon Sep 17 00:00:00 2001 From: ana Date: Sun, 8 Aug 2021 17:27:22 +0200 Subject: feat: display more info about all enemies --- src/App.svelte | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/bestiary.js | 15 +++++------ 2 files changed, 80 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/App.svelte b/src/App.svelte index 0de1e0e..a68b9ee 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -4,13 +4,18 @@ import { onMount } from "svelte"; import { formatUtc } from "./times"; import { getMatches } from "./bestiary"; + import day from "dayjs"; + import relativeTime from "dayjs/plugin/relativeTime"; + day.extend(relativeTime); onMount(async () => { updateWeatherStores(); }); let date = new Date().getTime() * (1440 / 70); + let matches, upMatches, otherMatches, normalMatches, pagosForecast; + newMatches(); setInterval(() => { date = new Date().getTime() * (1440 / 70); }, 1000); @@ -20,11 +25,47 @@ paWeather.set(ew.forecast(ew.PAGOS_WEATHER)); } - const pagosForecast = ew.forecast(ew.PAGOS_WEATHER); - getMatches(pagosForecast, $level); + function formatWeathers(weathers) { + if (weathers.length === 1) { + return ew.getWeatherName(weathers[0]); + } + return weathers + .map((w, i) => { + if (i + 1 === weathers.length) { + return `and ${ew.getWeatherName(w)}`; + } + return `${ew.getWeatherName(w)}, `; + }) + .join(""); + } + + function newMatches() { + pagosForecast = ew.forecast(ew.PAGOS_WEATHER); + matches = getMatches(pagosForecast, $level).sort( + (a, b) => a.level < b.level + ); + + upMatches = matches.filter((m) => m.uptime.isUp); + normalMatches = matches.filter((m) => !m.special); + otherMatches = matches.filter((m) => m.special && !m.uptime.isUp); + } + + function formatNextUptime(futures) { + let i; + futures.find((f, idx) => { + if (f) i = idx; + return f; + }); + + if (i) { + return `in ${day(pagosForecast[i + 1].date).fromNow()}`; + } + return "in the far future"; + } function levelChanged(evt) { level.set(Number(evt.target.value)); + newMatches(); } @@ -37,7 +78,37 @@ Time is {currentEzTime}
- Anemos Weather is {pagosForecast[0].weatherName} +
matches
+ + +
regular enemies
+ + +
special enemies that do not mutate/augment right now
+ + + Pagos Weather is {pagosForecast[0].weatherName} diff --git a/src/bestiary.js b/src/bestiary.js index 33779d3..0598abb 100644 --- a/src/bestiary.js +++ b/src/bestiary.js @@ -4,12 +4,12 @@ import isBetween from "dayjs/plugin/isBetween"; day.extend(isBetween); export function getMatches(forecast, level) { - console.log(level); let res = []; pagosB.forEach((b) => { if (b.level >= level && b.level - 2 < level) { res.push({ name: b.name, + level: b.level, elem: b.elem, special: b.type > 0, mutating: b.type === 1, @@ -19,6 +19,7 @@ export function getMatches(forecast, level) { } }); console.log(res); + return res; } function getEzTime() { @@ -29,19 +30,15 @@ function findForecastMatch(forecast, conditions) { const time = getEzTime(); const dn = time.isBetween(time.hour(8), time.hour(18)) ? "day" : "night"; return { - isUp: forecastMatches(forecast, conditions[dn], 0).length > 0, - weathers: forecastMatches(forecast, conditions[dn], 0), + isUp: forecastMatches(forecast, conditions[dn], 0), + weathers: conditions[dn], futureUptime: [1, 2, 3, 4].map((i) => { - const match = forecastMatches(forecast, conditions[dn], i); - return { - isUp: match.length > 0, - weathers: match, - }; + return forecastMatches(forecast, conditions[dn], i); }), }; } function forecastMatches(forecast, condition, index) { const currWeather = forecast[index].currWeather; - return condition.filter((c) => c === currWeather); + return condition.some((c) => c === currWeather); } -- cgit 1.4.1-2-gfad0