(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } }; // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.version = ''; // empty string to avoid regexp issues process.versions = {}; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.prependListener = noop; process.prependOnceListener = noop; process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); }; process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; },{}],2:[function(require,module,exports){ //For testing the ending without playing the whole game function testEnding() { playerState.moonGateStatus = 'RESOLVED'; playerState.bloodGateStatus = 'RESOLVED'; playerState.summerGateStatus = 'RESOLVED'; playerState.gameReadyToComplete = true; } ///*IMPORT CONTENT FROM AIRTABLE*/// //Create an array for each type of content var rooms = []; var examineL1 = []; var examineL2 = []; var items = []; var requirements = []; var misuse = []; //Import the Airtable base for this game var Airtable = require('airtable'); var base = new Airtable({ // apiKey: 'keyXfAK4ExDxxYfQ3' apiKey: 'key18KlZclxKXS4GP' }).base('appZ8ZjCFxWt2qMF5'); //Populate a content array with the contents of an Airtable table function importAirtableContent(table, itemArray) { base(table).select({ // Selecting the first 3 records in Grid view: maxRecords: 3, view: "Grid view" }).eachPage(function page(records, fetchNextPage) { // This function (`page`) will get called for each page of records. records.forEach(function (record) { itemArray.push(record.fields); console.log('Retrieved', record.get('id')); console.log(record.fields); }); //To fetch the next page of records, call `fetchNextPage`. If there are more records, `page` will get called again. If there are no more records, `done` will get called. fetchNextPage(); }, function done(err) { if (err) { console.error(err); return; } }); } //Airtable import is asynchronous. Keep checking whether it's all imported until it is. function checkContentLoad() { console.log("Content is loading."); //if (roomPool !== undefined && roomPool !== null && roomPool.length > 0 && roomDescTextletPool !== undefined && roomDescTextletPool !== null && roomDescTextletPool.length > 0 && itemTextletPool !== undefined && itemTextletPool !== null && itemTextletPool.length > 0 && explorableTextPool !== undefined && explorableTextPool.length > 0 && allChoiceQuestions != undefined && allChoiceQuestions.length != 0 && allChoiceOptions != undefined && allChoiceOptions.length != 0) { if (rooms !== [] && rooms.length > 0 && examineL1 !== [] && examineL1.length > 0 && examineL2 !== [] && examineL2.length > 0 && items !== [] && items.length > 0 && misuse !== [] && misuse.length > 0) { startGame(); } else { setTimeout(function () { checkContentLoad() }, 100); } } //When everything's imported, start the game function startGame() { displayRoomDesc(); revealMapSquare(playerState.x, playerState.y); addPlayerLocationIndicator(); displayMovementOptions(); } ///*STATE TRACKING*/// //The player's state tracks the player's location, and whether they are toggled to looking or interacting var playerState = { x: 1, y: 5, currentAction: 'look', currentFocus: 'nothing', currentRoomLevel: 0, currentRoom: "voidGate", hintMessageSeen: false, voidGateStatus: 'ALWAYS RESOLVED', moonGateStatus: 'UNRESOLVED', bloodGateStatus: 'UNRESOLVED', summerGateStatus: 'UNRESOLVED', gameReadyToComplete: false } //The game conditions track: // - Which exits are locked, unlocked, or alwaysOpen // - Which items are still in rooms, which have been taken and are in the inventory, and which have been used and are gone var gameConditions = { alwaysOpen: [], locked: [], unlocked: [], inRoom: [], inInv: [], used: [] } //At the start of the game, we add every item to the 'inRoom' condition, and every exit to either 'alwaysOpen' or 'locked' //Items: ///*STORY DISPLAY*/// //Object that stores the different numbers of - that appear before the text var hyphenDisplay = { l1: "-", l2: "--", l3: "---" } //Check which room the player is in, and display the relevant room name and description. function displayRoomDesc() { console.log('Displaying room descriptions.') emptyStoryElements(); var roomNameBackgroundShade = ""; for (room = 0; room < rooms.length; room++) { var roomXCoord = parseInt(rooms[room].x); var roomYCoord = parseInt(rooms[room].y); if (roomXCoord === playerState.x && roomYCoord === playerState.y) { var roomDesc = setRoomDesc(rooms[room]) rooms[room].revealed = true; //$('.' + rooms[room].id + 'Hint').removeClass('vanished'); - If I want to explore a dynamic hint-through. Not now. for (el1 = 0; el1 < examineL1.length; el1++) { if (rooms[room].examine === examineL1[el1].id) { examineL1[el1].revealed = true; for (el2 = 0; el2 < examineL2.length; el2++) { console.log('revealing l2'); console.log(examineL2[el2].id); console.log(examineL1[el1].examine); if (examineL1[el1].examine === examineL2[el2].id) { console.log('revealed l2!'); examineL2[el2].revealed = true; } } } } playerState.currentRoom = rooms[room].id; $('#roomName').append('

