Skip to content

Commit

Permalink
Merge branch 'bugfix-model'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaumRystra committed Jul 13, 2017
2 parents 09d1ac9 + 2bacb29 commit 54f055d
Show file tree
Hide file tree
Showing 33 changed files with 255 additions and 78 deletions.
1 change: 1 addition & 0 deletions rpg-docs/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ [email protected]
differential:vulcanize
reactive-dict
percolate:synced-cron
ongoworks:speakingurl
1 change: 1 addition & 0 deletions rpg-docs/.meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ [email protected]_1
[email protected]
[email protected]
[email protected]
ongoworks:[email protected]
[email protected]
percolate:[email protected]
percolate:[email protected]
Expand Down
2 changes: 2 additions & 0 deletions rpg-docs/Model/Character/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ Schemas.Action = new SimpleSchema({
},
name: {
type: String,
optional: true,
trim: false,
},
description: {
type: String,
optional: true,
trim: false,
},
type: {
Expand Down
1 change: 1 addition & 0 deletions rpg-docs/Model/Character/Attacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Schemas.Attack = new SimpleSchema({
name: {
type: String,
defaultValue: "New Attack",
optional: true,
trim: false,
},
details: {
Expand Down
1 change: 1 addition & 0 deletions rpg-docs/Model/Character/Buffs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Schemas.Buff = new SimpleSchema({
},
name: {
type: String,
optional: true,
trim: false,
},
description: {
Expand Down
12 changes: 11 additions & 1 deletion rpg-docs/Model/Character/Characters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Characters = new Mongo.Collection("characters");
Schemas.Character = new SimpleSchema({
//strings
name: {type: String, defaultValue: "", trim: false, optional: true},
urlName: {type: String, defaultValue: "", trim: false, optional: true},
alignment: {type: String, defaultValue: "", trim: false, optional: true},
gender: {type: String, defaultValue: "", trim: false, optional: true},
race: {type: String, defaultValue: "", trim: false, optional: true},
Expand Down Expand Up @@ -257,7 +258,10 @@ var attributeBase = preventLoop(function(charId, statName){
var result = (base + add) * mul;
if (result < min) result = min;
if (result > max) result = max;

// Don't round carry multiplier
if (statName === "carryMultiplier"){
return result;
}
return Math.floor(result);
});

Expand Down Expand Up @@ -537,6 +541,12 @@ if (Meteor.isServer){
Items .remove({charId: character._id});
Containers .remove({charId: character._id});
});
Characters.after.update(function(userId, doc, fieldNames, modifier, options) {
if (_.contains(fieldNames, "name")){
var urlName = getSlug(doc.name, {maintainCase: true});
Characters.update(doc._id, {$set: {urlName}});
}
});
}

Characters.allow({
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/Model/Character/Classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Classes = new Mongo.Collection("classes");

Schemas.Class = new SimpleSchema({
charId: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1},
name: {type: String, trim: false},
name: {type: String, optional: true, trim: false},
level: {type: Number},
createdAt: {
type: Date,
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/Model/Character/Experience.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Experiences = new Mongo.Collection("experience");

Schemas.Experience = new SimpleSchema({
charId: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1},
name: {type: String, defaultValue: "New Experience", trim: false},
name: {type: String, optional: true, trim: false, defaultValue: "New Experience"},
description: {type: String, optional: true, trim: false},
value: {type: Number, defaultValue: 0},
dateAdded: {
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/Model/Character/Features.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Features = new Mongo.Collection("features");

Schemas.Feature = new SimpleSchema({
charId: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1},
name: {type: String, trim: false},
name: {type: String, optional: true, trim: false},
description: {type: String, optional: true, trim: false},
uses: {type: String, optional: true, trim: false},
used: {type: Number, defaultValue: 0},
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/Model/Character/Notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Notes = new Mongo.Collection("notes");

Schemas.Note = new SimpleSchema({
charId: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1},
name: {type: String, trim: false},
name: {type: String, optional: true, trim: false},
description: {type: String, optional: true, trim: false},
color: {
type: String,
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/Model/Character/SpellLists.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SpellLists = new Mongo.Collection("spellLists");

Schemas.SpellLists = new SimpleSchema({
charId: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1},
name: {type: String, trim: false},
name: {type: String, optional: true, trim: false},
description: {type: String, optional: true, trim: false},
saveDC: {type: String, optional: true, trim: false},
attackBonus: {type: String, optional: true, trim: false},
Expand Down
1 change: 1 addition & 0 deletions rpg-docs/Model/Character/Spells.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Schemas.Spell = new SimpleSchema({
},
name: {
type: String,
optional: true,
trim: false,
defaultValue: "New Spell",
},
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/Model/Inventory/Containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Containers = new Mongo.Collection("containers");

Schemas.Container = new SimpleSchema({
name: {type: String, trim: false},
name: {type: String, optional: true, trim: false},
charId: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1},
isCarried: {type: Boolean},
weight: {type: Number, min: 0, defaultValue: 0, decimal: true},
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/Model/Inventory/Items.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Items = new Mongo.Collection("items");

Schemas.Item = new SimpleSchema({
name: {type: String, defaultValue: "New Item", trim: false},
name: {type: String, optional: true, trim: false, defaultValue: "New Item"},
plural: {type: String, optional: true, trim: false},
description:{type: String, optional: true, trim: false},
charId: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1}, //id of owner
Expand Down
22 changes: 19 additions & 3 deletions rpg-docs/Routes/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,35 @@ Router.map(function() {
this.route("characterList", {
path: "/characterList",
waitOn: function(){
return subsManager.subscribe("characterList", Meteor.userId());
return subsManager.subscribe("characterList");
},
onAfterAction: function() {
document.title = appName + " - Characters";
},
fastRender: true,
});

this.route("characterSheetNaked", {
path: "/character/:_id/",
waitOn: function(){
return [
subsManager.subscribe("singleCharacter", this.params._id),
];
},
action: function(){
var _id = this.params._id
var character = Characters.findOne(_id);
var urlName = character && character.urlName;
var path = `\/character\/${_id}\/${urlName}`;
Router.go(path,{},{replaceState:true});
},
});

this.route("characterSheet", {
path: "/character/:_id",
path: "/character/:_id/:urlName",
waitOn: function(){
return [
subsManager.subscribe("singleCharacter", this.params._id, Meteor.userId()),
subsManager.subscribe("singleCharacter", this.params._id),
];
},
data: function() {
Expand Down
4 changes: 4 additions & 0 deletions rpg-docs/client/globalHelpers/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Template.registerHelper("evaluateString", function(charId, string) {
return evaluateString(charId, string);
});

Template.registerHelper("evaluateSpellString", function(charId, spellListId, string) {
return evaluateSpellString(charId, spellListId, string);
});

Template.registerHelper("evaluateShortString", function(charId, string) {
if (_.isString(string)){
return evaluateString(
Expand Down
28 changes: 28 additions & 0 deletions rpg-docs/client/lib/requestAnimationFramePolyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel

// MIT license
var lastTime = 0;
var vendors = ["ms", "moz", "webkit", "o"];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + "RequestAnimationFrame"];
window.cancelAnimationFrame = window[vendors[x] + "CancelAnimationFrame"] ||
window[vendors[x] + "CancelRequestAnimationFrame"];
}

if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
};

if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
18 changes: 10 additions & 8 deletions rpg-docs/client/views/character/effects/effectEdit/effectEdit.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,28 @@
<div class="effectEdit layout horizontal flex">
<dicecloud-selector class="statMenu flex" selected={{stat}} selectable="paper-item" style="height: 100%; overflow-y: auto;">
{{#each statGroups}}
<div style="font-weight: bold; margin-top: 16px; padding-left: 8px;">
<div class="statGroupTitle clickable" style="font-weight: bold; margin-top: 16px; padding-left: 8px;">
{{this}}
</div>
{{#each stats}}
<paper-item name={{stat}}>{{name}}</paper-item>
{{/each}}
<iron-collapse opened={{isGroupSelected this ../stat}}>
{{#each stats}}
<paper-item name={{stat}} class="clickable">{{name}}</paper-item>
{{/each}}
</iron-collapse>
{{/each}}
</dicecloud-selector>
{{#if operations}}
<dicecloud-selector class="operationMenu flex" selected={{operation}} style="height: 100%; overflow-y: auto;">
{{#each operations}}
<paper-item name={{operation}}>{{name}}</paper-item>
<paper-item name={{operation}} class="clickable">{{name}}</paper-item>
{{/each}}
</dicecloud-selector>
{{else}} {{#if showMultiplierOperations}}
<dicecloud-selector class="multiplierMenu flex"
selected={{value}}>
<paper-item name="0.5">Resistance</paper-item>
<paper-item name="2">Vulnerability</paper-item>
<paper-item name="0">Immunity</paper-item>
<paper-item name="0.5" class="clickable">Resistance</paper-item>
<paper-item name="2" class="clickable">Vulnerability</paper-item>
<paper-item name="0" class="clickable">Immunity</paper-item>
</dicecloud-selector>
{{else}}
<div class="flex" style="height: 100%;"></div>
Expand Down
82 changes: 53 additions & 29 deletions rpg-docs/client/views/character/effects/effectEdit/effectEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,47 +149,71 @@ Template.effectEdit.helpers({
effectValue: function(){
return this.calculation || this.value;
},
isGroupSelected: function(groupName, statName){
var stat = statsDict[statName]
return stat && (stat.group === groupName);
},
});

var setStat = function(statName, effectId){
var setter = {stat: statName};
var effect = Effects.findOne(this._id);
var group = statsDict[statName].group;
if (group === "Saving Throws" || group === "Skills"){
// Skills must have a valid skill operation
if (!_.contains(
_.map(skillOperations, ao => ao.operation),
effect.operation
)){
setter.operation = "add";
}
} else if (group !== "Weakness/Resistance"){
// Attributes must have a valid attribute operation
if (!_.contains(
_.map(attributeOperations, ao => ao.operation),
effect.operation
)){
setter.operation = "base";
}
} else {
// Weakness/Resistance must have a mul operation and value
if (effect.operation !== "mul"){
setter.operation = "mul";
}
if (!_.contains([0, 0.5, 2], effect.value)){
setter.value = 0.5;
}
}
Effects.update(effectId, {$set: setter});
};

var scrollAnimationId;
var scrollElementToView = element => {
var scrollFunction = function(){
element.scrollIntoView();
scrollAnimationId = requestAnimationFrame(scrollFunction);
};
return scrollFunction;
}

Template.effectEdit.events({
"click #deleteButton": function(event, instance){
Effects.softRemoveNode(instance.data.id);
GlobalUI.deletedToast(instance.data.id, "Effects", "Effect");
popDialogStack();
},
"click .statGroupTitle": function(event, instance){
var groupName = this.toString();
var firstStat = statGroups[groupName][0].stat;
setStat(firstStat, instance.data.id);
scrollAnimationId = requestAnimationFrame(scrollElementToView(event.target));
_.delay(() => cancelAnimationFrame(scrollAnimationId), 300);
},
"iron-select .statMenu": function(event){
var detail = event.originalEvent.detail;
var statName = detail.item.getAttribute("name");
if (statName == this.stat) return;
var setter = {stat: statName};
var group = Blaze.getData(detail.item).group;
var effect = Effects.findOne(this._id);
if (group === "Saving Throws" || group === "Skills"){
// Skills must have a valid skill operation
if (!_.contains(
_.map(skillOperations, ao => ao.operation),
effect.operation
)){
setter.operation = "add";
}
} else if (group !== "Weakness/Resistance"){
// Attributes must have a valid attribute operation
if (!_.contains(
_.map(attributeOperations, ao => ao.operation),
effect.operation
)){
setter.operation = "base";
}
} else {
// Weakness/Resistance must have a mul operation and value
if (effect.operation !== "mul"){
setter.operation = "mul";
}
if (!_.contains([0, 0.5, 2], effect.value)){
setter.value = 0.5;
}
}
Effects.update(this._id, {$set: setter});
setStat(statName, this._id);
},
"iron-select .operationMenu": function(event){
var detail = event.originalEvent.detail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Template.effectsEditList.events({
template: "effectEdit",
data: {id: effectId},
element: event.currentTarget,
returnElement: instance.find(`tr.effect[data-id='${effectId}']`),
returnElement: () => instance.find(`tr.effect[data-id='${effectId}']`),
});
},
"tap .edit-effect": function(event, template){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</div>
{{/if}}
</div>
<div>{{#markdown}}{{evaluateString charId description}}{{/markdown}}</div>
<div>{{#markdown}}{{evaluateSpellString charId parent.id description}}{{/markdown}}</div>
{{> attacksViewList charId=charId parentId=_id}}
</template>

Expand Down
12 changes: 12 additions & 0 deletions rpg-docs/client/views/character/stats/skillDialog/skillDialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
<td>Total</td>
<td>{{characterCalculate "skillMod" charId skillName}}</td>
</tr>
{{#each passiveEffects}}
<tr>
<td>{{sourceName}}</td>
<td>Passive Bonus: {{statValue}}</td>
</tr>
{{/each}}
{{#if showPassiveTotal}}
<tr class="paper-font-body2">
<td>Passive Score</td>
<td>{{characterCalculate "passiveSkill" charId skillName}}</td>
</tr>
{{/if}}
</table>
</div>

Expand Down
Loading

0 comments on commit 54f055d

Please sign in to comment.