basic impl of players list and loot api in frontend
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<main id="app" class="section">
|
||||
<section id="content" class="columns is-desktop">
|
||||
<Player></Player>
|
||||
<Player v-if="fullyLoaded"></Player>
|
||||
<div class="column">
|
||||
<Chest :player="0"></Chest>
|
||||
<Chest :player="0" v-if="fullyLoaded"></Chest>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
@@ -32,11 +32,14 @@ function getCookie(cname) {
|
||||
|
||||
export default {
|
||||
name: 'app',
|
||||
data () { return {
|
||||
fullyLoaded: false,
|
||||
};},
|
||||
components: {
|
||||
Player,
|
||||
Chest
|
||||
},
|
||||
beforeCreate () {
|
||||
created () {
|
||||
const cookie = getCookie("player_id");
|
||||
let playerId;
|
||||
if (cookie == "") {
|
||||
@@ -44,9 +47,9 @@ export default {
|
||||
} else {
|
||||
playerId = Number(cookie);
|
||||
}
|
||||
AppStorage.initStorage(playerId);
|
||||
return;
|
||||
}
|
||||
AppStorage.initStorage(playerId)
|
||||
.then(_ => this.fullyLoaded = true);
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -6,14 +6,9 @@ const PLAYER_LIST = [
|
||||
{id: 3, name: "Fefi", wealth: [0,0,0,0], debt: 0},
|
||||
];
|
||||
|
||||
const fetchPlayerList = function () {
|
||||
fetch("http://localhost:8088/players")
|
||||
const __fetchPlayerList = function() {
|
||||
return fetch("http://localhost:8088/players")
|
||||
.then(r => r.json())
|
||||
.then(r => console.log(r));
|
||||
};
|
||||
|
||||
const fetchRequests = function () {
|
||||
|
||||
};
|
||||
|
||||
export const AppStorage = {
|
||||
@@ -27,12 +22,23 @@ export const AppStorage = {
|
||||
// Initiate the state
|
||||
initStorage (playerId) {
|
||||
if (this.debug) console.log('Initiate with player : ', playerId)
|
||||
fetchPlayerList();
|
||||
this.state.player_id = playerId;
|
||||
for (var idx in PLAYER_LIST) {
|
||||
var player = PLAYER_LIST[idx];
|
||||
this.state.player_list.push(player);
|
||||
this.state.requests[player.id] = [];
|
||||
return Promise.all([
|
||||
fetch("http://localhost:8088/players")
|
||||
.then(r => r.json()),
|
||||
])
|
||||
.then(data => {
|
||||
console.log("initiate ", data);
|
||||
this.initPlayerList(data[0]);
|
||||
})
|
||||
.catch(e => console.log("Fetch error ", e));
|
||||
|
||||
},
|
||||
initPlayerList(data) {
|
||||
for (var idx in data) {
|
||||
var p = data[idx];
|
||||
this.state.player_list.push(p);
|
||||
this.state.requests[p.id] = [5,];
|
||||
}
|
||||
},
|
||||
// Player actions
|
||||
|
||||
@@ -118,17 +118,22 @@
|
||||
data () {
|
||||
return {
|
||||
app_state: AppStorage.state,
|
||||
content: [
|
||||
{id: 10, name: "Épée longue +2 acérée",
|
||||
sell_value: 15000 },
|
||||
{id: 5, name: "Ceinture de force +6",
|
||||
sell_value: 80000 },
|
||||
],
|
||||
content: [],
|
||||
is_selling: false,
|
||||
is_adding: false,
|
||||
sell_selected: [],
|
||||
};
|
||||
},
|
||||
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: {
|
||||
// Can the active user sell items from this chest ?
|
||||
canSell () {
|
||||
@@ -158,6 +163,9 @@
|
||||
&& !this.is_adding);
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.fetchLoot();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="column is-one-third-desktop">
|
||||
<div id="sidebar" class="card">
|
||||
<header id="sidebar-heading" class="card-header">
|
||||
<p class="card-header-title">{{ name }}</p>
|
||||
<p class="card-header-title">{{ player.name }}</p>
|
||||
<div class="dropdown is-right"
|
||||
:class="{ 'is-active': show_dropdown }">
|
||||
<div class="dropdown-trigger" ref="dropdown_btn">
|
||||
@@ -26,7 +26,7 @@
|
||||
</div>
|
||||
</header>
|
||||
<div class="card-content">
|
||||
<Wealth :wealth="player.wealth"
|
||||
<Wealth :wealth="wealth"
|
||||
:edit="edit_wealth"
|
||||
@updated="edit_wealth = !edit_wealth">
|
||||
</Wealth>
|
||||
@@ -86,8 +86,8 @@
|
||||
const idx = this.state.player_list.findIndex(p => p.id == id);
|
||||
return this.state.player_list[idx];
|
||||
},
|
||||
name () {
|
||||
return this.player.name;
|
||||
wealth () {
|
||||
return [this.player.cp, this.player.sp, this.player.gp, this.player.pp];
|
||||
},
|
||||
// Check if the active player is the special 'Group' player
|
||||
playerIsGroup () {
|
||||
|
||||
Reference in New Issue
Block a user