From dd850119de8c63e598571f4ab9c2066bd5ae500b Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Mon, 2 Apr 2018 22:52:35 +0200 Subject: [PATCH] added sort + fixed cost display --- js/game.js | 2 +- js/userinterface.js | 26 +++++++++++++++++++++++--- modes.md | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/js/game.js b/js/game.js index 6258443..23c3351 100644 --- a/js/game.js +++ b/js/game.js @@ -311,7 +311,7 @@ function drawInfoBar() { } else { $('#infoDesc p').css("height", 166) } - if (mode == "selectbuilding" || mode == "building") { + if (mode == "selectbuilding" || mode == "build") { if (selectedTile != 0) { infoCtx.textAlign = "center" infoCtx.font = "18px Electrolize" diff --git a/js/userinterface.js b/js/userinterface.js index 679700a..0307840 100644 --- a/js/userinterface.js +++ b/js/userinterface.js @@ -374,6 +374,25 @@ function closeUi() { } } +function sort() { + if (itemId.length > 1) { + var swapped = true + while (swapped) { + swapped = false + for (var i = 0; i < itemId.length - 1; i++) { + if (itemId[i] > itemId[i + 1]) { + var id = itemId[i] + var count = itemCount[i] + itemId[i] = itemId[i + 1] + itemCount[i] = itemCount[i + 1] + itemCount[i + 1] = count + itemId[i + 1] = id + swapped = true + } + } + } + } +} function drawInventory(inventory, title) { if (!(inventory instanceof Inventory)) @@ -391,6 +410,7 @@ function drawInventory(inventory, title) { itemCount[index]++ } } + sort() inventoryCtx.clearRect(0, 0, innerWidth, innerHeight) inventoryCtx.font = "20px Electrolize" @@ -445,9 +465,9 @@ function drawBigInventory(inventory) { itemCount[index]++ } } - //var swapped = - for(var i=0;i