Some refactoring and some bug fixes.

This commit is contained in:
Michael
2013-11-01 23:00:51 -04:00
parent d8f6e73c6b
commit 994f01c78c
8 changed files with 177 additions and 242 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ div#header {
.manualSave { .manualSave {
position: absolute; position: absolute;
right: 120px; right: 125px;
bottom: 10px; bottom: 10px;
cursor: pointer; cursor: pointer;
} }
+6 -3
View File
@@ -274,13 +274,16 @@ var Engine = {
}); });
}, },
deleteSave: function() { deleteSave: function(noReload) {
if (!Engine.GAME_OVER) {
if(typeof Storage != 'undefined' && localStorage) { if(typeof Storage != 'undefined' && localStorage) {
var prestige = Prestige.get();
window.State = {};
localStorage.clear(); localStorage.clear();
Prestige.set(prestige);
} }
} if(!noReload) {
location.reload(); location.reload();
}
}, },
share: function() { share: function() {
+1 -1
View File
@@ -3433,7 +3433,7 @@ Events.Setpieces = {
], ],
onLoad: function() { onLoad: function() {
World.markVisited(World.curPos[0], World.curPos[1]); World.markVisited(World.curPos[0], World.curPos[1]);
Prestige.load(); Prestige.collectStores();
}, },
buttons: { buttons: {
'leave': { 'leave': {
+69 -87
View File
@@ -8,106 +8,88 @@ var Prestige = {
this.options = $.extend(this.options, options); this.options = $.extend(this.options, options);
}, },
saveStores: function(saveBool) { storesMap: [
var prevStores = [ //g = goods, w = weapons, a = ammo { store: 'wood', type: 'g' },
Math.floor($SM.get('stores["wood"]') / Prestige.randGen('g')), { store: 'fur', type: 'g' },
Math.floor($SM.get('stores["fur"]') / Prestige.randGen('g')), { store: 'meat', type: 'g' },
Math.floor($SM.get('stores["meat"]') / Prestige.randGen('g')), { store: 'iron', type: 'g' },
Math.floor($SM.get('stores["iron"]') / Prestige.randGen('g')), { store: 'coal', type: 'g' },
Math.floor($SM.get('stores["coal"]') / Prestige.randGen('g')), { store: 'sulphur', type: 'g' },
Math.floor($SM.get('stores["sulphur"]') / Prestige.randGen('g')), { store: 'steel', type: 'g' },
Math.floor($SM.get('stores["steel"]') / Prestige.randGen('g')), { store: 'cured meat', type: 'g' },
Math.floor($SM.get('stores["cured meat"]') / Prestige.randGen('g')), { store: 'scales', type: 'g' },
Math.floor($SM.get('stores["scales"]') / Prestige.randGen('g')), { store: 'teeth', type: 'g' },
Math.floor($SM.get('stores["teeth"]') / Prestige.randGen('g')), { store: 'leather', type: 'g' },
Math.floor($SM.get('stores["leather"]') / Prestige.randGen('g')), { store: 'bait', type: 'g' },
Math.floor($SM.get('stores["bait"]') / Prestige.randGen('g')), { store: 'torch', type: 'g' },
Math.floor($SM.get('stores["torch"]') / Prestige.randGen('g')), { store: 'cloth', type: 'g' },
Math.floor($SM.get('stores["cloth"]') / Prestige.randGen('g')), { store: 'bone spear', type: 'w' },
Math.floor($SM.get('stores["bone spear"]') / Prestige.randGen('w')), { store: 'iron sword', type: 'w' },
Math.floor($SM.get('stores["iron sword"]') / Prestige.randGen('w')), { store: 'steel sword', type: 'w' },
Math.floor($SM.get('stores["steel sword"]') / Prestige.randGen('w')), { store: 'bayonet', type: 'w' },
Math.floor($SM.get('stores["bayonet"]') / Prestige.randGen('w')), { store: 'rifle', type: 'w' },
Math.floor($SM.get('stores["rifle"]') / Prestige.randGen('w')), { store: 'laser rifle', type: 'w' },
Math.floor($SM.get('stores["laser rifle"]') / Prestige.randGen('w')), { store: 'bullets', type: 'a' },
Math.floor($SM.get('stores["bullets"]') / Prestige.randGen('a')), { store: 'energy cell', type: 'a' },
Math.floor($SM.get('stores["energy cell"]') / Prestige.randGen('a')), { store: 'grenade', type: 'a' },
Math.floor($SM.get('stores["grenade"]') / Prestige.randGen('a')), { store: 'bolas', type: 'a' }
Math.floor($SM.get('stores["bolas"]') / Prestige.randGen('a')) ],
];
for (var n = 0; n <= 23; n++) { getStores: function(reduce) {
if (isNaN(prevStores[n])) { var stores = [];
prevStores[n] = 0;
for(var i in this.storesMap) {
var s = this.storesMap[i];
stores.push($SM.get('stores["' + s.store + '"]', true) /
(reduce ? this.randGen(s.type) : 1));
} }
}
return prevStores; return stores;
}, },
saveScore: function() { get: function() {
var prevScore = Score.totalScore(); return {
$SM.set('previous.score',prevScore); stores: $SM.get('previous.stores'),
return prevScore; score: $SM.get('previous.score')
},
populateNewSave : function(newstate) {
State = {
previous : {
stores : newstate["stores"],
score : newstate["score"]
}
}; };
Engine.init({
state : State
});
}, },
load : function() { set: function(prestige) {
$SM.set('previous.stores', prestige.stores);
$SM.set('previous.score', prestige.score);
},
save: function() {
$SM.set('previous.stores', this.getStores(true));
$SM.set('previous.score', Score.totalScore());
},
collectStores : function() {
var prevStores = $SM.get('previous.stores'); var prevStores = $SM.get('previous.stores');
if(prevStores != null) { if(prevStores != null) {
$SM.add('stores["wood"]', prevStores[0]); var toAdd = {};
$SM.add('stores["fur"]', prevStores[1]); for(var i in this.storesMap) {
$SM.add('stores["meat"]', prevStores[2]); var s = this.storesMap[i];
$SM.add('stores["iron"]', prevStores[3]); toAdd[s.store] = prevStores[i];
$SM.add('stores["coal"]', prevStores[4]); }
$SM.add('stores["sulphur"]', prevStores[5]); $SM.addM('stores', toAdd);
$SM.add('stores["steel"]', prevStores[6]);
$SM.add('stores["cured meat"]', prevStores[7]); // Loading the stores clears em from the save
$SM.add('stores["scales"]', prevStores[8]); prevStores.length = 0;
$SM.add('stores["teeth"]', prevStores[9]);
$SM.add('stores["leather"]', prevStores[10]);
$SM.add('stores["bait"]', prevStores[11]);
$SM.add('stores["torch"]', prevStores[12]);
$SM.add('stores["cloth"]', prevStores[13]);
$SM.add('stores["bone spear"]', prevStores[14]);
$SM.add('stores["iron sword"]', prevStores[15]);
$SM.add('stores["steel sword"]', prevStores[16]);
$SM.add('stores["bayonet"]', prevStores[17]);
$SM.add('stores["rifle"]', prevStores[18]);
$SM.add('stores["laser rifle"]', prevStores[19]);
$SM.add('stores["bullets"]', prevStores[20]);
$SM.add('stores["energy cell"]', prevStores[21]);
$SM.add('stores["grenade"]', prevStores[22]);
$SM.add('stores["bolas"]', prevStores[23]);
} }
return prevStores;
}, },
randGen : function(storeType) { randGen : function(storeType) {
if (storeType == 'g') { switch(storeType) {
divisor = Math.floor(Math.random() * 10); case 'g':
} else if (storeType == 'w') { return Math.floor(Math.random() * 10);
divisor = Math.floor(Math.floor(Math.random() * 10) / 2); case 'w':
} else if (storeType == 'a') { return Math.floor(Math.floor(Math.random() * 10) / 2);
divisor = Math.ceil(Math.random() * 10 case 'a':
* Math.ceil(Math.random() * 10)); return Math.ceil(Math.random() * 10 * Math.ceil(Math.random() * 10));
} else { default:
divisor = 1; return 1;
} }
if (divisor === 0) {
divisor = 1;
}
return divisor;
} }
}; };
+1 -1
View File
@@ -974,7 +974,7 @@ var Room = {
if(Room.buttons[thing]) { if(Room.buttons[thing]) {
return true; return true;
} else if($SM.get('game.buildings["trading post"]', true) > 0) { } else if($SM.get('game.buildings["trading post"]', true) > 0) {
if(thing == 'compass' || $SM.get('stores["'+thing+'"]')) { if(thing == 'compass' || typeof $SM.get('stores["'+thing+'"]') != 'undefined') {
// Allow the purchase of stuff once you've seen it // Allow the purchase of stuff once you've seen it
return true; return true;
} }
+7 -11
View File
@@ -9,7 +9,7 @@ var Score = {
}, },
calculateScore : function() { calculateScore : function() {
var scoreUnadded = $SM.getStores(); var scoreUnadded = Prestige.getStores(false);
var fullScore = 0; var fullScore = 0;
fullScore = fullScore + scoreUnadded[0] * 1; fullScore = fullScore + scoreUnadded[0] * 1;
fullScore = fullScore + scoreUnadded[1] * 1.5; fullScore = fullScore + scoreUnadded[1] * 1.5;
@@ -35,20 +35,16 @@ var Score = {
fullScore = fullScore + scoreUnadded[21] * 3; fullScore = fullScore + scoreUnadded[21] * 3;
fullScore = fullScore + scoreUnadded[22] * 5; fullScore = fullScore + scoreUnadded[22] * 5;
fullScore = fullScore + scoreUnadded[23] * 4; fullScore = fullScore + scoreUnadded[23] * 4;
fullScore = fullScore + $SM.get('stores["alien alloy"]') * 10; fullScore = fullScore + $SM.get('stores["alien alloy"]', true) * 10;
fullScore = fullScore + Ship.getMaxHull() * 50; fullScore = fullScore + Ship.getMaxHull() * 50;
return fullScore; return Math.floor(fullScore);
}, },
saveScore: function() { save: function() {
var score = Score.calculateScore(); $SM.set('playStats.score', Score.calculateScore());
$SM.set('playStats.score',score);
return score;
}, },
totalScore : function() { totalScore : function() {
var totScore = $SM.get('previous.score') + Score.saveScore(); //$SM.get('playStats.score'); return $SM.get('previous.score', true) + Score.calculateScore();
if (!totScore) {totScore = $SM.get('playStats.score')};
return totScore;
}
} }
};
+6 -17
View File
@@ -5,7 +5,7 @@ var Space = {
SHIP_SPEED: 3, SHIP_SPEED: 3,
BASE_ASTEROID_DELAY: 500, BASE_ASTEROID_DELAY: 500,
BASE_ASTEROID_SPEED: 1500, BASE_ASTEROID_SPEED: 1500,
FTB_SPEED: 60000, FTB_SPEED: 1000,//60000,
STAR_WIDTH: 3000, STAR_WIDTH: 3000,
STAR_HEIGHT: 3000, STAR_HEIGHT: 3000,
NUM_STARS: 200, NUM_STARS: 200,
@@ -42,9 +42,6 @@ var Space = {
$('<div>').addClass('row_key').text('hull: ').appendTo(h); $('<div>').addClass('row_key').text('hull: ').appendTo(h);
$('<div>').addClass('row_val').appendTo(h); $('<div>').addClass('row_val').appendTo(h);
//save current score
Score.saveScore();
//subscribe to stateUpdates //subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Space.handleStateUpdates); $.Dispatch('stateUpdate').subscribe(Space.handleStateUpdates);
}, },
@@ -390,11 +387,9 @@ var Space = {
}, },
complete: function() { complete: function() {
Engine.GAME_OVER = true; Engine.GAME_OVER = true;
var backup = new Object();
backup.score = null; Score.save();
backup.stores = null; Prestige.save();
Prestige.saveStores();
Prestige.saveScore();
$('<center>') $('<center>')
.addClass('centerCont') .addClass('centerCont')
@@ -408,7 +403,7 @@ var Space = {
.appendTo('.centerCont'); .appendTo('.centerCont');
$('<span>') $('<span>')
.addClass('endGame') .addClass('endGame')
.text('total score: ' + Score.totalScore()) .text('total score: ' + Prestige.get().score)
.appendTo('.centerCont') .appendTo('.centerCont')
.animate({opacity:1},1500); .animate({opacity:1},1500);
$('<br />') $('<br />')
@@ -417,13 +412,6 @@ var Space = {
.appendTo('.centerCont'); .appendTo('.centerCont');
$('#starsContainer').remove(); $('#starsContainer').remove();
if(typeof Storage != 'undefined' && localStorage) {
backup.stores = $SM.getStores();
backup.score = Score.totalScore();
localStorage.clear();
}
delete window.State;
Prestige.populateNewSave(backup);
$('.deleteSave, .share, .manualSave').remove(); $('.deleteSave, .share, .manualSave').remove();
$('#content, #notifications').remove(); $('#content, #notifications').remove();
$('.deleteSave, .share, .manualSave').attr('style', 'color: white;').animate({opacity:0},1500); $('.deleteSave, .share, .manualSave').attr('style', 'color: white;').animate({opacity:0},1500);
@@ -434,6 +422,7 @@ var Space = {
.appendTo('.centerCont') .appendTo('.centerCont')
.animate({opacity:1},1500); .animate({opacity:1},1500);
Engine.options = {}; Engine.options = {};
Engine.deleteSave(true);
} }
}); });
}, 2000); }, 2000);
-35
View File
@@ -190,41 +190,6 @@ var StateManager = {
}; };
}, },
getStores: function() {
var stores = [
$SM.get('stores["wood"]'),
$SM.get('stores["fur"]'),
$SM.get('stores["meat"]'),
$SM.get('stores["iron"]'),
$SM.get('stores["coal"]'),
$SM.get('stores["sulphur"]'),
$SM.get('stores["steel"]'),
$SM.get('stores["cured meat"]'),
$SM.get('stores["scales"]'),
$SM.get('stores["teeth"]'),
$SM.get('stores["leather"]'),
$SM.get('stores["bait"]'),
$SM.get('stores["torch"]'),
$SM.get('stores["cloth"]'),
$SM.get('stores["bone spear"]'),
$SM.get('stores["iron sword"]'),
$SM.get('stores["steel sword"]'),
$SM.get('stores["bayonet"]'),
$SM.get('stores["rifle"]'),
$SM.get('stores["laser rifle"]'),
$SM.get('stores["bullets"]'),
$SM.get('stores["energy cell"]'),
$SM.get('stores["grenade"]'),
$SM.get('stores["bolas"]')
];
for (var n = 0; n <= 23; n++) {
if (isNaN(stores[n])) {
stores[n] = 0;
}
}
return stores;
},
//creates full reference from input //creates full reference from input
//hopefully this won't ever need to be more complicated //hopefully this won't ever need to be more complicated
buildPath: function(input){ buildPath: function(input){