Added Splatoon 1 map rotation data through the Pretendo Network and Oatmealdome's API.

This commit is contained in:
flash 2024-04-12 00:33:16 +00:00
parent 069ac97f71
commit 901f69a424
8 changed files with 328 additions and 0 deletions

View file

@ -0,0 +1,153 @@
<?php
namespace Satori\Splatoon\Splatoon1;
use Satori\SHttp;
use Satori\Splatoon\ISplatoonScheduleFestival;
use Satori\Splatoon\ISplatoonGame;
use Satori\Splatoon\ISplatoonHasSchedules;
use Satori\Splatoon\ISplatoonLocale;
class Splatoon1Game implements ISplatoonGame, ISplatoonHasSchedules {
private const URL = 'https://splatoon.oatmealdome.me/api/v1/one';
public function getName(): string {
return 's1';
}
public function getTitle(): string {
return 'Splatoon 1';
}
public function getColour(): int {
return 0xFFF17E3B;
}
private const LOCALE_URL = self::URL . '/resources/versus?language=%s';
private const DEFAULT_LOCALE = 'EUen';
private const LOCALES = ['EUen', 'EUes', 'EUfr', 'EUde', 'EUit', 'EUpt', 'JPja', 'USen', 'USes', 'USfr', 'USpt'];
private const LOCALE_ALIASES = [
'en-US' => '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;
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Satori\Splatoon\Splatoon1;
use Satori\Splatoon\ISplatoonGameMode;
class Splatoon1GameMode implements ISplatoonGameMode {
public function __construct(
private Splatoon1Locale $locale,
private string $name,
private string $title,
private int $colour
) {}
public function getName(): string {
return $this->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 [];
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Satori\Splatoon\Splatoon1;
use Satori\Splatoon\ISplatoonLocale;
class Splatoon1Locale implements ISplatoonLocale {
public function __construct(
private array $strings
) {}
public function getString(string $name, string $fallback): string {
$name = explode(':', $name);
if(count($name) >= 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;
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Satori\Splatoon\Splatoon1;
use Index\XArray;
use Satori\Splatoon\ISplatoonScheduleEntryVs;
use Satori\Splatoon\ISplatoonVsRuleset;
class Splatoon1ScheduleEntryVs implements ISplatoonScheduleEntryVs {
public function __construct(
private Splatoon1Locale $locale,
private string $gameMode,
private array $entryInfo,
private Splatoon1TimePeriod $timePeriod
) {}
public function getGameMode(): string {
return $this->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']);
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Satori\Splatoon\Splatoon1;
use Satori\Splatoon\ISplatoonStage;
class Splatoon1Stage implements ISplatoonStage {
public function __construct(
private Splatoon1Locale $locale,
private int $stageNum
) {}
public function getId(): string {
return (string)$this->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 '';
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Satori\Splatoon\Splatoon1;
use Satori\Splatoon\ISplatoonTimePeriod;
class Splatoon1TimePeriod implements ISplatoonTimePeriod {
private int $startTime;
private int $endTime;
public function __construct(
string $startTime,
string $endTime
) {
$this->startTime = strtotime($startTime);
$this->endTime = strtotime($endTime);
}
public function getStartTime(): int {
return $this->startTime;
}
public function getEndTime(): int {
return $this->endTime;
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace Satori\Splatoon\Splatoon1;
use Satori\Splatoon\ISplatoonVsRuleset;
class Splatoon1VsRuleset implements ISplatoonVsRuleset {
public function __construct(
private Splatoon1Locale $locale,
private string $ruleset
) {}
public function getId(): string {
if($this->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;
}
}

View file

@ -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 {