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