You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Game/www/js/inventory.js

49 lines
1.9 KiB
JavaScript

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
function loadInventory() {
$("#item-bin #bag-preloader").removeClass("display-none");
$("#item-bin .item-col").remove();
callAPI("inventory", {
username: localStorage.getItem("username"),
password: localStorage.getItem("password")
}, function (resp) {
var items = [];
for (var i = 0; i < resp.items.length; i++) {
var item = resp.items[i];
var found = false;
for (var j = 0; j < items.length; j++) {
if (items[j].id == item.id && items[j].json == item.json) {
items[j].qty += 1;
items[j].uuids.push(item.uuid);
found = true;
break;
}
}
if (!found) {
item["qty"] = 1;
item["uuids"] = [item.uuid];
items.push(item);
}
}
$("#item-bin #bag-preloader").addClass("display-none");
items.forEach(function (item) {
$("#item-bin").append('<div class="col-100 tablet-33 desktop-25 item-col">'
+ '<div class="item padding margin" data-uuids="' + item.uuids + '" data-qty="' + item.qty + '">'
+ '<i class="item-icon ' + item.icon + ' text-color-' + item.color + '"></i><br />'
+ (item.qty > 1 ? '<span class="badge color-green text-color-black padding">x' + item.qty + '</span>' : "")
+ '<h3>' + item.name + '</h3>'
+ item.description
+ '</div>'
+ '</div>');
})
}, function (msg) {
app.dialog.alert(msg, "Error");
});
}