' + rooms[room].name.toUpperCase() + '

'); $('#roomInitialDesc').append(roomDesc); switch (rooms[room].type) { case 'joy': roomNameBackgroundShade = "dark"; $('#roomName').css('background-color', '#D756AD'); break; case 'authority': roomNameBackgroundShade = "dark"; $('#roomName').css('background-color', '#ABABAB'); break; case 'energy': roomNameBackgroundShade = "light"; $('#roomName').css('background-color', '#FEF06D'); break; case 'bodymind': roomNameBackgroundShade = "dark"; $('#roomName').css('background-color', '#6455BC'); break; case 'mourning': roomNameBackgroundShade = "dark"; $('#roomName').css('background-color', '#2C006F'); break; case 'sky': roomNameBackgroundShade = "light"; $('#roomName').css('background-color', '#C3FBFF'); break; case 'greenery': roomNameBackgroundShade = "dark"; $('#roomName').css('background-color', '#029388'); break; case 'water': roomNameBackgroundShade = "light"; $('#roomName').css('background-color', '#52C4FE'); break; case 'blood': roomNameBackgroundShade = "dark"; $('#roomName').css('background-color', '#A10000'); break; case 'void': roomNameBackgroundShade = "dark"; $('#roomName').css('background-color', 'black'); break; case 'summer': roomNameBackgroundShade = "dark"; $('#roomName').css('background-color', '#009C04'); break; case 'moon': roomNameBackgroundShade = "light"; $('#roomName').css('background-color', '#FEFEFE'); break; default: console.log('Something has gone wrong.'); } switch (roomNameBackgroundShade) { case 'dark': $('#roomName').addClass('roomNameDarkBG'); $('#roomName').removeClass('roomNameLightBG'); break; case 'light': $('#roomName').addClass('roomNameLightBG'); $('#roomName').removeClass('roomNameDarkBG'); break; default: console.log('Something has gone wrong.'); } } } } //Display the room description. function setRoomDesc(room) { console.log('Setting room description for ' + room.name + '.'); var descriptionToSet = room.description.split("{{"); descriptionToSet[0] = descriptionToSet[0].toUpperCase(); var roomDesc = '

' + hyphenDisplay.l1 + ' ' + descriptionToSet[0] + ''; if (descriptionToSet.length > 1) { roomDesc = roomDesc + descriptionToSet[1]; } roomDesc = roomDesc + '.

