generated from nhcarrigan/template
Reviewed-on: https://codeberg.org/nhcarrigan/tingle-bot/pulls/1 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
/**
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
import { inarikoSeasons } from "../../data/weather/regions/inarikoSeasons.js";
|
|
import { rudaniaSeasons } from "../../data/weather/regions/rudaniaSeasons.js";
|
|
import { vhintlSeasons } from "../../data/weather/regions/vhintlSeasons.js";
|
|
import type { RegionName } from "../../interfaces/weather/names/regionName.js";
|
|
import type { Season } from "../../interfaces/weather/names/season.js";
|
|
import type { RegionRestriction } from "../../interfaces/weather/regions/regionRestriction.js";
|
|
|
|
/**
|
|
* Module to get the allowed weather for a region based on the season.
|
|
* Will throw an error if the data is not found.
|
|
* @param region - The name of the region.
|
|
* @param season - The season the region is in.
|
|
* @returns The allowed weather for the region.
|
|
*/
|
|
export const getRegionRestrictions = (
|
|
region: RegionName,
|
|
season: Season,
|
|
): RegionRestriction | null => {
|
|
let restrictions = null;
|
|
switch (region) {
|
|
case "Rudania":
|
|
restrictions = rudaniaSeasons;
|
|
break;
|
|
case "Inariko":
|
|
restrictions = inarikoSeasons;
|
|
break;
|
|
case "Vhintl":
|
|
restrictions = vhintlSeasons;
|
|
break;
|
|
default:
|
|
return null;
|
|
}
|
|
|
|
if (restrictions === null) {
|
|
return null;
|
|
}
|
|
|
|
const seasonalRestriction = restrictions.find((element) => {
|
|
return element.season === season;
|
|
});
|
|
|
|
if (!seasonalRestriction) {
|
|
return null;
|
|
}
|
|
|
|
return seasonalRestriction;
|
|
};
|