Added New Character Dialog
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
# but you can also edit it by hand.
|
||||
|
||||
meteor-platform
|
||||
insecure
|
||||
iron:router
|
||||
accounts-password
|
||||
accounts-ui
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<template name="newCharacterDialog">
|
||||
<div>
|
||||
<paper-input id="nameInput" label="Name"></paper-input><br>
|
||||
<paper-input id="genderInput" label="Gender"></paper-input><br>
|
||||
<paper-input id="raceInput" label="Race"></paper-input>
|
||||
<!--
|
||||
<div>
|
||||
<div layout horizontal center-justified>
|
||||
{{pointsUsed}}/<paper-input-decorator><input type="number" value="27"></paper-input-decorator>
|
||||
</div>
|
||||
<div layout horizontal wrap>
|
||||
<div>Strength</div>
|
||||
<paper-slider id="strSlider" min="8" max="15" value="8" secondaryProgress={{secondaryProgress}}></paper-slider>
|
||||
</div>
|
||||
<div layout horizontal wrap>
|
||||
<div>Dexterity</div>
|
||||
<paper-slider id="dexSlider" min="8" max="15" value="8" secondaryProgress={{secondaryProgress}}></paper-slider>
|
||||
</div>
|
||||
<div layout horizontal wrap>
|
||||
<div>Constitution</div>
|
||||
<paper-slider id="conSlider" min="8" max="15" value="8" secondaryProgress={{secondaryProgress}}></paper-slider>
|
||||
</div>
|
||||
<div layout horizontal wrap>
|
||||
<div>Intelligence</div>
|
||||
<paper-slider id="intSlider" min="8" max="15" value="8" secondaryProgress={{secondaryProgress}}></paper-slider>
|
||||
</div>
|
||||
<div layout horizontal wrap>
|
||||
<div>Wisdom</div>
|
||||
<paper-slider id="wisSlider" min="8" max="15" value="8" secondaryProgress={{secondaryProgress}}></paper-slider>
|
||||
</div>
|
||||
<div layout horizontal wrap>
|
||||
<div>Charisma</div>
|
||||
<paper-slider id="chaSlider" min="8" max="15" value="8" secondaryProgress={{secondaryProgress}}></paper-slider>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
<paper-button id="cancelButton" affirmative> Cancel </paper-button>
|
||||
<paper-button id="addButton" affirmative> Add </paper-button>
|
||||
</template>
|
||||
@@ -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});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -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"});
|
||||
},
|
||||
});
|
||||
|
||||
68
rpg-docs/lib/constants/pointBuy.js
Normal file
68
rpg-docs/lib/constants/pointBuy.js
Normal file
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user