' return roomDesc } //Empty whatever is in the Story display so that it's ready to have new content added instead. function emptyStoryElements() { console.log('Emptying story elements.'); $('#roomName').empty(); $('#roomInitialDesc').empty(); $('#roomExamine').empty(); $('#roomExamineFurther').empty(); } ///*MAP DISPLAY*/// //Check which directions the player can move from their current location. Add arrows around their current square as appropriate. This also includes removing any 'hidden' classes so the player can see the arrows. function displayMovementOptions() { console.log('Displaying movement options.'); var northGap = playerState.y + 0.5; var southGap = playerState.y - 0.5; var eastGap = playerState.x + 0.5; var westGap = playerState.x - 0.5; var exitLocked = 'false'; if ($('*[data-x="' + playerState.x + '"]*[data-y="' + northGap + '"]').is(':empty')) { console.log('No path north'); } else { exitLocked = checkExitState('north', 'currentRoom'); if (exitLocked === true) { addLockIcon(northGap, 'North', 'vertical') } else { addMovementArrow(northGap, 'North', 'vertical'); } $('*[data-x="' + playerState.x + '"]*[data-y="' + northGap + '"]').removeClass('hidden'); } if ($('*[data-x="' + playerState.x + '"]*[data-y="' + southGap + '"]').is(':empty')) { console.log('No path south'); } else { exitLocked = checkExitState('south', 'currentRoom'); if (exitLocked === true) { addLockIcon(southGap, 'South', 'vertical') } else { addMovementArrow(southGap, 'South', 'vertical'); } $('*[data-x="' + playerState.x + '"]*[data-y="' + southGap + '"]').removeClass('hidden'); } if ($('*[data-x="' + eastGap + '"]*[data-y="' + playerState.y + '"]').is(':empty')) { console.log('No path east'); } else { exitLocked = checkExitState('east', 'currentRoom'); console.log(exitLocked); if (exitLocked === true) { addLockIcon(eastGap, 'East', 'horizontal'); } else { addMovementArrow(eastGap, 'East', 'horizontal'); } $('*[data-x="' + eastGap + '"]*[data-y="' + playerState.y + '"]').removeClass('hidden'); } if ($('*[data-x="' + westGap + '"]*[data-y="' + playerState.y + '"]').is(':empty')) { console.log('No path west'); } else { console.log('Path west'); exitLocked = checkExitState('west', 'currentRoom'); if (exitLocked === true) { console.log('west exit locked') addLockIcon(westGap, 'West', 'horizontal'); } else { (console.log('west exit open')) addMovementArrow(westGap, 'West', 'horizontal'); } $('*[data-x="' + westGap + '"]*[data-y="' + playerState.y + '"]').removeClass('hidden'); } } //Give each movement arrow the correct classes and data function addMovementArrow(gap, direction, orientation) { var tabIndexForDirections = 0; switch (direction.toLowerCase) { case "north": tabIndexForDirections = 11; break; case "east": tabIndexForDirections = 12; break; case "south": tabIndexForDirections = 13; break; case "west": tabIndexForDirections = 14; break; default: console.log("Something has gone wrong."); } switch (orientation) { case 'horizontal': console.log('horizontal arrow'); console.log('*[data-x="' + gap + '"]*[data-y="' + playerState.y + '"]'); $('*[data-x="' + gap + '"]*[data-y="' + playerState.y + '"]').empty(); $('*[data-x="' + gap + '"]*[data-y="' + playerState.y + '"]').append(''); break; case 'vertical': $('*[data-x="' + playerState.x + '"]*[data-y="' + gap + '"]').empty(); //$('*[data-x="' + playerState.x + '"]*[data-y="' + gap + '"]').append(''); break; default: console.log('No orientation'); } } //Check if a particular exit is locked function checkExitState(direction, roomToCheck) { console.log('checking Exit State') if (roomToCheck === 'currentRoom') { for (room = 0; room < rooms.length; room++) { if (rooms[room].x === playerState.x.toString() && rooms[room].y === playerState.y.toString()) { switch (direction) { case 'north': if (rooms[room].north === 'locked') { return true } break; case 'south': if (rooms[room].south === 'locked') { return true } break; case 'east': console.log(rooms[room]); if (rooms[room].east === 'locked') { return true } break; case 'west': if (rooms[room].west === 'locked') { return true } break; default: console.log('Something has gone wrong.'); } } } } else { for (room = 0; room < rooms.length; room++) { if (rooms[room].id === roomToCheck) { switch (direction) { case 'north': return rooms[room].north break; case 'south': return rooms[room].south break; case 'east': return rooms[room].east break; case 'west': return rooms[room].west break; default: console.log('Something has gone wrong.'); } } } } } //If, for example, the south exit from the train platform is locked, add a lock symbol there function addLockIcon(gap, direction, orientation) { switch (orientation) { case 'horizontal': $('*[data-x="' + gap + '"]*[data-y="' + playerState.y + '"]').empty(); $('*[data-x="' + gap + '"]*[data-y="' + playerState.y + '"]').addClass('locked'); $('*[data-x="' + gap + '"]*[data-y="' + playerState.y + '"]').append('' + direction + ' exit locked'); break; case 'vertical': $('*[data-x="' + playerState.x + '"]*[data-y="' + gap + '"]').empty(); $('*[data-x="' + playerState.x + '"]*[data-y="' + gap + '"]').addClass('locked'); $('*[data-x="' + playerState.x + '"]*[data-y="' + gap + '"]').append('' + direction + ' exit locked'); break; default: console.log('No orientation'); } } //Clear away the currently displayed movement arrows ready for new ones to be added function removeMovementArrows() { var tempHParent = $('*[data-orientation="horizontal"]').parent(); var tempVParent = $('*[data-orientation="vertical"]').parent(); tempHParent.append('