Added character list. Fixed TempHP
This commit is contained in:
@@ -164,7 +164,7 @@ Schemas.Character = new SimpleSchema({
|
||||
deathSave: { type: Schemas.DeathSave },
|
||||
|
||||
//permissions
|
||||
owner: { type: String, regEx: SimpleSchema.RegEx.Id, optional: true },
|
||||
owner: { type: String, regEx: SimpleSchema.RegEx.Id },
|
||||
readers: { type: [String], regEx: SimpleSchema.RegEx.Id, defaultValue: [] },
|
||||
writers: { type: [String], regEx: SimpleSchema.RegEx.Id, defaultValue: [] },
|
||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"},
|
||||
|
||||
35
rpg-docs/Model/Character/TemporaryHitPoints.js
Normal file
35
rpg-docs/Model/Character/TemporaryHitPoints.js
Normal file
@@ -0,0 +1,35 @@
|
||||
TemporaryHitPoints = new Meteor.Collection("temporaryHitPoints");
|
||||
|
||||
Schemas.TemporaryHitPoints = new SimpleSchema({
|
||||
charId: {type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
maximum: {type: Number, defaultValue: 0},
|
||||
used: {type: Number, defaultValue: 0},
|
||||
deleteOnZero:{type: Boolean, defaultValue: true},
|
||||
dateAdded: {
|
||||
type: Date,
|
||||
autoValue: function() {
|
||||
if (this.isInsert) {
|
||||
return new Date;
|
||||
} else if (this.isUpsert) {
|
||||
return {$setOnInsert: new Date};
|
||||
} else {
|
||||
this.unset();
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
TemporaryHitPoints.attachSchema(Schemas.TemporaryHitPoints);
|
||||
|
||||
TemporaryHitPoints.helpers({
|
||||
left: function(){
|
||||
return this.maximum - this.used;
|
||||
}
|
||||
});
|
||||
|
||||
//remove the temporary hit points when they hit zero
|
||||
TemporaryHitPoints.after.update(function (userId, thp, fieldNames, modifier, options) {
|
||||
if(thp.used >= thp.maximum && thp.deleteOnZero){
|
||||
TemporaryHitPoints.remove(thp._id);
|
||||
}
|
||||
}, {fetchPrevious: false});
|
||||
@@ -4,6 +4,7 @@ Router.configure({
|
||||
});
|
||||
|
||||
Router.map( function () {
|
||||
/*
|
||||
this.route('home',
|
||||
{
|
||||
path: '/',
|
||||
@@ -15,6 +16,19 @@ Router.map( function () {
|
||||
return Characters.find({}, {fields: {_id: 1}});
|
||||
}
|
||||
}
|
||||
});*/ //add a home route and change characterList route
|
||||
|
||||
this.route('characterList',
|
||||
{
|
||||
path: '/',
|
||||
waitOn: function(){
|
||||
return Meteor.subscribe("characterList", Meteor.userId());
|
||||
},
|
||||
data: {
|
||||
characters: function(){
|
||||
return Characters.find({}, {fields: {_id: 1}});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.route('characterSheet', {
|
||||
@@ -22,7 +36,7 @@ Router.map( function () {
|
||||
waitOn: function(){
|
||||
return [
|
||||
Meteor.subscribe("singleCharacter", this.params._id, Meteor.userId()),
|
||||
];
|
||||
];
|
||||
},
|
||||
data: function() {
|
||||
var data = Characters.findOne({_id: this.params._id}, {fields: {_id: 1, name: 1, color: 1}});
|
||||
@@ -48,7 +62,7 @@ Router.map( function () {
|
||||
return data;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.route('loading', {
|
||||
path: '/loading'
|
||||
});
|
||||
|
||||
@@ -106,3 +106,9 @@ html /deep/ .white-text{
|
||||
color: #444;
|
||||
color: rgba(0,0,0,0.54);
|
||||
}
|
||||
|
||||
.white54 {
|
||||
color: #eee;
|
||||
color: rgba(255,255,255,0.54)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<template name="healthCard">
|
||||
<paper-shadow class="card container healthCard" hero-id="main" {{detailHero}} layout horizontal wrap>
|
||||
<div class="green white-text subhead padded leftRound" layout horizontal center>
|
||||
<div class="green white-text subhead padded leftRound" layout vertical center-justified>
|
||||
Hit Points
|
||||
<paper-icon-button class="white54" id="addTempHP" icon="add"></paper-icon-button>
|
||||
</div>
|
||||
<div class="padded" flex layout vertical center-justified style="min-width: 180px;">
|
||||
<paper-slider id="hitPointSlider"
|
||||
@@ -10,7 +11,14 @@
|
||||
editable pin
|
||||
role="slider"
|
||||
></paper-slider>
|
||||
<!--Temp hitpoints go here-->
|
||||
{{#each tempHitPoints}}
|
||||
<paper-slider class="tempHitPointSlider"
|
||||
value={{left}}
|
||||
max={{maximum}}
|
||||
editable pin
|
||||
role="slider"
|
||||
></paper-slider>
|
||||
{{/each}}
|
||||
<div class="caption">
|
||||
{{#if multipliers.immunities.length}} <div>Immune: {{#each multipliers.immunities}} {{name}} {{/each}}</div>{{/if}}
|
||||
{{#if multipliers.resistances.length}}<div>Resistance: {{#each multipliers.resistances}} {{name}} {{/each}}</div>{{/if}}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
Template.healthCard.helpers({
|
||||
tempHitPoints: function(){
|
||||
return TemporaryHitPoints.find({charId: this._id});
|
||||
},
|
||||
showDeathSave: function(){
|
||||
return this.attributeValue("hitPoints") <= 0;
|
||||
},
|
||||
@@ -55,6 +58,15 @@ Template.healthCard.events({
|
||||
var adjustment = value - this.attributeBase("hitPoints");
|
||||
Characters.update(this._id, {$set: {"hitPoints.adjustment": adjustment}});
|
||||
},
|
||||
"change .tempHitPointSlider": function(event){
|
||||
var value = event.currentTarget.value;
|
||||
var used = this.maximum - value;
|
||||
TemporaryHitPoints.update(this._id, {$set: {"used": used}});
|
||||
},
|
||||
"tap #addTempHP": function(event){
|
||||
var max = prompt("Add temporary hitpoints", "10");
|
||||
TemporaryHitPoints.insert({charId: this._id, maximum: max, used: 0});
|
||||
},
|
||||
"tap .failBubble": function(event){
|
||||
if(event.currentTarget.disabled) return;
|
||||
var char = Template.parentData();
|
||||
|
||||
8
rpg-docs/client/views/characterList/characterList.css
Normal file
8
rpg-docs/client/views/characterList/characterList.css
Normal file
@@ -0,0 +1,8 @@
|
||||
.characterCards {
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.characterCard{
|
||||
width: 272px;
|
||||
margin: 4px;
|
||||
}
|
||||
27
rpg-docs/client/views/characterList/characterList.html
Normal file
27
rpg-docs/client/views/characterList/characterList.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<template name="characterList">
|
||||
<core-toolbar class="blue-grey white-text">
|
||||
<core-icon-button icon="menu" core-drawer-toggle></core-icon-button>
|
||||
<div flex>
|
||||
Characters
|
||||
</div>
|
||||
</core-toolbar>
|
||||
<div class="scroll-y" fit>
|
||||
<div layout horizontal class="characterCards">
|
||||
{{# each characters}}
|
||||
{{#with characterDetails}}
|
||||
{{#containerCardHelper this}}{{alignment}} {{gender}} {{race}}{{/containerCardHelper}}
|
||||
{{/with}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{> gridPadding class="characterCard" num=12}}
|
||||
<div class="fab-buffer"></div>
|
||||
<paper-fab id="addCharacter"
|
||||
class="floatyButton"
|
||||
icon="add"
|
||||
title="Add"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
aria-label="Add"
|
||||
hero-id="main"></paper-fab>
|
||||
</div>
|
||||
</template>
|
||||
23
rpg-docs/client/views/characterList/characterList.js
Normal file
23
rpg-docs/client/views/characterList/characterList.js
Normal file
@@ -0,0 +1,23 @@
|
||||
Template.characterList.helpers({
|
||||
characterDetails: function(){
|
||||
var char = Characters.findOne(this._id, {fields: {name: 1, gender: 1, alignment: 1, race:1, color: 1}})
|
||||
char.title = char.name;
|
||||
char.field = "base"
|
||||
char.class = "characterCard"
|
||||
return char;
|
||||
}
|
||||
});
|
||||
|
||||
Template.characterList.events({
|
||||
"tap .characterCard": function(event, instance){
|
||||
console.log(this);
|
||||
Router.go("characterSheet", {_id: this._id});
|
||||
},
|
||||
"tap #addCharacter": function (event, template) {
|
||||
Characters.insert({owner: Meteor.userId()});
|
||||
},
|
||||
"tap #deleteChar": function(event, template){
|
||||
console.log("deleting", this);
|
||||
Characters.remove(this._id);
|
||||
}
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
Meteor.publish("characterList",function(userId){
|
||||
//TODO also return characters this user can view
|
||||
return Characters.find();
|
||||
if(!userId) return;
|
||||
return Characters.find({$or: [ {readers: userId}, {writers: userId}, {owner: userId} ] });
|
||||
});
|
||||
|
||||
@@ -14,5 +14,6 @@ Meteor.publish("singleCharacter", function(characterId, userId){
|
||||
Notes.find({charId: characterId}),
|
||||
Spells.find({charId: characterId}),
|
||||
SpellLists.find({charId: characterId}),
|
||||
TemporaryHitPoints.find({charId: characterId}),
|
||||
];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user