mirror of
https://github.com/misenhower/splatoon2.ink.git
synced 2026-03-21 17:24:37 -05:00
Modify Splatfest tweets to better handle multi-region Splatfests
I had previously updated this to handle global Splatfests, but the current Splatfest is only in NA/EU (and not JP) so it wasn't detected with the previous code.
This commit is contained in:
parent
712dac874f
commit
19bc5081d7
|
|
@ -21,7 +21,7 @@ import axios from 'axios';
|
|||
import Wrapper from '@/js/components/screenshots/Wrapper.vue';
|
||||
import SplatfestBox from '@/js/components/splatoon/SplatfestBox.vue';
|
||||
import SplatfestResultsBox from '@/js/components/splatoon/SplatfestResultsBox.vue';
|
||||
import regions from '@/js/regions';
|
||||
import { splatoonRegions } from '@/js/regions';
|
||||
|
||||
export default {
|
||||
components: { Wrapper, SplatfestBox, SplatfestResultsBox },
|
||||
|
|
@ -35,18 +35,22 @@ export default {
|
|||
now() {
|
||||
return this.startTime;
|
||||
},
|
||||
regionInfo() {
|
||||
return regions.splatoonRegions.find(r => r.key == this.region);
|
||||
regions() {
|
||||
let regions = this.$route.query.regions;
|
||||
if (regions)
|
||||
regions = regions.split(',');
|
||||
else
|
||||
regions = [this.region];
|
||||
|
||||
return regions;
|
||||
},
|
||||
isGlobal() {
|
||||
return this.$route.query.global == 'true';
|
||||
displayRegions() {
|
||||
if (this.regions.length === 3)
|
||||
return 'Global';
|
||||
return this.regions.map(region => splatoonRegions.find(r => r.key == region).demonym).join('/');
|
||||
},
|
||||
title() {
|
||||
let region = (this.isGlobal) ? 'Global' : this.regionInfo.demonym;
|
||||
|
||||
if (this.results)
|
||||
return `${region} Splatfest Results`;
|
||||
return `${region} Splatfest`;
|
||||
return `${this.displayRegions} Splatfest`;
|
||||
},
|
||||
festival() {
|
||||
if (this.festivals)
|
||||
|
|
|
|||
|
|
@ -74,12 +74,10 @@ function captureNewWeaponScreenshot(releaseTime) {
|
|||
return captureScreenshot({ url });
|
||||
}
|
||||
|
||||
function captureSplatfestScreenshot(region, startTime, global = false) {
|
||||
function captureSplatfestScreenshot(region, startTime, regions) {
|
||||
let url = new URL(htmlUrl);
|
||||
url.hash = `/splatfest/${region}/${startTime}`;
|
||||
|
||||
if (global)
|
||||
url.hash += '?global=true';
|
||||
regions = regions.join(',');
|
||||
url.hash = `/splatfest/${region}/${startTime}?regions=${regions}`;
|
||||
|
||||
return captureScreenshot({ url });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,22 @@
|
|||
const TwitterPostBase = require('./TwitterPostBase');
|
||||
const { captureSplatfestScreenshot } = require('../screenshots');
|
||||
const { readData } = require('../utilities');
|
||||
const regions = require('../../js/regions');
|
||||
const { splatoonRegions } = require('../../js/regions');
|
||||
|
||||
class SplatfestTweet extends TwitterPostBase {
|
||||
constructor(region) {
|
||||
super();
|
||||
|
||||
this.region = region;
|
||||
|
||||
let regionInfo = this.getRegionInfo();
|
||||
this.regionName = regionInfo.name;
|
||||
this.regionDemonym = regionInfo.demonym;
|
||||
this.regionInfo = this.getRegionInfo();
|
||||
}
|
||||
|
||||
getRegionInfo() {
|
||||
return regions.splatoonRegions.find(r => r.key == this.region);
|
||||
return splatoonRegions.find(r => r.key == this.region);
|
||||
}
|
||||
|
||||
getKey() { return `splatfest-${this.region}`; }
|
||||
getName() { return `Splatfest: ${this.regionName}`; }
|
||||
getName() { return `Splatfest: ${this.regionInfo.name}`; }
|
||||
|
||||
getFestivals(region = null) {
|
||||
region = region || this.region;
|
||||
|
|
@ -54,42 +51,24 @@ class SplatfestTweet extends TwitterPostBase {
|
|||
}
|
||||
}
|
||||
|
||||
isGlobal() {
|
||||
// Is this a global Splatfest?
|
||||
|
||||
// Which regions have this Splatfest?
|
||||
regions() {
|
||||
let festival = this.getData();
|
||||
if (!festival)
|
||||
return false;
|
||||
|
||||
// Look for the same festival ID in each region
|
||||
for (let region of ['na', 'eu', 'jp']) {
|
||||
// If the festival ID doesn't exist in this region, it's not a global festival
|
||||
if (!this.getFestivals(region).find(f => f.festival_id == festival.festival.festival_id))
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we reach this point, this festival ID exists in all regions
|
||||
return true;
|
||||
return ['na', 'eu', 'jp'].filter(region => this.getFestivals(region).find(f => f.festival_id == festival.festival.festival_id));
|
||||
}
|
||||
|
||||
// Is the current event (e.g., announcement, results, etc.) occurring simultaneously across all regions?
|
||||
isSimultaneous() {
|
||||
// Is the current event (e.g., announcement, results, etc.) occurring simultaneously across all regions?
|
||||
|
||||
let festivalIds = { na: null, eu: null, jp: null };
|
||||
for (let region in festivalIds) {
|
||||
let f = this.getData(region)
|
||||
if (f)
|
||||
festivalIds[region] = f.festival.festival_id;
|
||||
}
|
||||
|
||||
// Make sure we have a festival ID and that all festival IDs are the same
|
||||
return (festivalIds.na && festivalIds.na == festivalIds.eu && festivalIds.na == festivalIds.jp);
|
||||
return this.regions().every(region => this.getData(region))
|
||||
}
|
||||
|
||||
shouldPostForCurrentTime() {
|
||||
if (super.shouldPostForCurrentTime()) {
|
||||
// If this is a simultaneous event, only post the tweets from the NA instance to prevent duplicate tweets
|
||||
return (this.region == 'na' || !this.isSimultaneous());
|
||||
// Prevent duplicate tweets for Splatfests occurring in multiple regions
|
||||
return (this.region == this.regions()[0] || !this.isSimultaneous());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -100,24 +79,25 @@ class SplatfestTweet extends TwitterPostBase {
|
|||
}
|
||||
|
||||
getImage(data) {
|
||||
return captureSplatfestScreenshot(this.region, data.festival.times[data.type], this.isSimultaneous());
|
||||
return captureSplatfestScreenshot(this.region, data.festival.times[data.type], this.regions());
|
||||
}
|
||||
|
||||
getText(data) {
|
||||
let isGlobal = this.isGlobal();
|
||||
let regions = this.regions();
|
||||
let isSimultaneous = this.isSimultaneous();
|
||||
let region;
|
||||
let isGlobal = regions.length === 3;
|
||||
|
||||
let regionDemonyms = regions.map(region => splatoonRegions.find(r => r.key == region).demonym).join('/');
|
||||
|
||||
switch (data.type) {
|
||||
case 'announce':
|
||||
region = (isSimultaneous) ? 'global' : this.regionDemonym;
|
||||
return `You can now vote in the next ${region} Splatfest: ${data.festival.names.alpha_short} vs ${data.festival.names.bravo_short}! #splatfest #splatoon2`;
|
||||
return `You can now vote in the next ${isGlobal ? 'global' : regionDemonyms} Splatfest: ${data.festival.names.alpha_short} vs ${data.festival.names.bravo_short}! #splatfest #splatoon2`;
|
||||
|
||||
case 'start':
|
||||
if (isSimultaneous)
|
||||
return `The global Splatfest is now open! #splatfest #splatoon2`;
|
||||
if (isGlobal)
|
||||
return `The global Splatfest is now open in ${this.regionName}! #splatfest #splatoon2`;
|
||||
return `The ${this.regionDemonym} Splatfest is now open! #splatfest #splatoon2`;
|
||||
return `The ${isGlobal ? 'global' : regionDemonyms} Splatfest is now open! #splatfest #splatoon2`;
|
||||
return `The Splatfest is now open in ${this.regionInfo.name}! #splatfest #splatoon2`;
|
||||
|
||||
case 'result':
|
||||
let winner = data.results.summary.total ? 'bravo' : 'alpha';
|
||||
|
||||
|
|
@ -127,8 +107,7 @@ class SplatfestTweet extends TwitterPostBase {
|
|||
let teamName = (winner == 'alpha') ? data.festival.names.alpha_short : data.festival.names.bravo_short;
|
||||
let results = resultsFormat.replace('{team}', teamName);
|
||||
|
||||
region = (isGlobal) ? 'Global' : this.regionDemonym;
|
||||
return `${region} Splatfest results: ${results} #splatfest #splatoon2`;
|
||||
return `${isGlobal ? 'Global' : regionDemonyms} Splatfest results: ${results} #splatfest #splatoon2`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user