Added support for different Splatfest Pro and Open rotations.
This commit is contained in:
parent
fd03da959a
commit
b755646252
3 changed files with 49 additions and 21 deletions
|
@ -2,7 +2,16 @@
|
|||
namespace Satori;
|
||||
|
||||
final class SHttp {
|
||||
public static function getJson(string $url): mixed {
|
||||
public static function getJson(string $url, array $headers = []): mixed {
|
||||
// this isn't case insensitive so please promise me that
|
||||
// you'll always use proper casing for header names ok????
|
||||
if(!array_key_exists('Accept', $headers))
|
||||
$headers['Accept'] = 'application/json';
|
||||
|
||||
$rawHeaders = [];
|
||||
foreach($headers as $name => $value)
|
||||
$rawHeaders[] = sprintf('%s: %s', $name, $value);
|
||||
|
||||
$curl = curl_init($url);
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_AUTOREFERER => true,
|
||||
|
@ -18,7 +27,7 @@ final class SHttp {
|
|||
CURLOPT_CONNECTTIMEOUT => 2,
|
||||
CURLOPT_TIMEOUT => 5,
|
||||
CURLOPT_USERAGENT => sprintf('Satori/%s (+https://fii.moe/satori)', SAT_VERSION),
|
||||
CURLOPT_HTTPHEADER => ['Accept: application/json'],
|
||||
CURLOPT_HTTPHEADER => $rawHeaders,
|
||||
]);
|
||||
$response = json_decode(curl_exec($curl), true);
|
||||
curl_close($curl);
|
||||
|
@ -26,7 +35,7 @@ final class SHttp {
|
|||
return $response;
|
||||
}
|
||||
|
||||
public static function getJsonCached(string $url): mixed {
|
||||
return SFileCache::for15mins($url, fn() => self::getJson($url));
|
||||
public static function getJsonCached(string $url, array $headers = []): mixed {
|
||||
return SFileCache::for15mins($url, fn() => self::getJson($url, $headers));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,11 +55,11 @@ final class SatoriContext {
|
|||
public function createRouting(): RoutingContext {
|
||||
$routingCtx = new RoutingContext;
|
||||
|
||||
$routingCtx->register(new ExRate\ExRateRoutes($this->createExRates()));
|
||||
$routingCtx->register(new Dictionary\DictionaryRoutes($this->createDictionary()));
|
||||
$routingCtx->register(new Translation\TranslateRoutes($this->createTranslation()));
|
||||
$routingCtx->register(new Booru\BooruRoutes($this->createBooru()));
|
||||
$routingCtx->register(new Dictionary\DictionaryRoutes($this->createDictionary()));
|
||||
$routingCtx->register(new ExRate\ExRateRoutes($this->createExRates()));
|
||||
$routingCtx->register(new Splatoon\SplatoonRoutes($this->createSplatoon()));
|
||||
$routingCtx->register(new Translation\TranslateRoutes($this->createTranslation()));
|
||||
|
||||
return $routingCtx;
|
||||
}
|
||||
|
|
|
@ -104,9 +104,10 @@ class Splatoon3Game implements ISplatoonGame, ISplatoonHasFestivals, ISplatoonHa
|
|||
'coop' => 'coop',
|
||||
'eggstra' => 'eggstra',
|
||||
'bigrun' => 'bigrun',
|
||||
'fest' => 'fest',
|
||||
'splatfest' => 'fest',
|
||||
'festival' => 'fest',
|
||||
'fest' => 'bankara',
|
||||
'splatfest' => 'bankara',
|
||||
'festival' => 'bankara',
|
||||
'pro' => 'series',
|
||||
];
|
||||
|
||||
public function isValidScheduleFilter(string $filter): bool {
|
||||
|
@ -195,18 +196,33 @@ class Splatoon3Game implements ISplatoonGame, ISplatoonHasFestivals, ISplatoonHa
|
|||
}
|
||||
}
|
||||
|
||||
if(in_array('fest', $filters) && array_key_exists('festSchedules', $raw) && !empty($raw['festSchedules']['nodes'])) {
|
||||
if($includeRanked && array_key_exists('festSchedules', $raw) && !empty($raw['festSchedules']['nodes'])) {
|
||||
$variants = [];
|
||||
foreach($raw['festSchedules']['nodes'] as $info) {
|
||||
if(!empty($info['festMatchSettings'])) {
|
||||
$modes[] = new Splatoon3GameMode('fest', 'Splatfest Battle', 0xFF71717A);
|
||||
break;
|
||||
if(empty($info['festMatchSettings']))
|
||||
continue;
|
||||
|
||||
if($includeRankedSeries && !empty($info['festMatchSettings'][0])) {
|
||||
$includeRankedSeries = false;
|
||||
$variants[] = new Splatoon3GameModeVariant('PRO', 'Pro', 0xFF603BFF);
|
||||
}
|
||||
|
||||
if($includeRankedOpen && !empty($info['festMatchSettings'][1])) {
|
||||
$includeRankedOpen = false;
|
||||
$variants[] = new Splatoon3GameModeVariant('OPEN', 'Open', 0xFF603BFF);
|
||||
}
|
||||
|
||||
if(!$includeRankedSeries && !$includeRankedOpen)
|
||||
break;
|
||||
}
|
||||
|
||||
if(!empty($raw['currentFest']['tricolorStage']))
|
||||
$modes[] = new Splatoon3GameMode('tricolor', 'Tricolor Battle', 0xFF71717A);
|
||||
if(!empty($variants))
|
||||
$modes[] = new Splatoon3GameMode('fest', 'Splatfest Battle', 0xFFCFF622, $variants);
|
||||
}
|
||||
|
||||
if($includeRanked && !empty($raw['currentFest']['tricolorStage']))
|
||||
$modes[] = new Splatoon3GameMode('tricolor', 'Tricolor Battle', 0xFF71717A);
|
||||
|
||||
if(array_key_exists('coopGroupingSchedule', $raw)) {
|
||||
$coop = $raw['coopGroupingSchedule'];
|
||||
|
||||
|
@ -297,17 +313,20 @@ class Splatoon3Game implements ISplatoonGame, ISplatoonHasFestivals, ISplatoonHa
|
|||
$schedules[] = new Splatoon3ScheduleEntryVsLeague($locale, $info);
|
||||
}
|
||||
|
||||
if(in_array('fest', $filters) && array_key_exists('festSchedules', $raw) && !empty($raw['festSchedules']['nodes'])) {
|
||||
if($includeRanked && array_key_exists('festSchedules', $raw) && !empty($raw['festSchedules']['nodes']))
|
||||
foreach($raw['festSchedules']['nodes'] as $info) {
|
||||
if(empty($info['festMatchSettings']))
|
||||
continue;
|
||||
|
||||
$schedules[] = new Splatoon3ScheduleEntryVs($locale, 'fest', '', $info, $info['festMatchSettings']);
|
||||
if($includeRankedSeries && !empty($info['festMatchSettings'][0]))
|
||||
$schedules[] = new Splatoon3ScheduleEntryVs($locale, 'fest', 'PRO', $info, $info['festMatchSettings'][0]);
|
||||
|
||||
if($includeRankedOpen && !empty($info['festMatchSettings'][1]))
|
||||
$schedules[] = new Splatoon3ScheduleEntryVs($locale, 'fest', 'OPEN', $info, $info['festMatchSettings'][1]);
|
||||
}
|
||||
|
||||
if(!empty($raw['currentFest']['tricolorStage']))
|
||||
$schedules[] = new Splatoon3ScheduleEntryVsTricolor($locale, $raw['currentFest']['tricolorStage']);
|
||||
}
|
||||
if($includeRanked && !empty($raw['currentFest']['tricolorStage']))
|
||||
$schedules[] = new Splatoon3ScheduleEntryVsTricolor($locale, $raw['currentFest']['tricolorStage']);
|
||||
|
||||
if(array_key_exists('coopGroupingSchedule', $raw)) {
|
||||
$coop = $raw['coopGroupingSchedule'];
|
||||
|
|
Reference in a new issue