Gave effects their own collection, they no longer live in arrays attached to skills/attributes

Also improved the display of features and generally iterated on their manipulation.

Characters now fetch the relevant effects directly when making a calculation, simplifying almost everything.

Effects now store a reference to their source if they have one.

Effect names are now optional, they can be fetched from the source's name if the source exists.
This commit is contained in:
Thaum
2015-01-23 11:04:07 +00:00
parent 84512beb72
commit 6a2e7f0832
32 changed files with 340 additions and 642 deletions

View File

@@ -1,99 +1,5 @@
<template name="stats">
<core-animated-pages selected={{selectedSection}} transitions="hero-transition cross-fade" fit style="overflow-y: scroll">
<section id="stats">
{{> abilityCards}}
</section>
<section id="detailContainer">
<div cross-fade id="darkOverlay"></div>
{{> attributeDialog character=this}}
{{> skillDialog character=this}}
</section>
</core-animated-pages>
</template>
<template name="spellSlots">
{{attributeValue "level1SpellSlots"}}
{{attributeValue "level2SpellSlots"}}
{{attributeValue "level3SpellSlots"}}
{{attributeValue "level4SpellSlots"}}
{{attributeValue "level5SpellSlots"}}
{{attributeValue "level6SpellSlots"}}
{{attributeValue "level7SpellSlots"}}
{{attributeValue "level8SpellSlots"}}
{{attributeValue "level9SpellSlots"}}
</template>
<template name="statCard">
<paper-shadow {{isHero id}} class="card {{type}}" hero-id={{id}}>
<div id="{{id}}Heading" class="card-top headline {{class}}">
{{> UI.contentBlock}}
</div>
<div class="subhead">
{{title}}
</div>
</paper-shadow>
</template>
<template name="attributeDialog">
<!--needs character, attributeName, attributeTitle-->
{{#if attributeName}}
<paper-shadow id="attributeDialog"
class="detailCard"
hero-id={{session "selectedAttribute"}}
hero
heading={{session "selectedAttributeTitle"}}
z="2">
{{character.attributeValue attributeName}}<br>
{{#each effects.add}}
{{> attributeEffect}}
{{/each}}
{{#each effects.mul}}
{{> attributeEffect}}
{{/each}}
{{#each effects.min}}
{{> attributeEffect}}
{{/each}}
{{#each effects.max}}
{{> attributeEffect}}
{{/each}}
{{signedString attribute.adjustment}}
</paper-shadow>
{{/if}}
</template>
<template name="attributeEffect">
{{#if editing}}
<div class="editEffect">
<paper-dropdown-menu label="Operation">
<paper-dropdown layered class="dropdown">
<core-menu id="operationSelector" selected={{operationNumber}} class="menu">
<paper-item>add</paper-item>
<paper-item>multiply</paper-item>
<paper-item>min</paper-item>
<paper-item>max</paper-item>
</core-menu>
</paper-dropdown>
</paper-dropdown-menu>
<paper-input id="effectValueInput" label="Value" value={{value}} floatinglabel></paper-input>
<paper-input id="effectNameInput" label="Name" value={{name}} floatinglabel></paper-input>
<paper-icon-button id="doneButton" icon="done" title="save" role="button" aria-label="save"></paper-icon-button>
<paper-icon-button id="cancelButton" icon="clear" title="cancel" role="button" aria-label="cancel"></paper-icon-button>
<paper-icon-button id="deleteButton" icon="delete" title="delete" role="button" aria-label="delete"></paper-icon-button>
</div>
{{else}}
<div class="effect">
<div class="effectValue">{{operation}} {{signedEffectValue}}</div><div class="effectName"> {{name}}</div>
{{#if editable}}
<paper-icon-button id="editButton" icon="create" title="edit" role="button" aria-label="edit"></paper-icon-button>
{{/if}}
</div>
{{/if}}
</template>
<template name="skillDialog">
<!--needs character and skill string-->
<paper-dialog layered="false" id="skillDialog" backdrop transition="core-transition-center">
</paper-dialog>
<div class="scroll-y" fit>
{{> abilityCards}}
</div>
</template>

View File

@@ -1,151 +1,7 @@
selectAttribute = function(name, title){
Session.set("selectedAttribute", name);
Session.set("selectedAttributeTitle", title);
Session.set("editingEffect", null);
};
selectSkill = function(name, title){
Session.set("selectedSkill", name);
Session.set("selectedSkillTitle", title);
Session.set("editingEffect", null);
};
Template.stats.created = function(){
this.selectedSection = new ReactiveVar(0);
}
Template.stats.events({
"tap .attribute": function(event){
var instance = Template.instance();
var selected = $(event.currentTarget).attr("hero-id");
var current = Session.get("selectedAttribute");
var f = function(){
selectAttribute(selected, "Title");
instance.selectedSection.set(1);
}
//we already have the dialog open
if(instance.selectedSection.get() === 1 && current != selected){
instance.selectedSection.set(0);
_.delay(f, 200);
} else {
f();
}
},
"tap #darkOverlay": function(event){
Template.instance().selectedSection.set(0);
// let the user click through before it is completely gone
$("#darkOverlay").css("pointer-events", "none");
// make clickable again later
_.delay(function(){
$("#darkOverlay").css("pointer-events", "auto");
}, 500);
}
});
Template.stats.helpers({
selectedSection: function(){
return Template.instance().selectedSection.get();
},
isHero: function(string){
if(string === Session.get("selectedAttribute")||
string === Session.get("selectedSkill")){
return "hero";
}
}
});
Template.statCard.helpers({
isHero: function(string){
if(string === Session.get("selectedAttribute")||
string === Session.get("selectedSkill")){
return "hero";
}
}
});
Template.attributeDialog.helpers({
attributeTitle: function(){
return Session.get("selectedAttributeTitle");
},
attributeName: function(){
return Session.get("selectedAttribute");
},
attribute: function(){
return this.character.getField(Session.get("selectedAttribute"));
},
effects: function(){
var attribute = this.character.getField(Session.get("selectedAttribute"));
return _.groupBy(attribute.effects, "operation");
},
effectValue: function(){
return evaluateEffect(Template.parentData(1).character._id, this);
}
});
Template.attributeEffect.helpers({
editing: function(){
return Session.get("editingEffect") === this._id;
},
editable: function(){
return this.type === "editable";
},
operation: function(){
switch(this.operation){
case "add":
return;
case "mul":
return Spacebars.SafeString("&times;");
case "min":
return "min";
case "max":
return "max";
default:
return this.operation;
}
},
operationNumber: function(){
switch(this.operation){
case "add":
return 0;
case "mul":
return 1;
case "min":
return 2;
case "max":
return 3;
default:
return -1;
}
},
signedEffectValue: function(){
var value = evaluateEffect(Template.parentData(1).character._id, this);
return signedString(value);
}
});
Template.attributeEffect.events({
"tap #editButton": function(event){
Session.set("editingEffect", this._id);
},
"tap #doneButton": function(event){
var newEffect = {
};
//TODO setup the changed effect
var attribute = Session.get("selectedAttribute");
var charId = Template.parentData(2)._id;
Meteor.call("updateEffect", charId, attribute, this._id, newEffect)
Session.set("editingEffect", null);
},
"tap #cancelButton": function(event){
Session.set("editingEffect", null);
},
"tap #deleteButton": function(event){
var attribute = Session.get("selectedAttribute");
var pullObject = {};
pullObject[attribute + ".effects"] = {_id: this._id};
Characters.update(Template.parentData(2)._id, {$pull: pullObject});
Session.set("editingEffect", null);
}
});