Skip to content

Commit

Permalink
嘗試在 characters 表格中加入 inventory 欄位但失敗,找不出原因 orz 求救 @mrbigmouth
Browse files Browse the repository at this point in the history
在 local server 的錯誤訊息:
Uncaught TypeError: Cannot read property 'services' of undefined

於 index.js 1220 處:
…, character.inventory.services, …

我有認真檢查應該沒有錯字 >_<
  • Loading branch information
ETBlue committed Jan 4, 2016
1 parent f99e579 commit f68069a
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 5 deletions.
5 changes: 5 additions & 0 deletions index.html.slim
Expand Up @@ -252,6 +252,11 @@ html lang='en'
th data-toggle='weapons' Aquatic B
// Bags
th data-toggle='bags' Bags
th data-toggle='bags' Services
th data-toggle='bags' Special
th data-toggle='bags' Boosts
th data-toggle='bags' Style
th data-toggle='bags' Misc
// Gathering
th data-toggle='gathering' Sickle
th data-toggle='gathering' Axe
Expand Down
104 changes: 100 additions & 4 deletions jsSource/js/model/gw2Data/characters.es6
Expand Up @@ -104,13 +104,12 @@ class Character {
wvw: getSpecializationHtml(specializations.wvw)
};
}

get equipment() {
const equipmentArray = this._data.equipment;

// 先把 equipment array 轉成 hash
const equipment = {};
equipmentArray.forEach(function(element, index, array){
equipmentArray.forEach((element) => {
equipment[element.slot] = {};
equipment[element.slot].id = element.id;
equipment[element.slot].upgrades = element.upgrades;
Expand Down Expand Up @@ -142,14 +141,95 @@ class Character {
Pick: getEquipmentItemHtml(equipment.Pick)
};
}

get bags() {
const bags = this._data.bags;
return getBagHtml(bags);
}
get inventory() {
const bags = this._data.bags;
const inventory = {
services: [],
special: [],
boosts: [],
style: [],
misc: []
};

}
bags.forEach((bag) => {
if (bag) {
bag.inventory.forEach((item) => {
if (item) {
const itemData = items[item.id];
itemData.count = item.count || "";
itemData.binding = item.binding || "";
itemData.bound_to = item.bound_to || "";
if (itemData.type == "Consumable") {
if (itemData.details.type == "AppearanceChange") {
inventory.services.push(itemData);
}
if (itemData.details.type == "Booze") {
// alcohol
}
if (itemData.details.type == "ContractNpc") {
inventory.services.push(itemData);
}
if (itemData.details.type == "Food") {
inventory.boosts.push(itemData);
}
if (itemData.details.type == "Generic") {
inventory.misc.push(itemData);
}
if (itemData.details.type == "Halloween") {
inventory.boosts.push(itemData);
}
if (itemData.details.type == "Immediate") {
inventory.misc.push(itemData);
}
if (itemData.details.type == "Transmutation") {
inventory.style.push(itemData);
}
if (itemData.details.type == "Unlock") {
inventory.misc.push(itemData);
}
if (itemData.details.type == "UpgradeRemoval") {
inventory.special.push(itemData);
}
if (itemData.details.type == "Utility") {
inventory.boosts.push(itemData);
}
if (itemData.details.type == "TeleportToFriend") {
inventory.special.push(itemData);
}
}
if (itemData.type == "Gizmo") {
if (itemData.details.type == "Default") {
inventory.misc.push(itemData);
}
if (itemData.details.type == "ContainerKey") {
inventory.special.push(itemData);
}
if (itemData.details.type == "RentableContractNpc") {
inventory.services.push(itemData);
}
if (itemData.details.type == "UnlimitedConsumable") {
inventory.services.push(itemData);
}
}
}
});
}
});

return {
services: getInventoryHtml(inventory.services),
special: getInventoryHtml(inventory.special),
boosts: getInventoryHtml(inventory.boosts),
style: getInventoryHtml(inventory.style),
misc: getInventoryHtml(inventory.misc)
};
}

}

function getSpecializationHtml(dataList) {
return dataList.reduce((html, specializationData) => {
Expand Down Expand Up @@ -261,3 +341,19 @@ function getBagHtml(dataList) {
}, '');
}

function getInventoryHtml(dataList) {
return dataList.reduce((html, item) => {
if (item) {
return html + `
<div class="table-item">
<img data-toggle="tooltip" data-placement="left" title="${item.description}" class="icon medium item ${item.rarity}" src="${item.icon}" />
<span class="bold ${item.rarity}">${item.name}
</span>
</div>
`;
}
else {
return html;
}
}, '');
}
7 changes: 6 additions & 1 deletion jsSource/js/view/characters.es6
Expand Up @@ -42,6 +42,11 @@ export const characters = {
character.equipment.WeaponAquaticA,
character.equipment.WeaponAquaticB,
character.bags,
character.inventory.services,
character.inventory.special,
character.inventory.boosts,
character.inventory.style,
character.inventory.misc,
character.equipment.Sickle,
character.equipment.Axe,
character.equipment.Pick
Expand Down Expand Up @@ -70,7 +75,7 @@ export const characters = {
}
},
{
targets: [4,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],
targets: [4,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40],
visible: false
}
]
Expand Down

3 comments on commit f68069a

@mrbigmouth
Copy link
Collaborator

@mrbigmouth mrbigmouth commented on f68069a Jan 5, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrbigmouth
Copy link
Collaborator

@mrbigmouth mrbigmouth commented on f68069a Jan 9, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrbigmouth
Copy link
Collaborator

@mrbigmouth mrbigmouth commented on f68069a Jan 11, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.