[#4] Add the ability to craft multiple items

This commit is contained in:
Andrew Miner
2013-08-18 11:51:08 -07:00
parent c7d2fc85fd
commit b8190171d7
2 changed files with 20 additions and 4 deletions
+8 -3
View File
@@ -12,8 +12,10 @@ var __recipebooks = [];
$(function() {
$("#recipebook_load_button").click(onRecipeLoadButtonClicked);
$("#crafting_selector").change(onCraftingSelectorChanged);
$("#crafting_count").change(onCraftingSelectorChanged);
loadRecipebook("data/vanilla.json");
loadRecipebook("data/buildcraft.json");
});
function onCraftingSelectorChanged() {
@@ -23,8 +25,9 @@ function onCraftingSelectorChanged() {
$("#crafting_error").html("Cannot find recipe for " + recipeName);
$("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION);
} else {
var count = parseInt($("#crafting_count option:selected").val());
var inventory = createManifest();
var missingMaterials = recipe.computeMissingMaterials(inventory);
var missingMaterials = recipe.computeMissingMaterials(inventory, count);
$("#missing_materials").html(missingMaterials.toHtml());
$("#leftover_materials").html(inventory.toHtml());
$("#crafting_output").fadeIn(FADE_DURATION);
@@ -146,8 +149,9 @@ function createRecipe(data) {
// Methods ////////////////////////////////////////////
object.computeMissingMaterials = function(inventory) {
object.computeMissingMaterials = function(inventory, count) {
if (inventory === undefined) inventory = createManifest();
if (count === undefined) count = 1;
var missingMaterials = createManifest();
var queue = [];
@@ -177,7 +181,7 @@ function createRecipe(data) {
return recipe;
}
craftItem({count: 1, name: object.output[0].name});
queue.push({count: count, name: object.output[0].name});
while (queue.length > 0) {
var ingredient = queue.shift();
@@ -191,6 +195,7 @@ function createRecipe(data) {
}
}
inventory.add(object.output[0].count * count, object.output[0].name);
return missingMaterials;
}
+12 -1
View File
@@ -32,7 +32,18 @@
<div id="crafting" class="hidden">
<h1><img src="images/workbench_top.png"> Crafting</h1>
<p>Choose a recipe: <select id="crafting_selector" disabled></select></p>
<p>Choose a recipe:
<select id="crafting_count">
<option value="1">1</option>
<option value="2">2</option>
<option value="4">4</option>
<option value="8">8</option>
<option value="16">16</option>
<option value="32">32</option>
<option value="64">64</option>
</select>
<select id="crafting_selector" disabled></select>
</p>
<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><td id="missing_materials">&nbsp;</td><td id="leftover_materials"></td></tr>