Fixing whitespace conformity in Engine.js

This commit is contained in:
Travis Weston
2014-07-12 23:40:15 -04:00
parent b7a2c29aa0
commit 8cf3ab3dc9
+192 -186
View File
@@ -112,10 +112,10 @@
.addClass('menu') .addClass('menu')
.appendTo('body'); .appendTo('body');
var selectWrap = $('<span>') var selectWrap = $('<span>')
.addClass('select-wrap') .addClass('select-wrap')
.appendTo(menu); .appendTo(menu);
$('<select>') $('<select>')
.addClass('menuBtn') .addClass('menuBtn')
.append($('<option>').text("language.")) .append($('<option>').text("language."))
.append($('<option>').text("english").val("en")) .append($('<option>').text("english").val("en"))
@@ -123,7 +123,7 @@
.change(Engine.switchLanguage) .change(Engine.switchLanguage)
.appendTo(selectWrap); .appendTo(selectWrap);
$('<span>') $('<span>')
.addClass('lightsOff menuBtn') .addClass('lightsOff menuBtn')
.text(_('lights off.')) .text(_('lights off.'))
.click(Engine.turnLightsOff) .click(Engine.turnLightsOff)
@@ -190,14 +190,11 @@
}, },
browserValid: function() { browserValid: function() {
return location.search.indexOf('ignorebrowser=true') >= 0 || ( return ( location.search.indexOf( 'ignorebrowser=true' ) >= 0 || ( typeof Storage != 'undefined' && !oldIE ) );
typeof Storage != 'undefined' &&
!oldIE);
}, },
isMobile: function() { isMobile: function() {
return location.search.indexOf('ignorebrowser=true') < 0 && return ( location.search.indexOf( 'ignorebrowser=true' ) < 0 && /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test( navigator.userAgent ) );
/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
}, },
saveGame: function() { saveGame: function() {
@@ -228,97 +225,103 @@
} }
}, },
exportImport: function() { exportImport: function() {
Events.startEvent({ Events.startEvent({
title: 'Export / Import', title: 'Export / Import',
scenes: { scenes: {
start: { start: {
text: [_('export or import save data, for backing up'), text: [_('export or import save data, for backing up'),
_('or migrating computers')], _('or migrating computers')],
buttons: { buttons: {
'export': { 'export': {
text: _('export'), text: _('export'),
onChoose: Engine.export64 onChoose: Engine.export64
}, },
'import': { 'import': {
text: _('import'), text: _('import'),
nextScene: {1: 'confirm'}, nextScene: {
}, 1: 'confirm'
'cancel': { },
text: _('cancel'), },
nextScene: 'end' 'cancel': {
text: _('cancel'),
nextScene: 'end'
}
} }
} },
}, 'confirm': {
'confirm': { text: [
text: [_('are you sure?'), _('are you sure?'),
_('if the code is invalid, all data will be lost.'), _('if the code is invalid, all data will be lost.'),
_('this is irreversible.')], _('this is irreversible.')
buttons: { ],
'yes': { buttons: {
text: _('yes'), 'yes': {
nextScene: {1: 'inputImport'}, text: _('yes'),
onChoose: Engine.enableSelection nextScene: {1: 'inputImport'},
}, onChoose: Engine.enableSelection
'no': { },
text: _('no'), 'no': {
nextScene: 'end' text: _('no'),
nextScene: 'end'
}
} }
} },
}, 'inputImport': {
'inputImport': { text: [
text: [_('put the save code here.')], _('put the save code here.')
textarea: '', ],
buttons: { textarea: '',
'okay': { buttons: {
text: _('import'), 'okay': {
nextScene: 'end', text: _('import'),
onChoose: Engine.import64 nextScene: 'end',
}, onChoose: Engine.import64
'cancel': { },
text: _('cancel'), 'cancel': {
nextScene: 'end' text: _('cancel'),
nextScene: 'end'
}
} }
} }
} }
} });
}); },
},
export64: function() { export64: function() {
Engine.saveGame(); Engine.saveGame();
var string64 = Base64.encode(localStorage.gameState); var string64 = Base64.encode(localStorage.gameState);
string64 = string64.replace(/\s/g, ''); string64 = string64.replace(/\s/g, '');
string64 = string64.replace(/\./g, ''); string64 = string64.replace(/\./g, '');
string64 = string64.replace(/\n/g, ''); string64 = string64.replace(/\n/g, '');
Engine.enableSelection(); Engine.enableSelection();
Events.startEvent({ Events.startEvent({
title: _('Export'), title: _('Export'),
scenes: { scenes: {
start: { start: {
text: [_('save this.')], text: [_('save this.')],
textarea: string64, textarea: string64,
buttons: { buttons: {
'done': { 'done': {
text: _('got it'), text: _('got it'),
nextScene: 'end', nextScene: 'end',
onChoose: Engine.disableSelection onChoose: Engine.disableSelection
} }
} }
} }
} }
}); });
}, },
import64: function(string64) { import64: function(string64) {
Engine.disableSelection(); Engine.disableSelection();
string64 = string64.replace(/\s/g, ''); string64 = string64.replace(/\s/g, '');
string64 = string64.replace(/\./g, ''); string64 = string64.replace(/\./g, '');
string64 = string64.replace(/\n/g, ''); string64 = string64.replace(/\n/g, '');
var decodedSave = Base64.decode(string64); var decodedSave = Base64.decode(string64);
localStorage.gameState = decodedSave; localStorage.gameState = decodedSave;
location.reload(); location.reload();
}, },
event: function(cat, act) { event: function(cat, act) {
if(typeof ga === 'function') { if(typeof ga === 'function') {
@@ -349,15 +352,15 @@
}, },
deleteSave: function(noReload) { deleteSave: function(noReload) {
if(typeof Storage != 'undefined' && localStorage) { if(typeof Storage != 'undefined' && localStorage) {
var prestige = Prestige.get(); var prestige = Prestige.get();
window.State = {}; window.State = {};
localStorage.clear(); localStorage.clear();
Prestige.set(prestige); Prestige.set(prestige);
} }
if(!noReload) { if(!noReload) {
location.reload(); location.reload();
} }
}, },
share: function() { share: function() {
@@ -383,17 +386,17 @@
}, },
'twitter': { 'twitter': {
text: _('twitter'), text: _('twitter'),
nextScene: 'end',
onChoose: function() { onChoose: function() {
window.open('https://twitter.com/intent/tweet?text=A%20Dark%20Room&url=' + Engine.SITE_URL, 'sharer', 'width=660,height=260,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no'); window.open('https://twitter.com/intent/tweet?text=A%20Dark%20Room&url=' + Engine.SITE_URL, 'sharer', 'width=660,height=260,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no');
}, }
nextScene: 'end'
}, },
'reddit': { 'reddit': {
text: _('reddit'), text: _('reddit'),
nextScene: 'end',
onChoose: function() { onChoose: function() {
window.open('http://www.reddit.com/submit?url=' + Engine.SITE_URL, 'sharer', 'width=960,height=700,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no'); window.open('http://www.reddit.com/submit?url=' + Engine.SITE_URL, 'sharer', 'width=960,height=700,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no');
}, }
nextScene: 'end'
}, },
'close': { 'close': {
text: _('close'), text: _('close'),
@@ -402,52 +405,51 @@
} }
} }
} }
}, {width: '400px'}); },
{
width: '400px'
});
}, },
findStylesheet: function(title) { findStylesheet: function(title) {
for(var i=0; i<document.styleSheets.length; i++) { for(var i=0; i<document.styleSheets.length; i++) {
var sheet = document.styleSheets[i]; var sheet = document.styleSheets[i];
if(sheet.title == title) { if(sheet.title == title) {
return sheet; return sheet;
} }
} }
return null; return null;
}, },
isLightsOff: function() { isLightsOff: function() {
var darkCss = Engine.findStylesheet('darkenLights'); var darkCss = Engine.findStylesheet('darkenLights');
if (darkCss != null) { if ( darkCss != null && !darkCss.disabled ) {
if (darkCss.disabled) return true;
return false; }
return true; return false;
} },
return false;
},
turnLightsOff: function() { turnLightsOff: function() {
var darkCss = Engine.findStylesheet('darkenLights'); var darkCss = Engine.findStylesheet('darkenLights');
if (darkCss == null) { if (darkCss == null) {
$('head').append('<link rel="stylesheet" href="css/dark.css" type="text/css" title="darkenLights" />'); $('head').append('<link rel="stylesheet" href="css/dark.css" type="text/css" title="darkenLights" />');
Engine.turnLightsOff; Engine.turnLightsOff;
$('.lightsOff').text(_('lights on.')); $('.lightsOff').text(_('lights on.'));
} } else if (darkCss.disabled) {
else if (darkCss.disabled) { darkCss.disabled = false;
darkCss.disabled = false; $('.lightsOff').text(_('lights on.'));
$('.lightsOff').text(_('lights on.')); } else {
} $("#darkenLights").attr("disabled", "disabled");
else { darkCss.disabled = true;
$("#darkenLights").attr("disabled", "disabled"); $('.lightsOff').text(_('lights off.'));
darkCss.disabled = true; }
$('.lightsOff').text(_('lights off.')); },
}
},
// Gets a guid // Gets a guid
getGuid: function() { getGuid: function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16); return v.toString(16);
}); });
}, },
@@ -486,15 +488,15 @@
$('div#weapons').animate({opacity: 1}, 300); $('div#weapons').animate({opacity: 1}, 300);
} }
Notifications.printQueue(module); Notifications.printQueue(module);
} }
}, },
// Move the stores panel beneath top_container (or to top: 0px if top_container /* Move the stores panel beneath top_container (or to top: 0px if top_container
// either hasn't been filled in or is null) using transition_diff to sync with * either hasn't been filled in or is null) using transition_diff to sync with
// the animation in Engine.travelTo(). * the animation in Engine.travelTo().
*/
moveStoresView: function(top_container, transition_diff) { moveStoresView: function(top_container, transition_diff) {
var stores = $('#storesContainer'); var stores = $('#storesContainer');
@@ -510,8 +512,13 @@
stores.animate({top: '0px'}, {queue: false, duration: 300 * transition_diff}); stores.animate({top: '0px'}, {queue: false, duration: 300 * transition_diff});
} }
else { else {
stores.animate({top: top_container.height() + 26 + 'px'}, stores.animate({
{queue: false, duration: 300 * transition_diff}); top: top_container.height() + 26 + 'px'
},
{
queue: false,
duration: 300 * transition_diff
});
} }
}, },
@@ -551,38 +558,38 @@
if(Engine.activeModule.keyUp) { if(Engine.activeModule.keyUp) {
Engine.activeModule.keyUp(e); Engine.activeModule.keyUp(e);
} }
else else
{ {
switch(e.which) { switch(e.which) {
case 38: // Up case 38: // Up
case 87: case 87:
Engine.log('up'); Engine.log('up');
break; break;
case 40: // Down case 40: // Down
case 83: case 83:
Engine.log('down'); Engine.log('down');
break; break;
case 37: // Left case 37: // Left
case 65: case 65:
if(Engine.activeModule == Ship && Path.tab) if(Engine.activeModule == Ship && Path.tab)
Engine.travelTo(Path); Engine.travelTo(Path);
else if(Engine.activeModule == Path && Outside.tab) else if(Engine.activeModule == Path && Outside.tab)
Engine.travelTo(Outside); Engine.travelTo(Outside);
else if(Engine.activeModule == Outside && Room.tab) else if(Engine.activeModule == Outside && Room.tab)
Engine.travelTo(Room); Engine.travelTo(Room);
Engine.log('left'); Engine.log('left');
break; break;
case 39: // Right case 39: // Right
case 68: case 68:
if(Engine.activeModule == Room && Outside.tab) if(Engine.activeModule == Room && Outside.tab)
Engine.travelTo(Outside); Engine.travelTo(Outside);
else if(Engine.activeModule == Outside && Path.tab) else if(Engine.activeModule == Outside && Path.tab)
Engine.travelTo(Path); Engine.travelTo(Path);
else if(Engine.activeModule == Path && Ship.tab) else if(Engine.activeModule == Path && Ship.tab)
Engine.travelTo(Ship); Engine.travelTo(Ship);
Engine.log('right'); Engine.log('right');
break; break;
} }
} }
return false; return false;
@@ -655,8 +662,7 @@
//create jQuery Callbacks() to handle object events //create jQuery Callbacks() to handle object events
$.Dispatch = function( id ) { $.Dispatch = function( id ) {
var callbacks, var callbacks, topic = id && Engine.topics[ id ];
topic = id && Engine.topics[ id ];
if ( !topic ) { if ( !topic ) {
callbacks = jQuery.Callbacks(); callbacks = jQuery.Callbacks();
topic = { topic = {