diff --git a/rpg-docs/.meteor/release b/rpg-docs/.meteor/release
index 509b6f42..23c04296 100644
--- a/rpg-docs/.meteor/release
+++ b/rpg-docs/.meteor/release
@@ -1 +1 @@
-METEOR@1.0.4
+METEOR@1.0.4.1
diff --git a/rpg-docs/Model/Character/Attacks.js b/rpg-docs/Model/Character/Attacks.js
index ce317555..a85b8316 100644
--- a/rpg-docs/Model/Character/Attacks.js
+++ b/rpg-docs/Model/Character/Attacks.js
@@ -66,7 +66,7 @@ Schemas.Attack = new SimpleSchema({
Attacks.attachSchema(Schemas.Attack);
Attacks.attachBehaviour('softRemovable');
-makeChild(Attacks); //children of lots of things
+makeChild(Attacks, ['name', 'enabled']); //children of lots of things
Attacks.allow(CHARACTER_SUBSCHEMA_ALLOW);
Attacks.deny(CHARACTER_SUBSCHEMA_DENY);
diff --git a/rpg-docs/Model/Character/Buffs.js b/rpg-docs/Model/Character/Buffs.js
index 20d8cbe6..203b0aac 100644
--- a/rpg-docs/Model/Character/Buffs.js
+++ b/rpg-docs/Model/Character/Buffs.js
@@ -21,7 +21,7 @@ Schemas.Buff = new SimpleSchema({
Buffs.attachSchema(Schemas.Buff);
Buffs.attachBehaviour('softRemovable');
-makeParent(Buffs); //parents of effects and attacks
+makeParent(Buffs, 'name'); //parents of effects and attacks
Buffs.allow(CHARACTER_SUBSCHEMA_ALLOW);
Buffs.deny(CHARACTER_SUBSCHEMA_DENY);
diff --git a/rpg-docs/Model/Character/Classes.js b/rpg-docs/Model/Character/Classes.js
index d0513475..72b4ec3d 100644
--- a/rpg-docs/Model/Character/Classes.js
+++ b/rpg-docs/Model/Character/Classes.js
@@ -22,7 +22,7 @@ Schemas.Class = new SimpleSchema({
Classes.attachSchema(Schemas.Class);
Classes.attachBehaviour('softRemovable');
-makeParent(Classes); //parents of effects and attacks
+makeParent(Classes, 'name'); //parents of effects and attacks
Classes.allow(CHARACTER_SUBSCHEMA_ALLOW);
Classes.deny(CHARACTER_SUBSCHEMA_DENY);
diff --git a/rpg-docs/Model/Character/Effects.js b/rpg-docs/Model/Character/Effects.js
index 1fb7613b..1af8b531 100644
--- a/rpg-docs/Model/Character/Effects.js
+++ b/rpg-docs/Model/Character/Effects.js
@@ -90,7 +90,7 @@ Characters.after.insert(function (userId, char) {
});
Effects.attachBehaviour('softRemovable');
-makeChild(Effects); //children of lots of things
+makeChild(Effects, ['name', 'enabled']); //children of lots of things
Effects.allow(CHARACTER_SUBSCHEMA_ALLOW);
Effects.deny(CHARACTER_SUBSCHEMA_DENY);
diff --git a/rpg-docs/Model/Character/Features.js b/rpg-docs/Model/Character/Features.js
index 2e367521..65d84e7d 100644
--- a/rpg-docs/Model/Character/Features.js
+++ b/rpg-docs/Model/Character/Features.js
@@ -1,13 +1,14 @@
Features = new Mongo.Collection("features");
Schemas.Feature = new SimpleSchema({
- charId: {type: String, regEx: SimpleSchema.RegEx.Id},
- name: {type: String, trim: false},
- description:{type: String, optional: true, trim: false},
- uses: {type: String, optional: true, trim: false},
- used: {type: Number, defaultValue: 0},
- reset: {type: String, allowedValues: ["manual", "longRest", "shortRest"], defaultValue: "manual"},
- enabled: {type: String, allowedValues: ["enabled", "disabled", "alwaysEnabled"], defaultValue: "alwaysEnabled"},
+ charId: {type: String, regEx: SimpleSchema.RegEx.Id},
+ name: {type: String, trim: false},
+ description: {type: String, optional: true, trim: false},
+ uses: {type: String, optional: true, trim: false},
+ used: {type: Number, defaultValue: 0},
+ reset: {type: String, allowedValues: ["manual", "longRest", "shortRest"], defaultValue: "manual"},
+ enabled: {type: Boolean, defaultValue: true},
+ alwaysEnabled:{type: Boolean, defaultValue: true},
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
});
@@ -23,7 +24,7 @@ Features.helpers({
});
Features.attachBehaviour('softRemovable');
-makeParent(Features); //parents of effects and attacks
+makeParent(Features, ['name', 'enabled']); //parents of effects and attacks
Features.allow(CHARACTER_SUBSCHEMA_ALLOW);
Features.deny(CHARACTER_SUBSCHEMA_DENY);
diff --git a/rpg-docs/Model/Inventory/Containers.js b/rpg-docs/Model/Inventory/Containers.js
index e68f5a21..5335414f 100644
--- a/rpg-docs/Model/Inventory/Containers.js
+++ b/rpg-docs/Model/Inventory/Containers.js
@@ -27,6 +27,10 @@ Containers.helpers({
weight += item.totalWeight();
});
return weight;
+ },
+ moveToCharacter: function(characterId){
+ if(this.charId === characterId) return;
+ Items.update(this._id, {$set: {charId: characterId}});
}
});
diff --git a/rpg-docs/Model/Inventory/Items.js b/rpg-docs/Model/Inventory/Items.js
index dadf6508..c1eb687a 100644
--- a/rpg-docs/Model/Inventory/Items.js
+++ b/rpg-docs/Model/Inventory/Items.js
@@ -32,11 +32,31 @@ Items.helpers({
} else{
return this.name;
}
+ },
+ equip: function(){
+ Items.update(this._id, {$set: {enabled: true}});
+ },
+ unequip: function(){
+ Items.update(this._id, {$set: {enabled: false}});
+ },
+ moveToContainer: function(containerId){
+ Items.update(this._id, {$set: {"parent.collection": "Containers", "parent.id": containerId, enabled: false}});
+ },
+ moveToCharacter: function(characterId){
+ if(this.charId === characterId) return;
+ Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": characterId, charId: characterId, enabled: false}});
+ }
+});
+
+Items.before.update(function(userId, doc, fieldNames, modifier, options){
+ if(modifier && modifier.$set && modifier.$set.enabled){
+ modifier.$set["parent.collection"] = "Characters";
+ modifier.$set["parent.id"] = doc.charId;
}
});
Items.attachBehaviour('softRemovable');
makeChild(Items); //children of containers
-makeParent(Items); //parents of effects and attacks
+makeParent(Items, ['name', 'enabled']); //parents of effects and attacks
Items.allow(CHARACTER_SUBSCHEMA_ALLOW);
diff --git a/rpg-docs/client/views/character/features/featureDialog/featureDialog.js b/rpg-docs/client/views/character/features/featureDialog/featureDialog.js
index 8445df3d..9fb190d2 100644
--- a/rpg-docs/client/views/character/features/featureDialog/featureDialog.js
+++ b/rpg-docs/client/views/character/features/featureDialog/featureDialog.js
@@ -32,8 +32,16 @@ Template.featureDialog.events({
var detail = event.originalEvent.detail;
if(!detail.isSelected) return;
var value = detail.item.getAttribute("name");
- if (value === this.enabled) return;
- Features.update(this._id, {$set: {enabled: value}});
+ var setter;
+ if(value === "enabled"){
+ setter = {enabled: true, alwaysEnabled: false};
+ } else if (value === "disabled"){
+ setter = {enabled: false, alwaysEnabled: false};
+ } else{
+ setter = {enabled: true, alwaysEnabled: true};
+ }
+ if (setter.enabled === this.enabled && setter.alwaysEnabled === this.alwaysEnabled) return;
+ Features.update(this._id, {$set: setter});
},
});
diff --git a/rpg-docs/client/views/character/features/features.html b/rpg-docs/client/views/character/features/features.html
index c98e54d1..3427acee 100644
--- a/rpg-docs/client/views/character/features/features.html
+++ b/rpg-docs/client/views/character/features/features.html
@@ -71,7 +71,7 @@
{{#if canEnable}}
-
+
{{/if}}
diff --git a/rpg-docs/client/views/character/features/features.js b/rpg-docs/client/views/character/features/features.js
index 71778d39..4fad3968 100644
--- a/rpg-docs/client/views/character/features/features.js
+++ b/rpg-docs/client/views/character/features/features.js
@@ -26,10 +26,7 @@ Template.features.helpers({
return char && char.proficiencies;
},
canEnable: function(){
- return this.enabled !== "alwaysEnabled";
- },
- isEnabled: function(){
- return this.enabled !== "disabled";
+ return !this.alwaysEnabled;
}
});
@@ -94,9 +91,7 @@ Template.features.events({
event.stopPropagation();
},
"change .enabledCheckbox": function(event){
- var enabled;
- if(this.enabled === "enabled") enabled = "disabled";
- else enabled = "enabled";
+ var enabled = !this.enabled;
Features.update(this._id, {$set: {enabled: enabled}});
}
});
diff --git a/rpg-docs/lib/functions/parenting.js b/rpg-docs/lib/functions/parenting.js
index c29c04e9..38af32e2 100644
--- a/rpg-docs/lib/functions/parenting.js
+++ b/rpg-docs/lib/functions/parenting.js
@@ -7,7 +7,6 @@ var childSchema = new SimpleSchema({
var joinWithDefaultKeys = function(keys){
var defaultKeys = [
'charId',
- 'enabled',
'removed',
'removedAt',
'removedBy',
@@ -17,11 +16,21 @@ var joinWithDefaultKeys = function(keys){
return _.union(keys, defaultKeys);
}
+var limitModifierToKeys = function(modifier, keys){
+ if(!modifier) return;
+ modifier = _.pick(modifier, ['$set', '$unset']);
+ if(modifier.$set) modifier.$set = _.pick(modifier.$set, keys);
+ if(modifier.$unset) modifier.$unset = _.pick(modifier.$unset, keys);
+ if(_.isEmpty(modifier.$set)) delete modifier.$set;
+ if(_.isEmpty(modifier.$unset)) delete modifier.$unset;
+ return modifier;
+}
+
var childCollections = [];
makeChild = function(collection, inheritedKeys){
- collection.inheritedKeys = joinWithDefaultKeys(inheritedKeys);
-
+ inheritedKeys = inheritedKeys || [];
+ if(inheritedKeys) collection.inheritedKeys = joinWithDefaultKeys(inheritedKeys);
collection.helpers({
//returns the parent even if it's removed
getParent: function(){
@@ -53,16 +62,13 @@ makeChild = function(collection, inheritedKeys){
};
makeParent = function(collection, donatedKeys){
- collection.donatedKeys = joinWithDefaultKeys(donatedKeys);
+ donatedKeys = joinWithDefaultKeys(donatedKeys);
//after changing, push the changes to all children
collection.after.update(function (userId, doc, fieldNames, modifier, options) {
- if(!modifier) return;
- modifier = _.pick(modifier, ['$set', '$unset']);
- modifier.$set = _.pick(modifier.$set, donatedKeys);
- modifier.$unset = _.pick(modifier.$unset, donatedKeys);
+ modifier = limitModifierToKeys(modifier, donatedKeys);
doc = _.pick(doc, ['_id','charId']);
- Meteor.call('updateChildren', doc, modifier);
+ Meteor.call('updateChildren', doc, modifier, true);
});
collection.after.remove(function (userId, doc) {
@@ -86,17 +92,19 @@ var checkPermission = function(userId, charId){
};
Meteor.methods({
- updateChildren: function (parent, modifier) {
+ updateChildren: function (parent, modifier, limitToInheritance) {
check(parent, {_id: String, charId: String});
check(modifier, Object);
checkPermission(this.userId, parent.charId);
-
_.each(childCollections, function(collection){
- collection.update(
- {charId: parent.charId, 'parent.id': parent._id},
- modifier,
- {multi: true}
- );
+ var thisModifier;
+ if(limitToInheritance){
+ thisModifier = limitModifierToKeys(modifier, collection.inheritedKeys);
+ } else{
+ thisModifier = _.clone(modifier);
+ }
+ if(_.isEmpty(thisModifier)) return;
+ collection.update( {'parent.id': parent._id}, thisModifier, {multi: true});
});
},
removeChildren: function (parent) {