Commit 9824f39c authored by Martin Lehoux's avatar Martin Lehoux

merge

parents 2033262a f9110d24
......@@ -30,7 +30,7 @@ app.use(loginChecker);
// Routes
app.use('/users', usersRouter);
// app.use('/characters', charactersRouter);
app.use('/characters', charactersRouter);
mongoose.connect('mongodb://localhost/rolegame', err => {
if (err) {
......
......@@ -8,9 +8,14 @@ const router = express.Router();
const getScore = (data) => Object.keys(data).reduce((total, el) => total + costTable[data[el]], 0);
router.get('/avatars', (req, res) => {
const avatars = fs.readdirSync('../front/public/img/avatars');
res.json({ avatars });
})
router.get('/', async (req, res) => {
// TODO: Login required
const avatars = fs.readdirSync('media/avatars');
Character.find({ user: req.session.user._id }, (err, characters) => {
if (err) return res.status(400).json({ error: err });
return res.json(characters);
......
.ui.card.fluid
.content
img.right.floated.mini.image.ui(src="/media/avatars/"+character.avatar, alt="Avatar")
.header= character.name
.meta
.date Created on #{character.birthDate.toDateString()}
.ui.tiny.progress.yellow.progress(id="action-points-bar-"+character._id)
.bar
.label
span(id="action-points-value-"+character._id)= character.actionPoints
|&nbspaction points
//- .content
//- .ui.label(class=character.attributes.strength<=8 ? "orange" : character.attributes.strength>=12 ? "green" : "" )
//- | Strength
//- .detail= character.attributes.strength
//- .ui.label(class=character.attributes.constitution<=8 ? "orange" : character.attributes.constitution>=12 ? "green" : "" )
//- | Constitution
//- .detail= character.attributes.constitution
//- .ui.label(class=character.attributes.dexterity<=8 ? "orange" : character.attributes.dexterity>=12 ? "green" : "" )
//- | Dexterity
//- .detail= character.attributes.dexterity
//- .ui.label(class=character.attributes.intelligence<=8 ? "orange" : character.attributes.intelligence>=12 ? "green" : "" )
//- | Intelligence
//- .detail= character.attributes.intelligence
//- .ui.label(class=character.attributes.wisdom<=8 ? "orange" : character.attributes.wisdom>=12 ? "green" : "" )
//- | Wisdom
//- .detail= character.attributes.wisdom
//- .ui.label(class=character.attributes.charisma<=8 ? "orange" : character.attributes.charisma>=12 ? "green" : "" )
//- | Charisma
//- .detail= character.attributes.charisma
script $('#action-points-bar-#{character._id}').progress({ total: #{maxActionPoints}, value: #{character.actionPoints}});
script updateActionPoints('#{character._id}', #{character.actionPoints}, #{maxActionPoints});
......@@ -5,7 +5,7 @@
<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">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.0/semantic.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.0/semantic.min.css">
<title>front</title>
</head>
<body>
......
<template lang="pug">
sui-card(class="fluid")
sui-card-content
sui-image(floated="right", size="mini", :src="`avatars/${character.avatar}`")
sui-card-header {{ character.name }}
sui-card-meta Created on {{ character.birthDate }}
sui-progress(size="tiny", color="yellow", :label="`${character.actionPoints} action points`", :percent="character.actionPoints/480*100")
</template>
<script>
export default {
name: "CharacterItem",
props: ['character'],
data() {
return {
}
}
// TODO: Update action points
}
</script>
<style scoped>
</style>
import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";
import Characters from "./views/Characters.vue";
Vue.use(Router);
......@@ -12,6 +13,11 @@ export default new Router({
path: "/",
name: "home",
component: Home
},
{
path: "/characters",
name: "characters",
component: Characters
}
]
});
<template lang="pug">
div
sui-card-group
CharacterItem(v-for="character in characters", :key="character._id", :character="character")
sui-container(text-align="center")
sui-button(color="teal", basic, icon="add", @click="creationModal=true") Create character
sui-modal(v-model="creationModal")
sui-modal-header Create a new character
sui-modal-content(image)
sui-image(size="medium", :src="`avatars/${newCharacter.avatar}`")
sui-modal-description
sui-form(@submit.prevent="")
sui-header Details
sui-form-fields
sui-form-field
sui-input(type="text", v-model="newCharacter.name", placeholder="name")
sui-form-field
sui-dropdown(placeholder="Avatar", selection, :options="avatars", v-model="newCharacter.avatar")
sui-header Attributes: {{ availablePoints }} points remaning
sui-grid
sui-grid-column(:width="8", v-for="attribute in attributes" :key="attribute")
sui-segment
sui-statistic(horizontal)
sui-statistic-value {{ newCharacter.attributes[attribute] }}
sui-statistic-label {{ attribute }}
sui-button(color="orange", circular, floated="left", icon="minus")
sui-button(color="teal", circular, floated="right", icon="add")
sui-progress(attached, bottom, :percent="newCharacter.attributes[attribute]/20*100")
sui-modal-actions
sui-button(color="orange", basic, icon="close", @click="creationModal=false") Cancel
sui-button(color="grey", basic, icon="redo", @click="resetCharacter") Reset
sui-button(color="teal", basic, icon="check") Create
</template>
<script>
import http from "@/http";
import CharacterItem from "@/components/CharacterItem.vue";
export default {
name: "Characters",
components: {
CharacterItem
},
data() {
return {
characters: [{
_id: "13F3V34GBB",
avatar: "boris_by_charro_art_d8eta2f-pre.jpg",
name: "Kagamino",
birthDate: "01-01-1998",
actionPoints: 400
}],
creationModal: false,
newCharacter: { attributes: { } },
avatars: [],
attributes: ['strength', 'constitution', 'dexterity', 'intelligence', 'wisdom', 'charisma'],
availablePoints: 15
}
},
created() {
this.attributes.forEach(attribute => {
this.newCharacter.attributes[attribute] = 10
});
http()
.get('http://localhost:3000/characters/avatars')
.then(res => this.avatars = res.data.avatars.map(avatar => ({ text: avatar, value: avatar })))
},
methods: {
resetCharacter() {
this.characters = { attributes: { } };
this.attributes.forEach(attribute => {
this.newCharacter.attributes[attribute] = 10
});
}
}
}
</script>
<style scoped>
</style>
<template lang="pug">
.home
sui-image(src="img/wallpaper.jpg")
sui-image(src="img/wallpaper.jpg")
</template>
<script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment