audioThemeRadio.checked = true;
}
for(let unlockedFeather of settings['unlocks']) {
- let label = document.createElement('label');
- let radio = document.createElement('input');
- radio.type = 'radio';
- radio.name = 'upInTheAirGame-feather';
- radio.value = unlockedFeather.toLowerCase().replace(/ /g, '');
- label.appendChild(radio);
- let img = document.createElement('img');
- img.src = 'textures/feather-' + radio.value + '.png';
- img.alt = unlockedFeather + ' feather';
- label.appendChild(img);
- ui.querySelector('.feather').appendChild(label);
+ if(!game.ui.root.querySelector('.ui-page.options .feather input[value="' + unlockedFeather + '"]')) {
+ let radio = document.createElement('input');
+ radio.type = 'radio';
+ radio.name = 'upInTheAirGame-feather';
+ radio.value = unlockedFeather;
+ let img = document.createElement('img');
+ img.src = 'textures/feather-' + unlockedFeather + '.png';
+ img.alt = unlockedFeather[0].toUpperCase() + unlockedFeather.slice(1) + ' feather';
+ let label = document.createElement('label');
+ label.appendChild(radio);
+ label.appendChild(img);
+ game.ui.root.querySelector('.ui-page.options .feather').appendChild(label);
+ }
}
if(!ui.querySelector('.feather input[value="' + settings['feather'] + '"]')) {
settings['feather'] = 'blue';
game.view.scene.add(game.objects.backdrop);
}
+function unlockFeather(game, feather, url) {
+ if(game.settings['unlocks'].includes(feather)) {
+ return false;
+ }
+ game.settings['unlocks'].push(feather);
+ if(!url) {
+ url = 'textures/feather-' + feather + '.png';
+ }
+ if(!game.assets['textures']['feather-' + feather]) {
+ (new THREE.TextureLoader()).load(url, (result) => {
+ result.colorSpace = THREE.SRGBColorSpace;
+ result.minFilter = THREE.NearestFilter;
+ result.magFilter = THREE.NearestFilter;
+ result.repeat = new THREE.Vector2(1, -1);
+ result.wrapT = THREE.RepeatWrapping;
+ game.assets['textures']['feather-' + feather] = result;
+ }, () => {}, (err) => {
+ console.error('Error while loading ' + feather + ' feather texture: ' + err);
+ });
+ }
+ // Custom hash function that ensures our unlockables get stored in the same order,
+ // regardless of the order in which they get unlocked.
+ let miniHash = (input) => {
+ return 4 * input.charCodeAt(0) + 3 * input.charCodeAt(2) + 2 * input.charCodeAt(3);
+ }
+ game.settings['unlocks'].sort((u1, u2) => miniHash(u1) > miniHash(u2));
+ let insertAfterFeather = 'purple';
+ if(game.settings['unlocks'].indexOf(feather) >= 1) {
+ insertAfterFeather = game.settings['unlocks'][game.settings['unlocks'].indexOf(feather) - 1];
+ }
+ let radio = document.createElement('input');
+ radio.type = 'radio';
+ radio.name = 'upInTheAirGame-feather';
+ radio.value = feather;
+ let img = document.createElement('img');
+ img.src = url;
+ img.alt = feather[0].toUpperCase() + feather.slice(1) + ' feather';
+ let label = document.createElement('label');
+ label.appendChild(radio);
+ label.appendChild(img);
+ game.ui.root.querySelector('.ui-page.options .feather input[value="' + insertAfterFeather + '"]').parentNode.after(label);
+ applySettings(game);
+ let ui = game.ui.root.querySelector('.ui-page.unlock');
+ let img2 = ui.querySelector('img');
+ img2.src = img.src;
+ img2.alt = img.alt;
+ ui.querySelector('p.name').innerText = img2.alt;
+ return true;
+}
+
window['game'] = {
state: 'loadingAssets',
ui: {
game.ui.root.querySelector('.ui-page.outro .optionalPlural').innerText = 'word' + ((game.objects.words.collectedCount == 1) ? '' : 's') + '.';
let ratingElem = game.ui.root.querySelector('.ui-page.outro .rating');
let exampleElems = game.ui.root.querySelectorAll('.ui-page.outro .examples');
+ let finalParagraph = game.ui.root.querySelector('.ui-page.outro .area > p:last-child');
ratingElem.style.display = 'none';
exampleElems.forEach(elem => { elem.style.display = 'none'; });
+ let returnButton = game.ui.root.querySelector('.ui-page.outro button.goto');
+ if(game.objects.words.collectedCount == 100 || game.objects.words.collectedCount == 0) {
+ finalParagraph.style.display = 'none';
+ let neededUnlocking = false;
+ if(game.objects.words.collectedCount == 100) {
+ neededUnlocking = unlockFeather(game, 'golden');
+ } else {
+ neededUnlocking = unlockFeather(game, 'ghost');
+ }
+ if(neededUnlocking) {
+ returnButton.innerText = 'Continue';
+ returnButton.classList.remove('title');
+ returnButton.classList.add('unlock');
+ } else {
+ returnButton.innerText = 'Return to Title Screen';
+ returnButton.classList.remove('unlock');
+ returnButton.classList.add('title');
+ }
+ } else {
+ finalParagraph.style.display = 'block';
+ returnButton.innerText = 'Return to Title Screen';
+ returnButton.classList.remove('unlock');
+ returnButton.classList.add('title');
+ }
if(game.objects.words.collectedCount > 0) {
if(game.objects.words.collectedCount == 100) {
ratingElem.style.display = 'block';
}
} else {
ratingElem.style.display = 'block';
- ratingElem.innerText = 'You completed the course while dodging every word. That’s an achievement on its own. Respect!';
+ ratingElem.innerText = 'You completed the course while dodging every word. That’s an achievement all on its own. Respect!';
}
}
if(target == 'options') {