diff --git a/rpg-docs/.meteor/packages b/rpg-docs/.meteor/packages index f650cbb2..4dbe8550 100644 --- a/rpg-docs/.meteor/packages +++ b/rpg-docs/.meteor/packages @@ -4,7 +4,6 @@ # but you can also edit it by hand. meteor-platform -insecure iron:router accounts-password accounts-ui diff --git a/rpg-docs/.meteor/versions b/rpg-docs/.meteor/versions index 9c7ed8b9..7917ba6e 100644 --- a/rpg-docs/.meteor/versions +++ b/rpg-docs/.meteor/versions @@ -26,7 +26,6 @@ html-tools@1.0.4 htmljs@1.0.4 http@1.1.0 id-map@1.0.3 -insecure@1.0.3 iron:controller@1.0.7 iron:core@1.0.7 iron:dynamic-template@1.0.7 diff --git a/rpg-docs/client/globalHelpers/GlobalUI.js b/rpg-docs/client/globalHelpers/GlobalUI.js index c101f40c..2bb2f512 100644 --- a/rpg-docs/client/globalHelpers/GlobalUI.js +++ b/rpg-docs/client/globalHelpers/GlobalUI.js @@ -75,9 +75,13 @@ this.GlobalUI = (function() { } }; + var throttleBack = _.throttle(function(){ + history.back(); + }, 800, {trailing: false}); + GlobalUI.closeDetail = function(){ if(!!(window.history && window.history.pushState)){ - history.back(); + throttleBack(); } else{ Session.set("global.ui.detailShow", false); } diff --git a/rpg-docs/client/views/character/newCharacterDialog/newCharacterDialog.html b/rpg-docs/client/views/character/newCharacterDialog/newCharacterDialog.html new file mode 100644 index 00000000..3bacd87d --- /dev/null +++ b/rpg-docs/client/views/character/newCharacterDialog/newCharacterDialog.html @@ -0,0 +1,40 @@ + \ No newline at end of file diff --git a/rpg-docs/client/views/character/newCharacterDialog/newCharacterDialog.js b/rpg-docs/client/views/character/newCharacterDialog/newCharacterDialog.js new file mode 100644 index 00000000..31f17e44 --- /dev/null +++ b/rpg-docs/client/views/character/newCharacterDialog/newCharacterDialog.js @@ -0,0 +1,13 @@ +Template.newCharacterDialog.events({ + "tap #addButton": function(event, instance){ + Characters.insert({ + name: instance.find("#nameInput").value, + gender: instance.find("#genderInput").value, + race: instance.find("#raceInput").value, + owner: Meteor.userId() + }, function(err, id){ + if(err) throw err; + Router.go("characterSheet", {_id: id}); + }); + } +}); diff --git a/rpg-docs/client/views/characterList/characterList.js b/rpg-docs/client/views/characterList/characterList.js index 222dc02e..73f22b50 100644 --- a/rpg-docs/client/views/characterList/characterList.js +++ b/rpg-docs/client/views/characterList/characterList.js @@ -13,6 +13,6 @@ Template.characterList.events({ Router.go("characterSheet", {_id: this._id}); }, "tap .addCharacter": function (event, template) { - Characters.insert({owner: Meteor.userId()}); + GlobalUI.showDialog({heading: "New Character", template: "newCharacterDialog"}); }, }); diff --git a/rpg-docs/lib/constants/pointBuy.js b/rpg-docs/lib/constants/pointBuy.js new file mode 100644 index 00000000..b7157ef8 --- /dev/null +++ b/rpg-docs/lib/constants/pointBuy.js @@ -0,0 +1,68 @@ +pointBuyCost = { + "8": 0, + "9": 1, + "10": 2, + "11": 3, + "12": 4, + "13": 5, + "14": 7, + "15": 9 +}; + +var getPointBuyEffect = function(stat, value, pointsUsed, charId){ + return { + modifier:{ + charId: charId, + stat: stat, + name: pointsUsed + " Point Buy", + operation: "base", + value: value, + type: "inate", + parent: {collection: "Characters", id: charId}, + enabled: true, + }, + selector:{ + charId: charId, + stat: stat, + operation: "base", + type: "inate" + } + }; +}; + +var checkPermission = function(userId, charId){ + var char = Characters.findOne( charId, { fields: {owner: 1, writers: 1} } ); + if(!char) + throw new Meteor.Error('Access Denied', + 'Character '+charId+' does not exist'); + if (!userId) + throw new Meteor.Error('Access Denied', + 'No UserId set when trying to update character asset.'); + if (char.owner !== userId && !_.contains(char.writers, userId)) + throw new Meteor.Error('Access Denied', + 'Not permitted to update assets of this character.'); + return true; +}; + +Meteor.methods({ + pointBuyAbilityScores: function(charId, points){ + check(points, { + strength: Number, + dexterity: Number, + constitution: Number, + intelligence: Number, + wisdom: Number, + charisma: Number + }); + check(charId, String); + checkPermission(this.userId, charId); + var pointsUsed = 0; + _.each(points, function(value, key){ + pointsUsed += pointBuyCost[value]; + }); + _.each(points, function(value, ability){ + var pbEffect = getPointBuyEffect(ability, value, pointsUsed, charId); + Effects.upsert(pbEffect.selector, pbEffect.modifier); + }); + } +}); diff --git a/rpg-docs/lib/functions/parenting.js b/rpg-docs/lib/functions/parenting.js index 1481953e..0a386bd3 100644 --- a/rpg-docs/lib/functions/parenting.js +++ b/rpg-docs/lib/functions/parenting.js @@ -94,6 +94,7 @@ makeParent = function(collection, donatedKeys){ collection.after.update(function (userId, doc, fieldNames, modifier, options) { modifier = limitModifierToKeys(modifier, donatedKeys); doc = _.pick(doc, ['_id','charId']); + if(!modifier) return; Meteor.call('updateChildren', doc, modifier, true); });