Skip to content

Commit

Permalink
Converted min/max buttons to +-10 buttons. Also made code shorter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarkonnen committed Jul 5, 2013
1 parent 6d99cb7 commit ae04437
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 84 deletions.
30 changes: 15 additions & 15 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ div.button div.cooldown {

/* Up/Down buttons. They're complicated! */

.upBtn, .dnBtn, .maxBtn, .zeroBtn {
.upBtn, .dnBtn, .upManyBtn, .dnManyBtn {
position: absolute;
width: 14px;
height: 15px;
Expand All @@ -205,23 +205,23 @@ div.button div.cooldown {
right: 0px;
}

.maxBtn, .zeroBtn {
.upManyBtn, .dnManyBtn {
right: -11px;
}

.upBtn.disabled, .dnBtn.disabled, .maxBtn.disabled, .zeroBtn.disabled {
.upBtn.disabled, .dnBtn.disabled, .upManyBtn.disabled, .dnManyBtn.disabled {
cursor: default;
}

.upBtn {
top: -2px;
}

.maxBtn {
.upManyBtn {
top: -2px;
}

.upBtn:after, .upBtn:before, .maxBtn:after, .maxBtn:before {
.upBtn:after, .upBtn:before, .upManyBtn:after, .upManyBtn:before {
position: absolute;
border: medium solid transparent;
content: " ";
Expand All @@ -230,15 +230,15 @@ div.button div.cooldown {
bottom: 4px;
}

.upBtn:after, .maxBtn:after {
.upBtn:after, .upManyBtn:after {
border-color: transparent transparent white;
}

.upBtn:before, .maxBtn:before {
.upBtn:before, .upManyBtn:before {
border-color: transparent transparent black;
}

.upBtn.disabled:before, .maxBtn.disabled:before {
.upBtn.disabled:before, .upManyBtn.disabled:before {
border-color: transparent transparent #999;
}

Expand All @@ -247,11 +247,11 @@ div.button div.cooldown {
bottom: -3px;
}

.zeroBtn {
.dnManyBtn {
bottom: -3px;
}

.dnBtn:after, .dnBtn:before, .zeroBtn:after, .zeroBtn:before {
.dnBtn:after, .dnBtn:before, .dnManyBtn:after, .dnManyBtn:before {
position: absolute;
border: medium solid transparent;
content: " ";
Expand All @@ -266,27 +266,27 @@ div.button div.cooldown {
margin-left: -3px;
}

.upBtn:before, .dnBtn:before, .maxBtn:before, .zeroBtn:before {
.upBtn:before, .dnBtn:before, .upManyBtn:before, .dnManyBtn:before {
border-width: 5px;
left: 50%;
margin-left: -5px;
}

.maxBtn:after, .zeroBtn:after {
.upManyBtn:after, .dnManyBtn:after {
border-width: 2px;
left: 50%;
margin-left: -2px;
}

.dnBtn:after, .zeroBtn:after {
.dnBtn:after, .dnManyBtn:after {
border-color: white transparent transparent;
}

.dnBtn:before, .zeroBtn:before {
.dnBtn:before, .dnManyBtn:before {
border-color: black transparent transparent;
}

.dnBtn.disabled:before, .zeroBtn.disabled:before {
.dnBtn.disabled:before, .dnManyBtn.disabled:before {
border-color: #999 transparent transparent;
}

Expand Down
46 changes: 14 additions & 32 deletions script/outside.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand All @@ -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');
}


Expand All @@ -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);
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
53 changes: 16 additions & 37 deletions script/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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();
}
},
Expand Down

0 comments on commit ae04437

Please sign in to comment.