Conditions are now separate from buffs, like in #109

This commit is contained in:
Jacob
2017-09-04 19:25:05 +01:00
parent b3d0db1f02
commit 6dd92586a4
12 changed files with 118 additions and 52 deletions

View File

@@ -0,0 +1,42 @@
Conditions = new Mongo.Collection("conditions");
Schemas.Conditions = new SimpleSchema({
charId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
index: 1,
},
name: {
type: String,
optional: true,
trim: false,
},
description: {
type: String,
optional: true,
trim: false,
},
"lifeTime.total": {
type: Number,
defaultValue: 0, //0 is infinite
min: 0,
},
"lifeTime.spent": {
type: Number,
defaultValue: 0,
min: 0,
},
color: {
type: String,
allowedValues: _.pluck(colorOptions, "key"),
defaultValue: "q",
},
});
Conditions.attachSchema(Schemas.Conditions);
Conditions.attachBehaviour("softRemovable");
makeParent(Conditions, ["name"]); //parents of effects, attacks, proficiencies
Conditions.allow(CHARACTER_SUBSCHEMA_ALLOW);
Conditions.deny(CHARACTER_SUBSCHEMA_DENY);

View File

@@ -0,0 +1,7 @@
<template name="conditionView">
<div class="item conditionView layout horizontal center">
<div class="flex">
{{condition.name}}
</div>
</div>
</template>

View File

@@ -0,0 +1,11 @@
Template.conditionView.events({
"click .conditionView": function(event){
var condition = this.condition;
var charId = Template.parentData()._id;
pushDialogStack({
template: "conditionViewDialog",
data: {condition: condition},
element: event.currentTarget,
});
},
});

View File

