').addClass('clear').appendTo(wRow);
} else {
$('.row_val', wRow).text(World.getMaxWater());
}
var space = Path.getFreeSpace();
var total = 0;
// Add the non-craftables to the craftables
var carryable = $.extend({
'cured meat': { type: 'tool' },
'bullets': { type: 'tool' },
'grenade': {type: 'weapon' },
'bolas': {type: 'weapon' },
'laser rifle': {type: 'weapon' },
'energy cell': {type: 'tool' },
'bayonet': {type: 'weapon' },
'charm': {type: 'tool'},
'medicine': {type: 'tool'}
}, Room.Craftables);
for(var k in carryable) {
var store = carryable[k];
var have = $SM.get('stores["'+k+'"]');
var num = Path.outfit[k];
num = typeof num == 'number' ? num : 0;
var numAvailable = $SM.get('stores["'+k+'"]', true);
var row = $('div#outfit_row_' + k.replace(' ', '-'), outfit);
if((store.type == 'tool' || store.type == 'weapon') && have > 0) {
total += num * Path.getWeight(k);
if(row.length == 0) {
row = Path.createOutfittingRow(k, num);
var curPrev = null;
outfit.children().each(function(i) {
var child = $(this);
if(child.attr('id').indexOf('outfit_row_') == 0) {
var cName = child.attr('id').substring(11).replace('-', ' ');
if(cName < k && (curPrev == null || cName > curPrev)) {
curPrev = cName;
}
}
});
if(curPrev == null) {
row.insertAfter(wRow);
}
else
{
row.insertAfter(outfit.find('#outfit_row_' + curPrev.replace(' ', '-')));
}
} else {
$('div#' + row.attr('id') + ' > div.row_val > span', outfit).text(num);
$('div#' + row.attr('id') + ' .tooltip .numAvailable', outfit).text(numAvailable - num);
}
if(num == 0) {
$('.dnBtn', row).addClass('disabled');
$('.dnManyBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.dnManyBtn', row).removeClass('disabled');
}
if(num >= numAvailable || space < Path.getWeight(k)) {
$('.upBtn', row).addClass('disabled');
$('.upManyBtn', row).addClass('disabled');
} else if(space >= Path.getWeight(k)) {
$('.upBtn', row).removeClass('disabled');
$('.upManyBtn', row).removeClass('disabled');
}
} else if(have == 0 && row.length > 0) {
row.remove();
}
}
// Update bagspace
$('#bagspace').text('free ' + Math.floor(Path.getCapacity() - total) + '/' + Path.getCapacity());
if(Path.outfit['cured meat'] > 0) {
Button.setDisabled($('#embarkButton'), false);
} else {
Button.setDisabled($('#embarkButton'), true);
}
},
createOutfittingRow: function(name, num) {
var row = $('
').attr('id', 'outfit_row_' + name.replace(' ', '-')).addClass('outfitRow');
$('
').addClass('row_key').text(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["'+name+'"]', true);
var tt = $('
').addClass('tooltip bottom right').appendTo(row);
$('
').addClass('row_key').text('weight').appendTo(tt);
$('
').addClass('row_val').text(Path.getWeight(name)).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').children('.row_key').text().replace('-', ' ');
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;
var maxExtraByBtn = btn.data;
Path.outfit[supply] = cur + Math.min(maxExtraByBtn, Math.min(maxExtraByWeight, maxExtraByStore));
Path.updateOutfitting();
}
},
decreaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
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);
Path.updateOutfitting();
}
},
onArrival: function(transition_diff) {
Path.setTitle();
Path.updateOutfitting();
Path.updatePerks();
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;
},
handleStateUpdates: function(e){
if(e.category == 'character' && e.stateName.indexOf('character.perks') == 0 && Engine.activeModule == Path){
Path.updatePerks();
};
}
};