Fixing whitespace conformity on engine.js

This commit is contained in:
Travis Weston
2014-07-16 23:45:48 -04:00
parent d164d1d466
commit 33e9772a1a
+63 -89
View File
@@ -316,13 +316,19 @@
} }
}); });
}, },
export64: function() { generateExport64: function(){
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, '');
return string64;
},
export64: function() {
Engine.saveGame();
var string64 = Engine.generateExport64();
Engine.enableSelection(); Engine.enableSelection();
Events.startEvent({ Events.startEvent({
title: _('Export'), title: _('Export'),
@@ -339,58 +345,26 @@
} }
} }
} }
} });
}); Engine.autoSelect('#description textarea')
}, },
generateExport64: function(){ import64: function(string64) {
var string64 = Base64.encode(localStorage.gameState); 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);
localStorage.gameState = decodedSave;
location.reload();
},
return string64;
},
export64: function() {
Engine.saveGame();
var string64 = Engine.generateExport64();
Engine.enableSelection();
Events.startEvent({
title: _('Export'),
scenes: {
start: {
text: [_('save this.')],
textarea: string64,
buttons: {
'done': {
text: _('got it'),
nextScene: 'end',
onChoose: Engine.disableSelection
}
}
}
}
});
Engine.autoSelect('#description textarea')
},
import64: function(string64) {
Engine.disableSelection();
string64 = string64.replace(/\s/g, '');
string64 = string64.replace(/\./g, '');
string64 = string64.replace(/\n/g, '');
var decodedSave = Base64.decode(string64);
localStorage.gameState = decodedSave;
location.reload();
},
event: function(cat, act) { event: function(cat, act) {
if(typeof ga === 'function') { if(typeof ga === 'function') {
ga('send', 'event', cat, act); ga('send', 'event', cat, act);
} }
}, },
confirmDelete: function() { confirmDelete: function() {
Events.startEvent({ Events.startEvent({
title: _('Restart?'), title: _('Restart?'),
@@ -412,7 +386,7 @@
} }
}); });
}, },
deleteSave: function(noReload) { deleteSave: function(noReload) {
if(typeof Storage != 'undefined' && localStorage) { if(typeof Storage != 'undefined' && localStorage) {
var prestige = Prestige.get(); var prestige = Prestige.get();
@@ -424,7 +398,7 @@
location.reload(); location.reload();
} }
}, },
share: function() { share: function() {
Events.startEvent({ Events.startEvent({
title: _('Share'), title: _('Share'),
@@ -472,7 +446,7 @@
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];
@@ -482,7 +456,7 @@
} }
return null; return null;
}, },
isLightsOff: function() { isLightsOff: function() {
var darkCss = Engine.findStylesheet('darkenLights'); var darkCss = Engine.findStylesheet('darkenLights');
if ( darkCss != null && !darkCss.disabled ) { if ( darkCss != null && !darkCss.disabled ) {
@@ -490,7 +464,7 @@
} }
return false; return false;
}, },
turnLightsOff: function() { turnLightsOff: function() {
var darkCss = Engine.findStylesheet('darkenLights'); var darkCss = Engine.findStylesheet('darkenLights');
if (darkCss == null) { if (darkCss == null) {
@@ -506,7 +480,7 @@
$('.lightsOff').text(_('lights off.')); $('.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) {
@@ -514,30 +488,30 @@
return v.toString(16); return v.toString(16);
}); });
}, },
activeModule: null, activeModule: null,
travelTo: function(module) { travelTo: function(module) {
if(Engine.activeModule != module) { if(Engine.activeModule != module) {
var currentIndex = Engine.activeModule ? $('.location').index(Engine.activeModule.panel) : 1; var currentIndex = Engine.activeModule ? $('.location').index(Engine.activeModule.panel) : 1;
$('div.headerButton').removeClass('selected'); $('div.headerButton').removeClass('selected');
module.tab.addClass('selected'); module.tab.addClass('selected');
var slider = $('#locationSlider'); var slider = $('#locationSlider');
var stores = $('#storesContainer'); var stores = $('#storesContainer');
var panelIndex = $('.location').index(module.panel); var panelIndex = $('.location').index(module.panel);
var diff = Math.abs(panelIndex - currentIndex); var diff = Math.abs(panelIndex - currentIndex);
slider.animate({left: -(panelIndex * 700) + 'px'}, 300 * diff); slider.animate({left: -(panelIndex * 700) + 'px'}, 300 * diff);
if($SM.get('stores.wood') != undefined) { if($SM.get('stores.wood') != undefined) {
// FIXME Why does this work if there's an animation queue...? // FIXME Why does this work if there's an animation queue...?
stores.animate({right: -(panelIndex * 700) + 'px'}, 300 * diff); stores.animate({right: -(panelIndex * 700) + 'px'}, 300 * diff);
} }
Engine.activeModule = module; Engine.activeModule = module;
module.onArrival(diff); module.onArrival(diff);
if(Engine.activeModule == Room || Engine.activeModule == Path) { if(Engine.activeModule == Room || Engine.activeModule == Path) {
// Don't fade out the weapons if we're switching to a module // Don't fade out the weapons if we're switching to a module
// where we're going to keep showing them anyway. // where we're going to keep showing them anyway.
@@ -545,28 +519,28 @@
$('div#weapons').animate({opacity: 0}, 300); $('div#weapons').animate({opacity: 0}, 300);
} }
} }
if(module == Room || module == Path) { if(module == Room || module == Path) {
$('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');
// If we don't have a storesContainer yet, leave. // If we don't have a storesContainer yet, leave.
if(typeof(stores) === 'undefined') return; if(typeof(stores) === 'undefined') return;
if(typeof(transition_diff) === 'undefined') transition_diff = 1; if(typeof(transition_diff) === 'undefined') transition_diff = 1;
if(top_container === null) { if(top_container === null) {
stores.animate({top: '0px'}, {queue: false, duration: 300 * transition_diff}); stores.animate({top: '0px'}, {queue: false, duration: 300 * transition_diff});
} }
@@ -583,28 +557,28 @@
}); });
} }
}, },
log: function(msg) { log: function(msg) {
if(this._log) { if(this._log) {
console.log(msg); console.log(msg);
} }
}, },
updateSlider: function() { updateSlider: function() {
var slider = $('#locationSlider'); var slider = $('#locationSlider');
slider.width((slider.children().length * 700) + 'px'); slider.width((slider.children().length * 700) + 'px');
}, },
updateOuterSlider: function() { updateOuterSlider: function() {
var slider = $('#outerSlider'); var slider = $('#outerSlider');
slider.width((slider.children().length * 700) + 'px'); slider.width((slider.children().length * 700) + 'px');
}, },
getIncomeMsg: function(num, delay) { getIncomeMsg: function(num, delay) {
return _("{0} per {1}s", (num > 0 ? "+" : "") + num, delay); return _("{0} per {1}s", (num > 0 ? "+" : "") + num, delay);
//return (num > 0 ? "+" : "") + num + " per " + delay + "s"; //return (num > 0 ? "+" : "") + num + " per " + delay + "s";
}, },
keyDown: function(e) { keyDown: function(e) {
if(!Engine.keyPressed && !Engine.keyLock) { if(!Engine.keyPressed && !Engine.keyLock) {
Engine.pressed = true; Engine.pressed = true;
@@ -614,7 +588,7 @@
} }
return !(jQuery.inArray(window.event.keycode, [37,38,39,40])); return !(jQuery.inArray(window.event.keycode, [37,38,39,40]));
}, },
keyUp: function(e) { keyUp: function(e) {
Engine.pressed = false; Engine.pressed = false;
if(Engine.activeModule.keyUp) { if(Engine.activeModule.keyUp) {
@@ -653,52 +627,52 @@
break; break;
} }
} }
return false; return false;
}, },
swipeLeft: function(e) { swipeLeft: function(e) {
if(Engine.activeModule.swipeLeft) { if(Engine.activeModule.swipeLeft) {
Engine.activeModule.swipeLeft(e); Engine.activeModule.swipeLeft(e);
} }
}, },
swipeRight: function(e) { swipeRight: function(e) {
if(Engine.activeModule.swipeRight) { if(Engine.activeModule.swipeRight) {
Engine.activeModule.swipeRight(e); Engine.activeModule.swipeRight(e);
} }
}, },
swipeUp: function(e) { swipeUp: function(e) {
if(Engine.activeModule.swipeUp) { if(Engine.activeModule.swipeUp) {
Engine.activeModule.swipeUp(e); Engine.activeModule.swipeUp(e);
} }
}, },
swipeDown: function(e) { swipeDown: function(e) {
if(Engine.activeModule.swipeDown) { if(Engine.activeModule.swipeDown) {
Engine.activeModule.swipeDown(e); Engine.activeModule.swipeDown(e);
} }
}, },
disableSelection: function() { disableSelection: function() {
document.onselectstart = eventNullifier; // this is for IE document.onselectstart = eventNullifier; // this is for IE
document.onmousedown = eventNullifier; // this is for the rest document.onmousedown = eventNullifier; // this is for the rest
}, },
enableSelection: function() { enableSelection: function() {
document.onselectstart = eventPassthrough; document.onselectstart = eventPassthrough;
document.onmousedown = eventPassthrough; document.onmousedown = eventPassthrough;
}, },
autoSelect: function(selector) { autoSelect: function(selector) {
$(selector).focus().select(); $(selector).focus().select();
}, },
handleStateUpdates: function(e){ handleStateUpdates: function(e){
},
},
switchLanguage: function(dom){ switchLanguage: function(dom){
var lang = $(this).val(); var lang = $(this).val();
if(document.location.href.search(/[\?\&]lang=[a-z]+/) != -1){ if(document.location.href.search(/[\?\&]lang=[a-z]+/) != -1){
@@ -707,7 +681,7 @@
document.location.href = document.location.href + ( (document.location.href.search(/\?/) != -1 )?"&":"?") + "lang="+lang; document.location.href = document.location.href + ( (document.location.href.search(/\?/) != -1 )?"&":"?") + "lang="+lang;
} }
}, },
saveLanguage: function(){ saveLanguage: function(){
var lang = decodeURIComponent((new RegExp('[?|&]lang=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null; var lang = decodeURIComponent((new RegExp('[?|&]lang=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
if(lang && typeof Storage != 'undefined' && localStorage) { if(lang && typeof Storage != 'undefined' && localStorage) {
@@ -715,15 +689,15 @@
} }
} }
}; };
function eventNullifier(e) { function eventNullifier(e) {
return $(e.target).hasClass('menuBtn'); return $(e.target).hasClass('menuBtn');
} }
function eventPassthrough(e) { function eventPassthrough(e) {
return true; return true;
} }
})(); })();
//create jQuery Callbacks() to handle object events //create jQuery Callbacks() to handle object events