Compare commits
72 Commits
2.0-beta.5
...
2.0-beta.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5c16ba83a | ||
|
|
46501f2759 | ||
|
|
a6ed1004be | ||
|
|
8539356b9e | ||
|
|
93db5e9288 | ||
|
|
b4cb91a892 | ||
|
|
9c93747845 | ||
|
|
a51154e434 | ||
|
|
1bde0db0ba | ||
|
|
bc001202ec | ||
|
|
c7985af83b | ||
|
|
0f20cd4bd9 | ||
|
|
1ac01941c7 | ||
|
|
95d8d2cb9a | ||
|
|
47345b3694 | ||
|
|
308168791b | ||
|
|
7be4280508 | ||
|
|
56f9e82326 | ||
|
|
6ddea8a8ab | ||
|
|
e1ddfb2cab | ||
|
|
d36d5b15d0 | ||
|
|
2af687361e | ||
|
|
e572807082 | ||
|
|
c44aeac198 | ||
|
|
757cf5c34b | ||
|
|
8cbfec25b3 | ||
|
|
c4dc5895aa | ||
|
|
cffe0ee574 | ||
|
|
ce51be7b8e | ||
|
|
315073bd8e | ||
|
|
50b99ef54f | ||
|
|
9b01f5fb45 | ||
|
|
389785f5db | ||
|
|
e1bfb173ab | ||
|
|
ecba587253 | ||
|
|
3f540d0f14 | ||
|
|
dc18734d1f | ||
|
|
1535e00093 | ||
|
|
5198c655e9 | ||
|
|
8d41643136 | ||
|
|
ea8d036c72 | ||
|
|
93d566e263 | ||
|
|
b4da32f9ab | ||
|
|
986fe8fd93 | ||
|
|
dd4596851e | ||
|
|
bc3fc9574a | ||
|
|
db1ae5db3d | ||
|
|
d1e7eb2fa0 | ||
|
|
efb8b87a2d | ||
|
|
b04b915c7b | ||
|
|
21b823f85c | ||
|
|
4631579181 | ||
|
|
edf3920e84 | ||
|
|
fb91fd12df | ||
|
|
19f4735412 | ||
|
|
fb2f1efa72 | ||
|
|
f7ee09470e | ||
|
|
a5c42fea19 | ||
|
|
8f81614294 | ||
|
|
c56cebc652 | ||
|
|
d24fb5661d | ||
|
|
4bdc254627 | ||
|
|
db652ac47f | ||
|
|
32c9283569 | ||
|
|
060c44f384 | ||
|
|
8138cd98f1 | ||
|
|
5195e3fad5 | ||
|
|
eb97a98644 | ||
|
|
51845c62a7 | ||
|
|
56cd48da9d | ||
|
|
298f659829 | ||
|
|
b99d1a00f5 |
@@ -50,3 +50,6 @@ akryum:vue-component
|
||||
accounts-patreon
|
||||
bozhao:link-accounts
|
||||
peerlibrary:reactive-publish
|
||||
simple:rest
|
||||
simple:rest-method-mixin
|
||||
mikowals:batch-insert
|
||||
|
||||
@@ -72,6 +72,7 @@ meteorhacks:subs-manager@1.6.4
|
||||
meteortesting:browser-tests@1.3.3
|
||||
meteortesting:mocha@1.1.5
|
||||
meteortesting:mocha-core@7.0.1
|
||||
mikowals:batch-insert@1.1.9
|
||||
minifier-css@1.5.0
|
||||
minifier-js@2.6.0
|
||||
minimongo@1.6.0
|
||||
@@ -115,6 +116,9 @@ service-configuration@1.0.11
|
||||
session@1.2.0
|
||||
sha@1.0.9
|
||||
shell-server@0.5.0
|
||||
simple:json-routes@2.1.0
|
||||
simple:rest@1.1.1
|
||||
simple:rest-method-mixin@1.0.1
|
||||
socket-stream-client@0.3.0
|
||||
spacebars@1.0.15
|
||||
spacebars-compiler@1.1.3
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
let Encounters = new Mongo.Collection("encounters");
|
||||
|
||||
let EncounterSchema = new SimpleSchema({
|
||||
//an encounter is a single flow of time all parties in an encounter are in-sync time wise
|
||||
});
|
||||
|
||||
Encounters.attachSchema(EncounterSchema);
|
||||
|
||||
export default Encounters;
|
||||
@@ -1,49 +0,0 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
let Parties = new Mongo.Collection("parties");
|
||||
|
||||
let partySchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
defaultValue: "New Party",
|
||||
trim: false,
|
||||
optional: true,
|
||||
},
|
||||
characters: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
characters: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
index: 1,
|
||||
},
|
||||
owner: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
});
|
||||
|
||||
Parties.attachSchema(partySchema);
|
||||
|
||||
Parties.allow({
|
||||
insert: function(userId, doc) {
|
||||
return userId && doc.owner === userId;
|
||||
},
|
||||
update: function(userId, doc, fields, modifier) {
|
||||
return userId && doc.owner === userId;
|
||||
},
|
||||
remove: function(userId, doc) {
|
||||
return userId && doc.owner === userId;
|
||||
},
|
||||
fetch: ["owner"],
|
||||
});
|
||||
|
||||
Parties.deny({
|
||||
update: function(userId, docs, fields, modifier) {
|
||||
// can't change owners
|
||||
return _.contains(fields, "owner");
|
||||
}
|
||||
});
|
||||
|
||||
export default Parties;
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
||||
@@ -17,6 +18,9 @@ import {
|
||||
renewDocIds
|
||||
} from '/imports/api/parenting/parenting.js';
|
||||
import {setDocToLastOrder} from '/imports/api/parenting/order.js';
|
||||
import { storedIconsSchema } from '/imports/api/icons/Icons.js';
|
||||
|
||||
import '/imports/api/creature/actions/doAction.js';
|
||||
|
||||
let CreatureProperties = new Mongo.Collection('creatureProperties');
|
||||
|
||||
@@ -36,6 +40,10 @@ let CreaturePropertySchema = new SimpleSchema({
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
icon: {
|
||||
type: storedIconsSchema,
|
||||
optional: true,
|
||||
}
|
||||
});
|
||||
|
||||
for (let key in propertySchemasIndex){
|
||||
@@ -50,7 +58,7 @@ for (let key in propertySchemasIndex){
|
||||
});
|
||||
}
|
||||
|
||||
function getCreature(property){
|
||||
export function getCreature(property){
|
||||
if (!property) throw new Meteor.Error('No property provided');
|
||||
let creature = Creatures.findOne(property.ancestors[0].id);
|
||||
if (!creature) throw new Meteor.Error('Creature does not exist');
|
||||
@@ -71,8 +79,13 @@ function recomputeCreatures(property){
|
||||
}
|
||||
|
||||
const insertProperty = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.insert',
|
||||
name: 'creatureProperties.insert',
|
||||
validate: null,
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({creatureProperty}) {
|
||||
delete creatureProperty._id;
|
||||
assertPropertyEditPermission(creatureProperty, this.userId);
|
||||
@@ -83,13 +96,18 @@ const insertProperty = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const duplicateProperty = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.duplicate',
|
||||
name: 'creatureProperties.duplicate',
|
||||
validate: new SimpleSchema({
|
||||
_id: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
}
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id}) {
|
||||
let creatureProperty = CreatureProperties.findOne(_id);
|
||||
assertPropertyEditPermission(creatureProperty, this.userId);
|
||||
@@ -100,7 +118,7 @@ const duplicateProperty = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.insertPropertyFromLibraryNode',
|
||||
name: 'creatureProperties.insertPropertyFromLibraryNode',
|
||||
validate: new SimpleSchema({
|
||||
nodeId: {
|
||||
type: String,
|
||||
@@ -110,6 +128,11 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||
type: RefSchema,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({nodeId, parentRef}) {
|
||||
// get the new ancestry for the properties
|
||||
let {parentDoc, ancestors} = getAncestry({parentRef});
|
||||
@@ -135,7 +158,7 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||
'ancestors.id': nodeId,
|
||||
removed: {$ne: true},
|
||||
}).fetch();
|
||||
// The root node is last in the array of nodes
|
||||
// The root node is last in the array of nodes
|
||||
nodes.push(node);
|
||||
|
||||
// re-map all the ancestors
|
||||
@@ -158,22 +181,21 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||
});
|
||||
|
||||
// Insert the creature properties
|
||||
let docId;
|
||||
nodes.forEach(doc => {
|
||||
docId = CreatureProperties.insert(doc);
|
||||
});
|
||||
let insertedDocIds = CreatureProperties.batchInsert(nodes);
|
||||
|
||||
// get the root inserted doc
|
||||
let rootId = insertedDocIds[insertedDocIds.length - 1];
|
||||
|
||||
// Recompute the creatures doc was attached to
|
||||
let doc = CreatureProperties.findOne(docId);
|
||||
recomputeCreatures(doc);
|
||||
recomputeCreatures(node);
|
||||
|
||||
// Return the docId of the last property, the inserted root property
|
||||
return docId;
|
||||
return rootId;
|
||||
},
|
||||
})
|
||||
|
||||
const updateProperty = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.update',
|
||||
name: 'creatureProperties.update',
|
||||
validate({_id, path}){
|
||||
if (!_id) return false;
|
||||
// We cannot change these fields with a simple update
|
||||
@@ -187,6 +209,11 @@ const updateProperty = new ValidatedMethod({
|
||||
'This property can\'t be updated directly');
|
||||
}
|
||||
},
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, path, value}) {
|
||||
let property = CreatureProperties.findOne(_id);
|
||||
assertPropertyEditPermission(property, this.userId);
|
||||
@@ -205,8 +232,39 @@ const updateProperty = new ValidatedMethod({
|
||||
},
|
||||
});
|
||||
|
||||
export function damagePropertyWork({property, operation, value}){
|
||||
if (operation === 'set'){
|
||||
let currentValue = property.value;
|
||||
// Set represents what we want the value to be after damage
|
||||
// So we need the actual damage to get to that value
|
||||
let damage = currentValue - value;
|
||||
// Damage can't exceed total value
|
||||
if (damage > currentValue) damage = currentValue;
|
||||
// Damage must be positive
|
||||
if (damage < 0) damage = 0;
|
||||
CreatureProperties.update(property._id, {
|
||||
$set: {damage}
|
||||
}, {
|
||||
selector: property
|
||||
});
|
||||
} else if (operation === 'increment'){
|
||||
let currentValue = property.value - (property.damage || 0);
|
||||
let currentDamage = property.damage;
|
||||
let increment = value;
|
||||
// Can't increase damage above the remaining value
|
||||
if (increment > currentValue) increment = currentValue;
|
||||
// Can't decrease damage below zero
|
||||
if (-increment > currentDamage) increment = -currentDamage;
|
||||
CreatureProperties.update(property._id, {
|
||||
$inc: {damage: increment}
|
||||
}, {
|
||||
selector: property
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const damageProperty = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.adjust',
|
||||
name: 'creatureProperties.damage',
|
||||
validate: new SimpleSchema({
|
||||
_id: SimpleSchema.RegEx.Id,
|
||||
operation: {
|
||||
@@ -215,6 +273,11 @@ const damageProperty = new ValidatedMethod({
|
||||
},
|
||||
value: Number,
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 20,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, operation, value}) {
|
||||
let currentProperty = CreatureProperties.findOne(_id);
|
||||
// Check permissions
|
||||
@@ -227,41 +290,108 @@ const damageProperty = new ValidatedMethod({
|
||||
`Property of type "${currentProperty.type}" can't be damaged`
|
||||
);
|
||||
}
|
||||
if (operation === 'set'){
|
||||
let currentValue = currentProperty.value;
|
||||
// Set represents what we want the value to be after damage
|
||||
// So we need the actual damage to get to that value
|
||||
let damage = currentValue - value;
|
||||
// Damage can't exceed total value
|
||||
if (damage > currentValue) damage = currentValue;
|
||||
// Damage must be positive
|
||||
if (damage < 0) damage = 0;
|
||||
CreatureProperties.update(_id, {
|
||||
$set: {damage}
|
||||
}, {
|
||||
selector: currentProperty
|
||||
});
|
||||
} else if (operation === 'increment'){
|
||||
let currentValue = currentProperty.value - (currentProperty.damage || 0);
|
||||
let currentDamage = currentProperty.damage;
|
||||
let increment = value;
|
||||
// Can't increase damage above the remaining value
|
||||
if (increment > currentValue) increment = currentValue;
|
||||
// Can't decrease damage below zero
|
||||
if (-increment > currentDamage) increment = -currentDamage;
|
||||
CreatureProperties.update(_id, {
|
||||
$inc: {damage: increment}
|
||||
}, {
|
||||
selector: currentProperty
|
||||
});
|
||||
}
|
||||
damagePropertyWork({property: currentProperty, operation, value})
|
||||
recomputeCreatures(currentProperty);
|
||||
},
|
||||
});
|
||||
|
||||
export function adjustQuantityWork({property, operation, value}){
|
||||
// Check if property has quantity
|
||||
let schema = CreatureProperties.simpleSchema(property);
|
||||
if (!schema.allowsKey('quantity')){
|
||||
throw new Meteor.Error(
|
||||
'Adjust quantity failed',
|
||||
`Property of type "${property.type}" doesn't have a quantity`
|
||||
);
|
||||
}
|
||||
if (operation === 'set'){
|
||||
CreatureProperties.update(property._id, {
|
||||
$set: {quantity: value}
|
||||
}, {
|
||||
selector: property
|
||||
});
|
||||
} else if (operation === 'increment'){
|
||||
// value here is 'damage'
|
||||
value = -value;
|
||||
let currentQuantity = property.quantity;
|
||||
if (currentQuantity + value < 0) value = -currentQuantity;
|
||||
CreatureProperties.update(property._id, {
|
||||
$inc: {quantity: value}
|
||||
}, {
|
||||
selector: property
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const adjustQuantity = new ValidatedMethod({
|
||||
name: 'creatureProperties.adjustQuantity',
|
||||
validate: new SimpleSchema({
|
||||
_id: SimpleSchema.RegEx.Id,
|
||||
operation: {
|
||||
type: String,
|
||||
allowedValues: ['set', 'increment']
|
||||
},
|
||||
value: Number,
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, operation, value}) {
|
||||
let currentProperty = CreatureProperties.findOne(_id);
|
||||
// Check permissions
|
||||
assertPropertyEditPermission(currentProperty, this.userId);
|
||||
adjustQuantityWork({property: currentProperty, operation, value});
|
||||
recomputeCreatures(currentProperty);
|
||||
},
|
||||
});
|
||||
|
||||
const selectAmmoItem = new ValidatedMethod({
|
||||
name: 'creatureProperties.selectAmmoItem',
|
||||
validate: new SimpleSchema({
|
||||
actionId: SimpleSchema.RegEx.Id,
|
||||
itemId: SimpleSchema.RegEx.Id,
|
||||
itemConsumedIndex: Number,
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({actionId, itemId, itemConsumedIndex}) {
|
||||
let action = CreatureProperties.findOne(actionId);
|
||||
// Check permissions
|
||||
assertPropertyEditPermission(action, this.userId);
|
||||
// Check that this index has a document to edit
|
||||
let itemConsumed = action.resources.itemsConsumed[itemConsumedIndex];
|
||||
if (!itemConsumed){
|
||||
throw new Meteor.Error('Resouce not found',
|
||||
'Could not set ammo, because the ammo document was not found');
|
||||
}
|
||||
let itemToLink = CreatureProperties.findOne(itemId);
|
||||
if (!itemToLink){
|
||||
throw new Meteor.Error('Item not found',
|
||||
'Could not set ammo: the item was not found');
|
||||
}
|
||||
let path = `resources.itemsConsumed.${itemConsumedIndex}.itemId`;
|
||||
CreatureProperties.update(actionId, {
|
||||
$set: {[path]: itemId}
|
||||
}, {
|
||||
selector: action,
|
||||
});
|
||||
recomputeCreatures(action);
|
||||
},
|
||||
});
|
||||
|
||||
const pushToProperty = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.push',
|
||||
name: 'creatureProperties.push',
|
||||
validate: null,
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, path, value}){
|
||||
let property = CreatureProperties.findOne(_id);
|
||||
assertPropertyEditPermission(property, this.userId);
|
||||
@@ -275,8 +405,13 @@ const pushToProperty = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const pullFromProperty = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.pull',
|
||||
name: 'creatureProperties.pull',
|
||||
validate: null,
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, path, itemId}){
|
||||
let property = CreatureProperties.findOne(_id);
|
||||
assertPropertyEditPermission(property, this.userId);
|
||||
@@ -291,10 +426,15 @@ const pullFromProperty = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const softRemoveProperty = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.softRemove',
|
||||
name: 'creatureProperties.softRemove',
|
||||
validate: new SimpleSchema({
|
||||
_id: SimpleSchema.RegEx.Id
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id}){
|
||||
let property = CreatureProperties.findOne(_id);
|
||||
assertPropertyEditPermission(property, this.userId);
|
||||
@@ -312,6 +452,8 @@ export {
|
||||
insertPropertyFromLibraryNode,
|
||||
updateProperty,
|
||||
damageProperty,
|
||||
adjustQuantity,
|
||||
selectAmmoItem,
|
||||
pushToProperty,
|
||||
pullFromProperty,
|
||||
softRemoveProperty,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import deathSaveSchema from '/imports/api/properties/subSchemas/DeathSavesSchema.js'
|
||||
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
||||
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
||||
import {assertEditPermission} from '/imports/api/sharing/sharingPermissions.js';
|
||||
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||
import { assertUserHasPaidBenefits } from '/imports/api/users/patreon/tiers.js';
|
||||
|
||||
import '/imports/api/creature/removeCreature.js';
|
||||
import '/imports/api/creature/restCreature.js';
|
||||
@@ -65,24 +66,31 @@ let CreatureSchema = new SimpleSchema({
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
|
||||
// Mechanics
|
||||
deathSave: {
|
||||
type: deathSaveSchema,
|
||||
defaultValue: {},
|
||||
},
|
||||
xp: {
|
||||
// Stats that are computed and denormalised outside of recomputation
|
||||
denormalizedStats: {
|
||||
type: Object,
|
||||
defaultValue: {},
|
||||
},
|
||||
// Sum of all XP gained by this character
|
||||
'denormalizedStats.xp': {
|
||||
type: SimpleSchema.Integer,
|
||||
defaultValue: 0,
|
||||
},
|
||||
weightCarried: {
|
||||
// Sum of all levels granted by milestone XP
|
||||
'denormalizedStats.milestoneLevels': {
|
||||
type: SimpleSchema.Integer,
|
||||
defaultValue: 0,
|
||||
},
|
||||
// Sum of all weights of items and containers that are carried
|
||||
'denormalizedStats.weightCarried': {
|
||||
type: Number,
|
||||
defaultValue: 0,
|
||||
},
|
||||
level: {
|
||||
type: SimpleSchema.Integer,
|
||||
defaultValue: 0,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
defaultValue: 'pc',
|
||||
@@ -99,6 +107,17 @@ let CreatureSchema = new SimpleSchema({
|
||||
defaultValue: {}
|
||||
},
|
||||
|
||||
// Tabletop
|
||||
tabletop: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
optional: true,
|
||||
},
|
||||
initiativeRoll: {
|
||||
type: SimpleSchema.Integer,
|
||||
optional: true,
|
||||
},
|
||||
|
||||
// Settings
|
||||
settings: {
|
||||
type: CreatureSettingsSchema,
|
||||
@@ -113,20 +132,22 @@ Creatures.attachSchema(CreatureSchema);
|
||||
|
||||
const insertCreature = new ValidatedMethod({
|
||||
|
||||
name: 'Creatures.methods.insertCreature',
|
||||
name: 'creatures.insertCreature',
|
||||
|
||||
validate: null,
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run() {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('Creatures.methods.insert.denied',
|
||||
'You need to be logged in to insert a creature');
|
||||
}
|
||||
let tier = getUserTier(this.userId);
|
||||
if (!tier.paidBenefits){
|
||||
throw new Meteor.Error('Creatures.methods.insert.denied',
|
||||
`The ${tier.name} tier does not allow you to insert a creature`);
|
||||
}
|
||||
assertUserHasPaidBenefits(this.userId);
|
||||
|
||||
// Create the creature document
|
||||
let charId = Creatures.insert({
|
||||
@@ -139,22 +160,41 @@ const insertCreature = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const updateCreature = new ValidatedMethod({
|
||||
name: 'Creatures.methods.update',
|
||||
name: 'creatures.update',
|
||||
validate({_id, path}){
|
||||
if (!_id) return false;
|
||||
// Allowed fields
|
||||
let allowedFields = ['name', 'alignment', 'gender', 'picture', 'avatarPicture', 'settings'];
|
||||
let allowedFields = [
|
||||
'name',
|
||||
'alignment',
|
||||
'gender',
|
||||
'picture',
|
||||
'avatarPicture',
|
||||
'color',
|
||||
'settings',
|
||||
];
|
||||
if (!allowedFields.includes(path[0])){
|
||||
throw new Meteor.Error('Creatures.methods.update.denied',
|
||||
'This field can\'t be updated using this method');
|
||||
}
|
||||
},
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, path, value}) {
|
||||
let creature = Creatures.findOne(_id);
|
||||
assertEditPermission(creature, this.userId);
|
||||
Creatures.update(_id, {
|
||||
$set: {[path.join('.')]: value},
|
||||
});
|
||||
if (value === undefined || value === null){
|
||||
Creatures.update(_id, {
|
||||
$unset: {[path.join('.')]: 1},
|
||||
});
|
||||
} else {
|
||||
Creatures.update(_id, {
|
||||
$set: {[path.join('.')]: value},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
28
app/imports/api/creature/Parties.js
Normal file
28
app/imports/api/creature/Parties.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
let Parties = new Mongo.Collection('parties');
|
||||
|
||||
let partySchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
defaultValue: 'New Party',
|
||||
trim: false,
|
||||
optional: true,
|
||||
},
|
||||
creatures: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'creatures.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
owner: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
});
|
||||
|
||||
Parties.attachSchema(partySchema);
|
||||
|
||||
export default Parties;
|
||||
5
app/imports/api/creature/actions/applyAction.js
Normal file
5
app/imports/api/creature/actions/applyAction.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import spendResources from '/imports/api/creature/actions/spendResources.js'
|
||||
|
||||
export default function applyAction({prop}){
|
||||
spendResources(prop);
|
||||
}
|
||||
21
app/imports/api/creature/actions/applyAttack.js
Normal file
21
app/imports/api/creature/actions/applyAttack.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import math from '/imports/math.js';
|
||||
//if (Meteor.isServer){
|
||||
// var sendWebhook = require('/imports/server/discord/webhook.js').default;
|
||||
//}
|
||||
|
||||
export default function applyAttack({
|
||||
prop,
|
||||
//children,
|
||||
creature,
|
||||
//targets,
|
||||
//actionContext
|
||||
}){
|
||||
let result = math.roll(1, 20) + prop.rollBonusResult;
|
||||
if (Meteor.isClient){
|
||||
console.log(`${creature.name} makes a ${prop.name} attack! Rolls ${result} to hit`);
|
||||
}
|
||||
//if (Meteor.isServer) sendWebhook({
|
||||
// webhook: creature.webhook,
|
||||
// message: `${creature.name} makes a ${prop.name} attack! Rolls ${result} to hit`,
|
||||
//});
|
||||
}
|
||||
61
app/imports/api/creature/actions/applyBuff.js
Normal file
61
app/imports/api/creature/actions/applyBuff.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import {
|
||||
setLineageOfDocs,
|
||||
renewDocIds
|
||||
} from '/imports/api/parenting/parenting.js';
|
||||
import {setDocToLastOrder} from '/imports/api/parenting/order.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
|
||||
export default function applyBuff({
|
||||
prop,
|
||||
children,
|
||||
creature,
|
||||
targets = [],
|
||||
//actionContext,
|
||||
}){
|
||||
let buffTargets = prop.target === 'self' ? [creature] : targets;
|
||||
|
||||
//let scope = {
|
||||
// ...creature.variables,
|
||||
// ...actionContext,
|
||||
//};
|
||||
|
||||
// TODO
|
||||
// If the target is not self, walk through all decendants and replace
|
||||
// variables in calculations with their values from the creature scope
|
||||
// If the target is self, replace all the target.x references with just x
|
||||
|
||||
// Then copy the decendants of the buff to the targets
|
||||
prop.applied = true;
|
||||
let propList = [prop];
|
||||
function addChildrenToPropList(children){
|
||||
children.forEach(child => {
|
||||
propList.push(child.node);
|
||||
addChildrenToPropList(child.children);
|
||||
});
|
||||
}
|
||||
addChildrenToPropList(children);
|
||||
let oldParent = {
|
||||
id: prop.parent.id,
|
||||
collection: prop.parent.collection,
|
||||
};
|
||||
buffTargets.forEach(target => {
|
||||
copyNodeListToTarget(propList, target, oldParent);
|
||||
});
|
||||
}
|
||||
|
||||
function copyNodeListToTarget(propList, target, oldParent){
|
||||
let ancestry = [{collection: 'creatures', id: target._id}];
|
||||
setLineageOfDocs({
|
||||
docArray: propList,
|
||||
newAncestry: ancestry,
|
||||
oldParent,
|
||||
});
|
||||
renewDocIds({
|
||||
docArray: propList,
|
||||
});
|
||||
setDocToLastOrder({
|
||||
collection: CreatureProperties,
|
||||
doc: propList[0],
|
||||
});
|
||||
CreatureProperties.batchInsert(propList);
|
||||
}
|
||||
27
app/imports/api/creature/actions/applyDamage.js
Normal file
27
app/imports/api/creature/actions/applyDamage.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import evaluateAndRollString from '/imports/api/creature/computation/afterComputation/evaluateAndRollString.js';
|
||||
|
||||
//if (Meteor.isServer){
|
||||
// var sendWebhook = require('/imports/server/discord/webhook.js').default;
|
||||
//}
|
||||
|
||||
export default function applyDamage({
|
||||
prop,
|
||||
creature,
|
||||
//targets,
|
||||
actionContext
|
||||
}){
|
||||
//let damageTargets = prop.target === 'self' ? [creature] : targets;
|
||||
let scope = {
|
||||
...creature.variables,
|
||||
...actionContext,
|
||||
};
|
||||
let {result, errors} = evaluateAndRollString(prop.amount, scope);
|
||||
if (Meteor.isClient){
|
||||
errors.forEach(e => console.error(e));
|
||||
console.log(`${result} ${prop.damageType}${prop.damageType !== 'healing'? ' damage': ''}`);
|
||||
}
|
||||
//if (Meteor.isServer) sendWebhook({
|
||||
// webhook: creature.webhook,
|
||||
// message: `${result} ${prop.damageType}${prop.damageType !== 'healing'? ' damage': ''}`,
|
||||
//});
|
||||
}
|
||||
66
app/imports/api/creature/actions/applyProperties.js
Normal file
66
app/imports/api/creature/actions/applyProperties.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import applyAction from '/imports/api/creature/actions/applyAction.js';
|
||||
import applyAttack from '/imports/api/creature/actions/applyAttack.js';
|
||||
import applyDamage from '/imports/api/creature/actions/applyDamage.js';
|
||||
import applyBuff from '/imports/api/creature/actions/applyBuff.js';
|
||||
|
||||
function applyProperty(options){
|
||||
let prop = options.prop;
|
||||
if (
|
||||
prop.disabled === true || // ignore disabled props
|
||||
prop.equipped === false || // ignore unequipped items
|
||||
prop.toggleResult === false || // ignore untoggled toggles
|
||||
prop.applied === true // ignore buffs that are already applied
|
||||
){
|
||||
return false;
|
||||
}
|
||||
switch (prop.type){
|
||||
case 'action':
|
||||
case 'spell':
|
||||
applyAction(options);
|
||||
return true;
|
||||
case 'attack':
|
||||
applyAttack(options);
|
||||
applyAction(options);
|
||||
return true;
|
||||
case 'damage':
|
||||
applyDamage(options);
|
||||
return true;
|
||||
case 'adjustment':
|
||||
// applyAdjustment(options);
|
||||
return true;
|
||||
case 'buff':
|
||||
applyBuff(options);
|
||||
return false;
|
||||
case 'roll':
|
||||
// applyRoll(options);
|
||||
return true;
|
||||
case 'savingThrow':
|
||||
// applySavingThrow(options);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default function applyProperties({
|
||||
forest,
|
||||
creature,
|
||||
targets,
|
||||
actionContext
|
||||
}){
|
||||
forest.forEach(child => {
|
||||
let walkChildren = applyProperty({
|
||||
prop: child.node,
|
||||
children: child.children,
|
||||
creature,
|
||||
targets,
|
||||
actionContext
|
||||
});
|
||||
if (walkChildren){
|
||||
applyProperties({
|
||||
forest: child.children,
|
||||
creature,
|
||||
targets,
|
||||
actionContext
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
62
app/imports/api/creature/actions/doAction.js
Normal file
62
app/imports/api/creature/actions/doAction.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import CreatureProperties, { getCreature } from '/imports/api/creature/CreatureProperties.js';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||
import { nodesToTree } from '/imports/api/parenting/parenting.js';
|
||||
import applyProperties from '/imports/api/creature/actions/applyProperties.js';
|
||||
|
||||
const doAction = new ValidatedMethod({
|
||||
name: 'creatureProperties.doAction',
|
||||
validate: new SimpleSchema({
|
||||
actionId: SimpleSchema.RegEx.Id,
|
||||
targetId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 10,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({actionId, targetId}) {
|
||||
let action = CreatureProperties.findOne(actionId);
|
||||
// Check permissions
|
||||
let creature = getCreature(action);
|
||||
assertEditPermission(creature, this.userId);
|
||||
let target = undefined;
|
||||
if (targetId) {
|
||||
target = getCreature(targetId);
|
||||
assertEditPermission(target, this.userId);
|
||||
}
|
||||
doActionWork({action, creature, target});
|
||||
// Note this only recomputes the top-level creature, not the nearest one
|
||||
recomputeCreatureByDoc(creature);
|
||||
if (target){
|
||||
recomputeCreatureByDoc(target);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function doActionWork({action, creature, target}){
|
||||
let actionContext = {};
|
||||
let decendantForest = nodesToTree({
|
||||
collection: CreatureProperties,
|
||||
ancestorId: action._id,
|
||||
});
|
||||
let startingForest = [{
|
||||
node: action,
|
||||
children: decendantForest,
|
||||
}];
|
||||
applyProperties({
|
||||
forest: startingForest,
|
||||
creature,
|
||||
target,
|
||||
actionContext
|
||||
});
|
||||
}
|
||||
|
||||
export default doAction;
|
||||
57
app/imports/api/creature/actions/spendResources.js
Normal file
57
app/imports/api/creature/actions/spendResources.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import CreatureProperties, { damagePropertyWork, adjustQuantityWork } from '/imports/api/creature/CreatureProperties.js';
|
||||
|
||||
export default function spendResources(action){
|
||||
// Check Uses
|
||||
if (action.usesUsed >= action.usesResult){
|
||||
throw new Meteor.Error('Insufficient Uses',
|
||||
'This action has no uses left');
|
||||
}
|
||||
// Resources
|
||||
if (action.insufficientResources){
|
||||
throw new Meteor.Error('Insufficient Resources',
|
||||
'This creature doesn\'t have sufficient resources to perform this action');
|
||||
}
|
||||
// Items
|
||||
let itemQuantityAdjustments = [];
|
||||
action.resources.itemsConsumed.forEach(itemConsumed => {
|
||||
if (!itemConsumed.itemId){
|
||||
throw new Meteor.Error('Ammo not selected',
|
||||
'No ammo was selected for this action');
|
||||
}
|
||||
let item = CreatureProperties.findOne(itemConsumed.itemId);
|
||||
if (!item || item.ancestors[0].id !== action.ancestors[0].id){
|
||||
throw new Meteor.Error('Ammo not found',
|
||||
'The action\'s ammo was not found on the creature');
|
||||
}
|
||||
if (!item.equipped){
|
||||
throw new Meteor.Error('Ammo not equipped',
|
||||
'The selected ammo is not equipped');
|
||||
}
|
||||
if (!itemConsumed.quantity) return;
|
||||
itemQuantityAdjustments.push({
|
||||
property: item,
|
||||
operation: 'increment',
|
||||
value: itemConsumed.quantity,
|
||||
});
|
||||
});
|
||||
// No more errors should be thrown after this line
|
||||
// Now that we have confirmed that there are no errors, do actual work
|
||||
//Items
|
||||
itemQuantityAdjustments.forEach(adjustQuantityWork);
|
||||
// Use uses
|
||||
CreatureProperties.update(action._id, {
|
||||
$inc: {usesUsed: 1}
|
||||
}, {
|
||||
selector: action
|
||||
});
|
||||
// Damage stats
|
||||
action.resources.attributesConsumed.forEach(attConsumed => {
|
||||
if (!attConsumed.quantity) return;
|
||||
let stat = CreatureProperties.findOne(attConsumed.statId);
|
||||
damagePropertyWork({
|
||||
property: stat,
|
||||
operation: 'increment',
|
||||
value: attConsumed.quantity,
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { includes, cloneDeep } from 'lodash';
|
||||
// The computation memo is an in-memory data structure used only during the
|
||||
// computation process
|
||||
export default class ComputationMemo {
|
||||
constructor(props){
|
||||
constructor(props, creature){
|
||||
this.statsByVariableName = {};
|
||||
this.extraStatsByVariableName = {};
|
||||
this.statsById = {};
|
||||
@@ -15,6 +15,10 @@ export default class ComputationMemo {
|
||||
this.classes = {};
|
||||
this.togglesById = {};
|
||||
this.toggleIds = new Set();
|
||||
// Equipped items that might be used as ammo
|
||||
this.equipmentById = {};
|
||||
// Properties that have calculations, but don't impact other properties
|
||||
this.endStepPropsById = {};
|
||||
// First note all the ids of all the toggles
|
||||
props.forEach((prop) => {
|
||||
if (
|
||||
@@ -38,6 +42,10 @@ export default class ComputationMemo {
|
||||
) {
|
||||
// Add all the stats
|
||||
this.addStat(prop);
|
||||
} else if (
|
||||
prop.type === 'item'
|
||||
) {
|
||||
this.addEquipment(prop);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
@@ -49,8 +57,19 @@ export default class ComputationMemo {
|
||||
this.addProficiency(prop);
|
||||
} else if (prop.type === 'classLevel'){
|
||||
this.addClassLevel(prop);
|
||||
} else {
|
||||
this.addEndStepProp(prop);
|
||||
}
|
||||
});
|
||||
for (let name in creature.denormalizedStats){
|
||||
if (!this.statsByVariableName[name]){
|
||||
this.statsByVariableName[name] = {
|
||||
variableName: name,
|
||||
value: creature.denormalizedStats[name],
|
||||
computationDetails: propDetailsByType.denormalizedStat(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
registerProperty(prop){
|
||||
this.originalPropsById[prop._id] = cloneDeep(prop);
|
||||
@@ -172,6 +191,14 @@ export default class ComputationMemo {
|
||||
});
|
||||
return targets;
|
||||
}
|
||||
addEquipment(prop){
|
||||
prop = this.registerProperty(prop);
|
||||
this.equipmentById[prop._id] = prop;
|
||||
}
|
||||
addEndStepProp(prop){
|
||||
prop = this.registerProperty(prop);
|
||||
this.endStepPropsById[prop._id] = prop;
|
||||
}
|
||||
}
|
||||
|
||||
function isAbility(prop){
|
||||
@@ -197,10 +224,17 @@ function isSkillOperation(prop){
|
||||
}
|
||||
|
||||
function propDetails(prop){
|
||||
return propDetailsByType[prop.type]() || {};
|
||||
return propDetailsByType[prop.type] && propDetailsByType[prop.type]() ||
|
||||
propDetailsByType.default();
|
||||
}
|
||||
|
||||
const propDetailsByType = {
|
||||
default(){
|
||||
return {
|
||||
toggleAncestors: [],
|
||||
disabledByToggle: false,
|
||||
};
|
||||
},
|
||||
toggle(){
|
||||
return {
|
||||
computed: false,
|
||||
@@ -251,4 +285,10 @@ const propDetailsByType = {
|
||||
disabledByToggle: false,
|
||||
};
|
||||
},
|
||||
denormalizedStat(){
|
||||
return {
|
||||
toggleAncestors: [],
|
||||
disabledByToggle: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import math from '/imports/math.js';
|
||||
import bareSymbolSubtitutor from '/imports/api/creature/computation/utility/bareSymbolSubtitutor.js';
|
||||
import substituteRollsWithFunctions from '/imports/api/creature/computation/afterComputation/substituteRollsWithFunctions.js'
|
||||
|
||||
export default function evaluateAndRollString(string, scope){
|
||||
let errors = [];
|
||||
if (!string){
|
||||
errors.push('No string provided');
|
||||
return {result: string, errors};
|
||||
}
|
||||
|
||||
if (!scope) errors.push('No scope provided');
|
||||
|
||||
// Parse the string using mathjs
|
||||
let calc;
|
||||
try {
|
||||
calc = math.parse(string);
|
||||
} catch (e) {
|
||||
errors.push(e);
|
||||
return {result: string, errors};
|
||||
}
|
||||
|
||||
// Replace all bare symbols with symbol.value
|
||||
let transformedCalc = calc.transform(bareSymbolSubtitutor(scope));
|
||||
// Replace all rolls with the function to call them
|
||||
transformedCalc = calc.transform(substituteRollsWithFunctions);
|
||||
|
||||
// Evaluate the expression to a number or return with substitutions
|
||||
try {
|
||||
let result = transformedCalc.evaluate(scope);
|
||||
return {result, errors};
|
||||
} catch (e1){
|
||||
errors.push(e1);
|
||||
try {
|
||||
let result = simplifyWithAccessors(transformedCalc, scope).toHTML();
|
||||
return {result, errors};
|
||||
} catch (e2){
|
||||
errors.push(e2);
|
||||
return {result: transformedCalc.toHTML(), errors};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function simplifyWithAccessors(calc, scope){
|
||||
let noAccessorCalc = calc.transform(substituteAccessors(scope));
|
||||
return math.simplify(noAccessorCalc);
|
||||
}
|
||||
|
||||
// returns a function to replace all accessors with either their resolved value
|
||||
// or a symbol to simplify with
|
||||
function substituteAccessors(scope){
|
||||
return function(node){
|
||||
if (node.isAccessorNode){
|
||||
try {
|
||||
return evaluateAccessor(node, scope);
|
||||
} catch (e) {
|
||||
return replaceAccessorWithSymbol(node);
|
||||
}
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Throws error if symbol is undefined in scope
|
||||
function evaluateAccessor(node, scope){
|
||||
let value = node.evaluate(scope);
|
||||
if (value === undefined){
|
||||
throw 'Undefined symbol'
|
||||
}
|
||||
return new math.ConstantNode(value);
|
||||
}
|
||||
|
||||
function replaceAccessorWithSymbol(node){
|
||||
let symbolNode = new math.SymbolNode(node.toString());
|
||||
return symbolNode;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import math from '/imports/math.js';
|
||||
|
||||
const diceRegex = /d\d+/;
|
||||
|
||||
export default function substituteRollsWithFunctions(node){
|
||||
// TODO also replace dx as 1dx
|
||||
if (
|
||||
node.isOperatorNode &&
|
||||
node.fn === 'multiply' &&
|
||||
node.implicit &&
|
||||
node.args[1].isSymbolNode &&
|
||||
diceRegex.test(node.args[1].name)
|
||||
){
|
||||
let diceSize = node.args[1].name.slice(1);
|
||||
let diceSizeNode = new math.ConstantNode(diceSize);
|
||||
return new math.FunctionNode('roll', [node.args[0], diceSizeNode]);
|
||||
} else if (
|
||||
node.isSymbolNode &&
|
||||
diceRegex.test(node.name)
|
||||
) {
|
||||
let diceSize = node.name.slice(1);
|
||||
let diceSizeNode = new math.ConstantNode(diceSize);
|
||||
let diceNumberNode = new math.ConstantNode(1);
|
||||
return new math.FunctionNode('roll', [diceNumberNode, diceSizeNode]);
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import computeStat from '/imports/api/creature/computation/computeStat.js';
|
||||
import applyToggles from '/imports/api/creature/computation/applyToggles.js';
|
||||
import evaluateCalculation from '/imports/api/creature/computation/evaluateCalculation.js';
|
||||
|
||||
export default function combineStat(stat, aggregator, memo){
|
||||
if (stat.type === 'attribute'){
|
||||
combineAttribute(stat, aggregator);
|
||||
combineAttribute(stat, aggregator, memo);
|
||||
} else if (stat.type === 'skill'){
|
||||
combineSkill(stat, aggregator, memo);
|
||||
} else if (stat.type === 'damageMultiplier'){
|
||||
@@ -28,13 +29,18 @@ function getAggregatorResult(stat, aggregator){
|
||||
return result;
|
||||
}
|
||||
|
||||
function combineAttribute(stat, aggregator){
|
||||
function combineAttribute(stat, aggregator, memo){
|
||||
stat.value = getAggregatorResult(stat, aggregator);
|
||||
stat.baseValue = aggregator.statBaseValue;
|
||||
stat.baseValueErrors = aggregator.baseValueErrors;
|
||||
if (stat.attributeType === 'ability') {
|
||||
stat.modifier = Math.floor((stat.value - 10) / 2);
|
||||
}
|
||||
if (stat.attributeType === 'spellSlot'){
|
||||
let {value, errors} = evaluateCalculation(stat.spellSlotLevelCalculation, memo);
|
||||
stat.spellSlotLevelValue = value,
|
||||
stat.spellSlotLevelErrors = errors;
|
||||
}
|
||||
stat.currentValue = stat.value - (stat.damage || 0);
|
||||
stat.hide = aggregator.hasNoEffects &&
|
||||
stat.baseValue === undefined ||
|
||||
@@ -72,8 +78,11 @@ function combineSkill(stat, aggregator, memo){
|
||||
}
|
||||
// Multiply the proficiency bonus by the actual proficiency
|
||||
profBonus *= stat.proficiency;
|
||||
// Base value
|
||||
stat.baseValue = aggregator.statBaseValue;
|
||||
stat.baseValueErrors = aggregator.baseValueErrors;
|
||||
// Combine everything to get the final result
|
||||
let result = (stat.abilityMod + profBonus + aggregator.add) * aggregator.mul;
|
||||
let result = (aggregator.base + stat.abilityMod + profBonus + aggregator.add) * aggregator.mul;
|
||||
if (result < aggregator.min) result = aggregator.min;
|
||||
if (result > aggregator.max) result = aggregator.max;
|
||||
if (aggregator.set !== undefined) {
|
||||
@@ -103,6 +112,7 @@ function combineSkill(stat, aggregator, memo){
|
||||
stat.rollBonuses = aggregator.rollBonus;
|
||||
// Hide
|
||||
stat.hide = aggregator.hasNoEffects &&
|
||||
stat.baseValue === undefined &&
|
||||
stat.proficiency == 0 ||
|
||||
undefined;
|
||||
}
|
||||
|
||||
108
app/imports/api/creature/computation/computeEndStepProperty.js
Normal file
108
app/imports/api/creature/computation/computeEndStepProperty.js
Normal file
@@ -0,0 +1,108 @@
|
||||
import evaluateCalculation from '/imports/api/creature/computation/evaluateCalculation.js';
|
||||
|
||||
export default function computeEndStepProperty(prop, memo){
|
||||
switch (prop.type){
|
||||
case 'action':
|
||||
case 'spell':
|
||||
computeAction(prop, memo);
|
||||
break;
|
||||
case 'attack':
|
||||
computeAction(prop, memo);
|
||||
computeAttack(prop, memo);
|
||||
break;
|
||||
case 'savingThrow':
|
||||
computeSavingThrow(prop, memo);
|
||||
break;
|
||||
case 'spellList':
|
||||
computeSpellList(prop, memo);
|
||||
break;
|
||||
case 'propertySlot':
|
||||
computeSlot(prop, memo);
|
||||
}
|
||||
}
|
||||
|
||||
function computeAction(prop, memo){
|
||||
// Uses
|
||||
let {value, errors} = evaluateCalculation(prop.uses, memo);
|
||||
prop.usesResult = value;
|
||||
if (errors.length){
|
||||
prop.usesErrors = errors;
|
||||
} else {
|
||||
delete prop.usesErrors;
|
||||
}
|
||||
prop.insufficientResources = undefined;
|
||||
if (prop.usesUsed >= prop.usesResult){
|
||||
prop.insufficientResources = true;
|
||||
}
|
||||
// Attributes consumed
|
||||
prop.resources.attributesConsumed.forEach((attConsumed, i) => {
|
||||
if (attConsumed.variableName){
|
||||
let stat = memo.statsByVariableName[attConsumed.variableName];
|
||||
prop.resources.attributesConsumed[i].statId = stat && stat._id;
|
||||
prop.resources.attributesConsumed[i].statName = stat && stat.name;
|
||||
let available = stat && stat.currentValue || 0;
|
||||
prop.resources.attributesConsumed[i].available = available;
|
||||
if (available < attConsumed.quantity){
|
||||
prop.insufficientResources = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
// Items consumed
|
||||
prop.resources.itemsConsumed.forEach((itemConsumed, i) => {
|
||||
let item = itemConsumed.itemId && memo.equipmentById[itemConsumed.itemId];
|
||||
prop.resources.itemsConsumed[i].itemId = item && item._id;
|
||||
let available = item && item.quantity || 0;
|
||||
prop.resources.itemsConsumed[i].available = available;
|
||||
let name = item && item.name;
|
||||
if (item && item.quantity !== 1 && item.plural){
|
||||
name = item.plural;
|
||||
}
|
||||
prop.resources.itemsConsumed[i].itemName = name;
|
||||
prop.resources.itemsConsumed[i].itemIcon = item && item.icon;
|
||||
prop.resources.itemsConsumed[i].itemColor = item && item.color;
|
||||
if (!item || available < itemConsumed.quantity){
|
||||
prop.insufficientResources = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function computeAttack(prop, memo){
|
||||
// Roll bonus
|
||||
let {value, errors} = evaluateCalculation(prop.rollBonus, memo);
|
||||
prop.rollBonusResult = value;
|
||||
if (errors.length){
|
||||
prop.rollBonusErrors = errors;
|
||||
} else {
|
||||
delete prop.rollBonusErrors;
|
||||
}
|
||||
}
|
||||
|
||||
function computeSavingThrow(prop, memo){
|
||||
let {value, errors} = evaluateCalculation(prop.dc, memo);
|
||||
prop.dcResult = value;
|
||||
if (errors.length){
|
||||
prop.dcErrors = errors;
|
||||
} else {
|
||||
delete prop.dcErrors;
|
||||
}
|
||||
}
|
||||
|
||||
function computeSpellList(prop, memo){
|
||||
let {value, errors} = evaluateCalculation(prop.maxPrepared, memo);
|
||||
prop.maxPreparedResult = value;
|
||||
if (errors.length){
|
||||
prop.maxPreparedErrors = errors;
|
||||
} else {
|
||||
delete prop.maxPreparedErrors;
|
||||
}
|
||||
}
|
||||
|
||||
function computeSlot(prop, memo){
|
||||
let {value, errors} = evaluateCalculation(prop.slotCondition, memo);
|
||||
prop.slotConditionResult = value;
|
||||
if (errors.length){
|
||||
prop.slotConditionErrors = errors;
|
||||
} else {
|
||||
delete prop.slotConditionErrors;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import computeLevels from '/imports/api/creature/computation/computeLevels.js';
|
||||
import computeStat from '/imports/api/creature/computation/computeStat.js';
|
||||
import computeEffect from '/imports/api/creature/computation/computeEffect.js';
|
||||
import computeToggle from '/imports/api/creature/computation/computeToggle.js';
|
||||
import computeEndStepProperty from '/imports/api/creature/computation/computeEndStepProperty.js';
|
||||
|
||||
export default function computeMemo(memo){
|
||||
// Compute level
|
||||
@@ -15,8 +16,12 @@ export default function computeMemo(memo){
|
||||
each(memo.unassignedEffects, effect => {
|
||||
computeEffect(effect, memo);
|
||||
});
|
||||
// Compute toggles which didn't already get computed by dependencies
|
||||
forOwn(memo.togglesById, toggle => {
|
||||
computeToggle(toggle, memo);
|
||||
});
|
||||
// Compute class levels
|
||||
// Compute end step properties
|
||||
forOwn(memo.endStepPropsById, prop => {
|
||||
computeEndStepProperty(prop, memo);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import math from '/imports/math.js';
|
||||
|
||||
/* Convert a calculation into a constant output and errors*/
|
||||
export default function evaluateCalculation(string, memo){
|
||||
if (!string) return string;
|
||||
if (!string) return {errors: [], value: string};
|
||||
let errors = [];
|
||||
// Parse the string using mathjs
|
||||
let calc;
|
||||
@@ -79,7 +79,7 @@ function symbolSubtitutor(scope, errors){
|
||||
return new math.ConstantNode(0);
|
||||
}
|
||||
}
|
||||
} else if (node.isAccessorNode){
|
||||
} else if (node.isAccessorNode && node.object.isSymbolNode){
|
||||
try {
|
||||
let value = node.evaluate(scope);
|
||||
if (value === undefined) throw 'Not found';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import ComputationMemo from '/imports/api/creature/computation/ComputationMemo.js';
|
||||
@@ -6,19 +7,27 @@ import computeMemo from '/imports/api/creature/computation/computeMemo.js';
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
import writeAlteredProperties from '/imports/api/creature/computation/writeAlteredProperties.js';
|
||||
import writeCreatureVariables from '/imports/api/creature/computation/writeCreatureVariables.js';
|
||||
import { recomputeDamageMultipliersById } from '/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js'
|
||||
import { recomputeDamageMultipliersById } from '/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
|
||||
export const recomputeCreature = new ValidatedMethod({
|
||||
|
||||
name: 'Creatures.methods.recomputeCreature',
|
||||
name: 'creatures.recomputeCreature',
|
||||
|
||||
validate: new SimpleSchema({
|
||||
charId: { type: String }
|
||||
}).validator(),
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run({charId}) {
|
||||
let creature = Creatures.findOne(charId);
|
||||
// Permission
|
||||
assertEditPermission(charId, this.userId);
|
||||
assertEditPermission(creature, this.userId);
|
||||
// Work, call this direcly if you are already in a method that has checked
|
||||
// for permission to edit a given character
|
||||
recomputeCreatureById(charId);
|
||||
@@ -33,8 +42,21 @@ const calculationPropertyTypes = [
|
||||
'proficiency',
|
||||
'classLevel',
|
||||
'toggle',
|
||||
'item',
|
||||
// End step types
|
||||
'action',
|
||||
'attack',
|
||||
'savingThrow',
|
||||
'spellList',
|
||||
'spell',
|
||||
'propertySlot',
|
||||
];
|
||||
|
||||
export function recomputeCreatureById(creatureId){
|
||||
let creature = Creatures.findOne(creatureId);
|
||||
recomputeCreatureByDoc(creature);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is the heart of DiceCloud. It recomputes a creature's stats,
|
||||
* distilling down effects and proficiencies into the final stats that make up
|
||||
@@ -71,17 +93,18 @@ const calculationPropertyTypes = [
|
||||
* - Mark the stat as computed
|
||||
* - Write the computed results back to the database
|
||||
*/
|
||||
export function recomputeCreatureById(creatureId){
|
||||
export function recomputeCreatureByDoc(creature){
|
||||
const creatureId = creature._id;
|
||||
let props = getActiveProperties({
|
||||
ancestorId: creatureId,
|
||||
filter: {type: {$in: calculationPropertyTypes}},
|
||||
includeUntoggled: true,
|
||||
// TODO filter out expensive fields, particularly icon field
|
||||
});
|
||||
let computationMemo = new ComputationMemo(props);
|
||||
let computationMemo = new ComputationMemo(props, creature);
|
||||
computeMemo(computationMemo);
|
||||
writeAlteredProperties(computationMemo);
|
||||
writeCreatureVariables(computationMemo, creatureId);
|
||||
// if(Meteor.isClient) console.log(computationMemo);
|
||||
recomputeDamageMultipliersById(creatureId);
|
||||
return computationMemo;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,31 @@
|
||||
import { Meteor } from 'meteor/meteor'
|
||||
import { isEqual, forOwn } from 'lodash';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
// Schemas
|
||||
// Calculated props
|
||||
import { ComputedOnlySkillSchema } from '/imports/api/properties/Skills.js';
|
||||
import { ComputedOnlyAttributeSchema } from '/imports/api/properties/Attributes.js';
|
||||
import { ComputedOnlyEffectSchema } from '/imports/api/properties/Effects.js';
|
||||
import { ComputedOnlyToggleSchema } from '/imports/api/properties/Toggles.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
// End step props
|
||||
import { ComputedOnlyActionSchema } from '/imports/api/properties/Actions.js';
|
||||
import { ComputedOnlyAttackSchema } from '/imports/api/properties/Attacks.js';
|
||||
import { ComputedOnlySavingThrowSchema } from '/imports/api/properties/SavingThrows.js';
|
||||
import { ComputedOnlySpellListSchema } from '/imports/api/properties/SpellLists.js';
|
||||
import { ComputedOnlySpellSchema } from '/imports/api/properties/Spells.js';
|
||||
import { ComputedOnlySlotSchema } from '/imports/api/properties/Slots.js';
|
||||
|
||||
const schemasByType = {
|
||||
'skill': ComputedOnlySkillSchema,
|
||||
'attribute': ComputedOnlyAttributeSchema,
|
||||
'effect': ComputedOnlyEffectSchema,
|
||||
'toggle': ComputedOnlyToggleSchema,
|
||||
'action': ComputedOnlyActionSchema,
|
||||
'attack': ComputedOnlyAttackSchema,
|
||||
'savingThrow': ComputedOnlySavingThrowSchema,
|
||||
'spellList': ComputedOnlySpellListSchema,
|
||||
'spell': ComputedOnlySpellSchema,
|
||||
'propertySlot': ComputedOnlySlotSchema,
|
||||
};
|
||||
|
||||
export default function writeAlteredProperties(memo){
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
@@ -6,12 +7,18 @@ import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
|
||||
export const recomputeDamageMultipliers = new ValidatedMethod({
|
||||
|
||||
name: 'Creatures.methods.recomputeDamageMultipliers',
|
||||
name: 'creatures.recomputeDamageMultipliers',
|
||||
|
||||
validate: new SimpleSchema({
|
||||
creatureId: { type: String }
|
||||
}).validator(),
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run({creatureId}) {
|
||||
// Permission
|
||||
assertEditPermission(creatureId, this.userId);
|
||||
|
||||
197
app/imports/api/creature/experience/Experiences.js
Normal file
197
app/imports/api/creature/experience/Experiences.js
Normal file
@@ -0,0 +1,197 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import { recomputeCreatureById } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||
|
||||
let Experiences = new Mongo.Collection('experiences');
|
||||
|
||||
let ExperienceSchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
// The amount of XP this experience gives
|
||||
xp: {
|
||||
type: SimpleSchema.Integer,
|
||||
optional: true,
|
||||
min: 0,
|
||||
},
|
||||
// Setting levels instead of value grants whole levels
|
||||
levels: {
|
||||
type: SimpleSchema.Integer,
|
||||
optional: true,
|
||||
min: 0,
|
||||
index: 1,
|
||||
},
|
||||
// The real-world date that it occured, usually sorted by date
|
||||
date: {
|
||||
type: Date,
|
||||
autoValue: function() {
|
||||
// If the date isn't set, set it to now
|
||||
if (!this.isSet) {
|
||||
return new Date();
|
||||
}
|
||||
},
|
||||
index: 1,
|
||||
},
|
||||
creatureId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
index: 1,
|
||||
},
|
||||
});
|
||||
|
||||
Experiences.attachSchema(ExperienceSchema);
|
||||
|
||||
const insertExperienceForCreature = function({experience, creatureId, userId}){
|
||||
assertEditPermission(creatureId, userId);
|
||||
if (experience.xp){
|
||||
Creatures.update(creatureId, {$inc: {
|
||||
'denormalizedStats.xp': experience.xp
|
||||
}});
|
||||
}
|
||||
if (experience.levels) {
|
||||
Creatures.update(creatureId, {$inc: {
|
||||
'denormalizedStats.milestoneLevels': experience.levels
|
||||
}});
|
||||
}
|
||||
experience.creatureId = creatureId;
|
||||
let id = Experiences.insert(experience);
|
||||
recomputeCreatureById(creatureId);
|
||||
return id;
|
||||
};
|
||||
|
||||
const insertExperience = new ValidatedMethod({
|
||||
name: 'experiences.insert',
|
||||
validate: new SimpleSchema({
|
||||
experience: {
|
||||
type: ExperienceSchema.omit('creatureId'),
|
||||
},
|
||||
creatureIds: {
|
||||
type: Array,
|
||||
max: 12,
|
||||
},
|
||||
'creatureIds.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({experience, creatureIds}) {
|
||||
let userId = this.userId;
|
||||
if (!userId) {
|
||||
throw new Meteor.Error('Experiences.methods.insert.denied',
|
||||
'You need to be logged in to insert an experience');
|
||||
}
|
||||
let tier = getUserTier(this.userId);
|
||||
if (!tier.paidBenefits){
|
||||
throw new Meteor.Error('Experiences.methods.insert.denied',
|
||||
`The ${tier.name} tier does not allow you to grant experience`);
|
||||
}
|
||||
let insertedIds = [];
|
||||
creatureIds.forEach(creatureId => {
|
||||
let id = insertExperienceForCreature({experience, creatureId, userId});
|
||||
insertedIds.push(id);
|
||||
});
|
||||
return insertedIds;
|
||||
},
|
||||
});
|
||||
|
||||
const removeExperience = new ValidatedMethod({
|
||||
name: 'experiences.remove',
|
||||
validate: new SimpleSchema({
|
||||
experienceId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({experienceId}) {
|
||||
let userId = this.userId;
|
||||
if (!userId) {
|
||||
throw new Meteor.Error('Experiences.methods.remove.denied',
|
||||
'You need to be logged in to remove an experience');
|
||||
}
|
||||
let tier = getUserTier(this.userId);
|
||||
if (!tier.paidBenefits){
|
||||
throw new Meteor.Error('Experiences.methods.remove.denied',
|
||||
`The ${tier.name} tier does not allow you to remove an experience`);
|
||||
}
|
||||
let experience = Experiences.findOne(experienceId);
|
||||
if (!experience) return;
|
||||
let creatureId = experience.creatureId
|
||||
assertEditPermission(creatureId, userId);
|
||||
if (experience.xp){
|
||||
Creatures.update(creatureId, {$inc: {
|
||||
'denormalizedStats.xp': -experience.xp
|
||||
}});
|
||||
}
|
||||
if (experience.levels) {
|
||||
Creatures.update(creatureId, {$inc: {
|
||||
'denormalizedStats.milestoneLevels': -experience.levels
|
||||
}});
|
||||
}
|
||||
experience.creatureId = creatureId;
|
||||
let numRemoved = Experiences.remove(experienceId);
|
||||
recomputeCreatureById(creatureId);
|
||||
return numRemoved;
|
||||
},
|
||||
});
|
||||
|
||||
const recomputeExperiences = new ValidatedMethod({
|
||||
name: 'experiences.recompute',
|
||||
validate: new SimpleSchema({
|
||||
creatureId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({creatureId}) {
|
||||
let userId = this.userId;
|
||||
if (!userId) {
|
||||
throw new Meteor.Error('Experiences.methods.recompute.denied',
|
||||
'You need to be logged in to recompute a creature\'s experiences');
|
||||
}
|
||||
let tier = getUserTier(this.userId);
|
||||
if (!tier.paidBenefits){
|
||||
throw new Meteor.Error('Experiences.methods.recompute.denied',
|
||||
`The ${tier.name} tier does not allow you to recompute a creature's experiences`);
|
||||
}
|
||||
assertEditPermission(creatureId, userId);
|
||||
|
||||
let xp = 0;
|
||||
let milestoneLevels = 0;
|
||||
Experiences.find({
|
||||
creatureId
|
||||
}, {
|
||||
fields: {xp: 1, levels: 1}
|
||||
}).forEach(experience => {
|
||||
xp += experience.xp || 0;
|
||||
milestoneLevels += experience.levels || 0;
|
||||
});
|
||||
Creatures.update(creatureId, {$set: {
|
||||
'denormalizedStats.xp': xp,
|
||||
'denormalizedStats.milestoneLevels': milestoneLevels
|
||||
}});
|
||||
recomputeCreatureById(creatureId);
|
||||
},
|
||||
});
|
||||
|
||||
export default Experiences;
|
||||
export { ExperienceSchema, insertExperience, removeExperience, recomputeExperiences };
|
||||
@@ -4,17 +4,30 @@ import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
export default function getActiveProperties({
|
||||
ancestorId,
|
||||
filter = {},
|
||||
options,
|
||||
includeUntoggled = false
|
||||
options = {sort: {order: 1}},
|
||||
includeUntoggled = false,
|
||||
includeUnprepared = false,
|
||||
includeUnequipped = false,
|
||||
excludeAncestors,
|
||||
}){
|
||||
filter = getActivePropertyFilter({ancestorId, filter, includeUntoggled});
|
||||
filter = getActivePropertyFilter({
|
||||
ancestorId,
|
||||
filter,
|
||||
includeUntoggled,
|
||||
includeUnprepared,
|
||||
includeUnequipped,
|
||||
excludeAncestors,
|
||||
});
|
||||
return CreatureProperties.find(filter, options).fetch();
|
||||
}
|
||||
|
||||
export function getActivePropertyFilter({
|
||||
ancestorId,
|
||||
filter = {},
|
||||
includeUntoggled = false
|
||||
includeUntoggled = false,
|
||||
includeUnprepared = false,
|
||||
includeUnequipped = false,
|
||||
excludeAncestors = [],
|
||||
}){
|
||||
if (!ancestorId){
|
||||
throw 'Ancestor Id is required to get active properties'
|
||||
@@ -24,13 +37,22 @@ export function getActivePropertyFilter({
|
||||
'ancestors.id': ancestorId,
|
||||
$or: [
|
||||
{disabled: true}, // Everything can be disabled
|
||||
{equipped: false}, // Items can be equipped
|
||||
{applied: false}, // Buffs can be applied
|
||||
],
|
||||
};
|
||||
if (!includeUnequipped){
|
||||
disabledAncestorsFilter.$or.push({type: 'item', equipped: {$ne: true}});
|
||||
}
|
||||
if (!includeUntoggled){
|
||||
disabledAncestorsFilter.$or.push({toggleResult: false});
|
||||
}
|
||||
if (!includeUnprepared){
|
||||
disabledAncestorsFilter.$or.push({
|
||||
type: 'spell',
|
||||
prepared: {$ne: true},
|
||||
alwaysPrepared: {$ne: true}
|
||||
});
|
||||
}
|
||||
let disabledAncestorIds = CreatureProperties.find(disabledAncestorsFilter, {
|
||||
fields: {_id: 1},
|
||||
}).map(prop => prop._id);
|
||||
@@ -47,9 +69,12 @@ export function getActivePropertyFilter({
|
||||
|
||||
// Get all the properties that are decendents of the ancestor of interest but
|
||||
// aren't from the excluded decendents
|
||||
if (filter['ancestors.id'] && Meteor.isClient){
|
||||
console.warn('Filtering on ancestor id is ignored')
|
||||
}
|
||||
filter['ancestors.id'] = {
|
||||
$eq: ancestorId,
|
||||
$nin: disabledAncestorIds,
|
||||
$nin: disabledAncestorIds.concat(excludeAncestors),
|
||||
};
|
||||
// Get properties that aren't removed
|
||||
filter.removed = {$ne: true};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
let ExperienceSchema = new SimpleSchema({
|
||||
name: {
|
||||
title: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
@@ -10,11 +10,6 @@ let ExperienceSchema = new SimpleSchema({
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
// The amount of XP this experience gives
|
||||
value: {
|
||||
type: SimpleSchema.Integer,
|
||||
optional: true,
|
||||
},
|
||||
// The real-world date that it occured
|
||||
date: {
|
||||
type: Date,
|
||||
@@ -30,6 +25,20 @@ let ExperienceSchema = new SimpleSchema({
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
// Tags to better find this entry later
|
||||
tags: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'tags.$': {
|
||||
type: String,
|
||||
},
|
||||
// ID of the journal this entry belongs to
|
||||
journalId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
index: 1,
|
||||
}
|
||||
});
|
||||
|
||||
export { ExperienceSchema };
|
||||
@@ -1,20 +1,29 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js'
|
||||
import { assertOwnership } from '/imports/api/creature/creaturePermissions.js';
|
||||
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
||||
|
||||
function removeRelatedDocuments(charId){
|
||||
CreatureProperties.remove({'ancestors.id': charId});
|
||||
};
|
||||
function removeRelatedDocuments(creatureId){
|
||||
CreatureProperties.remove({'ancestors.id': creatureId});
|
||||
Experiences.remove({creatureId});
|
||||
}
|
||||
|
||||
const removeCreature = new ValidatedMethod({
|
||||
name: "Creatures.methods.removeCreature", // DDP method name
|
||||
name: 'Creatures.methods.removeCreature', // DDP method name
|
||||
validate: new SimpleSchema({
|
||||
charId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({charId}) {
|
||||
assertOwnership(charId, this.userId)
|
||||
Creatures.remove(charId);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import getActiveProperties, { getActivePropertyFilter } from '/imports/api/creature/getActiveProperties.js';
|
||||
import {assertEditPermission} from '/imports/api/creature/creaturePermissions.js';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import { recomputeCreatureById } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||
|
||||
const restCreature = new ValidatedMethod({
|
||||
name: 'creature.methods.longRest',
|
||||
@@ -17,6 +19,11 @@ const restCreature = new ValidatedMethod({
|
||||
allowedValues: ['shortRest', 'longRest'],
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({creatureId, restType}) {
|
||||
let creature = Creatures.findOne(creatureId, {
|
||||
fields: {
|
||||
@@ -87,7 +94,8 @@ const restCreature = new ValidatedMethod({
|
||||
let amountToRecover, resultingDamage;
|
||||
hitDice.forEach(hd => {
|
||||
if (!recoverableHd) return;
|
||||
amountToRecover = Math.min(recoverableHd, hd.damage);
|
||||
amountToRecover = Math.min(recoverableHd, hd.damage || 0);
|
||||
if (!amountToRecover) return;
|
||||
recoverableHd -= amountToRecover;
|
||||
resultingDamage = hd.damage - amountToRecover;
|
||||
CreatureProperties.update(hd._id, {
|
||||
@@ -97,6 +105,7 @@ const restCreature = new ValidatedMethod({
|
||||
});
|
||||
});
|
||||
}
|
||||
recomputeCreatureById(creatureId);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import { assertAdmin } from '/imports/api/sharing/sharingPermissions.js';
|
||||
|
||||
let Icons = new Mongo.Collection('icons');
|
||||
|
||||
iconsSchema = new SimpleSchema({
|
||||
let iconsSchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
unique: true,
|
||||
@@ -33,21 +36,62 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
|
||||
const storedIconsSchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
shape: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
Icons.attachSchema(iconsSchema);
|
||||
|
||||
/*
|
||||
console.warn("Write Icons is not secure, disable before deployment")
|
||||
// This method does not validate icons against the schema, use wisely;
|
||||
const writeIcons = new ValidatedMethod({
|
||||
name: 'writeIcons',
|
||||
name: 'icons.write',
|
||||
validate: null,
|
||||
run(icons){
|
||||
assertAdmin(this.userId);
|
||||
if (Meteor.isServer){
|
||||
this.unblock();
|
||||
Icons.rawCollection().insert(icons, {ordered: false});
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
export { writeIcons };
|
||||
const findIcons = new ValidatedMethod({
|
||||
name: 'icons.find',
|
||||
validate: new SimpleSchema({
|
||||
search: {
|
||||
type: String,
|
||||
max: 30,
|
||||
optional: true,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 20,
|
||||
timeInterval: 10000,
|
||||
},
|
||||
run({search}){
|
||||
if (!search) return [];
|
||||
if (!Meteor.isServer) return;
|
||||
return Icons.find(
|
||||
{ $text: {$search: search} },
|
||||
{
|
||||
// relevant documents have a higher score.
|
||||
fields: {
|
||||
score: { $meta: 'textScore' }
|
||||
},
|
||||
// `score` property specified in the projection fields above.
|
||||
sort: {
|
||||
score: { $meta: 'textScore' }
|
||||
}
|
||||
}
|
||||
).fetch();
|
||||
}
|
||||
})
|
||||
|
||||
export { writeIcons, findIcons, storedIconsSchema };
|
||||
export default Icons;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
||||
import simpleSchemaMixin from '/imports/api/creature/mixins/simpleSchemaMixin.js';
|
||||
@@ -34,7 +35,7 @@ Libraries.attachSchema(LibrarySchema);
|
||||
export default Libraries;
|
||||
|
||||
const insertLibrary = new ValidatedMethod({
|
||||
name: 'Libraries.methods.insert',
|
||||
name: 'libraries.insert',
|
||||
mixins: [
|
||||
simpleSchemaMixin,
|
||||
],
|
||||
@@ -55,7 +56,7 @@ const insertLibrary = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const updateLibraryName = new ValidatedMethod({
|
||||
name: 'Libraries.methods.updateName',
|
||||
name: 'libraries.updateName',
|
||||
validate: new SimpleSchema({
|
||||
_id: {
|
||||
type: String,
|
||||
@@ -65,6 +66,11 @@ const updateLibraryName = new ValidatedMethod({
|
||||
type: String,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, name}){
|
||||
let library = Libraries.findOne(_id);
|
||||
assertEditPermission(library, this.userId);
|
||||
@@ -73,7 +79,7 @@ const updateLibraryName = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const setLibraryDefault = new ValidatedMethod({
|
||||
name: 'Libraries.methods.makeLibraryDefault',
|
||||
name: 'libraries.makeLibraryDefault',
|
||||
validate: new SimpleSchema({
|
||||
_id: {
|
||||
type: String,
|
||||
@@ -83,6 +89,11 @@ const setLibraryDefault = new ValidatedMethod({
|
||||
type: Boolean,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, isDefault}) {
|
||||
if (!Meteor.users.isAdmin()){
|
||||
throw new Meteor.Error('Permission denied', 'User must be admin to set libraries as default');
|
||||
@@ -92,13 +103,18 @@ const setLibraryDefault = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const removeLibrary = new ValidatedMethod({
|
||||
name: 'Libraries.methods.remove',
|
||||
name: 'libraries.remove',
|
||||
validate: new SimpleSchema({
|
||||
_id: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id}){
|
||||
let library = Libraries.findOne(_id);
|
||||
assertOwnership(library, this.userId);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
||||
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
||||
@@ -9,6 +10,7 @@ import Libraries from '/imports/api/library/Libraries.js';
|
||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||
import { softRemove } from '/imports/api/parenting/softRemove.js';
|
||||
import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js';
|
||||
import { storedIconsSchema } from '/imports/api/icons/Icons.js';
|
||||
|
||||
let LibraryNodes = new Mongo.Collection('libraryNodes');
|
||||
|
||||
@@ -24,6 +26,10 @@ let LibraryNodeSchema = new SimpleSchema({
|
||||
'tags.$': {
|
||||
type: String,
|
||||
},
|
||||
icon: {
|
||||
type: storedIconsSchema,
|
||||
optional: true,
|
||||
}
|
||||
});
|
||||
|
||||
for (let key in propertySchemasIndex){
|
||||
@@ -51,8 +57,13 @@ function assertNodeEditPermission(node, userId){
|
||||
}
|
||||
|
||||
const insertNode = new ValidatedMethod({
|
||||
name: 'LibraryNodes.methods.insert',
|
||||
name: 'libraryNodes.insert',
|
||||
validate: null,
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run(libraryNode) {
|
||||
delete libraryNode._id;
|
||||
assertNodeEditPermission(libraryNode, this.userId);
|
||||
@@ -61,13 +72,18 @@ const insertNode = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const duplicateNode = new ValidatedMethod({
|
||||
name: 'LibraryNodes.methods.duplicate',
|
||||
name: 'libraryNodes.duplicate',
|
||||
validate: new SimpleSchema({
|
||||
_id: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
}
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id}) {
|
||||
let libraryNode = LibraryNodes.findOne(_id);
|
||||
assertNodeEditPermission(libraryNode, this.userId);
|
||||
@@ -77,7 +93,7 @@ const duplicateNode = new ValidatedMethod({
|
||||
})
|
||||
|
||||
const updateLibraryNode = new ValidatedMethod({
|
||||
name: 'LibraryNodes.methods.update',
|
||||
name: 'libraryNodes.update',
|
||||
validate({_id, path}){
|
||||
if (!_id) return false;
|
||||
// We cannot change these fields with a simple update
|
||||
@@ -89,6 +105,11 @@ const updateLibraryNode = new ValidatedMethod({
|
||||
return false;
|
||||
}
|
||||
},
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, path, value}) {
|
||||
let node = LibraryNodes.findOne(_id);
|
||||
assertNodeEditPermission(node, this.userId);
|
||||
@@ -107,8 +128,13 @@ const updateLibraryNode = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const pushToLibraryNode = new ValidatedMethod({
|
||||
name: 'LibraryNodes.methods.push',
|
||||
name: 'libraryNodes.push',
|
||||
validate: null,
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, path, value}){
|
||||
let node = LibraryNodes.findOne(_id);
|
||||
assertNodeEditPermission(node, this.userId);
|
||||
@@ -121,8 +147,13 @@ const pushToLibraryNode = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const pullFromLibraryNode = new ValidatedMethod({
|
||||
name: 'LibraryNodes.methods.pull',
|
||||
name: 'libraryNodes.pull',
|
||||
validate: null,
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id, path, itemId}){
|
||||
let node = LibraryNodes.findOne(_id);
|
||||
assertNodeEditPermission(node, this.userId);
|
||||
@@ -136,10 +167,15 @@ const pullFromLibraryNode = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const softRemoveLibraryNode = new ValidatedMethod({
|
||||
name: 'LibraryNodes.methods.softRemove',
|
||||
name: 'libraryNodes.softRemove',
|
||||
validate: new SimpleSchema({
|
||||
_id: SimpleSchema.RegEx.Id
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({_id}){
|
||||
let node = LibraryNodes.findOne(_id);
|
||||
assertNodeEditPermission(node, this.userId);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { union } from 'lodash';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import { updateParent } from '/imports/api/parenting/parenting.js';
|
||||
import { reorderDocs, safeUpdateDocOrder } from '/imports/api/parenting/order.js';
|
||||
import { RefSchema } from '/imports/api/parenting/ChildSchema.js';
|
||||
@@ -10,7 +11,7 @@ import getCollectionByName from '/imports/api/parenting/getCollectionByName.js';
|
||||
import { recomputeCreatureById } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||
|
||||
const organizeDoc = new ValidatedMethod({
|
||||
name: 'organize.methods.organizeDoc',
|
||||
name: 'organize.organizeDoc',
|
||||
validate: new SimpleSchema({
|
||||
docRef: RefSchema,
|
||||
parentRef: RefSchema,
|
||||
@@ -19,6 +20,11 @@ const organizeDoc = new ValidatedMethod({
|
||||
// Should end in 0.5 to place it reliably between two existing documents
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({docRef, parentRef, order}) {
|
||||
let doc = fetchDocByRef(docRef);
|
||||
let collection = getCollectionByName(docRef.collection);
|
||||
@@ -54,7 +60,7 @@ const organizeDoc = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const reorderDoc = new ValidatedMethod({
|
||||
name: 'organize.methods.reorderDoc',
|
||||
name: 'organize.reorderDoc',
|
||||
validate: new SimpleSchema({
|
||||
docRef: RefSchema,
|
||||
order: {
|
||||
@@ -62,6 +68,11 @@ const reorderDoc = new ValidatedMethod({
|
||||
// Should end in 0.5 to place it reliably between two existing documents
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({docRef, order}) {
|
||||
let doc = fetchDocByRef(docRef);
|
||||
assertDocEditPermission(doc, this.userId);
|
||||
|
||||
@@ -130,7 +130,7 @@ export function renewDocIds({docArray, collectionMap}){
|
||||
const remapReference = ref => {
|
||||
if (idMap[ref.id]){
|
||||
ref.id = idMap[ref.id];
|
||||
ref.collection = collectionMap[ref.collection] || ref.collection;
|
||||
ref.collection = collectionMap && collectionMap[ref.collection] || ref.collection;
|
||||
}
|
||||
}
|
||||
docArray.forEach(doc => {
|
||||
@@ -154,6 +154,14 @@ export function updateParent({docRef, parentRef}){
|
||||
// Get the parent and its ancestry
|
||||
let {parentDoc, parent, ancestors} = getAncestry({parentRef});
|
||||
|
||||
// Check that the doc isn't its own ancestor
|
||||
ancestors.forEach(ancestor => {
|
||||
if (docRef.id === ancestor.id){
|
||||
throw new Meteor.Error('invalid parenting',
|
||||
'A doc can\'t be its own ancestor')
|
||||
}
|
||||
});
|
||||
|
||||
// If the doc and its parent are in the same collection, apply the allowed
|
||||
// parent rules based on type
|
||||
if (docRef.collection === parentRef.collection){
|
||||
@@ -204,17 +212,11 @@ export function getName(doc){
|
||||
}
|
||||
}
|
||||
|
||||
export function nodesToTree({collection, ancestorId, filter, options}){
|
||||
// Store a dict of all the nodes
|
||||
export function nodeArrayToTree(nodes){
|
||||
// Store a dict and list of all the nodes
|
||||
let nodeIndex = {};
|
||||
let nodeList = [];
|
||||
if (!options) options = {};
|
||||
options.sort = {order: 1};
|
||||
collection.find({
|
||||
'ancestors.id': ancestorId,
|
||||
removed: {$ne: true},
|
||||
...filter,
|
||||
}, options).forEach( node => {
|
||||
nodes.forEach( node => {
|
||||
let treeNode = {
|
||||
node: node,
|
||||
children: [],
|
||||
@@ -238,3 +240,12 @@ export function nodesToTree({collection, ancestorId, filter, options}){
|
||||
});
|
||||
return forest;
|
||||
}
|
||||
|
||||
export function nodesToTree({collection, ancestorId, filter = {}, options = {}}){
|
||||
if (!('ancestors.id' in filter)) filter['ancestors.id'] = ancestorId;
|
||||
if (!('removed' in filter)) filter['removed'] = {$ne: true};
|
||||
if (!options.sort) options.sort = {order: 1};
|
||||
if (!('order' in options.sort)) options.sort.order = 1;
|
||||
let nodes = collection.find(filter, options);
|
||||
return nodeArrayToTree(nodes);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ResourcesSchema from '/imports/api/properties/subSchemas/ResourcesSchema.js'
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
import { storedIconsSchema } from '/imports/api/icons/Icons.js'
|
||||
|
||||
/*
|
||||
* Actions are things a character can do
|
||||
@@ -12,6 +13,10 @@ let ActionSchema = new SimpleSchema({
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
summary: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
optional: true,
|
||||
@@ -40,13 +45,60 @@ let ActionSchema = new SimpleSchema({
|
||||
'tags.$': {
|
||||
type: String,
|
||||
},
|
||||
// Duplicate the ResourceSchema here so we can extend it elegantly.
|
||||
resources: {
|
||||
type: ResourcesSchema,
|
||||
type: Object,
|
||||
defaultValue: {},
|
||||
},
|
||||
'resources.itemsConsumed': {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'resources.itemsConsumed.$': {
|
||||
type: Object,
|
||||
},
|
||||
'resources.itemsConsumed.$._id': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
autoValue(){
|
||||
if (!this.isSet) return Random.id();
|
||||
}
|
||||
},
|
||||
'resources.itemsConsumed.$.tag': {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
'resources.itemsConsumed.$.quantity': {
|
||||
type: Number,
|
||||
defaultValue: 1,
|
||||
},
|
||||
'resources.itemsConsumed.$.itemId': {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
'resources.attributesConsumed': {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'resources.attributesConsumed.$': {
|
||||
type: Object,
|
||||
},
|
||||
'resources.attributesConsumed.$._id': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
autoValue(){
|
||||
if (!this.isSet) return Random.id();
|
||||
}
|
||||
},
|
||||
'resources.attributesConsumed.$.variableName': {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
'resources.attributesConsumed.$.quantity': {
|
||||
type: Number,
|
||||
defaultValue: 1,
|
||||
},
|
||||
// Calculation of how many times this action can be used
|
||||
// Only set if this action tracks its own uses, rather than adjusting
|
||||
// resources
|
||||
uses: {
|
||||
type: String,
|
||||
optional: true,
|
||||
@@ -64,4 +116,69 @@ let ActionSchema = new SimpleSchema({
|
||||
},
|
||||
});
|
||||
|
||||
export { ActionSchema };
|
||||
const ComputedOnlyActionSchema = new SimpleSchema({
|
||||
usesResult: {
|
||||
type: SimpleSchema.Integer,
|
||||
optional: true,
|
||||
},
|
||||
usesErrors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'usesErrors.$':{
|
||||
type: ErrorSchema,
|
||||
},
|
||||
resources: Object,
|
||||
'resources.itemsConsumed': Array,
|
||||
'resources.itemsConsumed.$': Object,
|
||||
'resources.itemsConsumed.$.available': {
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
// This appears both in the computed and uncomputed schema because it can be
|
||||
// set by both a computation or a form
|
||||
'resources.itemsConsumed.$.itemId': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true,
|
||||
},
|
||||
'resources.itemsConsumed.$.itemName': {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
'resources.itemsConsumed.$.itemIcon': {
|
||||
type: storedIconsSchema,
|
||||
optional: true,
|
||||
},
|
||||
'resources.itemsConsumed.$.itemColor': {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
'resources.attributesConsumed': Array,
|
||||
'resources.attributesConsumed.$': Object,
|
||||
'resources.attributesConsumed.$.available': {
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
'resources.attributesConsumed.$.statId': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true,
|
||||
},
|
||||
'resources.attributesConsumed.$.statName': {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
// True if the uses left is zero, or any item or attribute consumed is
|
||||
// insufficient
|
||||
insufficientResources: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
const ComputedActionSchema = new SimpleSchema()
|
||||
.extend(ActionSchema)
|
||||
.extend(ComputedOnlyActionSchema);
|
||||
|
||||
export { ActionSchema, ComputedOnlyActionSchema, ComputedActionSchema};
|
||||
|
||||
@@ -2,6 +2,7 @@ import SimpleSchema from 'simpl-schema';
|
||||
|
||||
const AdjustmentSchema = new SimpleSchema({
|
||||
// The roll that determines how much to change the attribute
|
||||
// This can be simplified, but should only compute when activated
|
||||
amount: {
|
||||
type: String,
|
||||
optional: true,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ActionSchema } from '/imports/api/properties/Actions.js';
|
||||
import { ActionSchema, ComputedOnlyActionSchema } from '/imports/api/properties/Actions.js';
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
|
||||
// Attacks are special instances of actions
|
||||
let AttackSchema = new SimpleSchema()
|
||||
@@ -25,4 +26,24 @@ let AttackSchema = new SimpleSchema()
|
||||
},
|
||||
});
|
||||
|
||||
export { AttackSchema };
|
||||
const ComputedOnlyAttackSchema = new SimpleSchema()
|
||||
.extend(ComputedOnlyActionSchema)
|
||||
.extend({
|
||||
rollBonusResult: {
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
rollBonusErrors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'rollBonusErrors.$':{
|
||||
type: ErrorSchema,
|
||||
},
|
||||
});
|
||||
|
||||
const ComputedAttackSchema = new SimpleSchema()
|
||||
.extend(AttackSchema)
|
||||
.extend(ComputedOnlyAttackSchema);
|
||||
|
||||
export { AttackSchema, ComputedOnlyAttackSchema, ComputedAttackSchema };
|
||||
|
||||
@@ -39,6 +39,11 @@ let AttributeSchema = new SimpleSchema({
|
||||
type: String,
|
||||
allowedValues: ['d4', 'd6', 'd8', 'd10', 'd12', 'd20'],
|
||||
optional: true,
|
||||
},
|
||||
// For type spellSlot, the level needs to be stored separately
|
||||
spellSlotLevelCalculation: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
// The starting value, before effects
|
||||
baseValueCalculation: {
|
||||
@@ -81,6 +86,18 @@ let ComputedOnlyAttributeSchema = new SimpleSchema({
|
||||
},
|
||||
'baseValueErrors.$': {
|
||||
type: ErrorSchema,
|
||||
},
|
||||
// The result of spellSlotLevelCalculation
|
||||
spellSlotLevelValue: {
|
||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||
optional: true,
|
||||
},
|
||||
spellSlotLevelErrors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'spellSlotLevelErrors.$': {
|
||||
type: ErrorSchema,
|
||||
},
|
||||
// The computed value of the attribute
|
||||
value: {
|
||||
|
||||
@@ -18,12 +18,12 @@ let ContainerSchema = new SimpleSchema({
|
||||
weight: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
defaultValue: 0
|
||||
optional: true,
|
||||
},
|
||||
value: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
defaultValue: 0
|
||||
optional: true,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
@@ -32,4 +32,16 @@ let ContainerSchema = new SimpleSchema({
|
||||
},
|
||||
});
|
||||
|
||||
export { ContainerSchema };
|
||||
const ComputedOnlyContainerSchema = new SimpleSchema({
|
||||
// Weight of all the contents, zero if `contentsWeightless` is true
|
||||
contentsWeight:{
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
const ComputedContainerSchema = new SimpleSchema()
|
||||
.extend(ComputedOnlyContainerSchema)
|
||||
.extend(ContainerSchema);
|
||||
|
||||
export { ContainerSchema, ComputedContainerSchema };
|
||||
|
||||
@@ -3,6 +3,7 @@ import DAMAGE_TYPES from '/imports/constants/DAMAGE_TYPES.js';
|
||||
|
||||
const DamageSchema = new SimpleSchema({
|
||||
// The roll that determines how much to damage the attribute
|
||||
// This can be simplified, but only computed when applied
|
||||
amount: {
|
||||
type: String,
|
||||
optional: true,
|
||||
|
||||
@@ -38,7 +38,6 @@ let EffectSchema = new SimpleSchema({
|
||||
},
|
||||
'stats.$': {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ const ItemSchema = new SimpleSchema({
|
||||
weight: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
defaultValue: 0,
|
||||
optional: true,
|
||||
},
|
||||
// Value per item in the stack, in gold pieces
|
||||
value: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
defaultValue: 0,
|
||||
optional: true,
|
||||
},
|
||||
// If this item is equipped, it requires attunement
|
||||
// Being equipped is `enabled === true`
|
||||
|
||||
@@ -12,7 +12,6 @@ let ProficiencySchema = new SimpleSchema({
|
||||
},
|
||||
'stats.$': {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
// A number representing how proficient the character is
|
||||
value: {
|
||||
|
||||
@@ -19,7 +19,7 @@ import SimpleSchema from 'simpl-schema';
|
||||
* child rolls are applied
|
||||
*/
|
||||
let RollSchema = new SimpleSchema({
|
||||
// The roll
|
||||
// The roll, can be simplified, but only computed in context
|
||||
roll: {
|
||||
type: String,
|
||||
optional: true,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
|
||||
// These are the rolls made when saves are called for
|
||||
// For the saving throw bonus or proficiency, see ./Skills.js
|
||||
@@ -18,4 +19,22 @@ let SavingThrowSchema = new SimpleSchema ({
|
||||
},
|
||||
});
|
||||
|
||||
export { SavingThrowSchema };
|
||||
const ComputedOnlySavingThrowSchema = new SimpleSchema({
|
||||
dcResult: {
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
dcErrors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'dcErrors.$':{
|
||||
type: ErrorSchema,
|
||||
},
|
||||
});
|
||||
|
||||
const ComputedSavingThrowSchema = new SimpleSchema()
|
||||
.extend(SavingThrowSchema)
|
||||
.extend(ComputedOnlySavingThrowSchema);
|
||||
|
||||
export { SavingThrowSchema, ComputedOnlySavingThrowSchema, ComputedSavingThrowSchema };
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
|
||||
/*
|
||||
* Skills are anything that results in a modifier to be added to a D20
|
||||
@@ -37,9 +38,9 @@ let SkillSchema = new SimpleSchema({
|
||||
],
|
||||
defaultValue: 'skill',
|
||||
},
|
||||
// If the baseValue is higher than the computed value, it will be used as `value`
|
||||
baseValue: {
|
||||
type: Number,
|
||||
// The starting value, before effects
|
||||
baseValueCalculation: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
// The base proficiency of this skill
|
||||
@@ -59,6 +60,18 @@ let ComputedOnlySkillSchema = new SimpleSchema({
|
||||
value: {
|
||||
type: Number,
|
||||
defaultValue: 0,
|
||||
},
|
||||
// The result of baseValueCalculation
|
||||
baseValue: {
|
||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||
optional: true,
|
||||
},
|
||||
baseValueErrors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'baseValueErrors.$': {
|
||||
type: ErrorSchema,
|
||||
},
|
||||
// Computed value added by the ability
|
||||
abilityMod: {
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
|
||||
let SlotSchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
slotType: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
slotTags: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
@@ -8,6 +21,43 @@ let SlotSchema = new SimpleSchema({
|
||||
'slotTags.$': {
|
||||
type: String,
|
||||
},
|
||||
quantityExpected: {
|
||||
type: SimpleSchema.Integer,
|
||||
defaultValue: 1,
|
||||
},
|
||||
ignored: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
slotCondition: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
// How many properties have been selected to fill this slot
|
||||
quantityFilled: {
|
||||
type: SimpleSchema.Integer,
|
||||
defaultValue: 0,
|
||||
},
|
||||
});
|
||||
|
||||
export { SlotSchema };
|
||||
const ComputedOnlySlotSchema = new SimpleSchema({
|
||||
// The computed result of the effect
|
||||
slotConditionResult: {
|
||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||
optional: true,
|
||||
},
|
||||
// The errors encountered while computing the result
|
||||
slotConditionErrors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'slotConditionErrors.$':{
|
||||
type: ErrorSchema,
|
||||
},
|
||||
});
|
||||
|
||||
const ComputedSlotSchema = new SimpleSchema()
|
||||
.extend(ComputedOnlySlotSchema)
|
||||
.extend(SlotSchema);
|
||||
|
||||
export { SlotSchema, ComputedSlotSchema, ComputedOnlySlotSchema };
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||
|
||||
let SpellListSchema = new SimpleSchema({
|
||||
name: {
|
||||
@@ -9,6 +11,12 @@ let SpellListSchema = new SimpleSchema({
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
variableName: {
|
||||
type: String,
|
||||
regEx: VARIABLE_NAME_REGEX,
|
||||
min: 2,
|
||||
optional: true,
|
||||
},
|
||||
// Calculation of how many spells in this list can be prepared
|
||||
maxPrepared: {
|
||||
type: String,
|
||||
@@ -16,4 +24,22 @@ let SpellListSchema = new SimpleSchema({
|
||||
},
|
||||
});
|
||||
|
||||
export { SpellListSchema }
|
||||
const ComputedOnlySpellListSchema = new SimpleSchema({
|
||||
maxPreparedResult: {
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
maxPreparedErrors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'maxPreparedErrors.$':{
|
||||
type: ErrorSchema,
|
||||
},
|
||||
});
|
||||
|
||||
const ComputedSpellListSchema = new SimpleSchema()
|
||||
.extend(SpellListSchema)
|
||||
.extend(ComputedOnlySpellListSchema);
|
||||
|
||||
export { SpellListSchema, ComputedOnlySpellListSchema, ComputedSpellListSchema };
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ActionSchema } from '/imports/api/properties/Actions.js';
|
||||
import { ActionSchema, ComputedOnlyActionSchema } from '/imports/api/properties/Actions.js';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||
|
||||
const magicSchools = [
|
||||
'abjuration',
|
||||
@@ -25,6 +26,10 @@ let SpellSchema = new SimpleSchema({})
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
prepared: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
// This spell ignores spell slot rules
|
||||
castWithoutSpellSlots: {
|
||||
type: Boolean,
|
||||
@@ -33,14 +38,6 @@ let SpellSchema = new SimpleSchema({})
|
||||
hasAttackRoll: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
// Spell lists that this spell appears on
|
||||
spellLists: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'spellLists.$': {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
@@ -93,4 +90,11 @@ let SpellSchema = new SimpleSchema({})
|
||||
},
|
||||
});
|
||||
|
||||
export { SpellSchema };
|
||||
const ComputedOnlySpellSchema = new SimpleSchema()
|
||||
.extend(ComputedOnlyActionSchema);
|
||||
|
||||
const ComputedSpellSchema = new SimpleSchema()
|
||||
.extend(SpellSchema)
|
||||
.extend(ComputedOnlySpellSchema);
|
||||
|
||||
export { SpellSchema, ComputedOnlySpellSchema, ComputedSpellSchema };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ActionSchema } from '/imports/api/properties/Actions.js';
|
||||
import { ComputedActionSchema } from '/imports/api/properties/Actions.js';
|
||||
import { AdjustmentSchema } from '/imports/api/properties/Adjustments.js';
|
||||
import { AttackSchema } from '/imports/api/properties/Attacks.js';
|
||||
import { ComputedAttackSchema } from '/imports/api/properties/Attacks.js';
|
||||
import { ComputedAttributeSchema } from '/imports/api/properties/Attributes.js';
|
||||
import { BuffSchema } from '/imports/api/properties/Buffs.js';
|
||||
import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.js';
|
||||
@@ -9,41 +9,39 @@ import { ContainerSchema } from '/imports/api/properties/Containers.js';
|
||||
import { DamageSchema } from '/imports/api/properties/Damages.js';
|
||||
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
|
||||
import { ComputedEffectSchema } from '/imports/api/properties/Effects.js';
|
||||
import { ExperienceSchema } from '/imports/api/properties/Experiences.js';
|
||||
import { FeatureSchema } from '/imports/api/properties/Features.js';
|
||||
import { FolderSchema } from '/imports/api/properties/Folders.js';
|
||||
import { ItemSchema } from '/imports/api/properties/Items.js';
|
||||
import { NoteSchema } from '/imports/api/properties/Notes.js';
|
||||
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
|
||||
import { RollSchema } from '/imports/api/properties/Rolls.js';
|
||||
import { SavingThrowSchema } from '/imports/api/properties/SavingThrows.js';
|
||||
import { ComputedSavingThrowSchema } from '/imports/api/properties/SavingThrows.js';
|
||||
import { ComputedSkillSchema } from '/imports/api/properties/Skills.js';
|
||||
import { SlotSchema } from '/imports/api/properties/Slots.js';
|
||||
import { SpellSchema } from '/imports/api/properties/Spells.js';
|
||||
import { SpellListSchema } from '/imports/api/properties/SpellLists.js';
|
||||
import { ComputedSlotSchema } from '/imports/api/properties/Slots.js';
|
||||
import { ComputedSpellSchema } from '/imports/api/properties/Spells.js';
|
||||
import { ComputedSpellListSchema } from '/imports/api/properties/SpellLists.js';
|
||||
import { ToggleSchema } from '/imports/api/properties/Toggles.js';
|
||||
|
||||
const propertySchemasIndex = {
|
||||
action: ActionSchema,
|
||||
action: ComputedActionSchema,
|
||||
adjustment: AdjustmentSchema,
|
||||
attack: AttackSchema,
|
||||
attack: ComputedAttackSchema,
|
||||
attribute: ComputedAttributeSchema,
|
||||
buff: BuffSchema,
|
||||
classLevel: ClassLevelSchema,
|
||||
damage: DamageSchema,
|
||||
damageMultiplier: DamageMultiplierSchema,
|
||||
effect: ComputedEffectSchema,
|
||||
experience: ExperienceSchema,
|
||||
feature: FeatureSchema,
|
||||
folder: FolderSchema,
|
||||
note: NoteSchema,
|
||||
proficiency: ProficiencySchema,
|
||||
roll: RollSchema,
|
||||
savingThrow: SavingThrowSchema,
|
||||
savingThrow: ComputedSavingThrowSchema,
|
||||
skill: ComputedSkillSchema,
|
||||
slot: SlotSchema,
|
||||
spellList: SpellListSchema,
|
||||
spell: SpellSchema,
|
||||
propertySlot: ComputedSlotSchema,
|
||||
spellList: ComputedSpellListSchema,
|
||||
spell: ComputedSpellSchema,
|
||||
toggle: ToggleSchema,
|
||||
container: ContainerSchema,
|
||||
item: ItemSchema,
|
||||
|
||||
@@ -8,7 +8,6 @@ import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.js';
|
||||
import { DamageSchema } from '/imports/api/properties/Damages.js';
|
||||
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
|
||||
import { EffectSchema } from '/imports/api/properties/Effects.js';
|
||||
import { ExperienceSchema } from '/imports/api/properties/Experiences.js';
|
||||
import { FeatureSchema } from '/imports/api/properties/Features.js';
|
||||
import { FolderSchema } from '/imports/api/properties/Folders.js';
|
||||
import { NoteSchema } from '/imports/api/properties/Notes.js';
|
||||
@@ -33,7 +32,6 @@ const propertySchemasIndex = {
|
||||
damage: DamageSchema,
|
||||
damageMultiplier: DamageMultiplierSchema,
|
||||
effect: EffectSchema,
|
||||
experience: ExperienceSchema,
|
||||
feature: FeatureSchema,
|
||||
folder: FolderSchema,
|
||||
note: NoteSchema,
|
||||
@@ -41,7 +39,7 @@ const propertySchemasIndex = {
|
||||
roll: RollSchema,
|
||||
savingThrow: SavingThrowSchema,
|
||||
skill: SkillSchema,
|
||||
slot: SlotSchema,
|
||||
propertySlot: SlotSchema,
|
||||
spellList: SpellListSchema,
|
||||
spell: SpellSchema,
|
||||
toggle: ToggleSchema,
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
const ErrorSchema = new SimpleSchema({
|
||||
// The roll that determines how much to change the attribute
|
||||
message: {
|
||||
type: String,
|
||||
},
|
||||
// Who this adjustment applies to
|
||||
type: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
@@ -17,6 +17,10 @@ const ItemConsumedSchema = new SimpleSchema({
|
||||
type: Number,
|
||||
defaultValue: 1,
|
||||
},
|
||||
itemId: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
export default ItemConsumedSchema;
|
||||
|
||||
@@ -4,13 +4,19 @@ import fetchDocByRef from '/imports/api/parenting/fetchDocByRef.js';
|
||||
import getCollectionByName from '/imports/api/parenting/getCollectionByName.js';
|
||||
import { RefSchema } from '/imports/api/parenting/ChildSchema.js';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
|
||||
const setPublic = new ValidatedMethod({
|
||||
name: 'sharing.methods.setPublic',
|
||||
name: 'sharing.setPublic',
|
||||
validate: new SimpleSchema({
|
||||
docRef: RefSchema,
|
||||
isPublic: { type: Boolean },
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({docRef, isPublic}){
|
||||
let doc = fetchDocByRef(docRef);
|
||||
assertOwnership(doc, this.userId);
|
||||
@@ -21,7 +27,7 @@ const setPublic = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const updateUserSharePermissions = new ValidatedMethod({
|
||||
name: 'sharing.methods.updateUserSharePermissions',
|
||||
name: 'sharing.updateUserSharePermissions',
|
||||
validate: new SimpleSchema({
|
||||
docRef: RefSchema,
|
||||
userId: {
|
||||
@@ -33,6 +39,11 @@ const updateUserSharePermissions = new ValidatedMethod({
|
||||
allowedValues: ['reader', 'writer', 'none'],
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({docRef, userId, role}){
|
||||
let doc = fetchDocByRef(docRef);
|
||||
if (role === 'none'){
|
||||
|
||||
@@ -113,3 +113,17 @@ export function assertDocViewPermission(doc, userId){
|
||||
let root = getRoot(doc);
|
||||
assertViewPermission(root, userId);
|
||||
}
|
||||
|
||||
export function assertAdmin(userId){
|
||||
assertIdValid(userId);
|
||||
let user = Meteor.users.findOne(userId, {fields: {roles: 1}});
|
||||
if (!user){
|
||||
throw new Meteor.Error('Permission denied',
|
||||
'UserId does not match any existing user');
|
||||
}
|
||||
let isAdmin = user.roles && user.roles.includes('admin')
|
||||
if (!isAdmin){
|
||||
throw new Meteor.Error('Permission denied',
|
||||
'User does not have the admin role');
|
||||
}
|
||||
}
|
||||
|
||||
115
app/imports/api/tabletop/Messages.js
Normal file
115
app/imports/api/tabletop/Messages.js
Normal file
@@ -0,0 +1,115 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import Tabletops, { assertUserInTabletop } from '/imports/api/tabletop/Tabletops.js';
|
||||
|
||||
let Messages = new Mongo.Collection('messages');
|
||||
|
||||
let MessagesSchema = new SimpleSchema({
|
||||
tabletopId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
max: 1000,
|
||||
},
|
||||
timestamp: {
|
||||
type: Date,
|
||||
index: 1,
|
||||
},
|
||||
userId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
Messages.attachSchema(MessagesSchema);
|
||||
|
||||
const sendMessage = new ValidatedMethod({
|
||||
|
||||
name: 'messages.send',
|
||||
|
||||
validate: new SimpleSchema({
|
||||
content: {
|
||||
type: String,
|
||||
max: 1000,
|
||||
},
|
||||
tabletopId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
}).validator(),
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 10,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run({content, tabletopId}) {
|
||||
let user = Meteor.user();
|
||||
if (!user) {
|
||||
throw new Meteor.Error('messages.send.denied',
|
||||
'You need to be logged in to send a message');
|
||||
}
|
||||
assertUserInTabletop(tabletopId, this.userId);
|
||||
|
||||
return Messages.insert({
|
||||
content,
|
||||
tabletopId,
|
||||
timestamp: new Date(),
|
||||
userId: user._id,
|
||||
username: user.username,
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
const removeMessages = new ValidatedMethod({
|
||||
|
||||
name: 'messages.remove',
|
||||
|
||||
validate: new SimpleSchema({
|
||||
messageId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
}).validator(),
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run({messageId, tabletopId}) {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('messages.remove.denied',
|
||||
'You need to be logged in to remove a tabletop');
|
||||
}
|
||||
let message = Messages.findOne(messageId);
|
||||
let tabletop = Tabletops.findOne(message.tabletopId);
|
||||
if (this.userId !== message.userId && this.userId !== tabletop.gameMaster){
|
||||
throw new Meteor.Error('messages.remove.denied',
|
||||
'You don\'t have permission to remove this message');
|
||||
}
|
||||
let removed = Messages.remove({
|
||||
_id: messageId,
|
||||
});
|
||||
Creatures.update({
|
||||
tabletop: tabletopId,
|
||||
}, {
|
||||
$unset: {tabletop: 1},
|
||||
});
|
||||
return removed;
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
export default Messages;
|
||||
export { sendMessage, removeMessages };
|
||||
201
app/imports/api/tabletop/Tabletops.js
Normal file
201
app/imports/api/tabletop/Tabletops.js
Normal file
@@ -0,0 +1,201 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import { assertUserHasPaidBenefits } from '/imports/api/users/patreon/tiers.js';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
|
||||
let Tabletops = new Mongo.Collection('tabletops');
|
||||
|
||||
const InitiativeSchema = new SimpleSchema({
|
||||
active: {
|
||||
type: Boolean,
|
||||
defaultValue: false,
|
||||
},
|
||||
roundNumber: {
|
||||
type: SimpleSchema.Integer,
|
||||
defaultValue: 0,
|
||||
},
|
||||
initiativeNumber: {
|
||||
type: SimpleSchema.Integer,
|
||||
optional: true,
|
||||
},
|
||||
activeCreature: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
// All creatures in a tabletop have a shared time and space.
|
||||
let TabletopSchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
initiative: {
|
||||
type: InitiativeSchema,
|
||||
defaultValue: {},
|
||||
},
|
||||
gameMaster: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
players: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'players.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
});
|
||||
|
||||
Tabletops.attachSchema(TabletopSchema);
|
||||
|
||||
function assertUserIsTabletopOwner(tabletopId, userId){
|
||||
let tabletop = Tabletops.findOne(tabletopId);
|
||||
if (!tabletop){
|
||||
throw new Meteor.Error('Tabletop does not exist',
|
||||
'No tabletop could be found for the given tabletop id');
|
||||
}
|
||||
if (tabletop.gameMaster !== userId){
|
||||
throw new Meteor.Error('Not the owner',
|
||||
'The user is not the owner of the given tabletop');
|
||||
}
|
||||
}
|
||||
|
||||
export function assertUserInTabletop(tabletopId, userId){
|
||||
let tabletop = Tabletops.findOne(tabletopId);
|
||||
if (!tabletop){
|
||||
throw new Meteor.Error('Tabletop does not exist',
|
||||
'No tabletop could be found for the given tabletop id');
|
||||
}
|
||||
if (tabletop.gameMaster !== userId && !tabletop.players.includes(userId)){
|
||||
throw new Meteor.Error('Not in tabletop',
|
||||
'The user is not the gamemaster or a player in the given tabletop');
|
||||
}
|
||||
}
|
||||
|
||||
function assertUserIsAdmin(userId){
|
||||
if (!Meteor.users.isAdmin(userId)){
|
||||
throw new Meteor.Error('Admin only',
|
||||
'This is restricted to admins for now');
|
||||
}
|
||||
}
|
||||
|
||||
const insertTabletop = new ValidatedMethod({
|
||||
|
||||
name: 'tabletops.insert',
|
||||
|
||||
validate: null,
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run() {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('tabletops.insert.denied',
|
||||
'You need to be logged in to insert a tabletop');
|
||||
}
|
||||
assertUserHasPaidBenefits(this.userId);
|
||||
assertUserIsAdmin(this.userId);
|
||||
|
||||
return Tabletops.insert({
|
||||
gameMaster: this.userId,
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
const removeTabletop = new ValidatedMethod({
|
||||
|
||||
name: 'tabletops.remove',
|
||||
|
||||
validate: new SimpleSchema({
|
||||
tabletopId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
}).validator(),
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run({tabletopId}) {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('tabletops.remove.denied',
|
||||
'You need to be logged in to remove a tabletop');
|
||||
}
|
||||
assertUserHasPaidBenefits(this.userId);
|
||||
assertUserIsTabletopOwner(tabletopId, this.userId);
|
||||
assertUserIsAdmin(this.userId);
|
||||
|
||||
let removed = Tabletops.remove({
|
||||
_id: tabletopId,
|
||||
});
|
||||
Creatures.update({
|
||||
tabletop: tabletopId,
|
||||
}, {
|
||||
$unset: {tabletop: 1},
|
||||
});
|
||||
return removed;
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
const addCreaturesToTabletop = new ValidatedMethod({
|
||||
|
||||
name: 'tabletops.addCreatures',
|
||||
|
||||
validate: new SimpleSchema({
|
||||
'creatureIds': {
|
||||
type: Array,
|
||||
},
|
||||
'creatureIds.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
tabletopId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id,
|
||||
},
|
||||
}).validator(),
|
||||
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 10,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
|
||||
run({tabletopId, creatureIds}) {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('tabletops.addCreatures.denied',
|
||||
'You need to be logged in to remove a tabletop');
|
||||
}
|
||||
assertUserHasPaidBenefits(this.userId);
|
||||
assertUserInTabletop(tabletopId, this.userId);
|
||||
assertUserIsAdmin(this.userId);
|
||||
|
||||
Creatures.update({
|
||||
_id: {$in: creatureIds},
|
||||
$or: [
|
||||
{writers: this.userId},
|
||||
{owner: this.userId},
|
||||
],
|
||||
}, {
|
||||
$set: {tabletop: tabletopId},
|
||||
}, {
|
||||
multi: true,
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
export default Tabletops;
|
||||
export { insertTabletop, removeTabletop, addCreaturesToTabletop };
|
||||
@@ -1,5 +1,6 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||
|
||||
let Invites= new Mongo.Collection('invites');
|
||||
@@ -85,13 +86,18 @@ function alignInvitesWithPatreonTier(user){
|
||||
}
|
||||
|
||||
const getInviteToken = new ValidatedMethod({
|
||||
name: 'Invites.methods.getToken',
|
||||
name: 'invites.getToken',
|
||||
validate: new SimpleSchema({
|
||||
inviteId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({inviteId}) {
|
||||
let invite = Invites.findOne(inviteId);
|
||||
if (this.userId !== invite.inviter) {
|
||||
@@ -109,12 +115,17 @@ const getInviteToken = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const acceptInviteToken = new ValidatedMethod({
|
||||
name: 'Invites.methods.acceptToken',
|
||||
name: 'invites.acceptToken',
|
||||
validate: new SimpleSchema({
|
||||
inviteToken: {
|
||||
type: String,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({inviteToken}) {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('Invites.methods.acceptToken.denied',
|
||||
@@ -146,13 +157,18 @@ const acceptInviteToken = new ValidatedMethod({
|
||||
});
|
||||
|
||||
const revokeInvite = new ValidatedMethod({
|
||||
name: 'Invites.methods.revokeInvite',
|
||||
name: 'invites.revokeInvite',
|
||||
validate: new SimpleSchema({
|
||||
inviteId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({inviteId}) {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('Invites.methods.revokeInvite.denied',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
|
||||
const userSchema = new SimpleSchema({
|
||||
username: {
|
||||
@@ -82,13 +83,27 @@ const userSchema = new SimpleSchema({
|
||||
blackbox: true,
|
||||
optional: true,
|
||||
},
|
||||
preferences: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
defaultValue: {},
|
||||
},
|
||||
'preferences.swapAbilityScoresAndModifiers': {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.users.attachSchema(userSchema);
|
||||
|
||||
Meteor.users.generateApiKey = new ValidatedMethod({
|
||||
name: 'Users.methods.generateApiKey',
|
||||
name: 'users.generateApiKey',
|
||||
validate: null,
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run(){
|
||||
if(Meteor.isClient) return;
|
||||
var user = Meteor.users.findOne(this.userId);
|
||||
@@ -100,10 +115,15 @@ Meteor.users.generateApiKey = new ValidatedMethod({
|
||||
});
|
||||
|
||||
Meteor.users.setDarkMode = new ValidatedMethod({
|
||||
name: 'Users.methods.setDarkMode',
|
||||
name: 'users.setDarkMode',
|
||||
validate: new SimpleSchema({
|
||||
darkMode: { type: Boolean },
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({darkMode}){
|
||||
if (!this.userId) return;
|
||||
Meteor.users.update(this.userId, {$set: {darkMode}});
|
||||
@@ -111,7 +131,7 @@ Meteor.users.setDarkMode = new ValidatedMethod({
|
||||
});
|
||||
|
||||
Meteor.users.sendVerificationEmail = new ValidatedMethod({
|
||||
name: 'Users.methods.sendVerificationEmail',
|
||||
name: 'users.sendVerificationEmail',
|
||||
validate: new SimpleSchema({
|
||||
userId:{
|
||||
type: String,
|
||||
@@ -121,6 +141,11 @@ Meteor.users.sendVerificationEmail = new ValidatedMethod({
|
||||
type: String,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({userId, address}){
|
||||
userId = this.userId || userId;
|
||||
let user = Meteor.users.findOne(userId);
|
||||
@@ -143,8 +168,13 @@ Meteor.users.isAdmin = function(userId){
|
||||
}
|
||||
|
||||
Meteor.users.canPickUsername = new ValidatedMethod({
|
||||
name: 'Users.methods.canPickUsername',
|
||||
name: 'users.canPickUsername',
|
||||
validate: userSchema.pick('username').validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({username}){
|
||||
if (Meteor.isClient) return;
|
||||
let user = Accounts.findUserByUsername(username);
|
||||
@@ -157,8 +187,13 @@ Meteor.users.canPickUsername = new ValidatedMethod({
|
||||
});
|
||||
|
||||
Meteor.users.setUsername = new ValidatedMethod({
|
||||
name: 'Users.methods.setUsername',
|
||||
name: 'users.setUsername',
|
||||
validate: userSchema.pick('username').validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({username}){
|
||||
if (!this.userId) throw 'Can only set your username if logged in';
|
||||
if (Meteor.isClient) return;
|
||||
@@ -166,8 +201,38 @@ Meteor.users.setUsername = new ValidatedMethod({
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.users.setPreference = new ValidatedMethod({
|
||||
name: 'users.setPreference',
|
||||
validate: new SimpleSchema({
|
||||
preference:{
|
||||
type: String,
|
||||
},
|
||||
value: {
|
||||
type: SimpleSchema.oneOf(Boolean),
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({preference, value}){
|
||||
if (!this.userId) throw 'You can only set preferences once logged in';
|
||||
let prefPath = `preferences.${preference}`
|
||||
if (value == true){
|
||||
return Meteor.users.update(this.userId, {
|
||||
$set: {[prefPath]: true},
|
||||
});
|
||||
} else {
|
||||
return Meteor.users.update(this.userId, {
|
||||
$unset: {[prefPath]: 1},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.users.subscribeToLibrary = new ValidatedMethod({
|
||||
name: 'Users.methods.subscribeToLibrary',
|
||||
name: 'users.subscribeToLibrary',
|
||||
validate: new SimpleSchema({
|
||||
libraryId:{
|
||||
type: String,
|
||||
@@ -177,6 +242,11 @@ Meteor.users.subscribeToLibrary = new ValidatedMethod({
|
||||
type: Boolean,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({libraryId, subscribe}){
|
||||
if (!this.userId) throw 'Can only subscribe if logged in';
|
||||
if (subscribe){
|
||||
@@ -192,12 +262,17 @@ Meteor.users.subscribeToLibrary = new ValidatedMethod({
|
||||
});
|
||||
|
||||
Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({
|
||||
name: 'Users.methods.findUserByUsernameOrEmail',
|
||||
name: 'users.findUserByUsernameOrEmail',
|
||||
validate: new SimpleSchema({
|
||||
usernameOrEmail:{
|
||||
type: String,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({usernameOrEmail}){
|
||||
if (Meteor.isClient) return;
|
||||
let user = Accounts.findUserByUsername(usernameOrEmail) ||
|
||||
|
||||
@@ -77,5 +77,13 @@ export function getUserTier(user){
|
||||
}
|
||||
}
|
||||
|
||||
export function assertUserHasPaidBenefits(user){
|
||||
let tier = getUserTier(user);
|
||||
if (!tier.paidBenefits){
|
||||
throw new Meteor.Error('Creatures.methods.insert.denied',
|
||||
`The ${tier.name} tier does not allow you to insert a creature`);
|
||||
}
|
||||
}
|
||||
|
||||
export default TIERS;
|
||||
export { GUEST_TIER };
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
const PROPERTIES = Object.freeze({
|
||||
action: {
|
||||
icon: 'offline_bolt',
|
||||
icon: '$vuetify.icons.action',
|
||||
name: 'Action'
|
||||
},
|
||||
adjustment: {
|
||||
icon: 'warning',
|
||||
name: 'Attribute damage'
|
||||
},
|
||||
attack: {
|
||||
icon: 'bolt',
|
||||
icon: '$vuetify.icons.attack',
|
||||
name: 'Attack'
|
||||
},
|
||||
attribute: {
|
||||
icon: 'donut_small',
|
||||
icon: '$vuetify.icons.attribute',
|
||||
name: 'Attribute'
|
||||
},
|
||||
adjustment: {
|
||||
icon: '$vuetify.icons.attribute_damage',
|
||||
name: 'Attribute damage'
|
||||
},
|
||||
buff: {
|
||||
icon: 'star',
|
||||
icon: '$vuetify.icons.buff',
|
||||
name: 'Buff'
|
||||
},
|
||||
classLevel: {
|
||||
icon: 'school',
|
||||
icon: '$vuetify.icons.class_level',
|
||||
name: 'Class level'
|
||||
},
|
||||
container: {
|
||||
icon: 'work',
|
||||
name: 'Container'
|
||||
},
|
||||
damage: {
|
||||
icon: 'report',
|
||||
icon: '$vuetify.icons.damage',
|
||||
name: 'Damage'
|
||||
},
|
||||
damageMultiplier: {
|
||||
icon: 'layers',
|
||||
icon: '$vuetify.icons.damage_multiplier',
|
||||
name: 'Damage multiplier'
|
||||
},
|
||||
effect: {
|
||||
icon: 'show_chart',
|
||||
icon: '$vuetify.icons.effect',
|
||||
name: 'Effect'
|
||||
},
|
||||
experience: {
|
||||
icon: 'add',
|
||||
name: 'Experience'
|
||||
},
|
||||
feature: {
|
||||
icon: 'subject',
|
||||
name: 'Feature'
|
||||
@@ -47,6 +47,10 @@ const PROPERTIES = Object.freeze({
|
||||
icon: 'folder',
|
||||
name: 'Folder'
|
||||
},
|
||||
item: {
|
||||
icon: '$vuetify.icons.item',
|
||||
name: 'Item'
|
||||
},
|
||||
note: {
|
||||
icon: 'note',
|
||||
name: 'Note'
|
||||
@@ -56,35 +60,31 @@ const PROPERTIES = Object.freeze({
|
||||
name: 'Proficiency'
|
||||
},
|
||||
roll: {
|
||||
icon: 'flare',
|
||||
icon: '$vuetify.icons.roll',
|
||||
name: 'Roll'
|
||||
},
|
||||
savingThrow: {
|
||||
icon: 'all_out',
|
||||
icon: '$vuetify.icons.saving_throw',
|
||||
name: 'Saving throw'
|
||||
},
|
||||
skill: {
|
||||
icon: 'check_box',
|
||||
icon: '$vuetify.icons.skill',
|
||||
name: 'Skill'
|
||||
},
|
||||
propertySlot: {
|
||||
icon: 'tab_unselected',
|
||||
name: 'Slot'
|
||||
},
|
||||
spellList: {
|
||||
icon: 'list',
|
||||
icon: '$vuetify.icons.spell_list',
|
||||
name: 'Spell list'
|
||||
},
|
||||
spell: {
|
||||
icon: 'whatshot',
|
||||
icon: '$vuetify.icons.spell',
|
||||
name: 'Spell'
|
||||
},
|
||||
container: {
|
||||
icon: 'work',
|
||||
name: 'Container'
|
||||
},
|
||||
item: {
|
||||
icon: 'category',
|
||||
name: 'Item'
|
||||
},
|
||||
toggle: {
|
||||
icon: 'power_settings_new',
|
||||
icon: '$vuetify.icons.toggle',
|
||||
name: 'Toggle'
|
||||
},
|
||||
});
|
||||
|
||||
96
app/imports/constants/SVG_ICONS.js
Normal file
96
app/imports/constants/SVG_ICONS.js
Normal file
File diff suppressed because one or more lines are too long
@@ -1,8 +1,20 @@
|
||||
import { create, all } from 'mathjs';
|
||||
|
||||
const math = create(all);
|
||||
math.import({
|
||||
'if': function(pred, a, b) {
|
||||
return pred ? a : b;
|
||||
},
|
||||
'roll': function(number, diceSize){
|
||||
let randomSrc = DDP.randomStream('diceRoller');
|
||||
if (number > 100) throw 'Can only roll 100 dice at a time';
|
||||
let rollTotal = 0;
|
||||
let i, roll;
|
||||
for (i = 0; i < number; i++){
|
||||
roll = ~~(randomSrc.fraction() * diceSize) + 1
|
||||
rollTotal += roll;
|
||||
}
|
||||
return rollTotal;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
6
app/imports/server/config/SimpleRestConfig.js
Normal file
6
app/imports/server/config/SimpleRestConfig.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import { SimpleRest } from 'meteor/simple:rest';
|
||||
|
||||
SimpleRest.configure({
|
||||
// No default collection methods get end points
|
||||
collections: [],
|
||||
});
|
||||
@@ -1,11 +1,18 @@
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||
import { assertAdmin } from '/imports/api/sharing/sharingPermissions.js';
|
||||
import { SyncedCron } from 'meteor/percolate:synced-cron';
|
||||
|
||||
let collections = [LibraryNodes];
|
||||
Meteor.startup(() => {
|
||||
const collections = [
|
||||
CreatureProperties,
|
||||
LibraryNodes,
|
||||
];
|
||||
|
||||
if (Meteor.isServer) Meteor.startup(() => {
|
||||
/**
|
||||
* Deletes all soft removed documents that were removed more than 30 minutes ago
|
||||
* and were not restored
|
||||
* @return {Number} Number of documents removed
|
||||
*/
|
||||
const deleteOldSoftRemovedDocs = function(){
|
||||
const now = new Date();
|
||||
@@ -14,30 +21,30 @@ if (Meteor.isServer) Meteor.startup(() => {
|
||||
collection.remove({
|
||||
removed: true,
|
||||
removedAt: {$lt: thirtyMinutesAgo} // dates *before* 30 minutes ago
|
||||
}, error => {
|
||||
if (error) console.error(error);
|
||||
}, function(error){
|
||||
if (error){
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
return;
|
||||
};
|
||||
|
||||
SyncedCron.add({
|
||||
name: "Delete all soft removed items that haven't been restored",
|
||||
name: 'deleteSoftRemovedDocs',
|
||||
schedule: function(parser) {
|
||||
return parser.text('every 6 hours');
|
||||
return parser.text('every 2 hours');
|
||||
},
|
||||
job: function() {
|
||||
deleteOldSoftRemovedDocs();
|
||||
}
|
||||
job: deleteOldSoftRemovedDocs,
|
||||
});
|
||||
|
||||
SyncedCron.start();
|
||||
|
||||
// Add a method to manually trigger removal
|
||||
Meteor.methods({
|
||||
deleteOldSoftRemovedDocs() {
|
||||
const user = Meteor.users.findOne(this.userId);
|
||||
if (user && _.contains(user.roles, "admin")){
|
||||
return deleteOldSoftRemovedDocs();
|
||||
}
|
||||
assertAdmin(this.userId);
|
||||
this.unblock();
|
||||
deleteOldSoftRemovedDocs();
|
||||
},
|
||||
});
|
||||
});
|
||||
7
app/imports/server/discord/webhook.js
Normal file
7
app/imports/server/discord/webhook.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import Discord from 'discord.js'
|
||||
export default function sendWebhook({webhook, message}){
|
||||
// const hook = new Discord.WebhookClient(webhook.id, webhook.token);
|
||||
const hook = new Discord.WebhookClient('420492135716880394', 'KHmRsf9QHd81C4LZOyQe_cUw5ua4ugSaIlpDMNWo3vcNHs0p0JBOHfeGWtHKqPXMYgkk');
|
||||
// Send a message using the webhook
|
||||
hook.send(message);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import Parties from '/imports/api/campaign/Parties.js';
|
||||
import Parties from '/imports/api/creature/Parties.js';
|
||||
|
||||
Meteor.publish('characterList', function(){
|
||||
this.autorun(function (){
|
||||
|
||||
32
app/imports/server/publications/experiences.js
Normal file
32
app/imports/server/publications/experiences.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
||||
|
||||
let schema = new SimpleSchema({
|
||||
creatureId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.publish('experiences', function(creatureId){
|
||||
schema.validate({ creatureId });
|
||||
this.autorun(function (){
|
||||
let userId = this.userId;
|
||||
let creatureCursor = Creatures.find({
|
||||
_id: creatureId,
|
||||
$or: [
|
||||
{readers: userId},
|
||||
{writers: userId},
|
||||
{owner: userId},
|
||||
{public: true},
|
||||
],
|
||||
});
|
||||
if (!creatureCursor.count()) return this.ready();
|
||||
return [
|
||||
Experiences.find({
|
||||
creatureId,
|
||||
}),
|
||||
];
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,8 @@
|
||||
import '/imports/server/publications/publicationRateLimit.js';
|
||||
import '/imports/server/publications/characterList.js';
|
||||
import '/imports/server/publications/library.js';
|
||||
import '/imports/server/publications/singleCharacter.js';
|
||||
import '/imports/server/publications/experiences.js';
|
||||
import '/imports/server/publications/users.js';
|
||||
import '/imports/server/publications/icons.js';
|
||||
import '/imports/server/publications/tabletops.js';
|
||||
|
||||
4
app/imports/server/publications/publicationRateLimit.js
Normal file
4
app/imports/server/publications/publicationRateLimit.js
Normal file
@@ -0,0 +1,4 @@
|
||||
// Limit all subscriptions to 1/s
|
||||
DDPRateLimiter.addRule({
|
||||
type: 'subscription',
|
||||
}, 10, 10000);
|
||||
60
app/imports/server/publications/tabletops.js
Normal file
60
app/imports/server/publications/tabletops.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import Tabletops from '/imports/api/tabletop/Tabletops.js';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import Messages from '/imports/api/tabletop/Messages.js';
|
||||
|
||||
Meteor.publish('tabletops', function(){
|
||||
var userId = this.userId;
|
||||
if (!userId) {
|
||||
return this.ready();
|
||||
}
|
||||
return Tabletops.find({
|
||||
$or: [
|
||||
{players: userId},
|
||||
{gameMaster: userId},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
Meteor.publish('tabletop', function(tabletopId){
|
||||
var userId = this.userId;
|
||||
if (!userId) {
|
||||
return this.ready();
|
||||
}
|
||||
this.autorun(function (){
|
||||
let tabletopCursor = Tabletops.find({
|
||||
_id: tabletopId,
|
||||
$or: [
|
||||
{players: userId},
|
||||
{gameMaster: userId},
|
||||
]
|
||||
});
|
||||
let tabletop = tabletopCursor.fetch()[0];
|
||||
if (!tabletop){
|
||||
return this.ready();
|
||||
}
|
||||
// Warning, this leaks data to users of the same tabletop who may not have
|
||||
// read permission of this specific creature, so publish as few fields as
|
||||
// possible
|
||||
let creatureSummaries = Creatures.find({
|
||||
tabletop: tabletopId,
|
||||
}, {
|
||||
fields: {
|
||||
name: 1,
|
||||
picture: 1,
|
||||
avatarPicture: 1,
|
||||
variables: 1,
|
||||
tabletop: 1,
|
||||
initiativeRoll: 1,
|
||||
},
|
||||
});
|
||||
let recentMessages = Messages.find({
|
||||
tabletopId,
|
||||
}, {
|
||||
sort: {
|
||||
timeStamp: -1,
|
||||
},
|
||||
limit: 100,
|
||||
});
|
||||
return [ tabletopCursor, creatureSummaries, recentMessages]
|
||||
})
|
||||
});
|
||||
@@ -11,6 +11,7 @@ Meteor.publish('user', function(){
|
||||
darkMode: 1,
|
||||
subscribedLibraries: 1,
|
||||
profile: 1,
|
||||
preferences: 1,
|
||||
'services.patreon.id': 1,
|
||||
'services.patreon.entitledCents': 1,
|
||||
'services.patreon.entitledCentsOverride': 1,
|
||||
|
||||
40
app/imports/ui/components/CoinValue.vue
Normal file
40
app/imports/ui/components/CoinValue.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<template lang="html">
|
||||
<div>
|
||||
<span
|
||||
v-if="coinValue.gp || value === 0"
|
||||
>
|
||||
{{ coinValue.gp }} gp
|
||||
</span>
|
||||
<span
|
||||
v-if="coinValue.sp || (coinValue.gp && coinValue.cp)"
|
||||
>
|
||||
{{ coinValue.sp }} sp
|
||||
</span>
|
||||
<span
|
||||
v-if="coinValue.cp"
|
||||
>
|
||||
{{ coinValue.cp }} cp
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import valueToCoins from '/imports/ui/utility/valueToCoins.js';
|
||||
|
||||
export default {
|
||||
props:{
|
||||
value: {
|
||||
type: Number,
|
||||
default: undefined,
|
||||
},
|
||||
},
|
||||
computed:{
|
||||
coinValue(){
|
||||
return valueToCoins(this.value);
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
</style>
|
||||
@@ -56,7 +56,7 @@
|
||||
<v-scroll-y-transition>
|
||||
<v-icon
|
||||
v-if="kebabShade === shadeOption"
|
||||
:class="{dark: isDark(color, shade)}"
|
||||
:class="isDark(color, shade) ? 'dark' : 'light'"
|
||||
>
|
||||
check
|
||||
</v-icon>
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
<template lang="html">
|
||||
<v-autocomplete
|
||||
v-model="model"
|
||||
:search-input.sync="searchString"
|
||||
:items="items"
|
||||
:loading="!$subReady.searchIcons || isLoading"
|
||||
item-text="name"
|
||||
item-value="_id"
|
||||
label="Search icons"
|
||||
hide-no-data
|
||||
@input="input"
|
||||
>
|
||||
<template
|
||||
slot="item"
|
||||
slot-scope="{ item, tile }"
|
||||
>
|
||||
<v-list-tile-avatar>
|
||||
<svg class="avatar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path :d="item.shape"/></svg>
|
||||
</v-list-tile-avatar>
|
||||
<v-list-tile-content>
|
||||
<v-list-tile-title v-text="item.name"></v-list-tile-title>
|
||||
</v-list-tile-content>
|
||||
</template>
|
||||
</v-autocomplete>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Icons from '/imports/api/icons/Icons.js';
|
||||
|
||||
export default {
|
||||
data(){ return {
|
||||
model: this.value,
|
||||
searchString: null,
|
||||
serverSearchString: null,
|
||||
isLoading: false,
|
||||
}},
|
||||
props: {
|
||||
value: String,
|
||||
},
|
||||
watch: {
|
||||
searchString(string){
|
||||
this.isLoading = true;
|
||||
this.searchServer(string)
|
||||
},
|
||||
value(newValue){
|
||||
this.model = newValue;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
searchServer: _.debounce(function(string){
|
||||
this.serverSearchString = string;
|
||||
}, 200),
|
||||
input(e){
|
||||
this.$emit('input', e);
|
||||
}
|
||||
},
|
||||
meteor: {
|
||||
$subscribe: {
|
||||
searchIcons() {
|
||||
this.isLoading = false;
|
||||
return [this.serverSearchString];
|
||||
},
|
||||
},
|
||||
items(){
|
||||
return Icons.find({}, { sort: [['score', 'desc']] }).fetch();
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
.avatar {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.theme--dark .avatar {
|
||||
fill: white;
|
||||
}
|
||||
</style>
|
||||
59
app/imports/ui/components/IncrementButton.vue
Normal file
59
app/imports/ui/components/IncrementButton.vue
Normal file
@@ -0,0 +1,59 @@
|
||||
<template lang="html">
|
||||
<v-menu
|
||||
v-model="open"
|
||||
origin="center center"
|
||||
transition="scale-transition"
|
||||
:nudge-left="130"
|
||||
:min-width="305"
|
||||
:close-on-content-click="false"
|
||||
>
|
||||
<template #activator="{ on }">
|
||||
<v-btn
|
||||
v-bind="$attrs"
|
||||
v-on="on"
|
||||
@click.stop
|
||||
>
|
||||
<slot>
|
||||
<v-icon>add</v-icon>
|
||||
</slot>
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-card>
|
||||
<increment-menu
|
||||
flat
|
||||
:value="value"
|
||||
:open="open"
|
||||
@change="changeIncrementMenu"
|
||||
@close="open = false"
|
||||
/>
|
||||
</v-card>
|
||||
</v-menu>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import IncrementMenu from '/imports/ui/components/IncrementMenu.vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
IncrementMenu,
|
||||
},
|
||||
props: {
|
||||
value: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data(){return {
|
||||
open: false
|
||||
}},
|
||||
methods: {
|
||||
changeIncrementMenu(e){
|
||||
this.$emit('change', e);
|
||||
this.open = false;
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
</style>
|
||||
166
app/imports/ui/components/IncrementMenu.vue
Normal file
166
app/imports/ui/components/IncrementMenu.vue
Normal file
@@ -0,0 +1,166 @@
|
||||
<template>
|
||||
<v-layout
|
||||
row
|
||||
align-center
|
||||
justify-center
|
||||
class="increment-menu"
|
||||
>
|
||||
<v-spacer />
|
||||
<v-btn-toggle
|
||||
:value="operation === 'add' ? 0: operation === 'subtract' ? 1 : null"
|
||||
class="mx-2"
|
||||
@click="$refs.editInput.focus()"
|
||||
>
|
||||
<v-btn
|
||||
:disabled="context.editPermission === false"
|
||||
class="filled"
|
||||
@click="toggleAdd(); $nextTick(() => $refs.editInput.focus())"
|
||||
>
|
||||
<v-icon>add</v-icon>
|
||||
</v-btn>
|
||||
<v-btn
|
||||
:disabled="context.editPermission === false"
|
||||
class="filled"
|
||||
@click="toggleSubtract(); $nextTick(() => $refs.editInput.focus())"
|
||||
>
|
||||
<v-icon>remove</v-icon>
|
||||
</v-btn>
|
||||
</v-btn-toggle>
|
||||
<v-text-field
|
||||
ref="editInput"
|
||||
:solo="!flat"
|
||||
:class="flat && 'ma-0 pa-0'"
|
||||
hide-details
|
||||
type="number"
|
||||
style="max-width: 120px;"
|
||||
min="0"
|
||||
:value="editValue"
|
||||
:prepend-inner-icon="operationIcon(operation)"
|
||||
:disabled="context.editPermission === false"
|
||||
@focus="$event.target.select()"
|
||||
@keypress="keypress"
|
||||
@input="input"
|
||||
/>
|
||||
<v-btn
|
||||
:small="!flat"
|
||||
:fab="!flat"
|
||||
:flat="flat"
|
||||
:icon="flat"
|
||||
class="filled"
|
||||
@click="commitEdit"
|
||||
>
|
||||
<v-icon>done</v-icon>
|
||||
</v-btn>
|
||||
<v-btn
|
||||
:small="!flat"
|
||||
:fab="!flat"
|
||||
:flat="flat"
|
||||
:icon="flat"
|
||||
class="mx-0 filled"
|
||||
@click="cancelEdit"
|
||||
>
|
||||
<v-icon>close</v-icon>
|
||||
</v-btn>
|
||||
<v-spacer />
|
||||
</v-layout>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
inject: {
|
||||
context: { default: {} }
|
||||
},
|
||||
props: {
|
||||
value: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
open: Boolean,
|
||||
flat: Boolean,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
editValue: 0,
|
||||
operation: 'set',
|
||||
hover: false,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
open(newValue){
|
||||
if (newValue){
|
||||
this.resetData();
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
resetData(){
|
||||
this.editValue = this.value;
|
||||
this.operation = 'set';
|
||||
// this.$nextTick didn't work, using timeout instead did
|
||||
setTimeout(() => {
|
||||
if (this.$refs.editInput){
|
||||
this.$refs.editInput.focus();
|
||||
}
|
||||
}, 100);
|
||||
},
|
||||
cancelEdit() {
|
||||
this.$emit('close');
|
||||
},
|
||||
commitEdit() {
|
||||
this.editing = false;
|
||||
let value = +this.$refs.editInput.lazyValue;
|
||||
if (this.operation === 'add') {
|
||||
value = -value;
|
||||
}
|
||||
let type = this.operation === 'set' ? 'set' : 'increment';
|
||||
this.$emit('change', { type, value });
|
||||
},
|
||||
operationIcon(operation) {
|
||||
switch (operation) {
|
||||
case 'set':
|
||||
return 'forward';
|
||||
case 'add':
|
||||
return 'add';
|
||||
case 'subtract':
|
||||
return 'remove';
|
||||
}
|
||||
},
|
||||
toggleAdd(){
|
||||
this.operation = (this.operation === 'add') ? 'set': 'add';
|
||||
},
|
||||
toggleSubtract(){
|
||||
this.operation = (this.operation === 'subtract') ? 'set': 'subtract';
|
||||
},
|
||||
keypress(event) {
|
||||
let digitsOnly = /[0-9]/;
|
||||
let key = event.key;
|
||||
if (key === '+') {
|
||||
this.toggleAdd();
|
||||
event.preventDefault();
|
||||
} else if (key === '-') {
|
||||
this.toggleSubtract();
|
||||
event.preventDefault();
|
||||
} else if (key === 'Enter') {
|
||||
this.commitEdit();
|
||||
} else if (!digitsOnly.test(key)){
|
||||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
input(value){
|
||||
if (+value < 0){
|
||||
this.editValue = -value;
|
||||
this.operation = 'subtract';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.filled.theme--light {
|
||||
background: #fff !important;
|
||||
}
|
||||
.filled.theme--dark {
|
||||
background: #424242 !important;
|
||||
}
|
||||
</style>
|
||||
@@ -9,6 +9,7 @@
|
||||
:style="`transform: none; ${hasToolbarClickListener ? 'cursor: pointer;' : ''}`"
|
||||
:color="color"
|
||||
:dark="isDark"
|
||||
:light="!isDark"
|
||||
@click="$emit('toolbarclick')"
|
||||
>
|
||||
<slot name="toolbar" />
|
||||
|
||||
131
app/imports/ui/components/global/IconPicker.vue
Normal file
131
app/imports/ui/components/global/IconPicker.vue
Normal file
@@ -0,0 +1,131 @@
|
||||
<template lang="html">
|
||||
<v-menu
|
||||
v-model="menu"
|
||||
:close-on-content-click="false"
|
||||
lazy
|
||||
transition="slide-y-transition"
|
||||
min-width="290px"
|
||||
style="overflow-y: auto;"
|
||||
>
|
||||
<template #activator="{ on }">
|
||||
<div class="layout row align-center">
|
||||
<v-label>{{ label }}</v-label>
|
||||
<v-btn
|
||||
:loading="loading"
|
||||
large
|
||||
icon
|
||||
v-on="on"
|
||||
>
|
||||
<svg-icon
|
||||
v-if="safeValue && safeValue.shape"
|
||||
large
|
||||
:shape="safeValue.shape"
|
||||
/>
|
||||
<v-icon
|
||||
v-else
|
||||
large
|
||||
>
|
||||
highlight_alt
|
||||
</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
</template>
|
||||
<v-card>
|
||||
<v-card-text>
|
||||
<div class="layout row">
|
||||
<text-field
|
||||
ref="iconSearchField"
|
||||
label="Search icons"
|
||||
append-icon="search"
|
||||
clearable
|
||||
:value="searchString"
|
||||
@change="search"
|
||||
/>
|
||||
<v-btn
|
||||
icon
|
||||
@click="select()"
|
||||
>
|
||||
<v-icon>
|
||||
cancel
|
||||
</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
<v-layout
|
||||
row
|
||||
wrap
|
||||
style="max-height: 400px; overflow-y: auto;"
|
||||
>
|
||||
<v-scale-transition
|
||||
group
|
||||
hide-on-leave
|
||||
>
|
||||
<v-btn
|
||||
v-for="icon in icons"
|
||||
:key="icon._id"
|
||||
icon
|
||||
large
|
||||
@click="select(icon)"
|
||||
>
|
||||
<svg-icon
|
||||
:shape="icon.shape"
|
||||
x-large
|
||||
/>
|
||||
</v-btn>
|
||||
</v-scale-transition>
|
||||
</v-layout>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-menu>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import SvgIcon from '/imports/ui/components/global/SvgIcon.vue';
|
||||
import SmartInput from '/imports/ui/components/global/SmartInputMixin.js';
|
||||
import { findIcons } from '/imports/api/icons/Icons.js';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
SvgIcon,
|
||||
},
|
||||
mixins: [SmartInput],
|
||||
props: {
|
||||
label: {
|
||||
type: String,
|
||||
default: 'Icon',
|
||||
},
|
||||
},
|
||||
data(){return {
|
||||
menu: false,
|
||||
searchString: '',
|
||||
icons: [],
|
||||
};},
|
||||
watch: {
|
||||
menu(value){
|
||||
if (value){
|
||||
setTimeout(() => {
|
||||
if (this.$refs.iconSearchField){
|
||||
this.$refs.iconSearchField.$children[0].focus();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
search(value, ack){
|
||||
this.searchString = value;
|
||||
this.icons = [];
|
||||
findIcons.call({search: value}, (error, result) => {
|
||||
ack(error);
|
||||
this.icons = result;
|
||||
});
|
||||
},
|
||||
select(icon){
|
||||
this.menu = false;
|
||||
this.change(icon);
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
</style>
|
||||
@@ -23,7 +23,7 @@ export default {
|
||||
inputValue: this.value,
|
||||
};},
|
||||
props: {
|
||||
value: [String, Number, Date, Array, Boolean],
|
||||
value: [String, Number, Date, Array, Object, Boolean],
|
||||
errorMessages: [String, Array],
|
||||
disabled: Boolean,
|
||||
},
|
||||
@@ -75,7 +75,9 @@ export default {
|
||||
this.ackErrors = null;
|
||||
} else if (typeof error === 'string'){
|
||||
this.ackErrors = error;
|
||||
} else {
|
||||
} else if (error.reason){
|
||||
this.ackErrors = error.reason;
|
||||
} else {
|
||||
this.ackErrors = 'Something went wrong'
|
||||
console.error(error);
|
||||
}
|
||||
@@ -93,6 +95,9 @@ export default {
|
||||
this.safeValue = null;
|
||||
this.$nextTick(() => this.safeValue = this.value);
|
||||
},
|
||||
focus(){
|
||||
this.$refs.input.focus();
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
errors(){
|
||||
|
||||
97
app/imports/ui/components/global/SvgIcon.vue
Normal file
97
app/imports/ui/components/global/SvgIcon.vue
Normal file
@@ -0,0 +1,97 @@
|
||||
<template lang="html">
|
||||
<i
|
||||
ref="icon"
|
||||
aria-hidden
|
||||
role="img"
|
||||
class="v-icon"
|
||||
:class="themeClasses"
|
||||
:style="color && `color: ${color}`"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 512 512"
|
||||
:style="`height: ${size}; width: ${size}`"
|
||||
>
|
||||
<path
|
||||
:d="shape"
|
||||
/>
|
||||
</svg>
|
||||
</i>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const SIZE_MAP = {
|
||||
xSmall: '12px',
|
||||
small: '16px',
|
||||
default: '24px',
|
||||
medium: '28px',
|
||||
large: '36px',
|
||||
xLarge: '40px',
|
||||
}
|
||||
export default {
|
||||
inject: {
|
||||
theme: {
|
||||
default: {
|
||||
isDark: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
props: {
|
||||
shape: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: undefined,
|
||||
},
|
||||
xSmall: Boolean,
|
||||
small: Boolean,
|
||||
medium: Boolean,
|
||||
large: Boolean,
|
||||
xLarge: Boolean,
|
||||
},
|
||||
data(){return {
|
||||
inheritedSize: undefined,
|
||||
}},
|
||||
computed: {
|
||||
isDark () {
|
||||
if (this.dark === true) {
|
||||
// explicitly dark
|
||||
return true
|
||||
} else if (this.light === true) {
|
||||
// explicitly light
|
||||
return false
|
||||
} else {
|
||||
// inherit from parent, or default false if there is none
|
||||
return this.theme.isDark
|
||||
}
|
||||
},
|
||||
themeClasses() {
|
||||
return {
|
||||
'theme--dark': this.isDark,
|
||||
'theme--light': !this.isDark,
|
||||
}
|
||||
},
|
||||
size() {
|
||||
if (this.inheritedSize) return this.inheritedSize;
|
||||
if (this.xSmall) return SIZE_MAP['xSmall'];
|
||||
if (this.small) return SIZE_MAP['small'];
|
||||
if (this.medium) return SIZE_MAP['medium'];
|
||||
if (this.large) return SIZE_MAP['large'];
|
||||
if (this.xLarge) return SIZE_MAP['xLarge'];
|
||||
return SIZE_MAP['default'];
|
||||
},
|
||||
},
|
||||
mounted(){
|
||||
this.inheritedSize = this.$refs.icon.style.fontSize;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
svg {
|
||||
color: inherit;
|
||||
fill: currentColor;
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,6 @@
|
||||
<template lang="html">
|
||||
<v-text-field
|
||||
ref="input"
|
||||
v-bind="$attrs"
|
||||
:loading="loading"
|
||||
:error-messages="errors"
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
import Vue from 'vue';
|
||||
// Global components
|
||||
import DatePicker from '/imports/ui/components/global/DatePicker.vue';
|
||||
import IconPicker from '/imports/ui/components/global/IconPicker.vue';
|
||||
import TextField from '/imports/ui/components/global/TextField.vue';
|
||||
import TextArea from '/imports/ui/components/global/TextArea.vue';
|
||||
import SmartSelect from '/imports/ui/components/global/SmartSelect.vue';
|
||||
import SmartCombobox from '/imports/ui/components/global/SmartCombobox.vue';
|
||||
import SmartCheckbox from '/imports/ui/components/global/SmartCheckbox.vue';
|
||||
import SmartSwitch from '/imports/ui/components/global/SmartSwitch.vue';
|
||||
import SvgIcon from '/imports/ui/components/global/SvgIcon.vue';
|
||||
|
||||
Vue.component('DatePicker', DatePicker);
|
||||
Vue.component('IconPicker', IconPicker);
|
||||
Vue.component('TextField', TextField);
|
||||
Vue.component('TextArea', TextArea);
|
||||
Vue.component('SmartSelect', SmartSelect);
|
||||
Vue.component('SmartCombobox', SmartCombobox);
|
||||
Vue.component('SmartCheckbox', SmartCheckbox);
|
||||
Vue.component('SmartSwitch', SmartSwitch);
|
||||
Vue.component('SvgIcon', SvgIcon);
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
<v-toolbar
|
||||
:color="color || 'secondary'"
|
||||
:dark="isDark"
|
||||
:light="!isDark"
|
||||
:flat="flat"
|
||||
>
|
||||
<property-icon
|
||||
:type="model && model.type"
|
||||
:model="model"
|
||||
class="mr-2"
|
||||
/>
|
||||
<v-toolbar-title v-if="model">
|
||||
{{ model.name || getPropertyName(model.type) }}
|
||||
{{ title }}
|
||||
</v-toolbar-title>
|
||||
<v-spacer />
|
||||
<v-slide-y-transition
|
||||
@@ -141,13 +142,25 @@ export default {
|
||||
},
|
||||
color(){
|
||||
return this.model && this.model.color || this.$vuetify.theme.secondary;
|
||||
},
|
||||
title(){
|
||||
let model = this.model;
|
||||
if (model.quantity !== 1 && model.quantity !== undefined){
|
||||
if (model.plural){
|
||||
return `${model.quantity} ${model.plural}`;
|
||||
} else if (model.name) {
|
||||
return `${model.quantity} ${model.name}`;
|
||||
} else {
|
||||
return `${model.quantity} × ${getPropertyName(model.type)}`
|
||||
}
|
||||
}
|
||||
return model.name || getPropertyName(model.type);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
colorChanged(value){
|
||||
this.$emit('color-changed', value);
|
||||
},
|
||||
getPropertyName,
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -34,8 +34,7 @@
|
||||
drag_handle
|
||||
</v-icon>
|
||||
<!--{{node && node.order}}-->
|
||||
<component
|
||||
:is="treeNodeView"
|
||||
<tree-node-view
|
||||
:model="node"
|
||||
:selected="selected"
|
||||
/>
|
||||
@@ -80,13 +79,13 @@
|
||||
**/
|
||||
import { canBeParent } from '/imports/api/parenting/parenting.js';
|
||||
import { getPropertyIcon } from '/imports/constants/PROPERTIES.js';
|
||||
import treeNodeViewIndex from '/imports/ui/properties/treeNodeViews/treeNodeViewIndex.js';
|
||||
import TreeNodeView from '/imports/ui/properties/treeNodeViews/TreeNodeView.vue';
|
||||
|
||||
export default {
|
||||
name: 'TreeNode',
|
||||
components: {
|
||||
...treeNodeViewIndex
|
||||
},
|
||||
components: {
|
||||
TreeNodeView,
|
||||
},
|
||||
props: {
|
||||
node: Object,
|
||||
group: String,
|
||||
@@ -100,10 +99,6 @@
|
||||
expanded: false,
|
||||
}},
|
||||
computed: {
|
||||
treeNodeView(){
|
||||
let type = this.node.type;
|
||||
return treeNodeViewIndex[type] || treeNodeViewIndex.default;
|
||||
},
|
||||
hasChildren(){
|
||||
return this.children && this.children.length || this.lazy && !this.expanded;
|
||||
},
|
||||
|
||||
@@ -107,7 +107,6 @@
|
||||
let allowed = isParentAllowed({parentType, childType});
|
||||
return allowed;
|
||||
},
|
||||
log: console.log,
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
<template lang="html">
|
||||
<dialog-base>
|
||||
<v-toolbar-title slot="toolbar">
|
||||
Creature Form Dialog
|
||||
</v-toolbar-title>
|
||||
<dialog-base :color="model.color">
|
||||
<template slot="toolbar">
|
||||
<v-toolbar-title>
|
||||
Creature Form Dialog
|
||||
</v-toolbar-title>
|
||||
<v-spacer />
|
||||
<color-picker
|
||||
:value="model.color"
|
||||
@input="value => change({path: ['color'], value})"
|
||||
/>
|
||||
</template>
|
||||
<div>
|
||||
<creature-form
|
||||
:model="model"
|
||||
@@ -27,11 +34,13 @@ import {updateCreature} from '/imports/api/creature/Creatures.js';
|
||||
import DialogBase from '/imports/ui/dialogStack/DialogBase.vue';
|
||||
import CreatureForm from '/imports/ui/creature/CreatureForm.vue'
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import ColorPicker from '/imports/ui/components/ColorPicker.vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
DialogBase,
|
||||
CreatureForm,
|
||||
ColorPicker,
|
||||
},
|
||||
props: {
|
||||
_id: String,
|
||||
@@ -52,8 +61,16 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
change({path, value, ack}){
|
||||
updateCreature.call({_id: this._id, path, value}, (error, result) =>{
|
||||
ack && ack(error && error.reason || error);
|
||||
updateCreature.call({_id: this._id, path, value}, (error) =>{
|
||||
if (error){
|
||||
if(ack){
|
||||
ack(error && error.reason || error)
|
||||
} else {
|
||||
console.error(error)
|
||||
}
|
||||
} else if (ack) {
|
||||
ack();
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
47
app/imports/ui/creature/CreatureListTile.vue
Normal file
47
app/imports/ui/creature/CreatureListTile.vue
Normal file
@@ -0,0 +1,47 @@
|
||||
<template
|
||||
lang="html"
|
||||
functional
|
||||
>
|
||||
<v-list-tile v-bind="$attrs">
|
||||
<v-list-tile-avatar :color="model.color || 'grey'">
|
||||
<img
|
||||
v-if="model.avatarPicture"
|
||||
:src="model.avatarPicture"
|
||||
:alt="model.name"
|
||||
>
|
||||
<template v-else>
|
||||
{{ model.initial }}
|
||||
</template>
|
||||
</v-list-tile-avatar>
|
||||
<v-list-tile-content>
|
||||
<v-list-tile-title>
|
||||
{{ model.name }}
|
||||
</v-list-tile-title>
|
||||
<v-list-tile-sub-title>
|
||||
{{ model.alignment }} {{ model.gender }} {{ model.race }}
|
||||
</v-list-tile-sub-title>
|
||||
</v-list-tile-content>
|
||||
<v-list-tile-action v-if="selection">
|
||||
<v-checkbox
|
||||
:input-value="selected && selected.has(model._id)"
|
||||
@change="$emit('select')"
|
||||
/>
|
||||
</v-list-tile-action>
|
||||
</v-list-tile>
|
||||
</template>
|
||||
|
||||
<script type="text/javascript">
|
||||
export default {
|
||||
props: {
|
||||
model: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
selection: Boolean,
|
||||
selected: {
|
||||
type: Set,
|
||||
default: () => new Set(),
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -1,7 +1,6 @@
|
||||
<template lang="html">
|
||||
<v-btn
|
||||
:loading="loading"
|
||||
:disabled="loading"
|
||||
outline
|
||||
style="width: 160px;"
|
||||
@click="rest"
|
||||
|
||||
247
app/imports/ui/creature/character/CharacterSheetToolbar.vue
Normal file
247
app/imports/ui/creature/character/CharacterSheetToolbar.vue
Normal file
@@ -0,0 +1,247 @@
|
||||
<template lang="html">
|
||||
<v-toolbar
|
||||
app
|
||||
class="character-sheet-toolbar"
|
||||
:color="toolbarColor"
|
||||
:dark="isDark"
|
||||
:light="!isDark"
|
||||
tabs
|
||||
dense
|
||||
>
|
||||
<v-toolbar-side-icon @click="toggleDrawer" />
|
||||
<v-toolbar-title>
|
||||
<v-fade-transition
|
||||
mode="out-in"
|
||||
>
|
||||
<div :key="$store.state.pageTitle">
|
||||
{{ $store.state.pageTitle }}
|
||||
</div>
|
||||
</v-fade-transition>
|
||||
</v-toolbar-title>
|
||||
<v-spacer />
|
||||
<v-fade-transition
|
||||
mode="out-in"
|
||||
>
|
||||
<div :key="$route.meta.title">
|
||||
<v-toolbar-items v-if="creature">
|
||||
<v-btn
|
||||
v-if="editPermission"
|
||||
flat
|
||||
icon
|
||||
@click="recompute(creature._id)"
|
||||
>
|
||||
<v-icon>refresh</v-icon>
|
||||
</v-btn>
|
||||
<v-menu
|
||||
bottom
|
||||
left
|
||||
transition="slide-y-transition"
|
||||
data-id="creature-menu"
|
||||
>
|
||||
<template #activator="{ on }">
|
||||
<v-btn
|
||||
icon
|
||||
v-on="on"
|
||||
>
|
||||
<v-icon>more_vert</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-list v-if="editPermission">
|
||||
<v-list-tile @click="deleteCharacter">
|
||||
<v-list-tile-title>
|
||||
<v-icon>delete</v-icon> Delete
|
||||
</v-list-tile-title>
|
||||
</v-list-tile>
|
||||
<v-list-tile @click="showCharacterForm">
|
||||
<v-list-tile-title>
|
||||
<v-icon>create</v-icon> Edit details
|
||||
</v-list-tile-title>
|
||||
</v-list-tile>
|
||||
<v-list-tile @click="showShareDialog">
|
||||
<v-list-tile-title>
|
||||
<v-icon>share</v-icon> Sharing
|
||||
</v-list-tile-title>
|
||||
</v-list-tile>
|
||||
</v-list>
|
||||
<v-list v-else>
|
||||
<v-list-tile @click="unshareWithMe">
|
||||
<v-list-tile-title>
|
||||
<v-icon>delete</v-icon> Unshare with me
|
||||
</v-list-tile-title>
|
||||
</v-list-tile>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
</v-toolbar-items>
|
||||
</div>
|
||||
</v-fade-transition>
|
||||
<v-fade-transition
|
||||
slot="extension"
|
||||
mode="out-in"
|
||||
>
|
||||
<div
|
||||
:key="$route.meta.title"
|
||||
style="width: 100%"
|
||||
>
|
||||
<v-tabs
|
||||
v-if="creature"
|
||||
slot="extension"
|
||||
:value="value"
|
||||
centered
|
||||
grow
|
||||
max="100px"
|
||||
@change="e => $emit('input', e)"
|
||||
>
|
||||
<v-tab>
|
||||
Stats
|
||||
</v-tab>
|
||||
<v-tab>
|
||||
Features
|
||||
</v-tab>
|
||||
<v-tab>
|
||||
Inventory
|
||||
</v-tab>
|
||||
<v-tab>
|
||||
Spells
|
||||
</v-tab>
|
||||
<v-tab>
|
||||
Persona
|
||||
</v-tab>
|
||||
<v-tab>
|
||||
Tree
|
||||
</v-tab>
|
||||
</v-tabs>
|
||||
</div>
|
||||
</v-fade-transition>
|
||||
</v-toolbar>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import removeCreature from '/imports/api/creature/removeCreature.js';
|
||||
import { mapMutations } from 'vuex';
|
||||
import { theme } from '/imports/ui/theme.js';
|
||||
import { recomputeCreature } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import { updateUserSharePermissions } from '/imports/api/sharing/sharing.js';
|
||||
import isDarkColor from '/imports/ui/utility/isDarkColor.js';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
value: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data(){return {
|
||||
theme,
|
||||
}},
|
||||
computed: {
|
||||
creatureId(){
|
||||
return this.$route.params.id;
|
||||
},
|
||||
toolbarColor(){
|
||||
if (this.creature && this.creature.color){
|
||||
return this.creature.color;
|
||||
} else {
|
||||
return this.$vuetify.theme.secondary;
|
||||
}
|
||||
},
|
||||
isDark(){
|
||||
return isDarkColor(this.toolbarColor);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
...mapMutations([
|
||||
'toggleDrawer',
|
||||
]),
|
||||
recompute(charId){
|
||||
recomputeCreature.call({charId});
|
||||
},
|
||||
showCharacterForm(){
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'creature-form-dialog',
|
||||
elementId: 'creature-menu',
|
||||
data: {
|
||||
_id: this.creatureId,
|
||||
},
|
||||
});
|
||||
},
|
||||
showShareDialog(){
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'share-dialog',
|
||||
elementId: 'creature-menu',
|
||||
data: {
|
||||
docRef: {
|
||||
id: this.creatureId,
|
||||
collection: 'creatures',
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
deleteCharacter(){
|
||||
let that = this;
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'delete-confirmation-dialog',
|
||||
elementId: 'creature-menu',
|
||||
data: {
|
||||
name: this.creature.name,
|
||||
typeName: 'Character'
|
||||
},
|
||||
callback(confirmation){
|
||||
if(!confirmation) return;
|
||||
removeCreature.call({charId: that.creatureId}, (error) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
} else {
|
||||
that.$router.push('/characterList');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
unshareWithMe(){
|
||||
updateUserSharePermissions.call({
|
||||
docRef: {
|
||||
collection: 'creatures',
|
||||
id: this.creatureId,
|
||||
},
|
||||
userId: Meteor.userId(),
|
||||
role: 'none',
|
||||
}, (error) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
} else {
|
||||
this.$router.push('/characterList');
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
meteor: {
|
||||
$subscribe: {
|
||||
'singleCharacter'(){
|
||||
return [this.creatureId];
|
||||
},
|
||||
},
|
||||
creature(){
|
||||
return Creatures.findOne(this.creatureId);
|
||||
},
|
||||
editPermission(){
|
||||
try {
|
||||
assertEditPermission(this.creature, Meteor.userId());
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css">
|
||||
.character-sheet-toolbar .v-tabs__container--grow .v-tabs__div {
|
||||
max-width: 120px !important;
|
||||
}
|
||||
.character-sheet-toolbar .v-tabs__bar {
|
||||
background: none !important;
|
||||
}
|
||||
</style>
|
||||
@@ -53,7 +53,6 @@
|
||||
<script>
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import removeCreature from '/imports/api/creature/removeCreature.js';
|
||||
import isDarkColor from '/imports/ui/utility/isDarkColor.js';
|
||||
import { mapMutations } from 'vuex';
|
||||
import { theme } from '/imports/ui/theme.js';
|
||||
import { recomputeCreature } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||
@@ -134,7 +133,6 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
isDarkColor,
|
||||
},
|
||||
meteor: {
|
||||
$subscribe: {
|
||||
|
||||
11
app/imports/ui/creature/character/MiniCharacterSheet.vue
Normal file
11
app/imports/ui/creature/character/MiniCharacterSheet.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<template lang="html">
|
||||
<div class="mini-character-sheet" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
</style>
|
||||
@@ -16,7 +16,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
|
||||
import FeatureCard from '/imports/ui/properties/components/features/FeatureCard.vue';
|
||||
|
||||
@@ -33,13 +33,12 @@
|
||||
},
|
||||
meteor: {
|
||||
features(){
|
||||
return CreatureProperties.find({
|
||||
'ancestors.id': this.creatureId,
|
||||
type: 'feature',
|
||||
removed: {$ne: true},
|
||||
}, {
|
||||
sort: {order: 1},
|
||||
});
|
||||
return getActiveProperties({
|
||||
ancestorId: this.creatureId,
|
||||
filter: {
|
||||
type: 'feature',
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -1,27 +1,33 @@
|
||||
<template lang="html">
|
||||
<div class="inventory">
|
||||
<column-layout>
|
||||
<column-layout wide-columns>
|
||||
<div>
|
||||
<toolbar-card color="">
|
||||
<v-spacer slot="toolbar" />
|
||||
<v-switch
|
||||
v-if="context.editPermission !== false"
|
||||
slot="toolbar"
|
||||
v-model="organize"
|
||||
label="Organize"
|
||||
class="justify-end"
|
||||
/>
|
||||
<toolbar-card
|
||||
:color="context.creature.color"
|
||||
>
|
||||
<v-toolbar-title slot="toolbar">
|
||||
Equipped
|
||||
</v-toolbar-title>
|
||||
<v-card-text class="px-0">
|
||||
<creature-properties-tree
|
||||
:root="{collection: 'creatures', id: creatureId}"
|
||||
:filter="{
|
||||
type: {$in: ['item']},
|
||||
'ancestors.id': {$nin: containerIds}
|
||||
}"
|
||||
:organize="organize"
|
||||
group="inventory"
|
||||
@selected="e => clickProperty(e)"
|
||||
@reorganized="({doc}) => setEquipped(doc, false)"
|
||||
<item-list
|
||||
equipment
|
||||
:items="equippedItems"
|
||||
:parent-ref="{id: creatureId, collection: 'creatures'}"
|
||||
/>
|
||||
</v-card-text>
|
||||
</toolbar-card>
|
||||
</div>
|
||||
<div>
|
||||
<toolbar-card
|
||||
:color="context.creature.color"
|
||||
>
|
||||
<v-toolbar-title slot="toolbar">
|
||||
Carried
|
||||
</v-toolbar-title>
|
||||
<v-card-text class="px-0">
|
||||
<item-list
|
||||
:items="carriedItems"
|
||||
:parent-ref="{id: creatureId, collection: 'creatures'}"
|
||||
/>
|
||||
</v-card-text>
|
||||
</toolbar-card>
|
||||
@@ -32,7 +38,6 @@
|
||||
>
|
||||
<container-card
|
||||
:model="container"
|
||||
:organize="organize"
|
||||
/>
|
||||
</div>
|
||||
</column-layout>
|
||||
@@ -42,23 +47,27 @@
|
||||
<script>
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
|
||||
import CreaturePropertiesTree from '/imports/ui/creature/creatureProperties/CreaturePropertiesTree.vue';
|
||||
import ContainerCard from '/imports/ui/properties/components/inventory/ContainerCard.vue';
|
||||
import ToolbarCard from '/imports/ui/components/ToolbarCard.vue';
|
||||
import ItemList from '/imports/ui/properties/components/inventory/ItemList.vue';
|
||||
import { updateProperty } from '/imports/api/creature/CreatureProperties.js';
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
ColumnLayout,
|
||||
CreaturePropertiesTree,
|
||||
ContainerCard,
|
||||
ToolbarCard,
|
||||
ItemList,
|
||||
},
|
||||
inject: {
|
||||
context: { default: {} }
|
||||
},
|
||||
props: {
|
||||
creatureId: String,
|
||||
creatureId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data(){ return {
|
||||
organize: false,
|
||||
@@ -85,6 +94,26 @@ export default {
|
||||
sort: {order: 1},
|
||||
});
|
||||
},
|
||||
carriedItems(){
|
||||
return getActiveProperties({
|
||||
ancestorId: this.creatureId,
|
||||
includeUnequipped: true,
|
||||
filter: {
|
||||
type: 'item',
|
||||
equipped: {$ne: true},
|
||||
'parent.id': this.creatureId
|
||||
},
|
||||
});
|
||||
},
|
||||
equippedItems(){
|
||||
return getActiveProperties({
|
||||
ancestorId: this.creatureId,
|
||||
filter: {
|
||||
type: 'item',
|
||||
equipped: true,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
containerIds(){
|
||||
|
||||
@@ -20,6 +20,70 @@
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</div>
|
||||
<div>
|
||||
<v-card class="class-details">
|
||||
<v-card-title
|
||||
v-if="creature.variables.level"
|
||||
class="title"
|
||||
>
|
||||
Level {{ creature.variables.level.value }}
|
||||
</v-card-title>
|
||||
<v-list>
|
||||
<v-list-tile>
|
||||
<v-list-tile-content>
|
||||
<v-list-tile-title
|
||||
v-if="
|
||||
creature.variables.milestoneLevels &&
|
||||
creature.variables.milestoneLevels.value
|
||||
"
|
||||
>
|
||||
{{ creature.variables.milestoneLevels.value }} Milestone levels
|
||||
</v-list-tile-title>
|
||||
<v-list-tile-title v-else>
|
||||
{{
|
||||
creature.variables.xp &&
|
||||
creature.variables.xp.value ||
|
||||
0
|
||||
}} XP
|
||||
</v-list-tile-title>
|
||||
</v-list-tile-content>
|
||||
<v-list-tile-action>
|
||||
<v-btn
|
||||
flat
|
||||
icon
|
||||
data-id="experience-info-button"
|
||||
@click="showExperienceList"
|
||||
>
|
||||
<v-icon>info</v-icon>
|
||||
</v-btn>
|
||||
</v-list-tile-action>
|
||||
<v-list-tile-action>
|
||||
<v-btn
|
||||
flat
|
||||
icon
|
||||
data-id="experience-add-button"
|
||||
@click="addExperience"
|
||||
>
|
||||
<v-icon>add</v-icon>
|
||||
</v-btn>
|
||||
</v-list-tile-action>
|
||||
</v-list-tile>
|
||||
<v-list-tile
|
||||
v-for="classLevel in highestClassLevels"
|
||||
:key="classLevel._id"
|
||||
>
|
||||
<v-list-tile-content>
|
||||
<v-list-tile-title>
|
||||
{{ classLevel.name }}
|
||||
</v-list-tile-title>
|
||||
</v-list-tile-content>
|
||||
<v-list-tile-avatar>
|
||||
{{ classLevel.level }}
|
||||
</v-list-tile-avatar>
|
||||
</v-list-tile>
|
||||
</v-list>
|
||||
</v-card>
|
||||
</div>
|
||||
<div
|
||||
v-for="note in notes"
|
||||
:key="note._id"
|
||||
@@ -37,6 +101,7 @@ import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
|
||||
import NoteCard from '/imports/ui/properties/components/persona/NoteCard.vue';
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@@ -44,7 +109,10 @@ export default {
|
||||
NoteCard,
|
||||
},
|
||||
props: {
|
||||
creatureId: String,
|
||||
creatureId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
meteor: {
|
||||
notes(){
|
||||
@@ -58,8 +126,34 @@ export default {
|
||||
},
|
||||
creature(){
|
||||
return Creatures.findOne(this.creatureId);
|
||||
}
|
||||
},
|
||||
classLevels(){
|
||||
return getActiveProperties({
|
||||
ancestorId: this.creatureId,
|
||||
filter: {type: 'classLevel'},
|
||||
});
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
highestClassLevels(){
|
||||
let highestLevels = {};
|
||||
let highestLevelsList = [];
|
||||
this.classLevels.forEach(classLevel => {
|
||||
let name = classLevel.variableName;
|
||||
if (
|
||||
!highestLevels[name] ||
|
||||
highestLevels[name].level < classLevel.level
|
||||
){
|
||||
highestLevels[name] = classLevel;
|
||||
}
|
||||
});
|
||||
for (let name in highestLevels){
|
||||
highestLevelsList.push(highestLevels[name]);
|
||||
}
|
||||
highestLevelsList.sort((a, b) => a.level - b.level);
|
||||
return highestLevelsList;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
showCharacterForm(){
|
||||
this.$store.commit('pushDialogStack', {
|
||||
@@ -70,6 +164,28 @@ export default {
|
||||
},
|
||||
});
|
||||
},
|
||||
addExperience(){
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'experience-insert-dialog',
|
||||
elementId: 'experience-add-button',
|
||||
data: {
|
||||
creatureIds: [this.creatureId],
|
||||
startAsMilestone: this.creature.variables.milestoneLevels &&
|
||||
!!this.creature.variables.milestoneLevels.value,
|
||||
},
|
||||
});
|
||||
},
|
||||
showExperienceList(){
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'experience-list-dialog',
|
||||
elementId: 'experience-info-button',
|
||||
data: {
|
||||
creatureId: this.creatureId,
|
||||
startAsMilestone: this.creature.variables.milestoneLevels &&
|
||||
!!this.creature.variables.milestoneLevels.value,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
<template lang="html">
|
||||
<div class="spells">
|
||||
<column-layout>
|
||||
<div>
|
||||
<column-layout wide-columns>
|
||||
<div v-if="spellsWithoutList.length">
|
||||
<v-card>
|
||||
<v-card-text>
|
||||
<v-switch
|
||||
v-if="context.editPermission !== false"
|
||||
v-model="organize"
|
||||
label="Organize"
|
||||
class="justify-end"
|
||||
/>
|
||||
<creature-properties-tree
|
||||
:root="{collection: 'creatures', id: creatureId}"
|
||||
:filter="{
|
||||
equipped: {$ne: true},
|
||||
type: 'spell',
|
||||
'ancestors.id': {$nin: spellListIds}
|
||||
}"
|
||||
:organize="organize"
|
||||
group="spells"
|
||||
@selected="e => clickProperty(e)"
|
||||
/>
|
||||
</v-card-text>
|
||||
<spell-list
|
||||
:spells="spellsWithoutList"
|
||||
:parent-ref="{id: creatureId, collection: 'creatures'}"
|
||||
/>
|
||||
</v-card>
|
||||
</div>
|
||||
<div
|
||||
@@ -38,15 +23,15 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
|
||||
import CreaturePropertiesTree from '/imports/ui/creature/creatureProperties/CreaturePropertiesTree.vue';
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
import SpellListCard from '/imports/ui/properties/components/spells/SpellListCard.vue';
|
||||
import SpellList from '/imports/ui/properties/components/spells/SpellList.vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
ColumnLayout,
|
||||
CreaturePropertiesTree,
|
||||
SpellList,
|
||||
SpellListCard,
|
||||
},
|
||||
inject: {
|
||||
@@ -63,25 +48,36 @@ export default {
|
||||
}},
|
||||
meteor: {
|
||||
spellLists(){
|
||||
return CreatureProperties.find({
|
||||
'ancestors.id': this.creatureId,
|
||||
type: 'spellList',
|
||||
removed: {$ne: true},
|
||||
}, {
|
||||
sort: {order: 1},
|
||||
});
|
||||
return getActiveProperties({
|
||||
ancestorId: this.creatureId,
|
||||
filter: {
|
||||
type: 'spellList',
|
||||
},
|
||||
});
|
||||
},
|
||||
spellsWithoutList(){
|
||||
return getActiveProperties({
|
||||
ancestorId: this.creatureId,
|
||||
excludeAncestors: this.spellListIds,
|
||||
filter: {
|
||||
type: 'spell',
|
||||
},
|
||||
options: {
|
||||
sort: {
|
||||
level: 1,
|
||||
order: 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
spellListsWithoutAncestorSpellLists(){
|
||||
return CreatureProperties.find({
|
||||
'ancestors.id': {
|
||||
$eq: this.creatureId,
|
||||
$nin: this.spellListIds
|
||||
},
|
||||
type: 'spellList',
|
||||
removed: {$ne: true},
|
||||
}, {
|
||||
sort: {order: 1},
|
||||
});
|
||||
return getActiveProperties({
|
||||
ancestorId: this.creatureId,
|
||||
excludeAncestors: this.spellListIds,
|
||||
filter: {
|
||||
type: 'spellList',
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
@@ -93,7 +89,7 @@ export default {
|
||||
clickProperty(_id){
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'creature-property-dialog',
|
||||
elementId: `tree-node-${_id}`,
|
||||
elementId: `spell-list-tile-${_id}`,
|
||||
data: {_id},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -21,6 +21,39 @@
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="appliedBuffs.length"
|
||||
class="buffs"
|
||||
>
|
||||
<v-card>
|
||||
<v-list>
|
||||
<v-subheader>Buffs and conditions</v-subheader>
|
||||
<v-list-tile
|
||||
v-for="buff in appliedBuffs"
|
||||
:key="buff._id"
|
||||
:data-id="buff._id"
|
||||
@click="clickProperty({_id: buff._id})"
|
||||
>
|
||||
<v-list-tile-content>
|
||||
<v-list-tile-title>
|
||||
{{ buff.name }}
|
||||
</v-list-tile-title>
|
||||
</v-list-tile-content>
|
||||
<v-list-tile-action>
|
||||
<v-btn
|
||||
icon
|
||||
flat
|
||||
@click.stop="softRemove(buff._id)"
|
||||
>
|
||||
<v-icon>delete</v-icon>
|
||||
</v-btn>
|
||||
</v-list-tile-action>
|
||||
</v-list-tile>
|
||||
</v-list>
|
||||
</v-card>
|
||||
</div>
|
||||
|
||||
<div class="ability-scores">
|
||||
<v-card>
|
||||
<v-list>
|
||||
@@ -165,6 +198,30 @@
|
||||
</v-card>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="action in actions"
|
||||
:key="action._id"
|
||||
class="actions"
|
||||
>
|
||||
<action-card
|
||||
:model="action"
|
||||
:data-id="action._id"
|
||||
@click="clickProperty({_id: action._id})"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-for="attack in attacks"
|
||||
:key="attack._id"
|
||||
class="attacks"
|
||||
>
|
||||
<action-card
|
||||
attack
|
||||
:model="attack"
|
||||
:data-id="attack._id"
|
||||
@click="clickProperty({_id: attack._id})"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="weapons && weapons.length"
|
||||
class="weapon-proficiencies"
|
||||
@@ -187,7 +244,7 @@
|
||||
</div>
|
||||
<div
|
||||
v-if="armors && armors.length"
|
||||
class="weapon-proficiencies"
|
||||
class="armor-proficiencies"
|
||||
>
|
||||
<v-card>
|
||||
<v-list>
|
||||
@@ -207,7 +264,7 @@
|
||||
</div>
|
||||
<div
|
||||
v-if="tools && tools.length"
|
||||
class="weapon-proficiencies"
|
||||
class="tool-proficiencies"
|
||||
>
|
||||
<v-card>
|
||||
<v-list>
|
||||
@@ -245,54 +302,13 @@
|
||||
</v-list>
|
||||
</v-card>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="actions.length"
|
||||
class="actions"
|
||||
>
|
||||
<v-card>
|
||||
<v-list
|
||||
two-line
|
||||
subheader
|
||||
>
|
||||
<v-subheader>Actions</v-subheader>
|
||||
<action-list-tile
|
||||
v-for="action in actions"
|
||||
:key="action._id"
|
||||
:model="action"
|
||||
:data-id="action._id"
|
||||
@click="clickProperty({_id: action._id})"
|
||||
/>
|
||||
</v-list>
|
||||
</v-card>
|
||||
</div>
|
||||
<div
|
||||
v-if="attacks.length"
|
||||
class="actions"
|
||||
>
|
||||
<v-card>
|
||||
<v-list
|
||||
two-line
|
||||
subheader
|
||||
>
|
||||
<v-subheader>Attacks</v-subheader>
|
||||
<attack-list-tile
|
||||
v-for="attack in attacks"
|
||||
:key="attack._id"
|
||||
:model="attack"
|
||||
:data-id="attack._id"
|
||||
@click="clickProperty({_id: attack._id})"
|
||||
/>
|
||||
</v-list>
|
||||
</v-card>
|
||||
</div>
|
||||
</column-layout>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import CreatureProperties, { damageProperty } from '/imports/api/creature/CreatureProperties.js';
|
||||
import { damageProperty, softRemoveProperty } from '/imports/api/creature/CreatureProperties.js';
|
||||
import AttributeCard from '/imports/ui/properties/components/attributes/AttributeCard.vue';
|
||||
import AbilityListTile from '/imports/ui/properties/components/attributes/AbilityListTile.vue';
|
||||
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
|
||||
@@ -302,8 +318,7 @@
|
||||
import SkillListTile from '/imports/ui/properties/components/skills/SkillListTile.vue';
|
||||
import ResourceCard from '/imports/ui/properties/components/attributes/ResourceCard.vue';
|
||||
import SpellSlotListTile from '/imports/ui/properties/components/attributes/SpellSlotListTile.vue';
|
||||
import ActionListTile from '/imports/ui/properties/components/actions/ActionListTile.vue';
|
||||
import AttackListTile from '/imports/ui/properties/components/actions/AttackListTile.vue';
|
||||
import ActionCard from '/imports/ui/properties/components/actions/ActionCard.vue';
|
||||
import RestButton from '/imports/ui/creature/RestButton.vue';
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
|
||||
@@ -345,8 +360,7 @@
|
||||
SkillListTile,
|
||||
ResourceCard,
|
||||
SpellSlotListTile,
|
||||
ActionListTile,
|
||||
AttackListTile,
|
||||
ActionCard,
|
||||
},
|
||||
props: {
|
||||
creatureId: {
|
||||
@@ -400,8 +414,18 @@
|
||||
actions(){
|
||||
return getProperties(this.creature, {type: 'action'});
|
||||
},
|
||||
appliedBuffs(){
|
||||
return getProperties(this.creature, {type: 'buff', applied: true});
|
||||
},
|
||||
attacks(){
|
||||
return getProperties(this.creature, {type: 'attack'});
|
||||
let props = getProperties(this.creature, {type: 'attack'}).map(attack => {
|
||||
attack.children = getActiveProperties({
|
||||
ancestorId: attack._id,
|
||||
options: {sort: {order: 1}},
|
||||
});
|
||||
return attack;
|
||||
});
|
||||
return props;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
@@ -421,6 +445,11 @@
|
||||
if (!obj) return 0;
|
||||
return Object.keys(obj).length;
|
||||
},
|
||||
softRemove(_id){
|
||||
softRemoveProperty.call({_id}, error => {
|
||||
if (error) console.error(error);
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</p>
|
||||
</v-fade-transition>
|
||||
<template v-if="!editing && !embedded">
|
||||
<v-divider />
|
||||
<v-divider class="my-2" />
|
||||
<creature-properties-tree
|
||||
v-if="!editing"
|
||||
:root="{collection: 'creatureProperties', id: model._id}"
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
<template lang="html">
|
||||
<dialog-base :override-back-button="() => $emit('back')">
|
||||
<v-toolbar-title slot="toolbar">
|
||||
Add {{ propertyName }}
|
||||
</v-toolbar-title>
|
||||
<dialog-base
|
||||
:override-back-button="() => $emit('back')"
|
||||
:color="model.color"
|
||||
>
|
||||
<template slot="toolbar">
|
||||
<v-toolbar-title>
|
||||
Add {{ propertyName }}
|
||||
</v-toolbar-title>
|
||||
<v-spacer />
|
||||
<color-picker
|
||||
:value="model.color"
|
||||
@input="value => change({path: ['color'], value})"
|
||||
/>
|
||||
</template>
|
||||
<component
|
||||
:is="type"
|
||||
v-if="type"
|
||||
@@ -32,11 +42,14 @@
|
||||
import propertySchemasIndex from '/imports/api/properties/propertySchemasIndex.js';
|
||||
import DialogBase from '/imports/ui/dialogStack/DialogBase.vue';
|
||||
import propertyFormIndex from '/imports/ui/properties/forms/shared/propertyFormIndex.js';
|
||||
import ColorPicker from '/imports/ui/components/ColorPicker.vue';
|
||||
import schemaFormMixin from '/imports/ui/properties/forms/shared/schemaFormMixin.js';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
...propertyFormIndex,
|
||||
DialogBase,
|
||||
ColorPicker,
|
||||
},
|
||||
mixins: [schemaFormMixin],
|
||||
props: {
|
||||
|
||||
68
app/imports/ui/creature/experiences/ExperienceForm.vue
Normal file
68
app/imports/ui/creature/experiences/ExperienceForm.vue
Normal file
@@ -0,0 +1,68 @@
|
||||
<template lang="html">
|
||||
<div class="experience-form">
|
||||
<div class="layout column align-center">
|
||||
<smart-switch
|
||||
label="Milestone"
|
||||
class="mx-3"
|
||||
:value="milestone"
|
||||
@change="makeMilestone"
|
||||
/>
|
||||
<text-field
|
||||
v-if="milestone"
|
||||
label="Levels"
|
||||
type="number"
|
||||
class="base-value-field text-xs-center large-format no-flex"
|
||||
:value="model.levels"
|
||||
:error-messages="errors.levels"
|
||||
@change="change('levels', ...arguments)"
|
||||
/>
|
||||
<text-field
|
||||
v-else
|
||||
type="number"
|
||||
class="base-value-field text-xs-center large-format no-flex"
|
||||
suffix="XP"
|
||||
autofocus
|
||||
:value="model.xp"
|
||||
:error-messages="errors.xp"
|
||||
@change="change('xp', ...arguments)"
|
||||
/>
|
||||
</div>
|
||||
<text-field
|
||||
label="Name"
|
||||
:autofocus="milestone"
|
||||
:value="model.name"
|
||||
:error-messages="errors.name"
|
||||
@change="change('name', ...arguments)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
|
||||
|
||||
export default {
|
||||
mixins: [propertyFormMixin],
|
||||
props: {
|
||||
startAsMilestone: {
|
||||
type: Boolean,
|
||||
},
|
||||
},
|
||||
data(){return {
|
||||
milestone: this.startAsMilestone,
|
||||
}},
|
||||
methods: {
|
||||
makeMilestone(milestone, ack){
|
||||
this.milestone = milestone;
|
||||
if (milestone){
|
||||
this.change('xp', undefined);
|
||||
this.change('levels', 1, ack);
|
||||
} else {
|
||||
this.change('levels', undefined, ack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
</style>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user