').addClass('clear').appendTo(wRow);
} else {
$('.row_val', wRow).text(World.getMaxWater());
}
var space = Path.getFreeSpace();
var currentBagCapacity = 0;
// Add the non-craftables to the craftables
var carryable = $.extend({
'cured meat': { type: 'tool', desc: _('restores') + ' ' + World.MEAT_HEAL + ' ' + _('hp') },
'bullets': { type: 'tool', desc: _('use with rifle') },
'grenade': {type: 'weapon' },
'bolas': {type: 'weapon' },
'laser rifle': {type: 'weapon' },
'energy cell': {type: 'tool', desc: _('emits a soft red glow') },
'bayonet': {type: 'weapon' },
'charm': {type: 'tool'},
'alien alloy': { type: 'tool' },
'medicine': {type: 'tool', desc: _('restores') + ' ' + World.MEDS_HEAL + ' ' + _('hp') }
}, Room.Craftables, Fabricator.Craftables);
for(var k in carryable) {
var lk = _(k);
var store = carryable[k];
var have = $SM.get('stores["'+k+'"]');
var num = Path.outfit[k];
num = typeof num == 'number' ? num : 0;
if (have !== undefined) {
if (have < num) { num = have; }
$SM.set(k, num, true);
}
var row = $('div#outfit_row_' + k.replace(' ', '-'), outfit);
if((store.type == 'tool' || store.type == 'weapon') && have > 0) {
currentBagCapacity += num * Path.getWeight(k);
if(row.length === 0) {
row = Path.createOutfittingRow(k, num, store, store.name);
var curPrev = null;
outfit.children().each(function(i) {
var child = $(this);
if(child.attr('id').indexOf('outfit_row_') === 0) {
var cName = child.children('.row_key').text();
if(cName < lk) {
curPrev = child.attr('id');
}
}
});
if(curPrev == null) {
row.insertAfter(wRow);
} else {
row.insertAfter(outfit.find('#' + curPrev));
}
} else {
$('div#' + row.attr('id') + ' > div.row_val > span', outfit).text(num);
$('div#' + row.attr('id') + ' .tooltip .numAvailable', outfit).text(have - num);
}
if(num === 0) {
$('.dnBtn', row).addClass('disabled');
$('.dnManyBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.dnManyBtn', row).removeClass('disabled');
}
if(num == have || space < Path.getWeight(k)) {
$('.upBtn', row).addClass('disabled');
$('.upManyBtn', row).addClass('disabled');
} else {
$('.upBtn', row).removeClass('disabled');
$('.upManyBtn', row).removeClass('disabled');
}
} else if(have === 0 && row.length > 0) {
row.remove();
}
}
Path.updateBagSpace(currentBagCapacity);
},
updateBagSpace: function(currentBagCapacity) {
// Update bagspace
$('#bagspace').text(_('free {0}/{1}', Math.floor(Path.getCapacity() - currentBagCapacity) , Path.getCapacity()));
if(Path.outfit['cured meat'] > 0) {
Button.setDisabled($('#embarkButton'), false);
} else {
Button.setDisabled($('#embarkButton'), true);
}
},
createOutfittingRow: function(key, num, store) {
if(!store.name) store.name = _(key);
var row = $('
').attr('id', 'outfit_row_' + key.replace(' ', '-')).addClass('outfitRow').attr('key',key);
$('
').addClass('row_key').text(store.name).appendTo(row);
var val = $('
').addClass('row_val').appendTo(row);
$('
').text(num).appendTo(val);
$('').addClass('upBtn').appendTo(val).click([1], Path.increaseSupply);
$('
').addClass('dnBtn').appendTo(val).click([1], Path.decreaseSupply);
$('
').addClass('upManyBtn').appendTo(val).click([10], Path.increaseSupply);
$('
').addClass('dnManyBtn').appendTo(val).click([10], Path.decreaseSupply);
$('
').addClass('clear').appendTo(row);
var numAvailable = $SM.get('stores["'+key+'"]', true);
var tt = $('
').addClass('tooltip bottom right').appendTo(row);
if(store.type == 'weapon') {
$('
').addClass('row_key').text(_('damage')).appendTo(tt);
$('
').addClass('row_val').text(World.getDamage(key)).appendTo(tt);
} else if(store.type == 'tool' && store.desc != "undefined") {
$('
').addClass('row_key').text(store.desc).appendTo(tt);
}
$('
').addClass('row_key').text(_('weight')).appendTo(tt);
$('
').addClass('row_val').text(Path.getWeight(key)).appendTo(tt);
$('
').addClass('row_key').text(_('available')).appendTo(tt);
$('
').addClass('row_val').addClass('numAvailable').text(numAvailable).appendTo(tt);
return row;
},
increaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').attr('key');
Engine.log('increasing ' + supply + ' by up to ' + btn.data);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(Path.getFreeSpace() >= Path.getWeight(supply) && cur < $SM.get('stores["'+supply+'"]', true)) {
var maxExtraByWeight = Math.floor(Path.getFreeSpace() / Path.getWeight(supply));
var maxExtraByStore = $SM.get('stores["'+supply+'"]', true) - cur;
Path.outfit[supply] = cur + Math.min(btn.data, maxExtraByWeight, maxExtraByStore);
$SM.set('outfit['+supply+']', Path.outfit[supply]);
Path.updateOutfitting();
}
},
decreaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').attr('key');
Engine.log('decreasing ' + supply + ' by up to ' + btn.data);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(cur > 0) {
Path.outfit[supply] = Math.max(0, cur - btn.data);
$SM.set('outfit['+supply+']', Path.outfit[supply]);
Path.updateOutfitting();
}
},
onArrival: function(transition_diff) {
Path.setTitle();
Path.updateOutfitting();
Path.updatePerks(true);
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_DUSTY_PATH);
Engine.moveStoresView($('#perks'), transition_diff);
},
setTitle: function() {
document.title = _('A Dusty Path');
},
embark: function() {
for(var k in Path.outfit) {
$SM.add('stores["'+k+'"]', -Path.outfit[k]);
}
World.onArrival();
$('#outerSlider').animate({left: '-700px'}, 300);
Engine.activeModule = World;
AudioEngine.playSound(AudioLibrary.EMBARK);
},
handleStateUpdates: function(e){
if(e.category == 'character' && e.stateName.indexOf('character.perks') === 0 && Engine.activeModule == Path){
Path.updatePerks();
} else if(e.category == 'income' && Engine.activeModule == Path){
Path.updateOutfitting();
}
}
};