@@ -0,0 +1,14 @@
<template name="conditionViewDialog">
{{#baseDialog title=condition.name class="white" hideColor=true startEditing=true editOnly=true}}}
{{> conditionDetails condition=condition}}
{{else}}
{{> conditionDetails condition=condition}}
{{/baseDialog}}
</template>
<template name="conditionDetails">
{{#if condition.description}}
<div>{{#markdown}}{{evaluateString condition.charId condition.description}}{{/markdown}}</div>
{{/if}}
{{> effectsViewList charId=condition.charId parentId=condition._id}}
</template>

View File

@@ -0,0 +1,6 @@
Template.conditionViewDialog.events({
"click #deleteButton": function(event, instance){
Conditions.remove(instance.data.condition._id);
popDialogStack();
},
});

View File

@@ -1,31 +1,29 @@
<template name="customBuffEdit"> <template name="customBuffEdit">
{{#with buff}} {{#baseEditDialog title=buff.name hideColor=true}}
{{#baseEditDialog title=name hideColor=true}} <!--name-->
<!--name--> <paper-input id="buffNameInput" class="fullwidth" label="Name" value={{buff.name}}></paper-input>
<paper-input id="buffNameInput" class="fullwidth" label="Name" value={{name}}></paper-input>
<div class="layout horizontal center wrap justified"> <div class="layout horizontal center wrap justified">
<paper-dropdown-menu class=flex label="Target" style="flex-basis: 150px; max-width: 200px;"> <paper-dropdown-menu class=flex label="Target" style="flex-basis: 150px; max-width: 200px;">
<dicecloud-selector selected={{target}} class="dropdown-content target-dropdown"> <dicecloud-selector selected={{buff.target}} class="dropdown-content target-dropdown">
<paper-item name="self" style="width: 150px;"> <paper-item name="self" style="width: 150px;">
Self only Self only
</paper-item> </paper-item>
<paper-item name="others"> <paper-item name="others">
Others only Others only
</paper-item> </paper-item>
<paper-item name="both"> <paper-item name="both">
Both Both
</paper-item> </paper-item>
</dicecloud-selector> </dicecloud-selector>
</paper-dropdown-menu> </paper-dropdown-menu>
</div> </div>
<!--description--> <!--description-->
<paper-textarea label="Description" id="buffDescriptionInput" value={{description}}></paper-textarea> <paper-textarea label="Description" id="buffDescriptionInput" value={{buff.description}}></paper-textarea>
{{> effectsEditList parentId=_id parentCollection="Buffs" charId=charId name=name enabled=false}} {{> effectsEditList parentId=buff._id parentCollection="CustomBuffs" charId=buff.charId name=name enabled=false}}
{{> attackEditList parentId=_id parentCollection="Buffs" charId=charId name=name enabled=false}} {{> attackEditList parentId=buff._id parentCollection="CustomBuffs" charId=buff.charId name=name enabled=false}}
{{> proficiencyEditList parentId=_id parentCollection="Buffs" charId=charId enabled=false}} {{> proficiencyEditList parentId=buff._id parentCollection="CustomBuffs" charId=buff.charId enabled=false}}
{{/baseEditDialog}} {{/baseEditDialog}}
{{/with}}
</template> </template>

View File

@@ -1,9 +1,3 @@
Template.customBuffEdit.helpers({
buff: function(){
return CustomBuffs.findOne(this.buffId);
},
});
const debounce = (f) => _.debounce(f, 300); const debounce = (f) => _.debounce(f, 300);
Template.customBuffEdit.events({ Template.customBuffEdit.events({
@@ -15,7 +9,7 @@ Template.customBuffEdit.events({
input.errorMessage = "Name is required"; input.errorMessage = "Name is required";
} else { } else {
input.invalid = false; input.invalid = false;
CustomBuffs.update(this._id, { CustomBuffs.update(this.buff._id, {
$set: {name: name} $set: {name: name}
}, { }, {
removeEmptyStrings: false, removeEmptyStrings: false,
@@ -25,7 +19,7 @@ Template.customBuffEdit.events({
}), }),
"input #buffDescriptionInput": debounce(function(event){ "input #buffDescriptionInput": debounce(function(event){
var description = event.currentTarget.value; var description = event.currentTarget.value;
CustomBuffs.update(this._id, { CustomBuffs.update(this.buff._id, {
$set: {description: description} $set: {description: description}
}, { }, {
removeEmptyStrings: false, removeEmptyStrings: false,
@@ -35,7 +29,7 @@ Template.customBuffEdit.events({
"iron-select .target-dropdown": function(event){ "iron-select .target-dropdown": function(event){
var detail = event.originalEvent.detail; var detail = event.originalEvent.detail;
var value = detail.item.getAttribute("name"); var value = detail.item.getAttribute("name");
if (value === this.target) return; if (value === this.buff.target) return;
CustomBuffs.update(this._id, {$set: {target: value}}); CustomBuffs.update(this.buff._id, {$set: {target: value}});
}, },
}); });

View File

@@ -34,7 +34,7 @@ Template.customBuffEditListItem.events({
"tap .edit-buff": function(event, template){ "tap .edit-buff": function(event, template){
pushDialogStack({ pushDialogStack({
template: "customBuffEdit", template: "customBuffEdit",
data: {id: this.buff._id}, data: {buff: this.buff},
element: event.currentTarget.parentElement.parentElement, element: event.currentTarget.parentElement.parentElement,
}); });
}, },

View File

@@ -54,7 +54,7 @@
<div flex class="bottom list"> <div flex class="bottom list">
<div class="conditionsList"> <div class="conditionsList">
{{#each condition in conditions}} {{#each condition in conditions}}
{{>buffListItem buff=condition}} {{>conditionView condition=condition}}
{{/each}} {{/each}}
</div> </div>
{{#if buffs.count}} {{#if buffs.count}}

View File

@@ -1,15 +1,10 @@
Template.stats.helpers({ Template.stats.helpers({
conditions: function(){ conditions: function() {
var selector = { return Conditions.find({charId: this._id});
"charId": this._id,
"type": "inate",
};
return Buffs.find(selector);
}, },
buffs: function(){ buffs: function() {
var selector = { var selector = {
"charId": this._id, "charId": this._id,
"type": "custom",
}; };
return Buffs.find(selector); return Buffs.find(selector);
}, },

View File

@@ -28,21 +28,19 @@ Meteor.methods({
var buff = _.extend( var buff = _.extend(
{ {
charId: charId, charId: charId,
type: "inate",
appliedBy: charId,
}, },
condition.buff condition.buff
); );
//make sure the character doesn't already have the buff //make sure the character doesn't already have the buff
var existingBuffs = Buffs.find(_.clone(buff)).count(); var existingBuffs = Conditions.find(_.clone(buff)).count();
if (existingBuffs) return; if (existingBuffs) return;
//remove exclusive conditions //remove exclusive conditions
_.each(condition.exclusiveConditions, function(exCond) { _.each(condition.exclusiveConditions, function(exCond) {
Meteor.call("removeCondition", charId, exCond); Meteor.call("removeCondition", charId, exCond);
}); });
//insert the buff //insert the buff
var buffId = Buffs.insert(buff); var buffId = Conditions.insert(buff);
//extend and insert each effect //extend and insert each effect
_.each(condition.effects, function(effect) { _.each(condition.effects, function(effect) {
var newEffect = { var newEffect = {
@@ -53,7 +51,7 @@ Meteor.methods({
charId: charId, charId: charId,
parent: { parent: {
id: buffId, id: buffId,
collection: "Buffs", collection: "Conditions",
}, },
enabled: true, enabled: true,
}; };
@@ -81,7 +79,7 @@ Meteor.methods({
var buff = _.extend( var buff = _.extend(
{charId: charId, type: "inate"}, condition.buff {charId: charId, type: "inate"}, condition.buff
); );
Buffs.remove(buff); Conditions.remove(buff);
//dont remove the effects, they get removed automatically through parenting //dont remove the effects, they get removed automatically through parenting
}, },
getConditions: function() { getConditions: function() {

View File

@@ -17,6 +17,7 @@ Meteor.publish("singleCharacter", function(characterId){
Attacks.find ({charId: characterId}, {removed: true}), Attacks.find ({charId: characterId}, {removed: true}),
Buffs.find ({charId: characterId}, {removed: true}), Buffs.find ({charId: characterId}, {removed: true}),
Classes.find ({charId: characterId}, {removed: true}), Classes.find ({charId: characterId}, {removed: true}),
Conditions.find ({charId: characterId}, {removed: true}),
Containers.find ({charId: characterId}, {removed: true}), Containers.find ({charId: characterId}, {removed: true}),
CustomBuffs.find ({charId: characterId}, {removed: true}), CustomBuffs.find ({charId: characterId}, {removed: true}),
Effects.find ({charId: characterId}, {removed: true}), Effects.find ({charId: characterId}, {removed: true}),