finish add/buy in frontend

This commit is contained in:
2019-10-03 12:37:22 +02:00
parent 2e7afa9bb0
commit 60b489e8fd
6 changed files with 50 additions and 42 deletions

View File

@@ -31,7 +31,7 @@ export const Api = {
},
fetchLoot (playerId) {
return fetch(API_ENDPOINT("players/loot/" + playerId))
.then(r => r.json())
.then(r => r.json())
},
putClaim (player_id, item_id) {
const payload = { player_id, item_id };
@@ -117,12 +117,6 @@ export const AppStorage = {
switchPlayerChestVisibility () {
if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest)
this.state.show_player_chest = !this.state.show_player_chest
},
// TODO
// get the content of a player Chest, retrieve form cache or fetched
// will replace hack that loads *all* chest...
getPlayerLoot (playerId) {
},
updatePlayerWealth (goldValue) {
return Api.updateWealth(this.state.player_id, goldValue)
@@ -147,25 +141,23 @@ export const AppStorage = {
},
buyItems (items) {
return Api.buyItems(this.state.player_id, items)
.then(diff => this.__updatePlayerWealth(diff))
.then(() => {
// Add items to the player loot
console.log(items);
});
.then(([items, diff]) => {
this.__updatePlayerWealth(diff)
// Add items to the player loot
// TODO: needs refactoring because player mutation happens in
// 2 different places
return items;
});
},
sellItems (items) {
return Api.sellItems(this.state.player_id, items)
.then(diff => this.__updatePlayerWealth(diff))
.then(() => {
// Remove items from player chest
console.log(items);
});
},
// Withdraws a claim.
cancelRequest(itemId) {
const playerId = this.state.player_id
return Api.unClaim(playerId, itemId)
.then(done => {
.then(_ => {
var idx = this.state.player_claims[playerId].indexOf(itemId);
if (idx > -1) {
this.state.player_claims[playerId].splice(idx, 1);

View File

@@ -103,10 +103,10 @@
this.is_selling = false;
if (this.selected_items.length > 0) {
const items = this.items.filter(i => this.selected_items.includes(i.id));
var payload = [];
items.forEach(item => {
payload.push([item.id, null]);
});
var payload = [];
items.forEach(item => {
payload.push([item.id, null]);
});
this.$emit("sell", payload);
this.selected_items = [];
}

View File

@@ -23,11 +23,20 @@ export default {
},
buyItems(items) {
AppStorage.buyItems(items)
.then(_ => this.notifications.push(`Bought ${items.length} items`))
.then((items) => {
this.notifications.push(`Bought ${items.length} items`)
this.loot = this.loot.concat(items);
})
},
sellItems (items) {
AppStorage.sellItems(items)
.then(_ => this.notifications.push(`Sold ${items.length} items`))
.then(_ => {
this.notifications.push(`Sold ${items.length} items`)
for (var idx in items) {
var to_remove = items[idx][0];
this.loot = this.loot.filter((item) => item.id != to_remove);
}
})
},
parseLoot (items) {
this.loot = [];

View File

@@ -56,8 +56,8 @@
props: ["wealth", "debt"],
data () {
return {
editing: false,
edit_value: 0,
editing: false,
edit_value: 0,
};
},
methods: {
@@ -66,8 +66,8 @@
this.resetValues();
},
resetValues () {
this.editing = false;
this.edit_value = 0;
this.editing = false;
this.edit_value = 0;
}
},
computed: {