Added ability to add/remove basic conditions

Conditions are those listed in ./lib/methods/conditions.js
This commit is contained in:
Jacob
2017-07-16 04:27:32 +01:00
parent be92ef224c
commit b3ef43eb70
16 changed files with 316 additions and 54 deletions

View File

@@ -1,6 +1,8 @@
<template name="buffDialog">
{{#with buff}}
{{#baseDialog title=name class=colorClass hideEdit=true}}
{{#baseDialog title=name class=colorClass hideColor=true}}
{{> buffDetails}}
{{else}}
{{> buffDetails}}
{{/baseDialog}}
{{/with}}
@@ -8,8 +10,8 @@
<template name="buffDetails">
{{#if description}}
<div class="pre-wrap">{{evaluateString charId description}}</div>
<hr style="margin: 16px 0 16px 0;">
<div>{{#markdown}}{{evaluateString charId description}}{{/markdown}}</div>
{{/if}}
{{> effectsViewList charId=charId parentId=_id}}
</template>

View File

@@ -3,3 +3,10 @@ Template.buffDialog.helpers({
return Buffs.findOne(this.buffId);
},
});
Template.buffDialog.events({
"click #deleteButton": function(event, instance){
Buffs.remove(instance.data.buffId);
popDialogStack();
},
});

View File

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

View File

@@ -0,0 +1,17 @@
Template.buffView.helpers({
name: function() {
return this.name
}
});
Template.buffView.events({
"click .buffView": function(event){
var buffId = this._id;
var charId = Template.parentData()._id;
pushDialogStack({
template: "buffDialog",
data: {buffId: buffId, charId: charId},
element: event.currentTarget,
});
},
});

View File

@@ -0,0 +1,17 @@
<template name="buffViewList">
<div>
<paper-material class="card">
<div class="top white subhead layout horizontal center">
<div class="flex">Conditions</div>
{{#if canEditCharacter _id}}
<paper-icon-button class="black54" id="addBuff" icon="add"></paper-icon-button>
{{/if}}
</div>
<div flex class="bottom list">
{{#each buffs}}
{{>buffView}}
{{/each}}
</div>
</paper-material>
</div>
</template>

View File

@@ -0,0 +1,28 @@
Template.buffViewList.helpers({
buffs: function(){
var selector = {
// "parent.id": this.parentId,
"charId": this._id,
};
// if (this.parentGroup){
// selector["parent.group"] = this.parentGroup;
// }
return Buffs.find(selector);
}
});
Template.buffViewList.events({
"click #addBuff": function(event, template){
pushDialogStack({
template: "conditionLibraryDialog",
element: event.currentTarget,
callback: (result) => {
if (!result) {
return;
}
else Meteor.call("giveCondition", this._id, result)
},
//returnElement: () => $(`[data-id='${itemId}']`).get(0),
})
},
});

View File

@@ -0,0 +1,11 @@
.condition-library-dialog .item.selected {
background-color: #e4e4e4;
}
.condition-library-dialog table {
border-collapse: collapse;
}
.condition-library-dialog .library-condition td, tr {
position: relative;
}

View File

@@ -0,0 +1,34 @@
<template name="conditionLibraryDialog">
<div class="fit condition-library-dialog layout vertical">
<app-toolbar class="app-grey white-text">
<paper-icon-button id="backButton"
icon="arrow-back">
</paper-icon-button>
<div main-title>Conditions</div>
</app-toolbar>
<div class="flex scroll-y">
<div class="conditions" style="padding:8px">
<table style="width: 100%">
<tbody>
{{#each condition in conditions}}
{{>libraryCondition condition=condition selected=(isSelected condition)}}
{{/each}}
</tbody>
</table>
</div>
</div>
<div class="layout horizontal end-justified">
<paper-button class="cancelButton">Cancel</paper-button>
<paper-button class="okButton">OK</paper-button>
</div>
</div>
</template>
<template name="libraryCondition">
<tr class="item library-condition {{#if selected}}selected{{/if}}">
<td class="conditionName">
{{conditionName condition}}
<paper-ripple></paper-ripple>
</td>
</tr>
</template>

View File

@@ -0,0 +1,166 @@
Template.conditionLibraryDialog.onCreated(function(){
this.selectedCondition = new ReactiveVar();
});
Template.conditionLibraryDialog.helpers({
conditions: function(){
return Object.keys(LIBRARY_CONDITIONS)
},
isSelected(condition){
const selected = Template.instance().selectedCondition.get();
return selected && selected === condition;
},
});
Template.conditionLibraryDialog.events({
"click .cancelButton": function(event, template){
popDialogStack();
},
"click .okButton": function(event, template){
popDialogStack(template.selectedCondition.get());
},
"click .library-condition": function(event, template){
template.selectedCondition.set(this.condition);
},
"click #backButton": function(event, template){
popDialogStack();
},
});
Template.libraryCondition.helpers({
conditionName: function(name){
return LIBRARY_CONDITIONS[name].buff.name;
},
})
LIBRARY_CONDITIONS = {
//Conditions
blind: {
buff: {
name: "Blind",
description: "A blinded creature cant see and automatically fails any ability check that requires sight.\n\nAttack rolls against the creature have advantage, and the creatures attack rolls have disadvantage.",
},
},
deaf: {
buff: {
name: "Deaf",
description: "A deafened creature cant hear and automatically fails any ability check that requires hearing.",
},
},
frightened: {
buff: {
name: "Frightened",
description: "A frightened creature has disadvantage on ability checks and attack rolls while the source of its fear is within line of sight.\n\nThe creature cant willingly move closer to the source of its fear.",
}
},
grappled: {
buff:{
name: "Grappled",
description: "A grappled creatures speed becomes 0, and it cant benefit from any bonus to its speed.\n\nThe condition ends if the grappler is incapacitated.\n\nThe condition also ends if an effect removes the grappled creature from the reach of the grappler or grappling effect, such as when a creature is hurled away by the thunder wave spell.",
},
},
incapacitated: {
buff: {
name: "Incapacitated",
description: "An incapacitated creature cant take actions or reactions.",
}
},
invisible: {
buff: {
name: "Invisible",
description: "An invisible creature is impossible to see without the aid of magic or a special sense. For the purpose of hiding, the creature is heavily obscured. The creatures location can be detected by any noise it makes or any tracks it leaves.\n\nAttack rolls against the creature have disadvantage, and the creatures attack rolls have advantage.",
}
},
paralyzed: {
buff: {
name: "Paralyzed",
description: "A paralyzed creature is **incapacitated** and cant move or speak.\n\nAttack rolls against the creature have advantage.\n\nAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
},
},
petrified: {
buff: {
name: "Petrified",
description: "A petrified creature is transformed, along with any nonmagical object it is wearing or carrying, into a solid inanimate substance (usually stone). Its weight increases by a factor of ten, and it ceases aging.\n\nA petrified creature is **incapacitated** and cant move or speak, and is unaware of its surroundings.\n\nAttack rolls against the creature have advantage.\n\nThe creature is immune to poison and disease, although a poison or disease already in its system is suspended, not neutralized.",
},
},
poisoned: {
buff: {
name: "Poisoned",
description: "A poisoned creature has disadvantage on attack rolls and ability checks.",
},
},
prone: {
buff: {
name: "Prone",
description: "A prone creatures only movement option is to crawl, unless it stands up and thereby ends the condition.\n\nThe creature has disadvantage on attack rolls.\n\nAn attack roll against the creature has advantage if the attacker is within 5 feet of the creature. Otherwise, the attack roll has disadvantage.",
}
},
restrained: {
buff: {
name: "Restrained",
description: "A restrained creatures speed becomes 0, and it cant benefit from any bonus to its speed.\n\nAttack rolls against the creature have advantage, and the creatures attack rolls have disadvantage.\n\nThe creature has disadvantage on Dexterity saving throws.",
},
},
stunned: {
buff: {
name: "Stunned",
description: "A stunned creature is **incapacitated**, cant move, and can speak only falteringly\n\nThe creature automatically fails Strength and Dexterity saving throws.\n\nAttack rolls against the creature have advantage.",
},
},
unconscious: {
buff: {
name: "Unconscious",
description: "An unconscious creature is **incapacitated**, cant move or speak, and is unaware of its surroundings.\n\nThe creature drops whatever its holding and falls **prone**.\n\nThe creature automatically fails Strength and Dexterity saving throws.\n\nAttack rolls against the creature have advantage.\n\nAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
},
},
exhaustion1: {
buff: {
name: "Exhaustion - 1",
description: "Disadvantage on ability checks\n\nFinishing a long rest reduces a creatures exhaustion level by 1, provided that the creature has also ingested some food and drink.",
},
},
exhaustion2: {
buff: {
name: "Exhaustion - 2",
description: "Speed halved",
},
},
exhaustion3: {
buff: {
name: "Exhaustion - 3",
description: "Disadvantage on attack rolls and saving throws",
},
},
exhaustion4: {
buff: {
name: "Exhaustion - 4",
description: "Hit point maximum halved",
},
},
exhaustion5: {
buff: {
name: "Exhaustion - 5",
description: "Speed reduced to 0",
},
},
exhaustion6: {
buff: {
name: "Exhaustion - 6",
description: "You have died of exhaustion",
},
},
};

View File

@@ -62,10 +62,7 @@
<!--Description-->
<paper-textarea id="itemDescriptionInput" label="Description" value={{description}}>
<div suffix>
<paper-tooltip position="left" animation-delay="0">This field accepts formulae in {curly brackets}</paper-tooltip>
<iron-icon icon="dicecloud:code-braces"></iron-icon>
</div>
{{> bracketSuffix}}
</paper-textarea>
<!--Effects-->
{{> effectsEditList parentId=_id parentCollection="Items" charId=charId enabled=equipped name=name}}

View File

@@ -1,9 +0,0 @@
<template name="buff">
<div class="item-slot">
<div class="item inventoryItem layout horizontal center">
<div class="itemName flex">
{{name}}
</div>
</div>
</div>
</template>

View File

@@ -1,5 +0,0 @@
Template.buff.helpers({
name: function() {
return this.name
}
})

View File

@@ -1,14 +0,0 @@
<template name="buffViewList">
{{if buffs.count}}
<paper-material class="card">
<div class="top white paper-font-subhead">
Conditions
</div>
<div flex class="bottom list">
{{#each buffs}}
{{>buff}}
{{/each}}
</div>
</paper-material>
{{/if}}
</template>

View File

@@ -1,12 +0,0 @@
Template.buffViewList.helpers({
buffs: function(){
var selector = {
"parent.id": this.parentId,
"charId": this.charId,
};
if (this.parentGroup){
selector["parent.group"] = this.parentGroup;
}
return Buffs.find(selector);
}
});

View File

@@ -43,7 +43,7 @@
</paper-material>
</div>
<!--Condtions-->
<!-- { { buffViewList } } -->
{{> buffViewList}}
<!--Skills-->
<div>
<paper-material class="card">

View File

@@ -43,6 +43,7 @@ Meteor.methods({
var newEffect = {
stat: effect.stat,
operation: effect.operation,
calculation: effect.calculation,
value: effect.value,
charId: charId,
parent: {
@@ -78,6 +79,21 @@ Meteor.methods({
Buffs.remove(buff);
//dont remove the effects, they get removed automatically through parenting
},
getConditions: function() {
return Object.keys(CONDITIONS);
},
getConditionName: function(conditionName) {
//get condition from constant
var condition = CONDITIONS[conditionName];
//check that condition exists
if (!condition) {
throw new Meteor.Error(
"Invalid condition",
conditionName + " is not a known condition"
);
}
return condition.buff.name;
},
});
trackEncumbranceConditions = function(charId, templateInstance) {
@@ -150,7 +166,7 @@ CONDITIONS = {
{
stat: "perception",
operation: "conditional",
calculation: "You fail your perception check if it requires sight",
calculation: "You fail your Perception check if it requires sight",
}
],
},
@@ -164,7 +180,7 @@ CONDITIONS = {
{
stat: "perception",
operation: "conditional",
calculation: "You fail your perception check if it requires hearing",
calculation: "You fail your Perception check if it requires hearing",
}
],
},
@@ -207,7 +223,7 @@ CONDITIONS = {
paralyzed: {
buff: {
name: "Paralyzed",
description: "A paralyzed creature is incapacitated and cant move or speak.\n\nAttack rolls against the creature have advantage.\n\nAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
description: "A paralyzed creature is **incapacitated** and cant move or speak.\n\nAttack rolls against the creature have advantage.\n\nAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
},
effects: [
{
@@ -232,7 +248,7 @@ CONDITIONS = {
petrified: {
buff: {
name: "Petrified",
description: "A petrified creature is transformed, along with any nonmagical object it is wearing or carrying, into a solid inanimate substance (usually stone). Its weight increases by a factor of ten, and it ceases aging.\n\nA petrified creature is incapacitated and cant move or speak, and is unaware of its surroundings.\n\nAttack rolls against the creature have advantage.\n\nThe creature is immune to poison and disease, although a poison or disease already in its system is suspended, not neutralized.",
description: "A petrified creature is transformed, along with any nonmagical object it is wearing or carrying, into a solid inanimate substance (usually stone). Its weight increases by a factor of ten, and it ceases aging.\n\nA petrified creature is **incapacitated** and cant move or speak, and is unaware of its surroundings.\n\nAttack rolls against the creature have advantage.\n\nThe creature is immune to poison and disease, although a poison or disease already in its system is suspended, not neutralized.",
},
effects: (function() {
var effects = [
@@ -294,7 +310,7 @@ CONDITIONS = {
stunned: {
buff: {
name: "Stunned",
description: "A stunned creature is incapacitated, cant move, and can speak only falteringly\n\nThe creature automatically fails Strength and Dexterity saving throws.\n\nAttack rolls against the creature have advantage.",
description: "A stunned creature is **incapacitated**, cant move, and can speak only falteringly\n\nThe creature automatically fails Strength and Dexterity saving throws.\n\nAttack rolls against the creature have advantage.",
},
effects: [
{
@@ -317,7 +333,7 @@ CONDITIONS = {
unconscious: {
buff: {
name: "Unconscious",
description: "An unconscious creature is incapacitated, cant move or speak, and is unaware of its surroundings.\n\nThe creature drops whatever its holding and falls prone.\n\nThe creature automatically fails Strength and Dexterity saving throws.\n\nAttack rolls against the creature have advantage.\n\nAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
description: "An unconscious creature is **incapacitated**, cant move or speak, and is unaware of its surroundings.\n\nThe creature drops whatever its holding and falls **prone**.\n\nThe creature automatically fails Strength and Dexterity saving throws.\n\nAttack rolls against the creature have advantage.\n\nAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
},
subConditions: ["incapacitated", "prone"],
},