stardew-tracker/static/availability.js

42 lines
1.5 KiB
JavaScript
Raw Normal View History

(function exposeAvailability(root, factory) {
const api = factory();
if (typeof module === "object" && module.exports) module.exports = api;
if (root) root.ValleyAvailability = api;
})(typeof window === "undefined" ? globalThis : window, () => {
const weatherFor = entry => {
if (!String(entry.id || "").startsWith("fish-")) return null;
const detail = String(entry.meta || "").toLowerCase();
if (detail.includes("rain")) return "Rain";
if (detail.includes("sunny")) return "Sun";
return null;
};
const classify = (entry, { checked, chooseGroupComplete, season }) => {
const seasons = Array.isArray(entry.seasons) ? entry.seasons : [];
const seasonal = seasons.length > 0;
const inSeason = seasons.includes(season);
const availableNow = !seasonal || inSeason;
const needed = !checked && !chooseGroupComplete;
return {
checked,
needed,
seasonal,
inSeason,
availableNow,
seasonExclusive: needed && inSeason && seasons.length === 1,
weather: weatherFor(entry),
seasons
};
};
const matchesFilter = (status, filter) => {
if (filter === "open") return status.needed;
if (filter === "now") return status.needed && status.availableNow;
if (filter === "exclusive") return status.seasonExclusive;
if (filter === "weather") return status.needed && status.availableNow && Boolean(status.weather);
return true;
};
return { classify, matchesFilter, weatherFor };
});