Merge pull request #123 from Dumbgenius/spells-improvements

Spells improvements
This commit is contained in:
Stefan Zermatten
2017-09-08 08:30:56 +02:00
committed by GitHub
5 changed files with 91 additions and 46 deletions

View File

@@ -12,7 +12,7 @@
<template name="spellDetails">
<div class="paper-font-body2">
Level {{level}} {{school}} {{#if ritual}}ritual{{/if}}, {{preparedString}}
{{schoolAndLevel}}{{#if ritual}} (ritual){{/if}}, {{preparedString}}
</div>
<div style="margin: 16px 0 16px 0;">
{{#if castingTime}}

View File

@@ -29,6 +29,13 @@ Template.spellDialog.events({
});
Template.spellDetails.helpers({
schoolAndLevel: function(){
if (this.level == 0) {
return this.school + " cantrip";
} else {
return "Level " + this.level + " " + this.school;
}
},
getComponents: function(){
var components = "";
if (this.components.concentration) components += "C";

View File

@@ -253,8 +253,8 @@ Template.spells.events({
pushDialogStack({
template: "spellLibraryDialog",
element: event.currentTarget,
callback: (result) => {
if (!result) return;
callback: (resultArray) => {
if (!resultArray) return;
if (!listId){
listId = SpellLists.insert({
name: "New SpellList",
@@ -263,53 +263,59 @@ Template.spells.events({
attackBonus: "intelligenceMod + proficiencyBonus",
});
}
// Make the library spell into a regular spell
let spell = _.omit(result, "library", "attacks", "effects");
spell._id = spellId;
spell.charId = charId;
spell.parent = {
id: listId,
collection: "SpellLists",
};
spell.prepared = "prepared";
Spells.insert(spell);
// Copy over attacks and effects
_.each(result.attacks, (attack) => {
if (!("attackBonus" in attack)) {attack.attackBonus = "attackBonus"} //if no attack bonus provided, use spell list's
attack.charId = charId;
attack.parent = {id: spellId, collection: "Spells"};
Attacks.insert(attack);
});
_.each(result.effects, (effect) => {
effect.charId = charId;
effect.parent = {id: spellId, collection: "Spells"};
Effects.insert(effect);
});
/******[UNCOMMENT ONCE BUFFS ARE ADDED]*******
_.each(result.buffs, (buff) => {
buff.charId = charId;
buff.parent = {id: spellId, collection: "Spells"};
buffId = Buffs.insert(buff);
_.each(buff.attacks, (attack) => {
if (!(attackBonus in attack)) {attack.attackBonus = "attackBonus"} //if no attack bonus provided, use spell list's
//loop through all returned spells
_.each(resultArray, (rawSpell, index) =>{
// Make the library spell into a regular spell
let spell = _.omit(rawSpell, "library", "attacks", "effects");
if (index == 0) {
spell._id = spellId; //only do this for the first spell added
}
spell.charId = charId;
spell.parent = {
id: listId,
collection: "SpellLists",
};
spell.prepared = "prepared";
Spells.insert(spell);
// Copy over attacks and effects
_.each(rawSpell.attacks, (attack) => {
if (!("attackBonus" in attack)) {attack.attackBonus = "attackBonus"} //if no attack bonus provided, use spell list's
attack.charId = charId;
attack.parent = {id: buffId, collection: "Buffs"};
attack.parent = {id: spellId, collection: "Spells"};
Attacks.insert(attack);
});
_.each(buff.effects, (effect) => {
_.each(rawSpell.effects, (effect) => {
effect.charId = charId;
effect.parent = {id: buffId, collection: "Buffs"};
effect.parent = {id: spellId, collection: "Spells"};
Effects.insert(effect);
});
_.each(buff.proficiencies, (prof) => {
prof.charId = charId;
prof.parent = {id: buffId, collection: "Buffs"};
Proficiencies.insert(prof);
/******[UNCOMMENT ONCE BUFFS ARE ADDED]*******
_.each(rawSpell.buffs, (buff) => {
buff.charId = charId;
buff.parent = {id: spellId, collection: "Spells"};
buffId = Buffs.insert(buff);
_.each(buff.attacks, (attack) => {
if (!(attackBonus in attack)) {attack.attackBonus = "attackBonus"} //if no attack bonus provided, use spell list's
attack.charId = charId;
attack.parent = {id: buffId, collection: "Buffs"};
Attacks.insert(attack);
});
_.each(buff.effects, (effect) => {
effect.charId = charId;
effect.parent = {id: buffId, collection: "Buffs"};
Effects.insert(effect);
});
_.each(buff.proficiencies, (prof) => {
prof.charId = charId;
prof.parent = {id: buffId, collection: "Buffs"};
Proficiencies.insert(prof);
});
});
*******[UNCOMMENT ONCE BUFFS ARE ADDED]******/
});
*******[UNCOMMENT ONCE BUFFS ARE ADDED]******/
},
returnElement: () => $(`[data-id='${spellId}']`).get(0),
})

View File

@@ -14,7 +14,7 @@ const categories = [
];
Template.spellLibraryDialog.onCreated(function(){
this.selectedSpell = new ReactiveVar();
this.selectedSpells = new ReactiveVar([]); //this holds an array of the selected spells by ID
this.searchTerm = new ReactiveVar();
this.categoriesOpen = new ReactiveVar([]);
this.readyDict = new ReactiveDict();
@@ -59,8 +59,8 @@ Template.spellLibraryDialog.helpers({
});
},
isSelected(spell){
const selected = Template.instance().selectedSpell.get();
return selected && selected._id === spell._id;
const selected = Template.instance().selectedSpells.get();
return _.contains(selected, spell._id);
},
isOpen(key){
const cats = Template.instance().categoriesOpen.get();
@@ -89,10 +89,30 @@ Template.spellLibraryDialog.events({
popDialogStack();
},
"click .okButton": function(event, template){
popDialogStack(template.selectedSpell.get());
const selectedIds = template.selectedSpells.get();
var returnSpells = [];
_.each(selectedIds, (id) => {
let spell = LibrarySpells.findOne(id);
if (spell) {
returnSpells.push(spell)
}
});
popDialogStack(returnSpells);
},
"click .library-spell": function(event, template){
template.selectedSpell.set(this.spell);
let selected = template.selectedSpells.get();
const spellId = this.spell._id;
// Toggle whether this spellId is in the array or not
if (_.contains(selected, spellId)){
selected = _.without(selected, spellId);
} else {
selected.push(spellId);
}
template.selectedSpells.set(selected);
console.log("selectedSpells", Template.instance().selectedSpells.get());
console.log("spellId", this.spell._id);
},
"click #backButton": function(event, template){
popDialogStack();

View File

@@ -0,0 +1,12 @@
.base-dialog h1,
.base-dialog h2,
.base-dialog h3,
.base-dialog h4,
.base-dialog h5,
.base-dialog h6{
margin-bottom: 8px;
}
.base-dialog p{
margin-bottom: 20px;
}