[#25] Add "include tools" selector

This commit is contained in:
Andrew Miner
2013-08-20 19:36:48 -07:00
parent 7b239580c1
commit ab3321ce86
2 changed files with 28 additions and 8 deletions
+26 -8
View File
@@ -6,6 +6,7 @@ var ERROR_DISPLAY_DURATION = 5000; // ms
// Global Variables /////////////////////////////////////////////////////////////////////////////////////////////////// // Global Variables ///////////////////////////////////////////////////////////////////////////////////////////////////
var __recipebooks = []; var __recipebooks = [];
var __toolsIncluded = false;
// UI Functions /////////////////////////////////////////////////////////////////////////////////////////////////////// // UI Functions ///////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -13,6 +14,7 @@ $(function() {
$("#recipebook_load_button").click(onRecipeLoadButtonClicked); $("#recipebook_load_button").click(onRecipeLoadButtonClicked);
$("#crafting_selector").change(onCraftingSelectorChanged); $("#crafting_selector").change(onCraftingSelectorChanged);
$("#crafting_count").change(onCraftingSelectorChanged); $("#crafting_count").change(onCraftingSelectorChanged);
$("#tools_included").change(onIncludeToolsChanged);
loadRecipebook("data/vanilla.json", function() { loadRecipebook("data/vanilla.json", function() {
loadRecipebook("data/buildcraft.json", function() { loadRecipebook("data/buildcraft.json", function() {
@@ -60,6 +62,11 @@ function onRecipeLoadButtonClicked() {
}); });
} }
function onIncludeToolsChanged() {
__toolsIncluded = $("#tools_included").is(":checked");
onCraftingSelectorChanged()
}
// UI Helper Functions //////////////////////////////////////////////////////////////////////////////////////////////// // UI Helper Functions ////////////////////////////////////////////////////////////////////////////////////////////////
function loadRecipebook(recipebookUrl, onSuccess) { function loadRecipebook(recipebookUrl, onSuccess) {
@@ -111,6 +118,13 @@ function parseUrlParameters() {
$("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION); $("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION);
} }
} }
__toolsIncluded = $.url().param('toolsIncluded') === "true";
if (__toolsIncluded) {
$("#tools_included").attr("checked", true);
} else {
$("#tools_included").removeAttr("checked");
}
} }
function updateCraftingSelector() { function updateCraftingSelector() {
@@ -141,7 +155,9 @@ function updateCraftingSelector() {
function updatePageState(count, recipeName) { function updatePageState(count, recipeName) {
var newTitle = "Crafting Guide: " + count + " " + recipeName; var newTitle = "Crafting Guide: " + count + " " + recipeName;
var newLink = "?count=" + count + "&recipeName=" + encodeURIComponent(recipeName); var newLink = "?count=" + count +
"&recipeName=" + encodeURIComponent(recipeName) +
(__toolsIncluded ? "&toolsIncluded=true" : "");
newLink = newLink.replace(/%20/g, "+"); newLink = newLink.replace(/%20/g, "+");
document.title = newTitle; document.title = newTitle;
@@ -243,6 +259,15 @@ function createRecipe(data) {
toCraftManifest.removeAll(); toCraftManifest.removeAll();
} }
if (__toolsIncluded) {
$(object.tools).each(function(i, tool) {
if (! inventory.contains(1, tool)) {
toCraftManifest.add(1, tool);
}
});
drainCraftingManifest(false);
}
$(object.input).each(function(i, input) { $(object.input).each(function(i, input) {
for (var j = 0; j < input.count; j++) { for (var j = 0; j < input.count; j++) {
toCraftManifest.add(1, input.name); toCraftManifest.add(1, input.name);
@@ -250,13 +275,6 @@ function createRecipe(data) {
}); });
drainCraftingManifest(true); drainCraftingManifest(true);
$(object.tools).each(function(i, tool) {
if (! inventory.contains(1, tool)) {
toCraftManifest.add(1, tool);
}
});
drainCraftingManifest(false);
$(object.output).each(function(i, output) { $(object.output).each(function(i, output) {
craftedItems.add(output.count, output.name); craftedItems.add(output.count, output.name);
inventory.add(output.count, output.name); inventory.add(output.count, output.name);
+2
View File
@@ -43,6 +43,8 @@
<option value="64">64</option> <option value="64">64</option>
</select> </select>
<select id="crafting_selector" disabled></select> <select id="crafting_selector" disabled></select>
<input id="tools_included" name="tools_included" type="checkbox"></input>
<label for="include_tools">include tools</label>
</p> </p>
<table id="crafting_output" class="hidden" cellpadding="0" cellspacing="0"> <table id="crafting_output" class="hidden" cellpadding="0" cellspacing="0">
<tr> <tr>