Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md

Large diffs are not rendered by default.

448 changes: 448 additions & 0 deletions e63334287a3deaa3/boostball/carbon-star.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion e63334287a3deaa3/boostball/es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 130 additions & 7 deletions e63334287a3deaa3/boostball/index.html

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions e63334287a3deaa3/boostball/kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ function Stage(parent,spr,R,main,camera){
flash(a){if(main){const d=G.camera.position.distanceTo(S.world(S.x0,3,3));G.flash(a*clamp(1.2-d/150,.25,1))}},
snd(fn){const A=G.audio();if(A)try{fn(A,A.actx.currentTime,main?1:.6)}catch(e){}},
play(no,p,team){
const def=GOALS[no];if(!def)return false;
const def=GOALS[no];if(!def||def.gift)return false;
S.stop();
S.no=no;S.def=def;S.t=0;S.prev=-1;S.team=team;S.T=G.TEAM[team];S.col=S.T.col;S.q=G.low()?.5:1;S.d={};
if(main){S.sg=p.z>0?-1:1;S.ox=0;S.oz=p.z>0?G.AL:-G.AL;root.position.set(0,0,S.oz);root.rotation.y=S.sg>0?0:Math.PI;S.B.set(clamp(S.sg*p.x,-GW+3,GW-3),clamp(p.y,BR,GH-3),clamp(S.sg*(p.z-S.oz),-5,1.5))}
Expand Down Expand Up @@ -1263,11 +1263,15 @@ const GOALS=[null,
S.snd((A,tt,v)=>{popSnd(A,tt,v,900);for(let i=0;i<9;i++){const f=2200+Math.random()*1500;A.tone(tt+.1+i*.11,.07,'sine',f,f*1.25,.05*v)}})}
if(S.at(1.5))S.em(c.x+rand(-1,1),c.y+3,c.z,0,-.4,0,1.9,1.3,CELL.feather,0xffffff,O({grav:.8,wob:5,spin:1.5,drag:1}));
}
}
},
// 22 Carbon Star: an exclusive gift (../captains.js GIFTS). It is drawn by carbon-star.js, never by a Stage here, and
// only for a goal by a player who has it (index.html checks the scorer's account); this entry only lets the Kit list
// it for those players. An older page has no 22 here and plays the fireball.
{gift:'bb-goal-carbon-star',dur:0}
];
let mainStage=null;
function goal(no,p,team){
if(!GOALS[no])return false;
if(!GOALS[no]||GOALS[no].gift)return false;
const spr=sprites();
if(!mainStage)mainStage=Stage(G.scene,spr,{lo:TRAIL_SLOTS*TRAIL_MAX,hi:spr.n,i:TRAIL_SLOTS*TRAIL_MAX},true,G.camera);
return mainStage.play(no,p,team);
Expand All @@ -1283,17 +1287,20 @@ function clearGoal(){if(mainStage)mainStage.stop()}
// boostball-kit ({slot: item id}).
const CAT=()=>window.BackRoomCosmetics&&window.BackRoomCosmetics.gameItems?window.BackRoomCosmetics:null;
const LISTS=[DECALS,TRAILS,GOALS,TOPPERS,HATS,WHEELS,ENGINES],TABS=['Decal','Boost trail','Goal explosion','Topper','Hat','Wheels','Engine'];
// an exclusive gift (GOALS[22]) is listed only for a player who has it (G.giftOk: its owner, a captain, or the test switch)
const giftOf=(slot,no)=>{const d=LISTS[slot]&&LISTS[slot][no];return d&&d.gift||''};
const shown=(slot,no)=>{const g=giftOf(slot,no);return !g||!!(G.giftOk&&G.giftOk(g))};
function items(slot){
const C=CAT(),L=C?C.gameItems('boostball',SLOTS[slot]).filter(it=>has(slot,it.no)):[];
const C=CAT(),L=C?C.gameItems('boostball',SLOTS[slot]).filter(it=>has(slot,it.no)&&shown(slot,it.no)):[];
if(L.length||!LISTS[slot])return L;
return LISTS[slot].map((d,i)=>i?{no:i,id:'bb-'+SLOTS[slot]+'-'+i,name:TABS[slot]+' '+i,desc:'',rarity:'common'}:null).filter(Boolean); // no catalogue: numbers only
return LISTS[slot].map((d,i)=>i&&shown(slot,i)?{no:i,id:'bb-'+SLOTS[slot]+'-'+i,name:TABS[slot]+' '+i,desc:'',rarity:'common'}:null).filter(Boolean); // no catalogue: numbers only
}
const owns=it=>!G.cosOn()||CAT().owned().items.indexOf(it.id)>=0;
const owns=it=>!G.cosOn()||!!giftOf(SLOTS.indexOf(it.slot),it.no)||CAT().owned().items.indexOf(it.id)>=0;
let cur=[0,0,0,0,0,0,0];
function saved(){let o=null;try{o=JSON.parse(G.store.get('kit','')||'null')}catch(e){}return o&&typeof o==='object'?o:{}}
function mine(){
const k=[0,0,0,0,0,0,0];
if(G.cosOn()){const e=CAT().gameEquipped('boostball');SLOTS.forEach((s,i)=>{if(e[s]&&has(i,e[s].no))k[i]=e[s].no})}
if(G.cosOn()){const e=CAT().gameEquipped('boostball');SLOTS.forEach((s,i)=>{if(e[s]&&has(i,e[s].no)&&shown(i,e[s].no))k[i]=e[s].no})}
else if(G.garageOn){const o=saved();SLOTS.forEach((s,i)=>{const it=items(i).find(x=>x.id===o[s]);if(it)k[i]=it.no})}
cur=k;return G.kitOf(k);
}
Expand All @@ -1302,7 +1309,7 @@ function wear(slot,it){
else{const o=saved();if(it)o[SLOTS[slot]]=it.id;else delete o[SLOTS[slot]];G.store.set('kit',JSON.stringify(o))}
G.setKit(mine());paintMenu();
}
function botKit(){const r=(L,p)=>Math.random()<p?1+Math.floor(Math.random()*(L.length-1)):0;return G.kitOf([r(DECALS,.7),r(TRAILS,.7),r(GOALS,.8),r(TOPPERS,.3),r(HATS,.3),r(WHEELS,.4)])}
function botKit(){const r=(L,p)=>{if(Math.random()>=p)return 0;let i;do{i=1+Math.floor(Math.random()*(L.length-1))}while(L[i]&&L[i].gift);return i}; /* never a gift */return G.kitOf([r(DECALS,.7),r(TRAILS,.7),r(GOALS,.8),r(TOPPERS,.3),r(HATS,.3),r(WHEELS,.4)])}
let tab=0,note='',swKey='';
const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
function menu(){
Expand Down Expand Up @@ -1343,7 +1350,7 @@ function paintMenu(){
grid.innerHTML='<button type="button" data-no="0" aria-pressed="'+(!cur[tab])+'">None</button>'+L.map(it=>{
const lock=!owns(it),r=RC[it.rarity];
return '<button type="button" data-no="'+it.no+'" aria-pressed="'+(cur[tab]===it.no)+'"'+(lock?' class="locked" aria-disabled="true"':'')+' title="'+esc(it.desc||it.name)+(r?' ('+r.name+')':'')+'">'+
(tab===0?'<canvas width="96" height="32" aria-hidden="true"></canvas>':C&&C.itemSvg?C.itemSvg(it.id,26):'')+esc(it.name)+(r?'<i style="background:'+r.color+'" aria-hidden="true"></i>':'')+'</button>'}).join('');
(tab===0?'<canvas width="96" height="32" aria-hidden="true"></canvas>':C&&C.itemSvg?C.itemSvg(it.id,26):'')+esc(it.name)+(giftOf(tab,it.no)?'<small style="font-weight:600;opacity:.8">made for Carbon</small>':'')+(r?'<i style="background:'+r.color+'" aria-hidden="true"></i>':'')+'</button>'}).join('');
swKey='';
const it=L.find(x=>x.no===cur[tab]);
document.getElementById('kitNote').innerHTML=note||(it?'<b>'+esc(it.name)+'.</b> '+esc(it.desc||''):['No decal: plain team paint.','No trail: the usual boost flame.','No goal explosion: the usual fireball.','No topper.','No hat.','The usual wheels.','The usual engine sound.'][tab]);
Expand All @@ -1367,11 +1374,12 @@ function pvInit(Gr){
const b=Build();for(const s of[-1,1])b.cyl(.35,.35,GH,0xf4f6ff,s*GW,GH/2,0);b.cyl(.35,.35,GW*2,0xf4f6ff,0,GH,0,0,0,Math.PI/2);b.box(GW*2,GH,.2,0x16202c,0,GH/2,-9);set.add(b.mesh());
pv={spr,cam,stage,set,R:{lo:0,hi:TRAIL_MAX,i:0},st:{acc:0}};
}
function preview(no){const Gr=G.garage;if(!Gr||!GOALS[no])return;if(!pv)pvInit(Gr);pv.stage.play(no,new V3(2.5,3,-1.5),0)}
function preview(no){const Gr=G.garage;if(!Gr||!GOALS[no])return;if(GOALS[no].gift){if(pv)pv.stage.stop();if(G.giftPreview)G.giftPreview();return}if(!pv)pvInit(Gr);pv.stage.play(no,new V3(2.5,3,-1.5),0)}
const _z=new V3();
function garageFrame(Gr,dt){
paintSwatches();
if(!Gr.model)return false;
if(G.giftFrame&&G.giftFrame(Gr,dt))return true; // Carbon Star's preview (carbon-star.js) is playing in the garage picture
if(!pv){if(!(tab===1&&cur[1]))return false;pvInit(Gr)}
const car=Gr.model.g;
if(pv.stage.live){
Expand Down
47 changes: 43 additions & 4 deletions e63334287a3deaa3/captains.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@
* comes back into view, when account.js says the account changed (on this page or the page around this frame) and
* when another tab signs in or out (account.js's 'acct' entry in localStorage changes).
*
* EXCLUSIVE GIFTS: a few items are made for one player (GIFTS below: account id -> item ids). They are not for sale,
* not in any chest or pack and cannot be gifted on; the captains get the ones in CAPTAIN_GIFTS too. A game asks:
* gift(item) does the account signed in here have this gift? (false while the first check runs)
* gift(item, uid) does another player's account have it? Used to check who scored before drawing a
* gift for them: a page draws it only for a goal by a player whose id is in the table
* (or a captain, for CAPTAIN_GIFTS), whatever that player's data claims. A captain is
* known only once miles.js is here: call giftsReady() first (it fetches miles.js once).
* account() the id of the Google account signed in here ('' for a guest or signed out)
* onAccount(fn) fn(uid) whenever the signed-in account changes (captain or not)
* To add another gift: put '<account id>': ['<item id>'] in GIFTS (the account id is the player's Google account uid on this
* site's Firebase project), add the item to cosmetics.js with give: 'exclusive', and make its game draw it only when
* gift(item, scorer) is true. See README, captains.js.
*
* THIS IS NOT A LOCK. The check runs in the visitor's own browser and the account ids are public, so someone who
* edits the page in their browser can still open these screens. It keeps the options out of sight; nothing on the
* server enforces it. What a player wears is looks only in every game.
Expand All @@ -50,6 +63,14 @@
// false: Captains only (miles.js's OWNERS).
var VICE_CAPTAINS_TOO = false; // Captains only: Vice Captains see nothing, like everyone else

// EXCLUSIVE GIFTS (see the top): account id -> the item ids made for that player alone. Nobody else is offered them,
// and pages draw them only for these accounts. Ids are the cosmetics.js item ids.
var GIFTS = {
'BExn2DzDMQYrXn4AVp7BjzQT5dP2': ['bb-goal-carbon-star'] // Carbon: Boostball's Carbon Star goal explosion
};
// Gifts the captains (the same captains as above) may wear too, in their own Kit, labelled as made for their owner.
var CAPTAIN_GIFTS = ['bb-goal-carbon-star'];

var API_KEY = 'AIzaSyDZD_Ku8cixteXfwkDYzGv3GKiZFF8sRSM'; // the site's Firebase project (public; the same one as in stats.js)
var AUTH_KEY = 'firebase:authUser:' + API_KEY + ':[DEFAULT]';
var me0 = document.currentScript;
Expand Down Expand Up @@ -126,23 +147,36 @@
}

// ---------------- The answer ----------------
var cap = false, known = false, uid = '', seq = 0, listeners = [], readyDone, ready = new Promise(function (r) { readyDone = r; });
var cap = false, known = false, uid = '', seq = 0, listeners = [], accountListeners = [], readyDone, ready = new Promise(function (r) { readyDone = r; });
function settle(n, c, u) {
if (n !== seq) return; // a newer check is running: its answer is the one that counts
var changed = c !== cap;
var changed = c !== cap, moved = u !== uid;
cap = c; uid = u;
if (!known) { known = true; readyDone(cap); }
if (moved) accountListeners.forEach(function (f) { try { f(uid); } catch (e) { try { console.error(e); } catch (_) {} } });
if (!changed) return;
listeners.forEach(function (f) { try { f(cap); } catch (e) { try { console.error(e); } catch (_) {} } });
try { document.dispatchEvent(new CustomEvent('backroom:captain', { detail: { captain: cap } })); } catch (e) {}
}
function isCaptain(M, id) { return !!M && !!id && (M.isOwner(id) || (VICE_CAPTAINS_TOO && M.isVice(id))); }
// Has account `id` the gift `item`? Its own entry in GIFTS, or a captain for CAPTAIN_GIFTS. `id` omitted: the account
// signed in here (a captain as answered by the check above).
function gift(item, id) {
var mine = id === undefined;
id = mine ? uid : String(id || '');
if (!id || !/^[A-Za-z0-9]{1,128}$/.test(id)) return false;
var own = Object.prototype.hasOwnProperty.call(GIFTS, id) ? GIFTS[id] : null;
if (own && own.indexOf(item) >= 0) return true;
if (CAPTAIN_GIFTS.indexOf(item) < 0) return false;
return mine ? cap : isCaptain(miles(), id);
}
function check() {
var n = ++seq;
return (standIn !== undefined ? Promise.resolve(standIn) : peek()).then(function (u) {
var id = u && u.isAnonymous === false && typeof u.uid === 'string' && /^[A-Za-z0-9]{1,128}$/.test(u.uid) ? u.uid : '';
if (!id) return settle(n, false, ''); // signed out, or one of the games' guest accounts
if (known && id === uid) return settle(n, cap, uid);
return lists().then(function (M) { settle(n, !!M && (M.isOwner(id) || (VICE_CAPTAINS_TOO && M.isVice(id))), id); });
return lists().then(function (M) { settle(n, isCaptain(M, id), id); });
}).catch(function () { settle(n, false, ''); });
}
var again = 0;
Expand All @@ -169,13 +203,18 @@
known: function () { return known; },
ready: ready,
onChange: function (f) { if (typeof f === 'function') listeners.push(f); },
check: check
check: check,
gift: gift,
giftsReady: function () { return lists().then(function () {}, function () {}); },
account: function () { return uid; },
onAccount: function (f) { if (typeof f === 'function') accountListeners.push(f); }
};
// Test hook (automated browsers only): stand in for the signed-in account. as(uid) a Google account, as(uid, false)
// a guest (anonymous) account, as(null) signed out, real() the browser's own again. Each returns a promise for the check.
if (navigator.webdriver) window.__captains = {
as: function (id, google) { standIn = id ? { uid: String(id), isAnonymous: google === false } : null; return check().then(function () { return cap; }); },
real: function () { standIn = undefined; return check().then(function () { return cap; }); },
gift: function (id, items) { GIFTS[String(id)] = items ? [].concat(items) : []; }, // add or empty a GIFTS entry, for tests
peek: peek, AUTH_KEY: AUTH_KEY, get uid() { return uid; }, get viceToo() { return VICE_CAPTAINS_TOO; }
};
if (SWITCHES_ONLY) { known = true; readyDone(false); } else check();
Expand Down
1 change: 1 addition & 0 deletions e63334287a3deaa3/cosmetics.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
I('boostball', 'engine', 2, 'Buzz', 'uncommon', '#FFD23F', '#FF8A1F', 'High and angry, like a go-kart.');
I('boostball', 'engine', 3, 'Rumble', 'rare', '#7A5230', '#FF4D6D', 'A big lazy burble.');
I('boostball', 'engine', 4, 'Whirr', 'epic', '#3EE6FF', '#FFFFFF', 'Electric: it sings as it speeds up.');
I('boostball', 'goal', 22, 'Carbon Star', 'legendary', '#2A1048', '#FF6A2E', 'Made for Carbon: a red giant flares in the goal and the whole arena drifts into deep space.'); ITEM_BY_ID['bb-goal-carbon-star'].give = 'exclusive'; // an exclusive gift (../captains.js GIFTS): in no pack or chest, never sold or gifted on
// Slipstream sponsors (all made up): signing with one is free, and its sticker goes on the car. c1 and c2 are its colours.
I('slipstream', 'sponsor', 1, 'Zoomi Cola', 'common', '#12B5A6', '#FFF3D6', 'Fizzy, fast and slightly too sweet.');
I('slipstream', 'sponsor', 2, 'Burnout Coffee', 'common', '#3B2416', '#FFB347', 'Roasted until the tyres smoke.');
Expand Down
5 changes: 3 additions & 2 deletions e63334287a3deaa3/shop/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ <h1>The shop isn&rsquo;t open yet</h1>
// A Gift button for a pack, a chest or one item ('item:<id>'): same price as buying it, for someone else.
function giftBtn(id, cls) { var b = el('button', cls || 'btn igift', 'Gift'); b.type = 'button'; b.setAttribute('data-gift', id); return b; }
function giftHtml(id) { var gi = C.GAME_ITEMS_BY_ID && C.GAME_ITEMS_BY_ID[id]; return gi && gi.give ? '' : giftBtn('item:' + id).outerHTML; }
function shown(it) { return it.give !== 'exclusive'; } // exclusive gifts (../captains.js) are shown only in their own game
function drawLocker() {
var t = document.getElementById('t-locker'), own = C.owned(), eq = C.equipped();
var sk = eq.skin && C.SKINS_BY_ID[eq.skin];
Expand All @@ -380,7 +381,7 @@ <h1>The shop isn&rsquo;t open yet</h1>
C.SLOTS.forEach(function (k) { if (eq.accessories[k]) wear.push([k, C.ACCESSORIES_BY_ID[eq.accessories[k]].name]); });
// game items (worn inside one game, not on the avatar): a chip per game slot, filter keys 'g:<game>:<slot>'
var games = Object.keys(C.GAMES || {}), gchips = [];
games.forEach(function (gm) { var ge = C.gameEquipped(gm); C.GAMES[gm].slots.forEach(function (sl) { var all = C.gameItems(gm, sl[0]); if (!all.length) return; if (ge[sl[0]]) wear.push([gm + ':' + sl[0], C.GAMES[gm].name + ': ' + ge[sl[0]].name]);
games.forEach(function (gm) { var ge = C.gameEquipped(gm); C.GAMES[gm].slots.forEach(function (sl) { var all = C.gameItems(gm, sl[0]).filter(shown); if (!all.length) return; if (ge[sl[0]]) wear.push([gm + ':' + sl[0], C.GAMES[gm].name + ': ' + ge[sl[0]].name]);
gchips.push(['g:' + gm + ':' + sl[0], C.GAMES[gm].name + ' ' + sl[1].toLowerCase() + ' ' + all.filter(function (it) { return own.items.indexOf(it.id) >= 0; }).length + '/' + all.length]); }); });
var html = '<div class="locker"><div class="stage"><span class="big">' + C.avatarSvg(uid, 180) + '</span><div><div class="sn">' + esc(sk ? sk.name : 'Your own look') + '</div>' +
'<div class="sd">' + esc(sk ? sk.desc : 'Pick a skin and accessories from your locker.') + '</div><ul class="wearing">' +
Expand All @@ -390,7 +391,7 @@ <h1>The shop isn&rsquo;t open yet</h1>
return [k, C.SLOT_NAMES[k] + ' ' + n + '/' + all.length];
}), gchips).map(function (c) { return '<button type="button" data-filter="' + c[0] + '" aria-pressed="' + (filter === c[0]) + '">' + esc(c[1]) + '</button>'; }).join('') + '</div><div class="items">';
var gf = /^g:/.test(filter) ? filter.split(':') : null, gworn = gf ? C.gameEquipped(gf[1]) : {};
var list = filter === 'skins' ? C.SKINS : gf ? C.gameItems(gf[1], gf[2]) : C.ACCESSORIES.filter(function (a) { return a.slot === filter; });
var list = filter === 'skins' ? C.SKINS : gf ? C.gameItems(gf[1], gf[2]).filter(shown) : C.ACCESSORIES.filter(function (a) { return a.slot === filter; });
list.forEach(function (it) {
if (gf) {
var ghas = own.items.indexOf(it.id) >= 0, gon = !!gworn[it.slot] && gworn[it.slot].id === it.id, gr = RC[it.rarity];
Expand Down
Loading