[#21] Add support for linking to a certain recipe

This commit is contained in:
Andrew Miner
2013-08-18 17:09:02 -07:00
parent bdda57c1eb
commit 8b3e98c5e7
4 changed files with 302 additions and 2 deletions
+32 -2
View File
@@ -14,12 +14,18 @@ $(function() {
$("#crafting_selector").change(onCraftingSelectorChanged);
$("#crafting_count").change(onCraftingSelectorChanged);
loadRecipebook("data/vanilla.json");
loadRecipebook("data/buildcraft.json");
loadRecipebook("data/vanilla.json", function() {
loadRecipebook("data/buildcraft.json", function() {
parseUrlParameters();
onCraftingSelectorChanged();
});
});
});
function onCraftingSelectorChanged() {
var recipeName = $("#crafting_selector option:selected").val();
if (recipeName === undefined) return;
var recipe = findRecipe(recipeName);
if (recipe === undefined) {
$("#crafting_error").html("Cannot find recipe for " + recipeName);
@@ -77,6 +83,30 @@ function loadRecipebook(recipebookUrl, onSuccess) {
});
}
function parseUrlParameters() {
var quantity = $.url().param('quantity');
if (quantity !== undefined) {
$("#crafting_count").val(quantity);
if ($("#crafting_count option:selected").val() === undefined) {
$("#crafting_count").val(1);
$("#crafting_error").html("Unsupported quantity: " + quantity);
$("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION);
}
}
var recipeName = $.url().param('recipeName');
if (recipeName !== undefined) {
$("#crafting_selector").val(recipeName);
if ($("#crafting_selector option:selected").val() === undefined) {
$("#crafting_error").html("Cannot find recipe for " + recipeName);
$("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION);
}
}
}
function updateCraftingSelector() {
var $selector = $("#crafting_selector");
$selector.html("");