[#4] Add the ability to craft multiple items
This commit is contained in:
+8
-3
@@ -12,8 +12,10 @@ var __recipebooks = [];
|
|||||||
$(function() {
|
$(function() {
|
||||||
$("#recipebook_load_button").click(onRecipeLoadButtonClicked);
|
$("#recipebook_load_button").click(onRecipeLoadButtonClicked);
|
||||||
$("#crafting_selector").change(onCraftingSelectorChanged);
|
$("#crafting_selector").change(onCraftingSelectorChanged);
|
||||||
|
$("#crafting_count").change(onCraftingSelectorChanged);
|
||||||
|
|
||||||
loadRecipebook("data/vanilla.json");
|
loadRecipebook("data/vanilla.json");
|
||||||
|
loadRecipebook("data/buildcraft.json");
|
||||||
});
|
});
|
||||||
|
|
||||||
function onCraftingSelectorChanged() {
|
function onCraftingSelectorChanged() {
|
||||||
@@ -23,8 +25,9 @@ function onCraftingSelectorChanged() {
|
|||||||
$("#crafting_error").html("Cannot find recipe for " + recipeName);
|
$("#crafting_error").html("Cannot find recipe for " + recipeName);
|
||||||
$("#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 count = parseInt($("#crafting_count option:selected").val());
|
||||||
var inventory = createManifest();
|
var inventory = createManifest();
|
||||||
var missingMaterials = recipe.computeMissingMaterials(inventory);
|
var missingMaterials = recipe.computeMissingMaterials(inventory, count);
|
||||||
$("#missing_materials").html(missingMaterials.toHtml());
|
$("#missing_materials").html(missingMaterials.toHtml());
|
||||||
$("#leftover_materials").html(inventory.toHtml());
|
$("#leftover_materials").html(inventory.toHtml());
|
||||||
$("#crafting_output").fadeIn(FADE_DURATION);
|
$("#crafting_output").fadeIn(FADE_DURATION);
|
||||||
@@ -146,8 +149,9 @@ function createRecipe(data) {
|
|||||||
|
|
||||||
// Methods ////////////////////////////////////////////
|
// Methods ////////////////////////////////////////////
|
||||||
|
|
||||||
object.computeMissingMaterials = function(inventory) {
|
object.computeMissingMaterials = function(inventory, count) {
|
||||||
if (inventory === undefined) inventory = createManifest();
|
if (inventory === undefined) inventory = createManifest();
|
||||||
|
if (count === undefined) count = 1;
|
||||||
var missingMaterials = createManifest();
|
var missingMaterials = createManifest();
|
||||||
var queue = [];
|
var queue = [];
|
||||||
|
|
||||||
@@ -177,7 +181,7 @@ function createRecipe(data) {
|
|||||||
return recipe;
|
return recipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
craftItem({count: 1, name: object.output[0].name});
|
queue.push({count: count, name: object.output[0].name});
|
||||||
|
|
||||||
while (queue.length > 0) {
|
while (queue.length > 0) {
|
||||||
var ingredient = queue.shift();
|
var ingredient = queue.shift();
|
||||||
@@ -191,6 +195,7 @@ function createRecipe(data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inventory.add(object.output[0].count * count, object.output[0].name);
|
||||||
return missingMaterials;
|
return missingMaterials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -32,7 +32,18 @@
|
|||||||
|
|
||||||
<div id="crafting" class="hidden">
|
<div id="crafting" class="hidden">
|
||||||
<h1><img src="images/workbench_top.png"> Crafting</h1>
|
<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">
|
<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><th width="50%">You'll need:</th><th>You'll get:</th></tr>
|
||||||
<tr><td id="missing_materials"> </td><td id="leftover_materials"></td></tr>
|
<tr><td id="missing_materials"> </td><td id="leftover_materials"></td></tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user