Converted min/max buttons to +-10 buttons. Also made code shorter.

This commit is contained in:
Zarkonnen
2013-07-05 13:47:23 +02:00
parent 6d99cb7c3a
commit ae044376db
3 changed files with 45 additions and 84 deletions
+14 -32
View File
@@ -296,10 +296,10 @@ var Outside = {
numGatherers -= State.outside.workers[k];
if(State.outside.workers[k] == 0) {
$('.dnBtn', row).addClass('disabled');
$('.zeroBtn', row).addClass('disabled');
$('.dnManyBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.zeroBtn', row).removeClass('disabled');
$('.dnManyBtn', row).removeClass('disabled');
}
}
@@ -312,10 +312,10 @@ var Outside = {
if(numGatherers == 0) {
$('.upBtn', '#workers').addClass('disabled');
$('.maxBtn', '#workers').addClass('disabled');
$('.upManyBtn', '#workers').addClass('disabled');
} else {
$('.upBtn', '#workers').removeClass('disabled');
$('.maxBtn', '#workers').removeClass('disabled');
$('.upManyBtn', '#workers').removeClass('disabled');
}
@@ -342,10 +342,10 @@ var Outside = {
$('<span>').text(num).appendTo(val);
if(name != 'gatherer') {
$('<div>').addClass('maxBtn').appendTo(val).click(Outside.maxWorker);
$('<div>').addClass('upBtn').appendTo(val).click(Outside.increaseWorker);
$('<div>').addClass('dnBtn').appendTo(val).click(Outside.decreaseWorker);
$('<div>').addClass('zeroBtn').appendTo(val).click(Outside.zeroWorker);
$('<div>').addClass('upManyBtn').appendTo(val).click([10], Outside.increaseWorker);
$('<div>').addClass('upBtn').appendTo(val).click([1], Outside.increaseWorker);
$('<div>').addClass('dnBtn').appendTo(val).click([1], Outside.decreaseWorker);
$('<div>').addClass('dnManyBtn').appendTo(val).click([10], Outside.decreaseWorker);
}
$('<div>').addClass('clear').appendTo(row);
@@ -365,8 +365,9 @@ var Outside = {
increaseWorker: function(btn) {
var worker = $(this).closest('.workerRow').children('.row_key').text();
if(Outside.getNumGatherers() > 0) {
Engine.log('increasing ' + worker);
State.outside.workers[worker]++;
var increaseAmt = Math.min(Outside.getNumGatherers(), btn.data);
Engine.log('increasing ' + worker + ' by ' + increaseAmt);
State.outside.workers[worker] += increaseAmt;
Outside.updateVillageIncome();
Outside.updateWorkersView();
}
@@ -375,28 +376,9 @@ var Outside = {
decreaseWorker: function(btn) {
var worker = $(this).closest('.workerRow').children('.row_key').text();
if(State.outside.workers[worker] > 0) {
Engine.log('decreasing ' + worker);
State.outside.workers[worker]--;
Outside.updateVillageIncome();
Outside.updateWorkersView();
}
},
maxWorker: function(btn) {
var worker = $(this).closest('.workerRow').children('.row_key').text();
if(Outside.getNumGatherers() > 0) {
Engine.log('maxing ' + worker);
State.outside.workers[worker] += Outside.getNumGatherers();
Outside.updateVillageIncome();
Outside.updateWorkersView();
}
},
zeroWorker: function(btn) {
var worker = $(this).closest('.workerRow').children('.row_key').text();
if(State.outside.workers[worker] > 0) {
Engine.log('zeroing ' + worker);
State.outside.workers[worker] = 0;
var decreaseAmt = Math.min(State.outside.workers[worker] || 0, btn.data);
Engine.log('decreasing ' + worker + ' by ' + decreaseAmt);
State.outside.workers[worker] -= decreaseAmt;
Outside.updateVillageIncome();
Outside.updateWorkersView();
}
+16 -37
View File
@@ -194,17 +194,17 @@ var Path = {
}
if(num == 0) {
$('.dnBtn', row).addClass('disabled');
$('.zeroBtn', row).addClass('disabled');
$('.dnManyBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.zeroBtn', row).removeClass('disabled');
$('.dnManyBtn', row).removeClass('disabled');
}
if(num >= numAvailable || space < Path.getWeight(k)) {
$('.upBtn', row).addClass('disabled');
$('.maxBtn', row).addClass('disabled');
$('.upManyBtn', row).addClass('disabled');
} else if(space >= Path.getWeight(k)) {
$('.upBtn', row).removeClass('disabled');
$('.maxBtn', row).removeClass('disabled');
$('.upManyBtn', row).removeClass('disabled');
}
} else if(have == 0 && row.length > 0) {
row.remove();
@@ -227,10 +227,10 @@ var Path = {
var val = $('<div>').addClass('row_val').appendTo(row);
$('<span>').text(num).appendTo(val);
$('<div>').addClass('upBtn').appendTo(val).click(Path.increaseSupply);
$('<div>').addClass('dnBtn').appendTo(val).click(Path.decreaseSupply);
$('<div>').addClass('maxBtn').appendTo(val).click(Path.maxSupply);
$('<div>').addClass('zeroBtn').appendTo(val).click(Path.zeroSupply);
$('<div>').addClass('upBtn').appendTo(val).click([1], Path.increaseSupply);
$('<div>').addClass('dnBtn').appendTo(val).click([1], Path.decreaseSupply);
$('<div>').addClass('upManyBtn').appendTo(val).click([10], Path.increaseSupply);
$('<div>').addClass('dnManyBtn').appendTo(val).click([10], Path.decreaseSupply);
$('<div>').addClass('clear').appendTo(row);
var numAvailable = Engine.getStore(name);
@@ -243,48 +243,27 @@ var Path = {
return row;
},
increaseSupply: function() {
increaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
Engine.log('increasing ' + supply);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(Path.getFreeSpace() >= Path.getWeight(supply) && cur < Engine.getStore(supply)) {
Path.outfit[supply] = cur + 1;
Path.updateOutfitting();
}
},
decreaseSupply: function() {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
Engine.log('decreasing ' + supply);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(cur > 0) {
Path.outfit[supply] = cur - 1;
Path.updateOutfitting();
}
},
maxSupply: function() {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
Engine.log('maxing ' + supply);
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 < Engine.getStore(supply)) {
var maxExtraByWeight = Math.floor(Path.getFreeSpace() / Path.getWeight(supply));
var maxExtraByStore = Engine.getStore(supply) - cur;
Path.outfit[supply] = cur + Math.min(maxExtraByWeight, maxExtraByStore);
var maxExtraByStore = Engine.getStore(supply) - cur;
var maxExtraByBtn = btn.data;
Path.outfit[supply] = cur + Math.min(maxExtraByBtn, Math.min(maxExtraByWeight, maxExtraByStore));
Path.updateOutfitting();
}
},
zeroSupply: function() {
decreaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
Engine.log('zeroing ' + supply);
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] = 0;
Path.outfit[supply] = Math.max(0, cur - btn.data);
Path.updateOutfitting();
}
},