[#1] Add inventory and update calc's to use it
This commit is contained in:
+32
-2
@@ -6,6 +6,7 @@ var SLIDE_DURATION = 600; // ms
|
||||
|
||||
// Global Variables ///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var __inventory = createManifest();
|
||||
var __loadingCount = 0;
|
||||
var __recipebooks = [];
|
||||
var __toolsIncluded = false;
|
||||
@@ -17,6 +18,7 @@ $(function() {
|
||||
$("#crafting_count").change(onCraftingSelectorChanged);
|
||||
$("#tools_included").change(onIncludeToolsChanged);
|
||||
$("#crafting_selector").focus(onCraftingSelectorFocused);
|
||||
$("#inventory").keyup(onInventoryChanged);
|
||||
|
||||
loadRecipebook("data/vanilla.json");
|
||||
loadRecipebook("data/buildcraft.json");
|
||||
@@ -33,7 +35,7 @@ function onCraftingSelectorChanged() {
|
||||
if (recipe === undefined) {
|
||||
$("#crafting_output").slideUp(SLIDE_DURATION);
|
||||
} else {
|
||||
var inventory = createManifest();
|
||||
var inventory = __inventory.copy();
|
||||
var craftedItems = createManifest();
|
||||
var missingMaterials = createManifest();
|
||||
for (var i = 0; i < count; i++) {
|
||||
@@ -59,6 +61,27 @@ function onIncludeToolsChanged() {
|
||||
onCraftingSelectorChanged()
|
||||
}
|
||||
|
||||
function onInventoryChanged() {
|
||||
__inventory.removeAll();
|
||||
|
||||
var inventoryText = $("#inventory").val();
|
||||
if (inventoryText) {
|
||||
var inventoryLines = inventoryText.split("\n");
|
||||
for (var i = 0; i < inventoryLines.length; i++) {
|
||||
var line = inventoryLines[i].trim();
|
||||
var match = /^([0-9]+)(.*)$/.exec(line);
|
||||
|
||||
var count = (match) ? parseInt(match[1]) : 1;
|
||||
var itemName = (match) ? match[2].trim() : line;
|
||||
|
||||
if (itemName.length > 0) {
|
||||
__inventory.add(count, itemName);
|
||||
}
|
||||
}
|
||||
}
|
||||
onCraftingSelectorChanged();
|
||||
}
|
||||
|
||||
function onRecipeBookLoaded() {
|
||||
if (__loadingCount > 0 || __recipebooks.length === 0) {
|
||||
$("#crafting").fadeOut(FADE_DURATION);
|
||||
@@ -160,7 +183,6 @@ function updatePageState(count, recipeName) {
|
||||
newLink = newLink.replace(/%20/g, "+");
|
||||
state = {count: count, name: recipeName};
|
||||
}
|
||||
console.log("newTitle: " + newTitle + ", newLink: " + newLink);
|
||||
|
||||
document.title = newTitle;
|
||||
history.pushState(state, newTitle, newLink);
|
||||
@@ -185,6 +207,14 @@ function createManifest() {
|
||||
return (object.materials[name] >= count);
|
||||
};
|
||||
|
||||
object.copy = function(count, name) {
|
||||
var result = createManifest();
|
||||
for (var name in object.materials) {
|
||||
result.add(object.materials[name], name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
object.remove = function(count, name) {
|
||||
if (object.materials[name] !== undefined) {
|
||||
if (object.materials[name] <= count) {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ p { margin-left: 10px; margin-right: 10px; }
|
||||
#border_bedrock { background: url("../images/bedrock.png"); height: 32px; box-shadow: 2px 0px 4px #444; }
|
||||
#crafting { margin-bottom: 64px; }
|
||||
#crafting_error { margin-left: 10px; }
|
||||
#crafting_output { margin-left: 10px; width: 920px; }
|
||||
#crafting_output { margin-left: 10px; min-height: 400px; width: 920px; }
|
||||
#crafting_output th { background: #f8f8f8; border-left: 1px solid #bbb; font-weight: bold; padding: 10px; }
|
||||
#crafting_output td { background: #f8f8f8; border-left: 1px solid #bbb; padding: 10px; }
|
||||
#crafting_selector { width: 400px; }
|
||||
|
||||
+5
-3
@@ -49,10 +49,12 @@
|
||||
</p>
|
||||
<table id="crafting_output" class="hidden" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<th width="33%">You need to find:</th>
|
||||
<th width="34%">You need to make:</th>
|
||||
<th width="33%">You'll end up with:</th></tr>
|
||||
<th width="25%">I already have:</th>
|
||||
<th width="25%">You'll need to find:</th>
|
||||
<th width="25%">You'll need to make:</th>
|
||||
<th width="25%">You'll end up with:</th></tr>
|
||||
<tr>
|
||||
<td><textarea id="inventory" style="height: 100%; width: 100%" placeholder="2 Oak Log"></textarea></td>
|
||||
<td id="missing_materials"> </td>
|
||||
<td id="crafted_items"> </td>
|
||||
<td id="leftover_materials"> </td>
|
||||
|
||||
Reference in New Issue
Block a user