Compare commits
3 Commits
c483f29096
...
4454bd245c
| Author | SHA1 | Date | |
|---|---|---|---|
| 4454bd245c | |||
| ba1792ef55 | |||
| dc978fc87f |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,2 +1,6 @@
|
|||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
fontawesome
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,7 @@ version = "0.1.0"
|
|||||||
authors = ["Artus <artus@landoftheunicorn.ovh>"]
|
authors = ["Artus <artus@landoftheunicorn.ovh>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"lootalot_db"
|
||||||
|
]
|
||||||
|
|||||||
12
lootalot_db/Cargo.toml
Normal file
12
lootalot_db/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "lootalot-db"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Artus <artus@landoftheunicorn.ovh>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dotenv = "*"
|
||||||
|
|
||||||
|
[dependencies.diesel]
|
||||||
|
version = "1.0"
|
||||||
|
features = ["sqlite"]
|
||||||
BIN
lootalot_db/db.sqlite3
Normal file
BIN
lootalot_db/db.sqlite3
Normal file
Binary file not shown.
5
lootalot_db/diesel.toml
Normal file
5
lootalot_db/diesel.toml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# For documentation on how to configure this file,
|
||||||
|
# see diesel.rs/guides/configuring-diesel-cli
|
||||||
|
|
||||||
|
[print_schema]
|
||||||
|
file = "src/schema.rs"
|
||||||
0
lootalot_db/migrations/.gitkeep
Normal file
0
lootalot_db/migrations/.gitkeep
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
DROP TABLE items;
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE items (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name VARCHAR NOT NULL,
|
||||||
|
base_price INTEGER NOT NULL
|
||||||
|
);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE players;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE players (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name VARCHAR NOT NULL,
|
||||||
|
debt INTEGER DEFAULT 0, -- debt to the group in copper pieces
|
||||||
|
cp INTEGER DEFAULT 0,
|
||||||
|
sp INTEGER DEFAULT 0,
|
||||||
|
gp INTEGER DEFAULT 0,
|
||||||
|
pp INTEGER DEFAULT 0
|
||||||
|
);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE looted;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
CREATE TABLE looted (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
player_id INTEGER NOT NULL,
|
||||||
|
item_id INTEGER NOT NULL,
|
||||||
|
acquired_date DATE DEFAULT NOW,
|
||||||
|
FOREIGN KEY (player_id) REFERENCES players(id),
|
||||||
|
FOREIGN KEY (item_id) REFERENCES items(id)
|
||||||
|
);
|
||||||
52
lootalot_db/src/lib.rs
Normal file
52
lootalot_db/src/lib.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#[macro_use] extern crate diesel;
|
||||||
|
extern crate dotenv;
|
||||||
|
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use dotenv::dotenv;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
pub fn establish_connection() -> Result<SqliteConnection, String> {
|
||||||
|
dotenv().ok();
|
||||||
|
let database_url =
|
||||||
|
env::var("DATABASE_URL")
|
||||||
|
.expect("DATABASE_URL must be set !");
|
||||||
|
SqliteConnection::establish(&database_url)
|
||||||
|
.map_err(|e| format!("Error connecting to {} : {:?}", database_url, e))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod schema;
|
||||||
|
pub mod models;
|
||||||
|
|
||||||
|
pub fn list_players() -> Vec<models::Player> {
|
||||||
|
use schema::players::dsl::*;
|
||||||
|
let conn = establish_connection().unwrap();
|
||||||
|
players
|
||||||
|
.load::<models::Player>(&conn)
|
||||||
|
.expect("Error loading players")
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn with_db<F>(f: F) -> ()
|
||||||
|
where F: Fn(&SqliteConnection) -> (),
|
||||||
|
{
|
||||||
|
let conn = establish_connection().unwrap();
|
||||||
|
conn.test_transaction::<_,diesel::result::Error,_>(|| {
|
||||||
|
f(&conn);
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn database_connection() {
|
||||||
|
use crate::establish_connection;
|
||||||
|
let conn = establish_connection();
|
||||||
|
assert_eq!(conn.is_ok(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
61
lootalot_db/src/models.rs
Normal file
61
lootalot_db/src/models.rs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
use crate::*;
|
||||||
|
use crate::schema::players;
|
||||||
|
|
||||||
|
#[derive(Queryable)]
|
||||||
|
pub struct Player {
|
||||||
|
id: i32,
|
||||||
|
name: String,
|
||||||
|
debt: i32,
|
||||||
|
cp: i32,
|
||||||
|
sp: i32,
|
||||||
|
gp: i32,
|
||||||
|
pp: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable)]
|
||||||
|
#[table_name="players"]
|
||||||
|
pub struct NewPlayer<'a> {
|
||||||
|
name: &'a str,
|
||||||
|
cp: i32,
|
||||||
|
sp: i32,
|
||||||
|
gp: i32,
|
||||||
|
pp: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NewPlayer<'a> {
|
||||||
|
|
||||||
|
fn new(
|
||||||
|
name: &'a str,
|
||||||
|
wealth: Option<(i32,i32,i32,i32)>,
|
||||||
|
) -> Self {
|
||||||
|
let (cp,sp,gp,pp) = wealth.unwrap_or((0,0,0,0));
|
||||||
|
NewPlayer { name, cp, sp, gp, pp }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert(&self) -> Result<(),()> {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::tests;
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_player_only_with_name() {
|
||||||
|
let n = NewPlayer::new("Féfi", None);
|
||||||
|
assert_eq!(n.name, "Féfi");
|
||||||
|
assert_eq!(n.cp, 0);
|
||||||
|
assert_eq!(n.sp, 0);
|
||||||
|
assert_eq!(n.gp, 0);
|
||||||
|
assert_eq!(n.pp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_player_with_wealth() {
|
||||||
|
let initial_wealth = (1, 2, 3, 4);
|
||||||
|
let n = NewPlayer::new("Féfi", Some(initial_wealth));
|
||||||
|
assert_eq!(initial_wealth, (n.cp, n.sp, n.gp, n.pp));
|
||||||
|
}
|
||||||
|
}
|
||||||
37
lootalot_db/src/schema.rs
Normal file
37
lootalot_db/src/schema.rs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
table! {
|
||||||
|
items (id) {
|
||||||
|
id -> Nullable<Integer>,
|
||||||
|
name -> Text,
|
||||||
|
base_price -> Integer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
looted (id) {
|
||||||
|
id -> Nullable<Integer>,
|
||||||
|
player_id -> Integer,
|
||||||
|
item_id -> Integer,
|
||||||
|
acquired_date -> Nullable<Date>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
players (id) {
|
||||||
|
id -> Nullable<Integer>,
|
||||||
|
name -> Text,
|
||||||
|
debt -> Nullable<Integer>,
|
||||||
|
cp -> Nullable<Integer>,
|
||||||
|
sp -> Nullable<Integer>,
|
||||||
|
gp -> Nullable<Integer>,
|
||||||
|
pp -> Nullable<Integer>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
joinable!(looted -> items (item_id));
|
||||||
|
joinable!(looted -> players (player_id));
|
||||||
|
|
||||||
|
allow_tables_to_appear_in_same_query!(
|
||||||
|
items,
|
||||||
|
looted,
|
||||||
|
players,
|
||||||
|
);
|
||||||
21
lootalot_front/.gitignore
vendored
Normal file
21
lootalot_front/.gitignore
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
.DS_Store
|
||||||
|
node_modules
|
||||||
|
/dist
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Log files
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
29
lootalot_front/README.md
Normal file
29
lootalot_front/README.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# lootalot_front
|
||||||
|
|
||||||
|
## Project setup
|
||||||
|
```
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Compiles and hot-reloads for development
|
||||||
|
```
|
||||||
|
npm run serve
|
||||||
|
```
|
||||||
|
|
||||||
|
### Compiles and minifies for production
|
||||||
|
```
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run your tests
|
||||||
|
```
|
||||||
|
npm run test
|
||||||
|
```
|
||||||
|
|
||||||
|
### Lints and fixes files
|
||||||
|
```
|
||||||
|
npm run lint
|
||||||
|
```
|
||||||
|
|
||||||
|
### Customize configuration
|
||||||
|
See [Configuration Reference](https://cli.vuejs.org/config/).
|
||||||
5
lootalot_front/babel.config.js
Normal file
5
lootalot_front/babel.config.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
'@vue/app'
|
||||||
|
]
|
||||||
|
}
|
||||||
11499
lootalot_front/package-lock.json
generated
Normal file
11499
lootalot_front/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
lootalot_front/package.json
Normal file
47
lootalot_front/package.json
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"name": "lootalot_front",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"serve": "vue-cli-service serve",
|
||||||
|
"build": "vue-cli-service build",
|
||||||
|
"lint": "vue-cli-service lint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"bulma": "^0.7.5",
|
||||||
|
"core-js": "^2.6.5",
|
||||||
|
"vue": "^2.6.10"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vue/cli-plugin-babel": "^3.8.0",
|
||||||
|
"@vue/cli-plugin-eslint": "^3.8.0",
|
||||||
|
"@vue/cli-service": "^3.8.0",
|
||||||
|
"babel-eslint": "^10.0.1",
|
||||||
|
"eslint": "^5.16.0",
|
||||||
|
"eslint-plugin-vue": "^5.0.0",
|
||||||
|
"vue-template-compiler": "^2.6.10"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"root": true,
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"plugin:vue/essential",
|
||||||
|
"eslint:recommended"
|
||||||
|
],
|
||||||
|
"rules": {},
|
||||||
|
"parserOptions": {
|
||||||
|
"parser": "babel-eslint"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"postcss": {
|
||||||
|
"plugins": {
|
||||||
|
"autoprefixer": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"> 1%",
|
||||||
|
"last 2 versions"
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
lootalot_front/public/favicon.ico
Normal file
BIN
lootalot_front/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
19
lootalot_front/public/index.html
Normal file
19
lootalot_front/public/index.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||||
|
<title>Loot-a-Lot !</title>
|
||||||
|
<script defer src="fontawesome/js/all.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<!-- built files will be auto injected -->
|
||||||
|
<noscript>
|
||||||
|
<strong>We're sorry but lootalot_front doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||||
|
</noscript>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
47
lootalot_front/src/App.vue
Normal file
47
lootalot_front/src/App.vue
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<template>
|
||||||
|
<main id="app" class="section">
|
||||||
|
<section id="content" class="columns is-desktop">
|
||||||
|
<Player></Player>
|
||||||
|
<div class="column">
|
||||||
|
<section id="main" class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<div id="main-heading" class="columns is-mobile is-vcentered">
|
||||||
|
<div class="column is-narrow">
|
||||||
|
<span class="icon is-large"><i class="fas fa-3x fa-gem"></i></span>
|
||||||
|
</div>
|
||||||
|
<div class="column has-text-left">
|
||||||
|
<h1 class="title">Coffre de groupe</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Chest player_id="0"></Chest>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Player from './components/Player.vue'
|
||||||
|
import Chest from './components/Chest.vue'
|
||||||
|
import 'bulma/css/bulma.css'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'app',
|
||||||
|
components: {
|
||||||
|
Player,
|
||||||
|
Chest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#app {
|
||||||
|
font-family: 'Avenir', Helvetica, Arial, sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
text-align: center;
|
||||||
|
color: #2c3e50;
|
||||||
|
margin-top: 60px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
BIN
lootalot_front/src/assets/logo.png
Normal file
BIN
lootalot_front/src/assets/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
22
lootalot_front/src/components/Chest.vue
Normal file
22
lootalot_front/src/components/Chest.vue
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<table class="table is-fullwidth is-striped">
|
||||||
|
<thead>
|
||||||
|
<tr><th>Objets de {{ player_id }}</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td>Nom 1</td></tr>
|
||||||
|
<tr><td>Nom 2</td></tr>
|
||||||
|
<tr><td>Nom 3</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: ["player_id"],
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
66
lootalot_front/src/components/Player.vue
Normal file
66
lootalot_front/src/components/Player.vue
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<template>
|
||||||
|
<div class="column is-one-third-desktop">
|
||||||
|
<div id="sidebar" class="card">
|
||||||
|
<header id="sidebar-heading" class="card-header">
|
||||||
|
<a id="change_player" class="card-header-icon is-dark">
|
||||||
|
<span class="icon is-small">
|
||||||
|
<i class="fas fa-exchange-alt"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<p id="active_player" class="card-header-title">{{ name }}</p>
|
||||||
|
</header>
|
||||||
|
<div class="card-content">
|
||||||
|
<span class="icon is-large">
|
||||||
|
<i class="fas fa-2x fa-coins"></i>
|
||||||
|
</span>
|
||||||
|
<nav class="level is-mobile">
|
||||||
|
<div class="level-item">
|
||||||
|
<div><p class="heading">CP</p><p class="subtitle">{{ wealth[0] }}</p></div>
|
||||||
|
</div>
|
||||||
|
<div class="level-item">
|
||||||
|
<div><p class="heading">SP</p><p class="subtitle">{{ wealth[1] }}</p></div>
|
||||||
|
</div>
|
||||||
|
<div class="level-item">
|
||||||
|
<div><p class="heading">GP</p><p class="subtitle">{{ wealth[2] }}</p></div>
|
||||||
|
</div>
|
||||||
|
<div class="level-item">
|
||||||
|
<div><p class="heading">PP</p><p class="subtitle">{{ wealth[3] }}</p></div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<footer class="card-footer">
|
||||||
|
<a @click="showChest = !showChest" href="#" class="card-footer-item is-dark">Coffre</a>
|
||||||
|
<a href="#" class="card-footer-item">Argent</a>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
<div class="card" v-show="showChest" style="margin-top: 1em;">
|
||||||
|
<div class="card-content">
|
||||||
|
<Chest player_id="0"></Chest>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Chest from './Chest.vue'
|
||||||
|
/*
|
||||||
|
|
||||||
|
The Player control board.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
components: { Chest },
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
name: "Player name",
|
||||||
|
wealth: [1000,100,10,1],
|
||||||
|
showChest: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
</style>
|
||||||
8
lootalot_front/src/main.js
Normal file
8
lootalot_front/src/main.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import App from './App.vue'
|
||||||
|
|
||||||
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
|
new Vue({
|
||||||
|
render: h => h(App),
|
||||||
|
}).$mount('#app')
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
extern crate lootalot_db;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user