updates frontend to use DB api

This commit is contained in:
2019-07-04 14:53:50 +02:00
parent 4e28eb4159
commit 503ebf7b6b
5 changed files with 103 additions and 61 deletions

View File

@@ -72,7 +72,7 @@
id="`item-${idx}`"
:value="item.id"
v-model="sell_selected">
{{item.sell_value}} GP
{{item.base_price / 2}} GP
</label>
</div>
<PercentInput></PercentInput>
@@ -118,7 +118,6 @@
data () {
return {
app_state: AppStorage.state,
content: [],
is_selling: false,
is_adding: false,
sell_selected: [],
@@ -126,27 +125,25 @@
},
methods: {
fetchLoot () {
fetch(`http://localhost:8088/loot/${this.player}`)
.then(r => r.json())
.then(data => {
data.forEach(item => this.content.push(item));
})
.then(_ => console.log("Loot loaded !"))
}
},
computed: {
content () {
const playerId = this.player;
console.log("Refresh chest of", playerId);
return this.app_state.player_loot[playerId];
},
// Can the active user sell items from this chest ?
canSell () {
return this.player == this.app_state.player_id;
},
totalSellValue () {
const selected = this.sell_selected;
var value = this.content
return this.content
.filter(item => selected.includes(item.id))
.map(item => item.sell_value)
.map(item => item.base_price / 2)
.reduce((total,value) => total + value, 0);
return value;
},
// Can the user grab items from this chest ?
canGrab () {
@@ -163,9 +160,6 @@
&& !this.is_adding);
}
},
mounted () {
this.fetchLoot();
}
}
</script>

View File

@@ -82,8 +82,7 @@
},
computed: {
player () {
const id = this.state.player_id;
const idx = this.state.player_list.findIndex(p => p.id == id);
const idx = this.state.player_id;
return this.state.player_list[idx];
},
wealth () {
@@ -104,10 +103,9 @@
}
},
setActivePlayer (playerIdx) {
const newId = this.state.player_list[playerIdx].id;
AppStorage.setActivePlayer(newId);
if (newId == 0) { this.hidePlayerChest() }
this.player.name = this.state.player_list[playerIdx].name
var playerIdx = Number(playerIdx);
AppStorage.setActivePlayer(playerIdx);
if (playerIdx == 0) { this.hidePlayerChest() }
},
closeDropdown () {
this.show_dropdown = false

View File

@@ -35,7 +35,6 @@
data () {
return {
state: AppStorage.state,
_requested: false, // Dummy state
};
},
computed: {