From 6a2e7f0832df7651e31de63af57619106253d52b Mon Sep 17 00:00:00 2001 From: Thaum Date: Fri, 23 Jan 2015 11:04:07 +0000 Subject: [PATCH] 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. --- rpg-docs/.meteor/release | 2 +- rpg-docs/.meteor/versions | 40 ++--- rpg-docs/Model/Character/Characters.js | 148 +++++++----------- rpg-docs/Model/Character/Effects.js | 49 ++++++ rpg-docs/Model/Character/Features.js | 25 +-- .../Model/Character/SubSchemas/Attribute.js | 10 -- rpg-docs/Model/Character/SubSchemas/Buff.js | 4 - rpg-docs/Model/Character/SubSchemas/Skill.js | 1 - rpg-docs/Model/Inventory/Items.js | 25 --- rpg-docs/Routes/Routes.js | 1 + rpg-docs/client/globalHelpers/GlobalUI.js | 8 + rpg-docs/client/views/GeneralCSS/general.css | 19 +++ .../client/views/character/Stats/stats.html | 100 +----------- .../client/views/character/Stats/stats.js | 146 +---------------- .../character/features/featureDialog.html | 9 ++ .../views/character/features/featureDialog.js | 24 +-- .../character/features/featureEffect.html | 70 +++++---- .../views/character/features/featureEffect.js | 45 ++++-- .../views/character/features/features.css | 37 ++++- .../views/character/features/features.html | 41 ++--- .../views/character/features/features.js | 6 +- .../character/features/featuresDialog.css | 11 +- rpg-docs/client/views/layout/imports.html | 4 + rpg-docs/client/views/layout/layout.html | 4 +- rpg-docs/lib/functions/characterUtility.js | 2 +- rpg-docs/lib/methods/actionUtils.js | 22 --- rpg-docs/lib/methods/attackUtils.js | 22 --- rpg-docs/lib/methods/effectUtils.js | 41 ----- rpg-docs/lib/methods/featureUtils.js | 30 ---- rpg-docs/lib/methods/spellUtils.js | 22 --- rpg-docs/nohup.out | 8 + .../server/publications/singleCharacter.js | 6 +- 32 files changed, 340 insertions(+), 642 deletions(-) create mode 100644 rpg-docs/Model/Character/Effects.js delete mode 100644 rpg-docs/lib/methods/actionUtils.js delete mode 100644 rpg-docs/lib/methods/attackUtils.js delete mode 100644 rpg-docs/lib/methods/effectUtils.js delete mode 100644 rpg-docs/lib/methods/featureUtils.js delete mode 100644 rpg-docs/lib/methods/spellUtils.js create mode 100644 rpg-docs/nohup.out diff --git a/rpg-docs/.meteor/release b/rpg-docs/.meteor/release index fdc65835..90f87be9 100644 --- a/rpg-docs/.meteor/release +++ b/rpg-docs/.meteor/release @@ -1 +1 @@ -METEOR@1.0.2.1 +METEOR@1.0.3.1 diff --git a/rpg-docs/.meteor/versions b/rpg-docs/.meteor/versions index 27dd0d74..0434d325 100644 --- a/rpg-docs/.meteor/versions +++ b/rpg-docs/.meteor/versions @@ -1,23 +1,23 @@ accounts-base@1.1.3 -accounts-password@1.0.5 +accounts-password@1.0.6 accounts-ui@1.1.4 -accounts-ui-unstyled@1.1.5 +accounts-ui-unstyled@1.1.6 aldeed:autoform@4.2.2 aldeed:collection2@2.3.1 aldeed:simple-schema@1.1.0 application-configuration@1.0.4 -autoupdate@1.1.4 +autoupdate@1.1.5 base64@1.0.2 binary-heap@1.0.2 blaze@2.0.4 blaze-tools@1.0.2 boilerplate-generator@1.0.2 callback-hook@1.0.2 -check@1.0.3 +check@1.0.4 conielo:autoform-polymer-paper@0.1.1 cw4gn3r:jquery-event-drag@2.2.0 dburles:collection-helpers@1.0.2 -ddp@1.0.13 +ddp@1.0.14 deps@1.0.6 differential:vulcanize@0.0.3 ejson@1.0.5 @@ -27,18 +27,18 @@ follower-livedata@1.0.3 geojson-utils@1.0.2 html-tools@1.0.3 htmljs@1.0.3 -http@1.0.9 +http@1.0.10 id-map@1.0.2 insecure@1.0.2 -iron:controller@1.0.6 -iron:core@1.0.6 -iron:dynamic-template@1.0.6 -iron:layout@1.0.6 -iron:location@1.0.6 -iron:middleware-stack@1.0.6 -iron:router@1.0.6 -iron:url@1.0.6 -jquery@1.0.2 +iron:controller@1.0.7 +iron:core@1.0.7 +iron:dynamic-template@1.0.7 +iron:layout@1.0.7 +iron:location@1.0.7 +iron:middleware-stack@1.0.7 +iron:router@1.0.7 +iron:url@1.0.7 +jquery@1.11.3 json@1.0.2 launch-screen@1.0.1 less@1.0.12 @@ -60,17 +60,17 @@ reactive-dict@1.0.5 reactive-var@1.0.4 reload@1.1.2 retry@1.0.2 -routepolicy@1.0.3 +routepolicy@1.0.4 service-configuration@1.0.3 session@1.0.5 sha@1.0.2 -spacebars@1.0.4 +spacebars@1.0.5 spacebars-compiler@1.0.4 srp@1.0.2 -templating@1.0.10 -tracker@1.0.4 +templating@1.0.11 +tracker@1.0.5 ui@1.0.5 underscore@1.0.2 url@1.0.3 -webapp@1.1.5 +webapp@1.1.6 webapp-hashing@1.0.2 diff --git a/rpg-docs/Model/Character/Characters.js b/rpg-docs/Model/Character/Characters.js index 5a51a189..48091545 100644 --- a/rpg-docs/Model/Character/Characters.js +++ b/rpg-docs/Model/Character/Characters.js @@ -17,40 +17,22 @@ Schemas.Character = new SimpleSchema({ //attributes //ability scores - strength: {type: Schemas.Attribute}, - dexterity: {type: Schemas.Attribute}, - constitution: {type: Schemas.Attribute}, - intelligence: {type: Schemas.Attribute}, - wisdom: {type: Schemas.Attribute}, - charisma: {type: Schemas.Attribute}, + strength: {type: Schemas.Attribute}, + dexterity: {type: Schemas.Attribute}, + constitution: {type: Schemas.Attribute}, + intelligence: {type: Schemas.Attribute}, + wisdom: {type: Schemas.Attribute}, + charisma: {type: Schemas.Attribute}, //stats - hitPoints: {type: Schemas.Attribute}, - "hitPoints.effects": { - type: [Schemas.Effect], - defaultValue: [ - {name: "Constitution modifier for each level", calculation: "level * constitutionMod", operation: "add", type: "inate"} - ] - }, - experience: {type: Schemas.Attribute}, - proficiencyBonus: {type: Schemas.Attribute}, - "proficiencyBonus.effects": { - type: [Schemas.Effect], - defaultValue: [ - {name: "Proficiency bonus by level", calculation: "floor(level / 4 + 1.75)", operation: "add", type: "inate"} - ] - }, - speed: {type: Schemas.Attribute}, - weight: {type: Schemas.Attribute}, - age: {type: Schemas.Attribute}, - ageRate: {type: Schemas.Attribute}, - armor: {type: Schemas.Attribute}, - "armor.effects": { - type: [Schemas.Effect], - defaultValue: [ - {name: "Dexterity Modifier", calculation: "dexterityArmor", operation: "add", type: "inate"} - ] - }, + hitPoints: {type: Schemas.Attribute}, + experience: {type: Schemas.Attribute}, + proficiencyBonus: {type: Schemas.Attribute}, + speed: {type: Schemas.Attribute}, + weight: {type: Schemas.Attribute}, + age: {type: Schemas.Attribute}, + ageRate: {type: Schemas.Attribute}, + armor: {type: Schemas.Attribute}, //resources level1SpellSlots: {type: Schemas.Attribute}, @@ -199,61 +181,52 @@ Schemas.Character = new SimpleSchema({ "dexterityArmor.ability": { type: String, defaultValue: "dexterity" }, //proficiencies - weaponsProficiencies: { - type: [Schemas.Proficiency], - defaultValue: [] - }, - toolsProficiencies: { - type: [Schemas.Proficiency], - defaultValue: [] - }, - languages: { - type: [Schemas.Proficiency], - defaultValue: [] - }, + weaponsProficiencies: { type: [Schemas.Proficiency], defaultValue: [] }, + toolsProficiencies: { type: [Schemas.Proficiency], defaultValue: [] }, + languages: { type: [Schemas.Proficiency], defaultValue: [] }, //mechanics - actions: { type: [Schemas.Action], defaultValue: []}, - deathSave: { type: Schemas.DeathSave }, - time: { type: Number, min: 0, decimal: true, defaultValue: 0}, + actions: { type: [Schemas.Action], defaultValue: []}, + deathSave: { type: Schemas.DeathSave }, + time: { type: Number, min: 0, decimal: true, defaultValue: 0}, initiativeOrder:{ type: Number, min: 0, max: 1, decimal: true, defaultValue: 0}, - buffs: { type: [Schemas.Buff], defaultValue: []} + buffs: { type: [Schemas.Buff], defaultValue: []} //TODO add permission stuff for owner, readers and writers //TODO add per-character settings }); Characters.attachSchema(Schemas.Character); -//reactively remove expired effects -//TODO broken with the move from expirations -> buffs -//TODO fix by finding every buff whose expiry is >= current time, pull those buffs -Characters.find({},{fields: {time: 1, expirations: 1, features: 1}}).observe({ - changed: function(character){ - var currentTime = character.time; - _.each(character.expirations, function(expiration){ - if(expiration.expiry <= currentTime){ - var charId = character._id; - var stat = expiration.stat; - //remove expired effects - _.each(expiration.effectIds, function(effectId){ - pullEffect(charId, stat, effectId); - }); - //disable expired features - _.each(expiration.featureIds, function(featureId){ - var feature = Characters.findOne({_id: charId, "features._id": featureId}, {fields: {features: 1}}).features[0]; - feature.enabled = false; - Characters.update({_id: charId, "features._id": featureId}, {$set: {"features.$": feature}}); - }); - pullExpiry(charId, expiration._id); - } - }); - } -}); +//TODO on creating a new character, these effects need to be set up +/* +"hitPoints.effects": { + type: [Schemas.Effect], + defaultValue: [ + {name: "Constitution modifier for each level", calculation: "level * constitutionMod", operation: "add", type: "inate"} + ] + }, + "proficiencyBonus.effects": { + type: [Schemas.Effect], + defaultValue: [ + {name: "Proficiency bonus by level", calculation: "floor(level / 4 + 1.75)", operation: "add", type: "inate"} + ] + }, + "armor.effects": { + type: [Schemas.Effect], + defaultValue: [ + {name: "Dexterity Modifier", calculation: "dexterityArmor", operation: "add", type: "inate"} + ] + }, + {type: "inate", name: "Resistance doesn't stack", operation: "min", value: 0.5}, + {type: "inate", name: "Vulnerability doesn't stack", operation: "max", value: 2} +*/ -var attributeBase = function(charId, attribute){ - var effects = _.groupBy(attribute.effects, "operation"); +var attributeBase = function(charId, statName){ + check(statName, String); + var effects = Effects.find({charId: charId, stat: statName}).fetch(); + effects = _.groupBy(effects, "operation"); var value = 0; - + //start with the highest base value _.each(effects.base, function(effect){ var efv = evaluateEffect(charId, effect) @@ -261,23 +234,23 @@ var attributeBase = function(charId, attribute){ value = effect.value; } }); - + //add all the add values _.each(effects.add, function(effect){ value += evaluateEffect(charId, effect); }); - + //multiply all the mul values _.each(effects.mul, function(effect){ value *= evaluateEffect(charId, effect); }); - + //ensure value is >= all mins _.each(effects.min, function(effect){ var min = evaluateEffect(charId, effect); value = value > min? value : min; }); - + //ensure value is <= all maxes _.each(effects.max, function(effect){ var max = evaluateEffect(charId, effect); @@ -348,9 +321,8 @@ Characters.helpers({ visitedAttributes.push(attributeName); try{ var charId = this._id; - var attribute = this.getField(attributeName); //base value - var value = attributeBase(charId, attribute); + var value = attributeBase(charId, attributeName); }finally{ //this attribute returns or fails, pull it from the array, we may visit it again safely visitedAttributes = _.without(visitedAttributes, attributeName); @@ -388,8 +360,7 @@ Characters.helpers({ //add multiplied proficiency bonus to modifier mod += prof * this.attributeValue("proficiencyBonus"); - - _.each(skill.effects, function(effect){ + Effects.find({charId: charId, stat: skillName}).forEach(function(effect){ switch(effect.operation) { case "add": mod += evaluateEffect(charId, effect); @@ -415,14 +386,11 @@ Characters.helpers({ } })(), - proficiency: function(skill){ - if (_.isString(skill)){ - skill = this.getField(skill); - } + proficiency: function(skillName){ var charId = this._id; //return largest value in proficiency array var prof = 0; - _.each(skill.effects, function(effect){ + Effects.find({charId: charId, stat: skillName}).forEach(function(effect){ if(effect.operation === "proficiency"){ var newProf = evaluateEffect(charId, effect); if (newProf > prof){ @@ -440,7 +408,7 @@ Characters.helpers({ var charId = this._id var mod = +this.skillMod(skillName); var value = 10 + mod; - _.each(skill.effects, function(effect){ + Effects.find({charId: charId, stat: skillName}).forEach(function(effect){ if(effect.operation === "passiveAdd"){ value += evaluateEffect(charId, effect); } diff --git a/rpg-docs/Model/Character/Effects.js b/rpg-docs/Model/Character/Effects.js new file mode 100644 index 00000000..3d0c5ade --- /dev/null +++ b/rpg-docs/Model/Character/Effects.js @@ -0,0 +1,49 @@ +Effects = new Meteor.Collection("effects"); + +/* + * Effects are reason-value attached to skills and abilities + * that modify their final value or presentation in some way + */ +Schemas.Effect = new SimpleSchema({ + charId: { + type: String, + regEx: SimpleSchema.RegEx.Id + }, + name: { + type: String, + optional: true //TODO make necessary if there is no owner + }, + operation: { + type: String, + defaultValue: "add", + allowedValues: ["base", "proficiency","add","mul","min","max","advantage","disadvantage","passiveAdd","fail","conditional"] + }, + value: { + type: Number, + decimal: true, + optional: true + }, + calculation: { + type: String, + optional: true + }, + //indicates what the effect originated from + type: { + type: String, + defaultValue: "editable", + allowedValues: ["editable", "feature", "buff", "equipment", "inate"] + }, + //the id of the feature, buff or item that created this effect + sourceId: { + type: String, + regEx: SimpleSchema.RegEx.Id, + optional: true + }, + //which stat the effect is applied to + stat: { + type: String, + optional: true + } +}); + +Effects.attachSchema(Schemas.Effect); diff --git a/rpg-docs/Model/Character/Features.js b/rpg-docs/Model/Character/Features.js index b65cdfba..bf91f924 100644 --- a/rpg-docs/Model/Character/Features.js +++ b/rpg-docs/Model/Character/Features.js @@ -1,35 +1,12 @@ Features = new Meteor.Collection("features"); Schemas.Feature = new SimpleSchema({ - charId: {type: String, regEx: SimpleSchema.RegEx.Id, optional: true}, + charId: {type: String, regEx: SimpleSchema.RegEx.Id}, name: {type: String}, description:{type: String, optional: true}, - effects: {type: [Schemas.Effect], defaultValue: []}, actions: {type: [Schemas.Action], defaultValue: []}, attacks: {type: [Schemas.Attack], defaultValue: []}, spells: {type: [Schemas.Spell] , defaultValue: []}, }); Features.attachSchema(Schemas.Feature); - -//update the features of the items as needed -Features.find({}, {fields: {name: 0, description: 0}}).observe({ - added: function(newFeature){ - if(newFeature.charId){ - //make sure existing versions of this feature's effects aren't duplicated - removeFeatureEffects(newFeature.charId, newFeature); - //add the new feature's effects - addFeatureEffects(newFeature.charId, newFeature); - } - }, - changed: function(newFeature, oldFeature){ - if(oldFeature.charId) - removeFeatureEffects(oldFeature.charId, oldFeature); - if(newFeature.charId) - addFeatureEffects(newFeature.charId, newFeature); - }, - removed: function(oldFeature){ - if(oldFeature.charId) - removeFeatureEffects(oldFeature.charId, oldFeature); - } -}); diff --git a/rpg-docs/Model/Character/SubSchemas/Attribute.js b/rpg-docs/Model/Character/SubSchemas/Attribute.js index b9975eda..69cf05cf 100644 --- a/rpg-docs/Model/Character/SubSchemas/Attribute.js +++ b/rpg-docs/Model/Character/SubSchemas/Attribute.js @@ -5,8 +5,6 @@ Schemas.Attribute = new SimpleSchema({ type: Number, defaultValue: 0 }, - //effect arrays - effects: { type: [Schemas.Effect], defaultValue: [] }, reset: { type: String, defaultValue: "longRest", @@ -21,14 +19,6 @@ Schemas.Vulnerability = new SimpleSchema({ type: Number, defaultValue: 0 }, - //effect arrays - effects: { - type: [Schemas.Effect], - defaultValue: [ - {type: "inate", name: "Resistance doesn't stack", operation: "min", value: 0.5}, - {type: "inate", name: "Vulnerability doesn't stack", operation: "max", value: 2} - ] - }, reset: { type: String, defaultValue: "longRest", diff --git a/rpg-docs/Model/Character/SubSchemas/Buff.js b/rpg-docs/Model/Character/SubSchemas/Buff.js index f658da52..3d0e66b4 100644 --- a/rpg-docs/Model/Character/SubSchemas/Buff.js +++ b/rpg-docs/Model/Character/SubSchemas/Buff.js @@ -8,10 +8,6 @@ Schemas.Buff = new SimpleSchema({ if(!this.isSet) return Random.id(); }}, - //things that expire - effects: { type: [Schemas.Effect], defaultValue: [] }, - actions: { type: [Schemas.Action], defaultValue: [] }, - //expiry time expiry: { type: Number, optional: true}, duration: { type: Number } diff --git a/rpg-docs/Model/Character/SubSchemas/Skill.js b/rpg-docs/Model/Character/SubSchemas/Skill.js index 70f30320..21600fee 100644 --- a/rpg-docs/Model/Character/SubSchemas/Skill.js +++ b/rpg-docs/Model/Character/SubSchemas/Skill.js @@ -1,5 +1,4 @@ Schemas.Skill = new SimpleSchema({ //attribute name that this skill used as base mod for roll ability: { type: String, defaultValue: "" }, - effects: { type: [Schemas.Effect], defaultValue: [] }, }); \ No newline at end of file diff --git a/rpg-docs/Model/Inventory/Items.js b/rpg-docs/Model/Inventory/Items.js index 1dc9281e..d7cd1649 100644 --- a/rpg-docs/Model/Inventory/Items.js +++ b/rpg-docs/Model/Inventory/Items.js @@ -11,13 +11,6 @@ Schemas.Item = new SimpleSchema({ value: {type: Number, min: 0, defaultValue: 0, decimal: true}, tradeGood: {type: Boolean, defaultValue: false}, stackable: {type: Boolean, defaultValue: false}, - feature: {type: Schemas.Feature}, - "feature.name": {type: String, autoValue: function(){return this.field("name").value}}, - "feature.description": {type: String, autoValue: function(){return this.field("description").value}}, - "feature.source": {type: String, autoValue: function(){return this.field("name").value}}, - "feature.effects.$.name": {type: String, autoValue: function(){return this.field("name").value}}, - "feature.effects.$.type": {type: String, autoValue: function(){return "equipment"}}, - "feature.attacks.$.name": {type: String, autoValue: function(){return this.field("name").value}}, equipmentSlot: { type: String, defaultValue: "none", @@ -28,24 +21,6 @@ Schemas.Item = new SimpleSchema({ Items.attachSchema(Schemas.Item); -//update the features of the items as needed -Items.find({}, {fields: {feature: 1, charId: 1, equipped: 1}}).observe({ - added: function(newItem){ - if(newItem.feature && newItem.charId) - addFeatureEffects(newItem.charId, newItem.feature); - }, - changed: function(newItem, oldItem){ - if(oldItem.feature && oldItem.charId) - removeFeatureEffects(oldItem.charId, oldItem.feature); - if(newItem.feature && newItem.charId) - addFeatureEffects(newItem.charId, newItem.feature); - }, - removed: function(oldItem){ - if(oldItem.feature && oldItem.charId) - removeFeatureEffects(oldItem.charId, oldItem.feature); - } -}); - Items.helpers({ totalValue: function(){ return this.value * this.quantity; diff --git a/rpg-docs/Routes/Routes.js b/rpg-docs/Routes/Routes.js index 4713a04e..f389aa7a 100644 --- a/rpg-docs/Routes/Routes.js +++ b/rpg-docs/Routes/Routes.js @@ -25,6 +25,7 @@ Router.map( function () { Meteor.subscribe("characterContainers", this.params._id, Meteor.userId()), Meteor.subscribe("characterItems", this.params._id, Meteor.userId()), Meteor.subscribe("characterFeatures", this.params._id, Meteor.userId()), + Meteor.subscribe("characterEffects", this.params._id, Meteor.userId()), ]; }, data: function() { diff --git a/rpg-docs/client/globalHelpers/GlobalUI.js b/rpg-docs/client/globalHelpers/GlobalUI.js index 1b36e788..cb066932 100644 --- a/rpg-docs/client/globalHelpers/GlobalUI.js +++ b/rpg-docs/client/globalHelpers/GlobalUI.js @@ -9,6 +9,14 @@ this.GlobalUI = (function() { toast.text = text; return toast.show(); }; + + GlobalUI.setDialog = function(opts){ + this.dialog = $("[global-dialog]")[0]; + Session.set("global.ui.dialogHeader", opts.heading); + Session.set("global.ui.dialogData", opts.data); + Session.set("global.ui.dialogTemplate", opts.template); + Session.set("global.ui.dialogFullOnMobile", opts.fullOnMobile != null); + }; GlobalUI.showDialog = function(opts) { this.dialog = $("[global-dialog]")[0]; diff --git a/rpg-docs/client/views/GeneralCSS/general.css b/rpg-docs/client/views/GeneralCSS/general.css index 18d6b9e9..9e0c2e89 100644 --- a/rpg-docs/client/views/GeneralCSS/general.css +++ b/rpg-docs/client/views/GeneralCSS/general.css @@ -90,6 +90,25 @@ paper-button { transform: translate(-50%, -50%); } +.scroll-y { + overflow-y: auto; +} + +.fab-buffer { + height: 88px; +} + *[hidden] { visibility: hidden; } + +@media (max-width: 640px) { + html /deep/ paper-action-dialog[global-dialog] { + top: 0 !important; + left: 0 !important; + width: 100%; + height: 100%; + margin: 0; + border-radius: 0; + } +} diff --git a/rpg-docs/client/views/character/Stats/stats.html b/rpg-docs/client/views/character/Stats/stats.html index 0d00fc2f..f5b4b095 100644 --- a/rpg-docs/client/views/character/Stats/stats.html +++ b/rpg-docs/client/views/character/Stats/stats.html @@ -1,99 +1,5 @@ - - - - - - - - - - diff --git a/rpg-docs/client/views/character/Stats/stats.js b/rpg-docs/client/views/character/Stats/stats.js index 721aec22..3e4ac439 100644 --- a/rpg-docs/client/views/character/Stats/stats.js +++ b/rpg-docs/client/views/character/Stats/stats.js @@ -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("×"); - 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); - } }); diff --git a/rpg-docs/client/views/character/features/featureDialog.html b/rpg-docs/client/views/character/features/featureDialog.html index 0b8e9bc6..70ee89f4 100644 --- a/rpg-docs/client/views/character/features/featureDialog.html +++ b/rpg-docs/client/views/character/features/featureDialog.html @@ -6,6 +6,15 @@