removes obsolete AppStorage.js
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<PlayerView
|
||||
:id="state.player_id"
|
||||
:id="player_id"
|
||||
v-slot="{ player, loot, notifications, actions, claims }"
|
||||
>
|
||||
<main id="app" class="container">
|
||||
<header>
|
||||
<HeaderBar :app_state="state">
|
||||
<HeaderBar>
|
||||
<template v-slot:title>
|
||||
{{ player.name }}
|
||||
</template>
|
||||
@@ -19,7 +19,7 @@
|
||||
</template>
|
||||
<hr class="navbar-divider">
|
||||
<div class="navbar-item heading">Changer</div>
|
||||
<a v-for="(p,i) in state.player_list" :key="i"
|
||||
<a v-for="(p,i) in playerList" :key="i"
|
||||
@click="setActivePlayer(i)"
|
||||
href="#" class="navbar-item">
|
||||
{{ p.name }}</a>
|
||||
@@ -57,14 +57,14 @@
|
||||
<main class="section">
|
||||
<template v-if="isAdding">
|
||||
<Loot v-if="playerIsGroup"
|
||||
:inventory="state.inventory"
|
||||
:inventory="itemsInventory"
|
||||
@addItem="item => pending_loot.push(item)"
|
||||
@confirmAction="addNewLoot"
|
||||
></Loot>
|
||||
<AddingChest
|
||||
:player="player.id"
|
||||
:claims="claims"
|
||||
:items="playerIsGroup ? pending_loot : state.inventory"
|
||||
:items="playerIsGroup ? pending_loot : itemsInShop"
|
||||
:perms="playerIsGroup ? {} : { canBuy: true }"
|
||||
@buy="(data) => { switchView('player'); actions.buyItems(data); }">
|
||||
</AddingChest>
|
||||
@@ -72,7 +72,7 @@
|
||||
<Chest v-else
|
||||
:player="player.id"
|
||||
:claims="claims"
|
||||
:items="showPlayerChest ? loot : state.group_loot"
|
||||
:items="showPlayerChest ? loot : groupLoot"
|
||||
:perms="{
|
||||
canGrab: !(showPlayerChest || playerIsGroup),
|
||||
canSell: showPlayerChest || playerIsGroup
|
||||
@@ -92,7 +92,7 @@ import HeaderBar from './components/HeaderBar.vue'
|
||||
import Wealth from './components/Wealth.vue'
|
||||
import Chest from './components/Chest.vue'
|
||||
import Loot from './components/Loot.vue'
|
||||
import { Api, AppStorage } from './AppStorage'
|
||||
import { api } from './lootalot.js'
|
||||
|
||||
function getCookie(cname) {
|
||||
var name = cname + "=";
|
||||
@@ -114,10 +114,14 @@ export default {
|
||||
name: 'app',
|
||||
data () {
|
||||
return {
|
||||
state: AppStorage.state,
|
||||
player_id: 0,
|
||||
playerList: [],
|
||||
activeView: 'group',
|
||||
shopInventory: [{id: 1, name: "Item from shop #1", base_price: 2000}],
|
||||
groupLoot: [],
|
||||
itemsInventory: [],
|
||||
itemsInShop: [{id: 1, name: "Item from shop #1", base_price: 2000}],
|
||||
pending_loot: [],
|
||||
initiated: false,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
@@ -129,21 +133,26 @@ export default {
|
||||
Loot,
|
||||
},
|
||||
created () {
|
||||
// Initiate with active player set to value found in cookie
|
||||
// or as group by default.
|
||||
const cookie = getCookie("player_id");
|
||||
let playerId;
|
||||
if (cookie == "") {
|
||||
playerId = 0;
|
||||
} else {
|
||||
playerId = Number(cookie);
|
||||
}
|
||||
AppStorage.initStorage(playerId);
|
||||
const cookie = getCookie("player_id");
|
||||
this.player_id = cookie ? Number(cookie) : 0;
|
||||
Promise.all([
|
||||
api.fetch("players/", "GET", null),
|
||||
api.fetch("players/0/loot", "GET", null),
|
||||
api.fetch("items", "GET", null),
|
||||
])
|
||||
.then(([players, loot, items]) => {
|
||||
this.playerList = players.value;
|
||||
this.groupLoot = loot.value;
|
||||
this.itemsInventory = items.value;
|
||||
})
|
||||
.catch(r => alert("Error ! \n" + r))
|
||||
.then(() => this.initiated = true);
|
||||
},
|
||||
methods: {
|
||||
setActivePlayer (idx) {
|
||||
if (idx == 0) this.switchView('group');
|
||||
AppStorage.setActivePlayer(idx);
|
||||
this.player_id = Number(idx)
|
||||
document.cookie = `player_id=${idx};`;
|
||||
},
|
||||
switchView (viewId) {
|
||||
if (!['group', 'player', 'adding'].includes(viewId)) {
|
||||
@@ -151,21 +160,19 @@ export default {
|
||||
}
|
||||
this.activeView = viewId;
|
||||
},
|
||||
switchPlayerChestVisibility () {
|
||||
AppStorage.switchPlayerChestVisibility();
|
||||
},
|
||||
addNewLoot () {
|
||||
Api.newLoot(this.pending_loot)
|
||||
.then(_ => {
|
||||
api.fetch("admin/add-loot", "POST", this.pending_loot)
|
||||
.then(() => {
|
||||
this.pending_loot = []
|
||||
this.switchView('group');
|
||||
});
|
||||
})
|
||||
.catch(r => alert("Error: " + r));
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
showPlayerChest () { return this.activeView == 'player' },
|
||||
isAdding () { return this.activeView == 'adding' },
|
||||
playerIsGroup () { return this.state.player_id == 0 },
|
||||
playerIsGroup () { return this.player_id == 0 },
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user