adds a working inventory
This commit is contained in:
2255
lootalot_db/res/items.csv
Normal file
2255
lootalot_db/res/items.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -66,8 +66,10 @@ impl<'q> DbApi<'q> {
|
||||
Ok(schema::players::table.load::<models::Player>(self.0)?)
|
||||
}
|
||||
/// Fetch the inventory of items
|
||||
///
|
||||
/// TODO: remove limit used for debug
|
||||
pub fn fetch_inventory(self) -> QueryResult<Vec<models::Item>> {
|
||||
Ok(schema::items::table.load::<models::Item>(self.0)?)
|
||||
Ok(schema::items::table.limit(100).load::<models::Item>(self.0)?)
|
||||
}
|
||||
/// Fetch all existing claims
|
||||
pub fn fetch_claims(self) -> QueryResult<Vec<models::Claim>> {
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<template v-if="isAdding">
|
||||
<h2 v-show="playerIsGroup">ItemInput</h2>
|
||||
<AddingChest
|
||||
:items="playerIsGroup ? [] : shopInventory"
|
||||
:items="playerIsGroup ? [] : state.inventory"
|
||||
:perms="playerIsGroup ? {} : { canBuy: true }"
|
||||
@buy="(data) => { switchView('player'); actions.buyItems(data); }">
|
||||
</AddingChest>
|
||||
|
||||
@@ -21,6 +21,10 @@ export const Api = {
|
||||
return fetch(API_ENDPOINT("players/all"))
|
||||
.then(r => r.json())
|
||||
},
|
||||
fetchInventory () {
|
||||
return fetch(API_ENDPOINT("items"))
|
||||
.then(r => r.json())
|
||||
},
|
||||
fetchClaims () {
|
||||
return fetch(API_ENDPOINT("claims"))
|
||||
.then(r => r.json())
|
||||
@@ -51,6 +55,7 @@ export const AppStorage = {
|
||||
player_list: {},
|
||||
group_loot: [],
|
||||
player_claims: {},
|
||||
inventory: [],
|
||||
initiated: false,
|
||||
show_player_chest: false,
|
||||
},
|
||||
@@ -63,13 +68,15 @@ export const AppStorage = {
|
||||
.all([
|
||||
Api.fetchPlayerList(),
|
||||
Api.fetchClaims(),
|
||||
Api.fetchInventory(),
|
||||
Api.fetchLoot(0)
|
||||
])
|
||||
.then(data => {
|
||||
const [players, claims, group_loot] = data;
|
||||
const [players, claims, inventory, group_loot] = data;
|
||||
this.__initPlayerList(players);
|
||||
this.__initClaimsStore(claims);
|
||||
Vue.set(this.state, 'group_loot', group_loot);
|
||||
Vue.set(this.state, 'inventory', inventory);
|
||||
})
|
||||
.then(_ => this.state.initiated = true)
|
||||
.catch(e => { alert(e); this.state.initiated = false });
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
<PercentInput v-show="is_selling"></PercentInput>
|
||||
</div>
|
||||
<div v-else-if="perms.canBuy">
|
||||
<button class="button is-danger is-fullwidth" @click="buySelectedItems">Acheter</button>
|
||||
<button class="button is-danger is-fullwidth"
|
||||
:disabled="selected_items.length == 0"
|
||||
@click="buySelectedItems">Acheter</button>
|
||||
</div>
|
||||
<div v-else-if="perms.canGrab">
|
||||
<button class="button is-static is-fullwidth">Demander</button>
|
||||
|
||||
@@ -83,6 +83,9 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
||||
)
|
||||
.service(
|
||||
web::scope("/api")
|
||||
.route("/items", web::get().to_async(move |pool: AppPool| {
|
||||
db_call(pool, move |api| api.fetch_inventory())
|
||||
}))
|
||||
.service(
|
||||
web::scope("/players")
|
||||
.route(
|
||||
|
||||
Reference in New Issue
Block a user