74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
import { Api, AppStorage } from '../AppStorage'
|
|
|
|
export default {
|
|
props: ["id"],
|
|
data () { return {
|
|
notifications: [],
|
|
loot: [],
|
|
}},
|
|
methods: {
|
|
updateWealth (value) {
|
|
AppStorage.updatePlayerWealth(value)
|
|
.then(_ => {if (AppStorage.debug) this.notifications.push("Wealth updated")})
|
|
.catch(e => {if (AppStorage.debug) console.error("wealthUpdate Error", e)})
|
|
},
|
|
putClaim (itemId) {
|
|
AppStorage.putRequest(itemId)
|
|
.then(_ => { if (AppStorage.debug) this.notifications.push("Claim put")})
|
|
},
|
|
withdrawClaim (itemId) {
|
|
AppStorage.cancelRequest(itemId)
|
|
.then(_ => { if (AppStorage.debug) this.notifications.push("Claim withdrawn")})
|
|
|
|
},
|
|
buyItems(items) {
|
|
AppStorage.buyItems(items)
|
|
.then(_ => this.notifications.push(`Bought ${items.length} items`))
|
|
},
|
|
sellItems (items) {
|
|
AppStorage.sellItems(items)
|
|
.then(_ => this.notifications.push(`Sold ${items.length} items`))
|
|
},
|
|
parseLoot (items) {
|
|
this.loot = [];
|
|
items.map(item => {
|
|
this.loot.push(item);
|
|
});
|
|
}
|
|
},
|
|
watch: {
|
|
id: {
|
|
immediate: true,
|
|
handler: function(newId) {
|
|
Api.fetchLoot(newId).then(this.parseLoot);
|
|
}
|
|
},
|
|
},
|
|
computed: {
|
|
player () {
|
|
if (!AppStorage.state.initiated) {
|
|
return { name: "Loading",
|
|
id: 0,
|
|
cp: '-', sp: '-', gp: '-', pp: '-',
|
|
debt: 0 };
|
|
} else {
|
|
return AppStorage.state.player_list[this.id];
|
|
}
|
|
},
|
|
},
|
|
render () {
|
|
return this.$scopedSlots.default({
|
|
player: this.player,
|
|
loot: this.loot,
|
|
notifications: this.notifications,
|
|
actions: {
|
|
updateWealth: this.updateWealth,
|
|
putClaim: this.putClaim,
|
|
withdrawClaim: this.withdrawClaim,
|
|
buyItems: this.buyItems,
|
|
sellItems: this.sellItems,
|
|
}
|
|
})
|
|
}
|
|
}
|