Spell library now allows you to select multiple spells
This commit is contained in:
@@ -253,8 +253,8 @@ Template.spells.events({
|
|||||||
pushDialogStack({
|
pushDialogStack({
|
||||||
template: "spellLibraryDialog",
|
template: "spellLibraryDialog",
|
||||||
element: event.currentTarget,
|
element: event.currentTarget,
|
||||||
callback: (result) => {
|
callback: (resultArray) => {
|
||||||
if (!result) return;
|
if (!resultArray) return;
|
||||||
if (!listId){
|
if (!listId){
|
||||||
listId = SpellLists.insert({
|
listId = SpellLists.insert({
|
||||||
name: "New SpellList",
|
name: "New SpellList",
|
||||||
@@ -263,53 +263,59 @@ Template.spells.events({
|
|||||||
attackBonus: "intelligenceMod + proficiencyBonus",
|
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]*******
|
//loop through all returned spells
|
||||||
_.each(result.buffs, (buff) => {
|
_.each(resultArray, (rawSpell, index) =>{
|
||||||
buff.charId = charId;
|
// Make the library spell into a regular spell
|
||||||
buff.parent = {id: spellId, collection: "Spells"};
|
let spell = _.omit(rawSpell, "library", "attacks", "effects");
|
||||||
buffId = Buffs.insert(buff);
|
if (index == 0) {
|
||||||
|
spell._id = spellId; //only do this for the first spell added
|
||||||
_.each(buff.attacks, (attack) => {
|
}
|
||||||
if (!(attackBonus in attack)) {attack.attackBonus = "attackBonus"} //if no attack bonus provided, use spell list's
|
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.charId = charId;
|
||||||
attack.parent = {id: buffId, collection: "Buffs"};
|
attack.parent = {id: spellId, collection: "Spells"};
|
||||||
Attacks.insert(attack);
|
Attacks.insert(attack);
|
||||||
});
|
});
|
||||||
_.each(buff.effects, (effect) => {
|
_.each(rawSpell.effects, (effect) => {
|
||||||
effect.charId = charId;
|
effect.charId = charId;
|
||||||
effect.parent = {id: buffId, collection: "Buffs"};
|
effect.parent = {id: spellId, collection: "Spells"};
|
||||||
Effects.insert(effect);
|
Effects.insert(effect);
|
||||||
});
|
});
|
||||||
_.each(buff.proficiencies, (prof) => {
|
|
||||||
prof.charId = charId;
|
/******[UNCOMMENT ONCE BUFFS ARE ADDED]*******
|
||||||
prof.parent = {id: buffId, collection: "Buffs"};
|
_.each(rawSpell.buffs, (buff) => {
|
||||||
Proficiencies.insert(prof);
|
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),
|
returnElement: () => $(`[data-id='${spellId}']`).get(0),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const categories = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
Template.spellLibraryDialog.onCreated(function(){
|
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.searchTerm = new ReactiveVar();
|
||||||
this.categoriesOpen = new ReactiveVar([]);
|
this.categoriesOpen = new ReactiveVar([]);
|
||||||
this.readyDict = new ReactiveDict();
|
this.readyDict = new ReactiveDict();
|
||||||
@@ -59,8 +59,8 @@ Template.spellLibraryDialog.helpers({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
isSelected(spell){
|
isSelected(spell){
|
||||||
const selected = Template.instance().selectedSpell.get();
|
const selected = Template.instance().selectedSpells.get();
|
||||||
return selected && selected._id === spell._id;
|
return _.contains(selected, spell._id);
|
||||||
},
|
},
|
||||||
isOpen(key){
|
isOpen(key){
|
||||||
const cats = Template.instance().categoriesOpen.get();
|
const cats = Template.instance().categoriesOpen.get();
|
||||||
@@ -89,10 +89,30 @@ Template.spellLibraryDialog.events({
|
|||||||
popDialogStack();
|
popDialogStack();
|
||||||
},
|
},
|
||||||
"click .okButton": function(event, template){
|
"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){
|
"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){
|
"click #backButton": function(event, template){
|
||||||
popDialogStack();
|
popDialogStack();
|
||||||
|
|||||||
Reference in New Issue
Block a user