Some general code cleanup.

This commit is contained in:
Michael
2013-10-10 20:49:19 -04:00
parent fbdc84dcf1
commit dde477aade
10 changed files with 75 additions and 79 deletions
+6 -7
View File
@@ -376,21 +376,21 @@ var Engine = {
case 37: // Left
case 65:
if(Engine.activeModule == Ship && Path.tab)
Engine.travelTo(Path)
Engine.travelTo(Path);
else if(Engine.activeModule == Path && Outside.tab)
Engine.travelTo(Outside)
Engine.travelTo(Outside);
else if(Engine.activeModule == Outside && Room.tab)
Engine.travelTo(Room)
Engine.travelTo(Room);
Engine.log('left');
break;
case 39: // Right
case 68:
if(Engine.activeModule == Room && Outside.tab)
Engine.travelTo(Outside)
Engine.travelTo(Outside);
else if(Engine.activeModule == Outside && Path.tab)
Engine.travelTo(Path)
Engine.travelTo(Path);
else if(Engine.activeModule == Path && Ship.tab)
Engine.travelTo(Ship)
Engine.travelTo(Ship);
Engine.log('right');
break;
}
@@ -431,7 +431,6 @@ var Engine = {
//create jQuery Callbacks() to handle object events
$.Dispatch = function( id ) {
var callbacks,
method,
topic = id && Engine.topics[ id ];
if ( !topic ) {
callbacks = jQuery.Callbacks();
+5 -6
View File
@@ -298,7 +298,7 @@ var Events = {
dmg = weapon.damage;
if(typeof dmg == 'number') {
if(weapon.type == 'unarmed' && $SM.hasPerk('boxer')) {
dmg *= 2
dmg *= 2;
}
if(weapon.type == 'unarmed' && $SM.hasPerk('martial artist')) {
dmg *= 3;
@@ -336,7 +336,7 @@ var Events = {
fighter.stop(true, true).animate(start, Events._FIGHT_SPEED, function() {
var enemyHp = enemy.data('hp');
var msg;
var msg = "";
if(typeof dmg == 'number') {
if(dmg < 0) {
msg = 'miss';
@@ -381,7 +381,7 @@ var Events = {
$('<div>').css(start).addClass('bullet').text('o').appendTo('#description')
.animate(end, Events._FIGHT_SPEED * 2, 'linear', function() {
var enemyHp = enemy.data('hp');
var msg;
var msg = "";
if(typeof dmg == 'number') {
if(dmg < 0) {
msg = 'miss';
@@ -508,7 +508,7 @@ var Events = {
dropStuff: function(e) {
e.stopPropagation();
var btn = $(this)
var btn = $(this);
var thing = btn.data('thing');
var num = btn.data('num');
var lootButtons = $('#lootButtons');
@@ -537,7 +537,6 @@ var Events = {
var weight = Path.getWeight(name);
var freeSpace = Path.getFreeSpace();
if(weight <= freeSpace) {
var loot = Events.activeEvent().scenes[Events.activeScene].loot[name];
var num = btn.data('numLeft');
num--;
btn.data('numLeft', num);
@@ -791,7 +790,7 @@ var Events = {
scheduleNextEvent: function(scale) {
var nextEvent = Math.floor(Math.random()*(Events._EVENT_TIME_RANGE[1] - Events._EVENT_TIME_RANGE[0])) + Events._EVENT_TIME_RANGE[0];
if(scale > 0) { nextEvent *= scale }
if(scale > 0) { nextEvent *= scale; }
Engine.log('next event scheduled in ' + nextEvent + ' minutes');
Events._eventTimeout = setTimeout(Events.triggerEvent, nextEvent * 60 * 1000);
},
+2 -2
View File
@@ -43,8 +43,8 @@ var Notifications = {
Engine.saveGame();
},
printMessage: function(text) {
var text = $('<div>').addClass('notification').css('opacity', '0').text(text).prependTo('div#notifications');
printMessage: function(t) {
var text = $('<div>').addClass('notification').css('opacity', '0').text(t).prependTo('div#notifications');
text.animate({opacity: 1}, 500, 'linear');
},
+27 -27
View File
@@ -350,36 +350,36 @@ var Outside = {
updateVillageRow: function(name, num, village) {
var id = 'building_row_' + name.replace(' ', '-');
var row = $('div#' + id, village);
if(row.length == 0 && num > 0) {
var row = $('<div>').attr('id', id).addClass('storeRow');
$('<div>').addClass('row_key').text(name).appendTo(row);
$('<div>').addClass('row_val').text(num).appendTo(row);
$('<div>').addClass('clear').appendTo(row);
var curPrev = null;
village.children().each(function(i) {
var child = $(this);
if(child.attr('id') != 'population') {
var cName = child.attr('id').substring(13).replace('-', ' ');
if(cName < name && (curPrev == null || cName > curPrev)) {
curPrev = cName;
}
if(row.length == 0 && num > 0) {
row = $('<div>').attr('id', id).addClass('storeRow');
$('<div>').addClass('row_key').text(name).appendTo(row);
$('<div>').addClass('row_val').text(num).appendTo(row);
$('<div>').addClass('clear').appendTo(row);
var curPrev = null;
village.children().each(function(i) {
var child = $(this);
if(child.attr('id') != 'population') {
var cName = child.attr('id').substring(13).replace('-', ' ');
if(cName < name && (curPrev == null || cName > curPrev)) {
curPrev = cName;
}
});
if(curPrev == null) {
row.prependTo(village);
} else {
row.insertAfter('#building_row_' + curPrev.replace(' ', '-'));
}
} else if(num > 0) {
$('div#' + row.attr('id') + ' > div.row_val', village).text(num);
} else if(num == 0) {
row.remove();
});
if(curPrev == null) {
row.prependTo(village);
} else {
row.insertAfter('#building_row_' + curPrev.replace(' ', '-'));
}
} else if(num > 0) {
$('div#' + row.attr('id') + ' > div.row_val', village).text(num);
} else if(num == 0) {
row.remove();
}
},
updateVillage: function() {
var village = $('div#village');
var pop = $('div#population');
var population = $('div#population');
var needsAppend = false;
if(village.length == 0) {
needsAppend = true;
@@ -440,7 +440,7 @@ var Outside = {
'sulphur mine': ['sulphur miner'],
'steelworks': ['steelworker'],
'armoury' : ['armourer']
}
};
var jobs = jobMap[name];
var added = false;
@@ -449,7 +449,7 @@ var Outside = {
var job = jobs[i];
if(typeof $SM.get('game.buildings["'+name+'"]') == 'number' &&
typeof $SM.get('game.workers["'+job+'"]') != 'number') {
Engine.log('adding ' + job + ' to the workers list')
Engine.log('adding ' + job + ' to the workers list');
$SM.set('game.workers["'+job+'"]', 0);
added = true;
}
@@ -545,7 +545,7 @@ var Outside = {
},
gatherWood: function() {
Notifications.notify(Outside, "dry brush and dead branches litter the forest floor")
Notifications.notify(Outside, "dry brush and dead branches litter the forest floor");
var gatherAmt = $SM.get('game.buildings["cart"]', true) > 0 ? 50 : 10;
$SM.add('stores.wood', gatherAmt);
},
@@ -561,7 +561,7 @@ var Outside = {
for(var j in Outside.TrapDrops) {
var drop = Outside.TrapDrops[j];
if(roll < drop.rollUnder) {
var num = drops[drop.name]
var num = drops[drop.name];
if(typeof num == 'undefined') {
num = 0;
msg.push(drop.message);
+5 -5
View File
@@ -35,7 +35,7 @@ var Path = {
// Add the outfitting area
var outfitting = $('<div>').attr('id', 'outfitting').appendTo(this.panel);
var bagspace = $('<div>').attr('id', 'bagspace').appendTo(outfitting);
$('<div>').attr('id', 'bagspace').appendTo(outfitting);
// Add the embark button
new Button.Button({
@@ -114,10 +114,10 @@ var Path = {
if(needsAppend && perks.children().length > 0) {
perks.appendTo(Path.panel);
}
}
if(Engine.activeModule === Path) {
$('#storesContainer').css({top: perks.height() + 26 + 'px'});
if(Engine.activeModule === Path) {
$('#storesContainer').css({top: perks.height() + 26 + 'px'});
}
}
},
+19 -19
View File
@@ -65,7 +65,7 @@ var Room = {
wood: 200,
fur: 10,
meat: 5
}
};
}
},
'trading post': {
@@ -261,7 +261,7 @@ var Room = {
return {
'leather': 200,
'iron': 100
}
};
}
},
's armour': {
@@ -272,7 +272,7 @@ var Room = {
return {
'leather': 200,
'steel': 100
}
};
}
},
'iron sword': {
@@ -307,7 +307,7 @@ var Room = {
'wood': 200,
'steel': 50,
'sulphur': 50
}
};
}
}
},
@@ -331,7 +331,7 @@ var Room = {
return {
'fur': 150,
'scales': 50
}
};
}
},
'coal': {
@@ -340,7 +340,7 @@ var Room = {
return {
'fur': 200,
'teeth': 50
}
};
}
},
'steel': {
@@ -350,7 +350,7 @@ var Room = {
'fur': 300,
'scales': 50,
'teeth': 50
}
};
}
},
'medicine': {
@@ -358,7 +358,7 @@ var Room = {
cost: function() {
return {
'scales': 50, 'teeth': 30
}
};
}
},
'bullets': {
@@ -366,7 +366,7 @@ var Room = {
cost: function() {
return {
'scales': 10
}
};
}
},
'energy cell': {
@@ -375,7 +375,7 @@ var Room = {
return {
'scales': 10,
'teeth': 10
}
};
}
},
'bolas': {
@@ -383,7 +383,7 @@ var Room = {
cost: function() {
return {
'teeth': 10
}
};
}
},
'grenade': {
@@ -392,7 +392,7 @@ var Room = {
return {
'scales': 100,
'teeth': 50
}
};
}
},
'bayonet': {
@@ -401,7 +401,7 @@ var Room = {
return {
'scales': 500,
'teeth': 250
}
};
}
},
'alien alloy': {
@@ -411,7 +411,7 @@ var Room = {
'fur': 1500,
'scales': 750,
'teeth': 300
}
};
}
},
'compass': {
@@ -468,7 +468,7 @@ var Room = {
Engine.updateSlider();
// Create the light button
var lbtn = new Button.Button({
new Button.Button({
id: 'lightButton',
text: 'light fire',
click: Room.lightFire,
@@ -478,7 +478,7 @@ var Room = {
}).appendTo('div#roomPanel');
// Create the stoke button
var btn = new Button.Button({
new Button.Button({
id: 'stokeButton',
text: "stoke fire",
click: Room.stokeFire,
@@ -537,7 +537,7 @@ var Room = {
stores: {'wood' : 2 }
});
Room.updateIncomeView();
Notifications.notify(Room, "the stranger is standing by the fire. she says she can help. says she builds things.")
Notifications.notify(Room, "the stranger is standing by the fire. she says she can help. says she builds things.");
}
Engine.moveStoresView(null, transition_diff);
@@ -703,7 +703,7 @@ var Room = {
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
}
else if(lBuilder < 3 && Room.temperature.value >= Room.TempEnum.Warm.value) {
var msg;
var msg = "";
switch(lBuilder) {
case 1:
msg = "the stranger shivers, and mumbles quietly. her words are unintelligible.";
@@ -781,7 +781,7 @@ var Room = {
}
if(row.length == 0 && num > 0) {
var row = $('<div>').attr('id', id).addClass('storeRow');
row = $('<div>').attr('id', id).addClass('storeRow');
$('<div>').addClass('row_key').text(k).appendTo(row);
$('<div>').addClass('row_val').text(Math.floor(num)).appendTo(row);
$('<div>').addClass('clear').appendTo(row);
+1 -1
View File
@@ -120,7 +120,7 @@ var Ship = {
return false;
}
$SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_THRUSTER);
$SM.add('game.spaceShip.thrusters', 1)
$SM.add('game.spaceShip.thrusters', 1);
$('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters'));
},
+2 -2
View File
@@ -103,7 +103,7 @@ var Space = {
if(r < 0.2)
c = '#';
else if(r < 0.4)
c = '$'
c = '$';
else if(r < 0.6)
c = '%';
else if(r < 0.8)
@@ -112,7 +112,7 @@ var Space = {
c = 'H';
var x = Math.floor(Math.random() * 700);
var a = $('<div>').addClass('asteroid').text(c).appendTo('#spacePanel').css('left', x + 'px')
var a = $('<div>').addClass('asteroid').text(c).appendTo('#spacePanel').css('left', x + 'px');
a.data({
xMin: x,
xMax: x + a.width(),
+5 -5
View File
@@ -83,8 +83,8 @@ var StateManager = {
//stores values can not be negative
if(stateName.indexOf('stores') == 0 && $SM.get(stateName, true) < 0) {
eval('('+fullPath+') = 0');;
Engine.log('WARNING: state:' + stateName + ' can not be a negative value. Set to 0 instead.')
eval('('+fullPath+') = 0');
Engine.log('WARNING: state:' + stateName + ' can not be a negative value. Set to 0 instead.');
}
if(!noEvent) {
@@ -95,7 +95,7 @@ var StateManager = {
//sets a list of states
setM: function(parentName, list, noEvent) {
var whichParent = $SM.buildPath(parentName);
$SM.buildPath(parentName);
//make sure the state exists to avoid errors,
if($SM.get(parentName) == undefined) $SM.set(parentName, {}, true);
@@ -125,7 +125,7 @@ var StateManager = {
$SM.set(stateName, old + value, noEvent);
} else if(typeof old != 'number' || typeof value != 'number'){
Engine.log('WARNING: Can not do math with state:'+stateName+' or value:'+value+' because at least one is not a number.');
err = 1
err = 1;
} else {
$SM.set(stateName, old + value, noEvent); //setState handles event and save
}
@@ -199,7 +199,7 @@ var StateManager = {
fireUpdate: function(stateName, save){
var category = $SM.getCategory(stateName);
if(stateName == undefined) stateName = category = 'all'; //best if this doesn't happen as it will trigger more stuff
$.Dispatch('stateUpdate').publish({'category': category, 'stateName':stateName})
$.Dispatch('stateUpdate').publish({'category': category, 'stateName':stateName});
if(save) Engine.saveGame();
},
+3 -5
View File
@@ -334,7 +334,7 @@ var World = {
World.doSpace();
if(World.checkDanger()) {
if(World.danger) {
Notifications.notify(World, 'dangerous to be this far from the village without proper protection')
Notifications.notify(World, 'dangerous to be this far from the village without proper protection');
} else {
Notifications.notify(World, 'safer here');
}
@@ -441,7 +441,7 @@ var World = {
// Starvation! Hooray!
num = 0;
if(!World.starvation) {
Notifications.notify(World, 'starvation sets in')
Notifications.notify(World, 'starvation sets in');
World.starvation = true;
} else {
$SM.set('character.starved', $SM.get('character.starved', true));
@@ -620,7 +620,7 @@ var World = {
// Spiral out from there
map[World.RADIUS][World.RADIUS] = World.TILE.VILLAGE;
for(var r = 1; r <= World.RADIUS; r++) {
for(t = 0; t < r * 8; t++) {
for(var t = 0; t < r * 8; t++) {
var x, y;
if(t < 2 * r) {
x = World.RADIUS - r + t;
@@ -689,8 +689,6 @@ var World = {
chooseTile: function(x, y, map) {
var log = x == World.RADIUS + 1 && y == World.RADIUS + 1;
var adjacent = [
y > 0 ? map[x][y-1] : null,
y < World.RADIUS * 2 ? map[x][y+1] : null,