[#14] Add list of crafted items

* This is step toward implementing #14 in that it shows you a list of the items
  which need to be crafted.  However, it still doesn't show you the steps and
  proper order in which to craft everything.
This commit is contained in:
Andrew Miner
2013-08-19 23:05:26 -07:00
parent 87c6664363
commit ba83e8d205
2 changed files with 16 additions and 5 deletions
+7 -3
View File
@@ -38,13 +38,15 @@ function onCraftingSelectorChanged() {
$("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION); $("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION);
} else { } else {
var inventory = createManifest(); var inventory = createManifest();
var craftedItems = createManifest();
var missingMaterials = createManifest(); var missingMaterials = createManifest();
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
recipe.craft(inventory, missingMaterials); recipe.craft(inventory, craftedItems, missingMaterials);
if (inventory.contains(count, recipeName)) break; if (inventory.contains(count, recipeName)) break;
} }
$("#missing_materials").html(missingMaterials.toHtml()); $("#missing_materials").html(missingMaterials.toHtml());
$("#crafted_items").html(craftedItems.toHtml());
$("#leftover_materials").html(inventory.toHtml()); $("#leftover_materials").html(inventory.toHtml());
$("#crafting_output").fadeIn(FADE_DURATION); $("#crafting_output").fadeIn(FADE_DURATION);
} }
@@ -209,8 +211,9 @@ function createRecipe(data) {
// Methods //////////////////////////////////////////// // Methods ////////////////////////////////////////////
object.craft = function(inventory, missingMaterials) { object.craft = function(inventory, craftedItems, missingMaterials) {
if (inventory === undefined) inventory = createManifest(); if (inventory === undefined) inventory = createManifest();
if (craftedItems === undefined) craftedItems = createManifest();
if (missingMaterials === undefined) missingMaterials = createManifest(); if (missingMaterials === undefined) missingMaterials = createManifest();
var toCraftManifest = createManifest(); var toCraftManifest = createManifest();
@@ -230,7 +233,7 @@ function createRecipe(data) {
inventory.add(1, name); inventory.add(1, name);
} }
} else { } else {
itemRecipe.craft(inventory, missingMaterials); itemRecipe.craft(inventory, craftedItems, missingMaterials);
if (consumeItems) { if (consumeItems) {
inventory.remove(1, name); inventory.remove(1, name);
} }
@@ -255,6 +258,7 @@ function createRecipe(data) {
drainCraftingManifest(false); drainCraftingManifest(false);
$(object.output).each(function(i, output) { $(object.output).each(function(i, output) {
craftedItems.add(output.count, output.name);
inventory.add(output.count, output.name); inventory.add(output.count, output.name);
}); });
}; };
+9 -2
View File
@@ -45,8 +45,15 @@
<select id="crafting_selector" disabled></select> <select id="crafting_selector" disabled></select>
</p> </p>
<table id="crafting_output" class="hidden" cellpadding="0" cellspacing="0"> <table id="crafting_output" class="hidden" cellpadding="0" cellspacing="0">
<tr><th width="50%">You'll need:</th><th>You'll get:</th></tr> <tr>
<tr><td id="missing_materials">&nbsp;</td><td id="leftover_materials"></td></tr> <th width="33%">You need to find:</th>
<th width="34%">You need to make:</th>
<th width="33%">You'll end up with:</th></tr>
<tr>
<td id="missing_materials">&nbsp;</td>
<td id="crafted_items">&nbsp;</td>
<td id="leftover_materials">&nbsp;</td>
</tr>
</table> </table>
<div id="crafting_error" class="error"></div> <div id="crafting_error" class="error"></div>
</div> <!-- #crafting --> </div> <!-- #crafting -->