diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..e43b0f988
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.DS_Store
diff --git a/html/crafting.js b/html/crafting.js
index 56cbe057d..1fd845819 100644
--- a/html/crafting.js
+++ b/html/crafting.js
@@ -3,18 +3,22 @@
var FADE_DURATION = 250; // ms
var ERROR_DISPLAY_DURATION = 5000; // ms
+// Global Variables ///////////////////////////////////////////////////////////////////////////////////////////////////
+
+var __recipebooks = [];
+
// UI Functions ///////////////////////////////////////////////////////////////////////////////////////////////////////
-function onPageLoad() {
- $("#recipe_load_button").click(onRecipeLoadButtonClicked);
+$(function() {
+ $("#recipebook_load_button").click(onRecipeLoadButtonClicked);
$("#crafting_selector").change(onCraftingSelectorChanged);
- loadRecipes("data/vanilla.json");
-}
+ loadRecipebook("data/vanilla.json");
+});
function onCraftingSelectorChanged() {
var recipeName = $("#crafting_selector option:selected").val();
- var recipe = __recipes[recipeName];
+ var recipe = findRecipe(recipeName);
if (recipe === undefined) {
$("#crafting_error").html("Cannot find recipe for " + recipeName);
$("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION);
@@ -28,24 +32,30 @@ function onCraftingSelectorChanged() {
}
function onRecipeLoadButtonClicked() {
- loadRecipes($("#recipe_url").val());
+ $("#reipebook_load_button").attr("disabled", true);
+ loadRecipebook($("#recipebook_url").val(), function() {
+ $("#recipebook_url").val("");
+ $("#reipebook_load_button").removeAttr("disabled");
+ });
}
// UI Helper Functions ////////////////////////////////////////////////////////////////////////////////////////////////
-function loadRecipes(recipeUrl) {
+function loadRecipebook(recipebookUrl, onSuccess) {
$.ajax({
- url: recipeUrl,
+ url: recipebookUrl,
dataType: "text",
- success: function(data) {
+ success: function(text) {
try {
- recipeData = $.parseJSON(data)["recipes"];
- __recipes = parseRecipeData(recipeData);
- $("#loaded_recipes ul").append("
" + recipeUrl + "");
- $("#loaded_recipes").fadeIn(FADE_DURATION);
+ var recipebook = createRecipebook(recipebookUrl, $.parseJSON(text));
+ __recipebooks.push(recipebook);
+
+ recipebook.asTableRow().insertBefore($("#recipebook_table tr").last());
updateCraftingSelector();
$("#crafting").fadeIn(FADE_DURATION);
+
+ if (onSuccess !== undefined) onSuccess();
} catch (e) {
$("#load_error").html(e);
$("#load_error").slideDown(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).slideUp(FADE_DURATION);
@@ -60,13 +70,20 @@ function loadRecipes(recipeUrl) {
function updateCraftingSelector() {
var $selector = $("#crafting_selector");
- if (__recipes.length == 0) {
+ $selector.html("");
+
+ if (__recipebooks.length == 0) {
$selector.attr("disabled", "disabled");
+ $selector.html("");
} else {
- for (var name in __recipes) {
- if (!__recipes.hasOwnProperty(name)) continue;
- $selector.append("");
- }
+ $(__recipebooks).each(function(i, recipebook) {
+ var $optgroup = $("