From 901f69a4242245af0b76069045017b815eea8bf0 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 12 Apr 2024 00:33:16 +0000 Subject: [PATCH] Added Splatoon 1 map rotation data through the Pretendo Network and Oatmealdome's API. --- src/Splatoon/Splatoon1/Splatoon1Game.php | 153 ++++++++++++++++++ src/Splatoon/Splatoon1/Splatoon1GameMode.php | 33 ++++ src/Splatoon/Splatoon1/Splatoon1Locale.php | 18 +++ .../Splatoon1/Splatoon1ScheduleEntryVs.php | 35 ++++ src/Splatoon/Splatoon1/Splatoon1Stage.php | 24 +++ .../Splatoon1/Splatoon1TimePeriod.php | 25 +++ src/Splatoon/Splatoon1/Splatoon1VsRuleset.php | 39 +++++ src/Splatoon/SplatoonContext.php | 1 + 8 files changed, 328 insertions(+) create mode 100644 src/Splatoon/Splatoon1/Splatoon1Game.php create mode 100644 src/Splatoon/Splatoon1/Splatoon1GameMode.php create mode 100644 src/Splatoon/Splatoon1/Splatoon1Locale.php create mode 100644 src/Splatoon/Splatoon1/Splatoon1ScheduleEntryVs.php create mode 100644 src/Splatoon/Splatoon1/Splatoon1Stage.php create mode 100644 src/Splatoon/Splatoon1/Splatoon1TimePeriod.php create mode 100644 src/Splatoon/Splatoon1/Splatoon1VsRuleset.php diff --git a/src/Splatoon/Splatoon1/Splatoon1Game.php b/src/Splatoon/Splatoon1/Splatoon1Game.php new file mode 100644 index 0000000..3eaf84f --- /dev/null +++ b/src/Splatoon/Splatoon1/Splatoon1Game.php @@ -0,0 +1,153 @@ + 'USen', 'en-GB' => 'EUen', + 'es-ES' => 'EUes', 'es-MX' => 'USes', + 'fr-FR' => 'EUfr', 'fr-CA' => 'USfr', + 'de-DE' => 'EUde', 'it-IT' => 'EUit', + 'ja-JP' => 'JPja', + ]; + + public function getDefaultLocale(): string { + return self::DEFAULT_LOCALE; + } + + public function isSupportedLocale(string $locale): bool { + return in_array($locale, self::LOCALES); + } + + public function getLocales(): array { + return self::LOCALES; + } + + public function getLocaleAlias(string $locale): string { + if($locale === '') + return self::DEFAULT_LOCALE; + + if(array_key_exists($locale, self::LOCALE_ALIASES)) + return self::LOCALE_ALIASES[$locale]; + + return $locale; + } + + public function createLocale(string $locale): ISplatoonLocale { + return new Splatoon1Locale( + SHttp::getJsonCached(sprintf(self::LOCALE_URL, $locale)) + ); + } + + private const SCHED_URL = self::URL . '/versus/pretendo/phases?count=5'; + private const SCHED_FILTERS = [ + 'regular' => 'regular', + 'turf' => 'regular', + 'series' => 'gachi', + 'open' => 'gachi', + 'ranked' => 'gachi', + 'bankara' => 'gachi', + 'gachi' => 'gachi', + // look into these again if Pretendo adds Splatfest support + // 'fest' => 'fest', + // 'splatfest' => 'fest', + // 'festival' => 'fest', + ]; + + public function isValidScheduleFilter(string $filter): bool { + return array_key_exists($filter, self::SCHED_FILTERS); + } + + public function getScheduleFilters(): array { + return array_unique(array_values(self::SCHED_FILTERS)); + } + + public function getScheduleFilterAlias(string $filter): string { + if(array_key_exists($filter, self::SCHED_FILTERS)) + return self::SCHED_FILTERS[$filter]; + + return $filter; + } + + private ?array $rawSchedule = null; + private function getRawScheduleData(): array { + if($this->rawSchedule === null) + $this->rawSchedule = SHttp::getJsonCached(self::SCHED_URL); + + return $this->rawSchedule; + } + + public function getScheduleModes(ISplatoonLocale $locale, array $filters): array { + $modes = []; + + $includeRegular = in_array('regular', $filters); + $includeGachi = in_array('gachi', $filters); + + if($includeRegular || $includeGachi) { + $schedule = $this->getRawScheduleData(); + + if(!empty($schedule) && is_array($schedule)) { + if($includeRegular && !empty($schedule[0]['Regular'])) + $modes[] = new Splatoon1GameMode($locale, 'Regular', 'Regular Battle', 0xFF19D719); + + if($includeGachi && !empty($schedule[0]['Gachi'])) + $modes[] = new Splatoon1GameMode($locale, 'Gachi', 'Ranked Battle', 0xFFF54910); + } + } + + return $modes; + } + + public function getScheduleFestival(ISplatoonLocale $locale): ?ISplatoonScheduleFestival { + return null; + } + + public function getSchedules(ISplatoonLocale $locale, array $filters): array { + $schedules = []; + + $includeRegular = in_array('regular', $filters); + $includeGachi = in_array('gachi', $filters); + + if($includeRegular || $includeGachi) { + $phases = $this->getRawScheduleData(); + + foreach($phases as $phaseInfo) { + // assume corrupt + if(empty($phaseInfo['startTime']) || empty($phaseInfo['endTime'])) + continue; + + $timePeriod = new Splatoon1TimePeriod($phaseInfo['startTime'], $phaseInfo['endTime']); + + if($includeRegular && !empty($phaseInfo['Regular'])) + $schedules[] = new Splatoon1ScheduleEntryVs($locale, 'Regular', $phaseInfo['Regular'], $timePeriod); + + if($includeGachi && !empty($phaseInfo['Gachi'])) + $schedules[] = new Splatoon1ScheduleEntryVs($locale, 'Gachi', $phaseInfo['Gachi'], $timePeriod); + } + } + + return $schedules; + } +} diff --git a/src/Splatoon/Splatoon1/Splatoon1GameMode.php b/src/Splatoon/Splatoon1/Splatoon1GameMode.php new file mode 100644 index 0000000..f20a09d --- /dev/null +++ b/src/Splatoon/Splatoon1/Splatoon1GameMode.php @@ -0,0 +1,33 @@ +name; + } + + public function getTitle(): string { + return $this->locale->getString(sprintf('modes:%s', $this->name), $this->title); + } + + public function getColour(): int { + return $this->colour; + } + + public function hasVariants(): bool { + return false; + } + + public function getVariants(): array { + return []; + } +} diff --git a/src/Splatoon/Splatoon1/Splatoon1Locale.php b/src/Splatoon/Splatoon1/Splatoon1Locale.php new file mode 100644 index 0000000..3bb241b --- /dev/null +++ b/src/Splatoon/Splatoon1/Splatoon1Locale.php @@ -0,0 +1,18 @@ += 2 && array_key_exists($name[0], $this->strings) && array_key_exists($name[1], $this->strings[$name[0]])) + return $this->strings[$name[0]][$name[1]]; + + return $fallback; + } +} diff --git a/src/Splatoon/Splatoon1/Splatoon1ScheduleEntryVs.php b/src/Splatoon/Splatoon1/Splatoon1ScheduleEntryVs.php new file mode 100644 index 0000000..ea8552b --- /dev/null +++ b/src/Splatoon/Splatoon1/Splatoon1ScheduleEntryVs.php @@ -0,0 +1,35 @@ +gameMode; + } + + public function getGameModeVariant(): string { + return ''; + } + + public function getTimePeriods(): array { + return [ $this->timePeriod ]; + } + + public function getStages(): array { + return XArray::select($this->entryInfo['stages'], fn($stageNum) => new Splatoon1Stage($this->locale, $stageNum)); + } + + public function getRuleset(): ?ISplatoonVsRuleset { + return new Splatoon1VsRuleset($this->locale, $this->entryInfo['rule']); + } +} diff --git a/src/Splatoon/Splatoon1/Splatoon1Stage.php b/src/Splatoon/Splatoon1/Splatoon1Stage.php new file mode 100644 index 0000000..eccd15b --- /dev/null +++ b/src/Splatoon/Splatoon1/Splatoon1Stage.php @@ -0,0 +1,24 @@ +stageNum; + } + + public function getName(): string { + return $this->locale->getString(sprintf('stages:%d', $this->stageNum), (string)$this->stageNum); + } + + public function getImage(): string { + // images on oatmealdome's website are in webp format which is a little bit disgusting so we'll leave it empty for now + return ''; + } +} diff --git a/src/Splatoon/Splatoon1/Splatoon1TimePeriod.php b/src/Splatoon/Splatoon1/Splatoon1TimePeriod.php new file mode 100644 index 0000000..42f88ae --- /dev/null +++ b/src/Splatoon/Splatoon1/Splatoon1TimePeriod.php @@ -0,0 +1,25 @@ +startTime = strtotime($startTime); + $this->endTime = strtotime($endTime); + } + + public function getStartTime(): int { + return $this->startTime; + } + + public function getEndTime(): int { + return $this->endTime; + } +} diff --git a/src/Splatoon/Splatoon1/Splatoon1VsRuleset.php b/src/Splatoon/Splatoon1/Splatoon1VsRuleset.php new file mode 100644 index 0000000..b311011 --- /dev/null +++ b/src/Splatoon/Splatoon1/Splatoon1VsRuleset.php @@ -0,0 +1,39 @@ +ruleset === 'Lift') + return 'LOFT'; + if($this->ruleset === 'Area') + return 'AREA'; + if($this->ruleset === 'Goal') + return 'GOAL'; + if($this->ruleset === 'Paint') + return 'TURF_WAR'; + return $this->ruleset; + } + + public function getName(): string { + return $this->locale->getString(sprintf('rules:%s', $this->ruleset), $this->ruleset); + } + + public function getShortName(): string { + if($this->ruleset === 'Lift') + return 'TC'; + if($this->ruleset === 'Area') + return 'SZ'; + if($this->ruleset === 'Goal') + return 'RM'; + if($this->ruleset === 'Paint') + return 'TW'; + return $this->ruleset; + } +} diff --git a/src/Splatoon/SplatoonContext.php b/src/Splatoon/SplatoonContext.php index 8c76e3e..7c50967 100644 --- a/src/Splatoon/SplatoonContext.php +++ b/src/Splatoon/SplatoonContext.php @@ -9,6 +9,7 @@ class SplatoonContext { public function __construct(private IConfig $config) { $this->games[] = new Splatoon3\Splatoon3Game; $this->games[] = new Splatoon2\Splatoon2Game; + $this->games[] = new Splatoon1\Splatoon1Game; } public function getConfig(): IConfig {