add helper to set santa's route

main
Sam Thorogood 2 years ago committed by Sam Thorogood
parent 59c6dc1722
commit 88414fba7b

@ -104,7 +104,7 @@ module.exports = async (id, content, onwarn=null) => {
name: id,
format: 'es',
sourcemap: true,
treeshake: false, // we want to cache the results
//treeshake: false, // we want to cache the results
});
if (out.output.length !== 1) {
@ -112,4 +112,4 @@ module.exports = async (id, content, onwarn=null) => {
}
const first = out.output[0];
return {code: first.code, map: first.map};
};
};

@ -51,6 +51,9 @@ import isAndroid from './src/core/android.js';
import {_msg} from './src/magic.js';
window.santaApp = {};
maybeLoadCast();
@ -212,6 +215,9 @@ document.body.addEventListener('click', globalClickHandler(scope, go));
const kplayInstance = kplay.prepare();
/**
* Handles audio.
*/
(function() {
if (isAndroid()) {
if (kplayInstance.suspended) {
@ -274,6 +280,10 @@ scoreOverlayElement.addEventListener('resume', () => global.setState({status: ''
scoreOverlayElement.addEventListener('home', () => go(''));
/**
* Manage singleton element state based on global state. Just updates things like loaders, score
* overlays and so on.
*/
global.subscribe((state) => {
// This happens first, as we modify state as a side-effect.
if (state.status === 'restart') {
@ -437,20 +447,22 @@ async function prepare(control, data) {
return resolve(config);
}
// If the page wants a subscription, they're listening to the Firebase config data.
// If the page wants a subscription, they're listening to the Firebase config data PLUS
// the page's params (in "data" key). This only happens for modvil.
const listener = () => {
if (control.done) {
firebaseConfig.remove(listener);
global.unsubscribe(listener);
return;
}
const {playNextRoute} = global.getState();
const {playNextRoute, trackerOffset} = global.getState();
const payload = {
android: isAndroid(),
routes: firebaseConfig.routesSnapshot(),
featured: firebaseConfig.featuredRoute(),
play: playNextRoute,
trackerFlags: firebaseConfig.trackerFlags(),
trackerOffset,
loudCard: firebaseConfig.loudCard(),
data,
};
@ -734,4 +746,26 @@ loaderElement.addEventListener(gameloader.events.prepare, (ev) => {
});
configureCustomKeys(loaderElement);
configureCustomKeys(loaderElement);
// Support skewing the tracker.
(function() {
/**
* Adjust Santa's location between 0-1 along his total route.
*/
window.santaApp.adjustSanta = (ratio, offset = 0) => {
const year = new Date().getFullYear();
const santaStart = +Date.UTC(year, 11, 24, 10, 0, 0); // 24th Dec at 10:00 UTC
const flightDuration = 25 * 60 * 60 * 1000;
const timeUntilStart = santaStart - +new Date();
const trackerOffset = timeUntilStart + (ratio * flightDuration) + offset;
console.warn('setting trackerOffset', trackerOffset);
global.setState({trackerOffset});
};
}());

@ -40,6 +40,8 @@ const g = createStore({
playNextRoute: '',
shareUrl: null,
trackerOffset: 0,
});
export default g;

@ -38,6 +38,7 @@ common.preload.images(
const focusTimeoutDelay = 20 * 1000; // refocus on Santa after this much inactivity
// This
if (!localStorage['routeJitter']) {
localStorage['routeJitter'] = (Math.random() * 2) - 1; // between [-1,+1]
}
@ -56,6 +57,7 @@ class ModvilTrackerElement extends LitElement {
_focusOnSanta: {type: Boolean},
_stops: {type: Array},
_temporaryDestination: {type: Object},
trackerOffset: {type: Number, attribute: 'tracker-offset'},
// nb. _details isn't here as it changes only based on now/destinations
};
}

@ -92,7 +92,7 @@ const fallbackFeaturedImageSrc = featuredImage.src;
api.addEventListener('data', (ev) => {
const payload = ev.detail;
const {trackerFlags} = payload;
const {trackerFlags, trackerOffset} = payload;
if (trackerFlags.showTracker) {
if (trackerElement.parentNode !== mainElement) {
@ -103,6 +103,7 @@ api.addEventListener('data', (ev) => {
trackerElement.remove();
}
trackerElement.routeJitter = trackerFlags.routeJitter;
trackerElement.trackerOffset = trackerOffset ?? 0;
loudCardElement.hidden = !payload.loudCard;
loudCardElement.scene = payload.loudCard || null;

@ -243,7 +243,7 @@ export function featuredRoute() {
/**
* @return {!Object} misc tracker flags
* @return {!Object} misc tracker flags, subset of Firebase config
*/
export function trackerFlags() {
return {

@ -165,7 +165,7 @@ function routeToAndroid(route) {
* @return {{scope: string, go: function(string, !Object<string, string>): void}}
*/
export function configureProdRouter(callback) {
if (window.santaApp) {
if (window.santaApp.go) {
throw new Error('cannot configureProdRouter twice');
}
@ -204,7 +204,7 @@ export function configureProdRouter(callback) {
internalRoute(load);
// Provide expected `santaApp` helper.
window.santaApp = {
Object.assign(window.santaApp, {
get route() {
return wh.state && wh.state.route;
},
@ -222,7 +222,7 @@ export function configureProdRouter(callback) {
internalRoute({route: normalizeRoute(route), data, hash}, true);
},
};
});
// Add global 'go' event listener.
window.addEventListener(goEvent, (ev) => {

Loading…
Cancel
Save