Compare commits
114 Commits
2.0-beta.2
...
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 | ||
|
|
15ad8b1f5d | ||
|
|
d4804e5292 | ||
|
|
36c23e1eb5 | ||
|
|
9236f3e477 | ||
|
|
cd413ba64f | ||
|
|
2c671acf72 | ||
|
|
44e726417e | ||
|
|
7f2401da81 | ||
|
|
d31f980002 | ||
|
|
4c8512af80 | ||
|
|
edf68b1355 | ||
|
|
868b9e11fa | ||
|
|
14f5c3e797 | ||
|
|
66e25c53d0 | ||
|
|
7a75d34246 | ||
|
|
70a6c817cb | ||
|
|
56879f1911 | ||
|
|
6d12bcb063 | ||
|
|
1c26b7717c | ||
|
|
a41b267364 | ||
|
|
dfb144b8dc | ||
|
|
2859bf0e00 | ||
|
|
469822d4d7 | ||
|
|
c7de96c8c3 | ||
|
|
f7cbee27f9 | ||
|
|
b61dd6e81a | ||
|
|
add0cac31d | ||
|
|
e9c643699c | ||
|
|
3ec0f9500c | ||
|
|
a55c1382b1 | ||
|
|
7571806cd0 | ||
|
|
afa641a290 | ||
|
|
81131ddb9f | ||
|
|
7a442d8fb9 | ||
|
|
26d836767b | ||
|
|
c4a52ca744 | ||
|
|
b640ce457f | ||
|
|
13a0d66433 | ||
|
|
47aad6d186 | ||
|
|
32eb85a099 | ||
|
|
048b150c88 | ||
|
|
65d367942e |
@@ -49,3 +49,7 @@ aldeed:schema-index
|
|||||||
akryum:vue-component
|
akryum:vue-component
|
||||||
accounts-patreon
|
accounts-patreon
|
||||||
bozhao:link-accounts
|
bozhao:link-accounts
|
||||||
|
peerlibrary:reactive-publish
|
||||||
|
simple:rest
|
||||||
|
simple:rest-method-mixin
|
||||||
|
mikowals:batch-insert
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ caching-html-compiler@1.1.3
|
|||||||
callback-hook@1.3.0
|
callback-hook@1.3.0
|
||||||
check@1.3.1
|
check@1.3.1
|
||||||
chuangbo:marked@0.3.5_1
|
chuangbo:marked@0.3.5_1
|
||||||
|
coffeescript@2.4.1
|
||||||
|
coffeescript-compiler@2.4.1
|
||||||
dburles:collection-helpers@1.1.0
|
dburles:collection-helpers@1.1.0
|
||||||
dburles:mongo-collection-instances@0.3.5
|
dburles:mongo-collection-instances@0.3.5
|
||||||
ddp@1.4.0
|
ddp@1.4.0
|
||||||
@@ -70,6 +72,7 @@ meteorhacks:subs-manager@1.6.4
|
|||||||
meteortesting:browser-tests@1.3.3
|
meteortesting:browser-tests@1.3.3
|
||||||
meteortesting:mocha@1.1.5
|
meteortesting:mocha@1.1.5
|
||||||
meteortesting:mocha-core@7.0.1
|
meteortesting:mocha-core@7.0.1
|
||||||
|
mikowals:batch-insert@1.1.9
|
||||||
minifier-css@1.5.0
|
minifier-css@1.5.0
|
||||||
minifier-js@2.6.0
|
minifier-js@2.6.0
|
||||||
minimongo@1.6.0
|
minimongo@1.6.0
|
||||||
@@ -91,6 +94,12 @@ observe-sequence@1.0.16
|
|||||||
ongoworks:speakingurl@9.0.0
|
ongoworks:speakingurl@9.0.0
|
||||||
ordered-dict@1.1.0
|
ordered-dict@1.1.0
|
||||||
patreon-oauth@0.1.0
|
patreon-oauth@0.1.0
|
||||||
|
peerlibrary:assert@0.3.0
|
||||||
|
peerlibrary:extend-publish@0.6.0
|
||||||
|
peerlibrary:fiber-utils@0.10.0
|
||||||
|
peerlibrary:reactive-mongo@0.4.0
|
||||||
|
peerlibrary:reactive-publish@0.10.0
|
||||||
|
peerlibrary:server-autorun@0.8.0
|
||||||
percolate:migrations@0.9.8
|
percolate:migrations@0.9.8
|
||||||
percolate:synced-cron@1.3.2
|
percolate:synced-cron@1.3.2
|
||||||
promise@0.11.2
|
promise@0.11.2
|
||||||
@@ -107,6 +116,9 @@ service-configuration@1.0.11
|
|||||||
session@1.2.0
|
session@1.2.0
|
||||||
sha@1.0.9
|
sha@1.0.9
|
||||||
shell-server@0.5.0
|
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
|
socket-stream-client@0.3.0
|
||||||
spacebars@1.0.15
|
spacebars@1.0.15
|
||||||
spacebars-compiler@1.1.3
|
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,7 +1,9 @@
|
|||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { Mongo } from 'meteor/mongo';
|
import { Mongo } from 'meteor/mongo';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
||||||
import ChildSchema, { RefSchema } from '/imports/api/parenting/ChildSchema.js';
|
import ChildSchema, { RefSchema } from '/imports/api/parenting/ChildSchema.js';
|
||||||
import { recomputeCreature } from '/imports/api/creature/computation/recomputeCreature.js';
|
import { recomputeCreature } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||||
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||||
@@ -16,6 +18,9 @@ import {
|
|||||||
renewDocIds
|
renewDocIds
|
||||||
} from '/imports/api/parenting/parenting.js';
|
} from '/imports/api/parenting/parenting.js';
|
||||||
import {setDocToLastOrder} from '/imports/api/parenting/order.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');
|
let CreatureProperties = new Mongo.Collection('creatureProperties');
|
||||||
|
|
||||||
@@ -35,12 +40,17 @@ let CreaturePropertySchema = new SimpleSchema({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
icon: {
|
||||||
|
type: storedIconsSchema,
|
||||||
|
optional: true,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let key in propertySchemasIndex){
|
for (let key in propertySchemasIndex){
|
||||||
let schema = new SimpleSchema({});
|
let schema = new SimpleSchema({});
|
||||||
schema.extend(propertySchemasIndex[key]);
|
schema.extend(propertySchemasIndex[key]);
|
||||||
schema.extend(CreaturePropertySchema);
|
schema.extend(CreaturePropertySchema);
|
||||||
|
schema.extend(ColorSchema);
|
||||||
schema.extend(ChildSchema);
|
schema.extend(ChildSchema);
|
||||||
schema.extend(SoftRemovableSchema);
|
schema.extend(SoftRemovableSchema);
|
||||||
CreatureProperties.attachSchema(schema, {
|
CreatureProperties.attachSchema(schema, {
|
||||||
@@ -48,7 +58,7 @@ for (let key in propertySchemasIndex){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCreature(property){
|
export function getCreature(property){
|
||||||
if (!property) throw new Meteor.Error('No property provided');
|
if (!property) throw new Meteor.Error('No property provided');
|
||||||
let creature = Creatures.findOne(property.ancestors[0].id);
|
let creature = Creatures.findOne(property.ancestors[0].id);
|
||||||
if (!creature) throw new Meteor.Error('Creature does not exist');
|
if (!creature) throw new Meteor.Error('Creature does not exist');
|
||||||
@@ -69,9 +79,15 @@ function recomputeCreatures(property){
|
|||||||
}
|
}
|
||||||
|
|
||||||
const insertProperty = new ValidatedMethod({
|
const insertProperty = new ValidatedMethod({
|
||||||
name: 'CreatureProperties.methods.insert',
|
name: 'creatureProperties.insert',
|
||||||
validate: null,
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({creatureProperty}) {
|
run({creatureProperty}) {
|
||||||
|
delete creatureProperty._id;
|
||||||
assertPropertyEditPermission(creatureProperty, this.userId);
|
assertPropertyEditPermission(creatureProperty, this.userId);
|
||||||
let _id = CreatureProperties.insert(creatureProperty);
|
let _id = CreatureProperties.insert(creatureProperty);
|
||||||
let property = CreatureProperties.findOne(_id);
|
let property = CreatureProperties.findOne(_id);
|
||||||
@@ -79,8 +95,30 @@ const insertProperty = new ValidatedMethod({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const duplicateProperty = new ValidatedMethod({
|
||||||
|
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);
|
||||||
|
delete creatureProperty._id;
|
||||||
|
CreatureProperties.insert(creatureProperty);
|
||||||
|
recomputeCreatures(creatureProperty);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const insertPropertyFromLibraryNode = new ValidatedMethod({
|
const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||||
name: 'CreatureProperties.methods.insertPropertyFromLibraryNode',
|
name: 'creatureProperties.insertPropertyFromLibraryNode',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
nodeId: {
|
nodeId: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -90,6 +128,11 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
|||||||
type: RefSchema,
|
type: RefSchema,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({nodeId, parentRef}) {
|
run({nodeId, parentRef}) {
|
||||||
// get the new ancestry for the properties
|
// get the new ancestry for the properties
|
||||||
let {parentDoc, ancestors} = getAncestry({parentRef});
|
let {parentDoc, ancestors} = getAncestry({parentRef});
|
||||||
@@ -115,7 +158,7 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
|||||||
'ancestors.id': nodeId,
|
'ancestors.id': nodeId,
|
||||||
removed: {$ne: true},
|
removed: {$ne: true},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
// The root node is last in the array of nodes
|
// The root node is last in the array of nodes
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
|
|
||||||
// re-map all the ancestors
|
// re-map all the ancestors
|
||||||
@@ -138,22 +181,21 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Insert the creature properties
|
// Insert the creature properties
|
||||||
let docId;
|
let insertedDocIds = CreatureProperties.batchInsert(nodes);
|
||||||
nodes.forEach(doc => {
|
|
||||||
docId = CreatureProperties.insert(doc);
|
// get the root inserted doc
|
||||||
});
|
let rootId = insertedDocIds[insertedDocIds.length - 1];
|
||||||
|
|
||||||
// Recompute the creatures doc was attached to
|
// Recompute the creatures doc was attached to
|
||||||
let doc = CreatureProperties.findOne(docId);
|
recomputeCreatures(node);
|
||||||
recomputeCreatures(doc);
|
|
||||||
|
|
||||||
// Return the docId of the last property, the inserted root property
|
// Return the docId of the last property, the inserted root property
|
||||||
return docId;
|
return rootId;
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateProperty = new ValidatedMethod({
|
const updateProperty = new ValidatedMethod({
|
||||||
name: 'CreatureProperties.methods.update',
|
name: 'creatureProperties.update',
|
||||||
validate({_id, path}){
|
validate({_id, path}){
|
||||||
if (!_id) return false;
|
if (!_id) return false;
|
||||||
// We cannot change these fields with a simple update
|
// We cannot change these fields with a simple update
|
||||||
@@ -167,6 +209,11 @@ const updateProperty = new ValidatedMethod({
|
|||||||
'This property can\'t be updated directly');
|
'This property can\'t be updated directly');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, path, value}) {
|
run({_id, path, value}) {
|
||||||
let property = CreatureProperties.findOne(_id);
|
let property = CreatureProperties.findOne(_id);
|
||||||
assertPropertyEditPermission(property, this.userId);
|
assertPropertyEditPermission(property, this.userId);
|
||||||
@@ -185,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({
|
const damageProperty = new ValidatedMethod({
|
||||||
name: 'CreatureProperties.methods.adjust',
|
name: 'creatureProperties.damage',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
_id: SimpleSchema.RegEx.Id,
|
_id: SimpleSchema.RegEx.Id,
|
||||||
operation: {
|
operation: {
|
||||||
@@ -195,6 +273,11 @@ const damageProperty = new ValidatedMethod({
|
|||||||
},
|
},
|
||||||
value: Number,
|
value: Number,
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 20,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, operation, value}) {
|
run({_id, operation, value}) {
|
||||||
let currentProperty = CreatureProperties.findOne(_id);
|
let currentProperty = CreatureProperties.findOne(_id);
|
||||||
// Check permissions
|
// Check permissions
|
||||||
@@ -207,41 +290,108 @@ const damageProperty = new ValidatedMethod({
|
|||||||
`Property of type "${currentProperty.type}" can't be damaged`
|
`Property of type "${currentProperty.type}" can't be damaged`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (operation === 'set'){
|
damagePropertyWork({property: currentProperty, operation, value})
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
recomputeCreatures(currentProperty);
|
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({
|
const pushToProperty = new ValidatedMethod({
|
||||||
name: 'CreatureProperties.methods.push',
|
name: 'creatureProperties.push',
|
||||||
validate: null,
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, path, value}){
|
run({_id, path, value}){
|
||||||
let property = CreatureProperties.findOne(_id);
|
let property = CreatureProperties.findOne(_id);
|
||||||
assertPropertyEditPermission(property, this.userId);
|
assertPropertyEditPermission(property, this.userId);
|
||||||
@@ -255,8 +405,13 @@ const pushToProperty = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pullFromProperty = new ValidatedMethod({
|
const pullFromProperty = new ValidatedMethod({
|
||||||
name: 'CreatureProperties.methods.pull',
|
name: 'creatureProperties.pull',
|
||||||
validate: null,
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, path, itemId}){
|
run({_id, path, itemId}){
|
||||||
let property = CreatureProperties.findOne(_id);
|
let property = CreatureProperties.findOne(_id);
|
||||||
assertPropertyEditPermission(property, this.userId);
|
assertPropertyEditPermission(property, this.userId);
|
||||||
@@ -271,10 +426,15 @@ const pullFromProperty = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const softRemoveProperty = new ValidatedMethod({
|
const softRemoveProperty = new ValidatedMethod({
|
||||||
name: 'CreatureProperties.methods.softRemove',
|
name: 'creatureProperties.softRemove',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
_id: SimpleSchema.RegEx.Id
|
_id: SimpleSchema.RegEx.Id
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id}){
|
run({_id}){
|
||||||
let property = CreatureProperties.findOne(_id);
|
let property = CreatureProperties.findOne(_id);
|
||||||
assertPropertyEditPermission(property, this.userId);
|
assertPropertyEditPermission(property, this.userId);
|
||||||
@@ -288,9 +448,12 @@ export default CreatureProperties;
|
|||||||
export {
|
export {
|
||||||
CreaturePropertySchema,
|
CreaturePropertySchema,
|
||||||
insertProperty,
|
insertProperty,
|
||||||
|
duplicateProperty,
|
||||||
insertPropertyFromLibraryNode,
|
insertPropertyFromLibraryNode,
|
||||||
updateProperty,
|
updateProperty,
|
||||||
damageProperty,
|
damageProperty,
|
||||||
|
adjustQuantity,
|
||||||
|
selectAmmoItem,
|
||||||
pushToProperty,
|
pushToProperty,
|
||||||
pullFromProperty,
|
pullFromProperty,
|
||||||
softRemoveProperty,
|
softRemoveProperty,
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import deathSaveSchema from '/imports/api/properties/subSchemas/DeathSavesSchema.js'
|
import deathSaveSchema from '/imports/api/properties/subSchemas/DeathSavesSchema.js'
|
||||||
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
||||||
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
||||||
import {assertEditPermission} from '/imports/api/sharing/sharingPermissions.js';
|
import {assertEditPermission} from '/imports/api/sharing/sharingPermissions.js';
|
||||||
|
import { assertUserHasPaidBenefits } from '/imports/api/users/patreon/tiers.js';
|
||||||
|
|
||||||
import '/imports/api/creature/removeCreature.js';
|
import '/imports/api/creature/removeCreature.js';
|
||||||
|
import '/imports/api/creature/restCreature.js';
|
||||||
|
|
||||||
//set up the collection for creatures
|
//set up the collection for creatures
|
||||||
let Creatures = new Mongo.Collection('creatures');
|
let Creatures = new Mongo.Collection('creatures');
|
||||||
@@ -26,6 +29,18 @@ let CreatureSettingsSchema = new SimpleSchema({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
// Hide all the unused stats
|
||||||
|
hideUnusedStats: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
// How much each hitDice resets on a long rest
|
||||||
|
hitDiceResetMultiplier: {
|
||||||
|
type: Number,
|
||||||
|
optional: true,
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let CreatureSchema = new SimpleSchema({
|
let CreatureSchema = new SimpleSchema({
|
||||||
@@ -51,24 +66,31 @@ let CreatureSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Mechanics
|
// Mechanics
|
||||||
deathSave: {
|
deathSave: {
|
||||||
type: deathSaveSchema,
|
type: deathSaveSchema,
|
||||||
defaultValue: {},
|
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,
|
type: SimpleSchema.Integer,
|
||||||
defaultValue: 0,
|
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,
|
type: Number,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
},
|
},
|
||||||
level: {
|
|
||||||
type: SimpleSchema.Integer,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
defaultValue: 'pc',
|
defaultValue: 'pc',
|
||||||
@@ -85,6 +107,17 @@ let CreatureSchema = new SimpleSchema({
|
|||||||
defaultValue: {}
|
defaultValue: {}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Tabletop
|
||||||
|
tabletop: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.id,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
initiativeRoll: {
|
||||||
|
type: SimpleSchema.Integer,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
settings: {
|
settings: {
|
||||||
type: CreatureSettingsSchema,
|
type: CreatureSettingsSchema,
|
||||||
@@ -99,15 +132,22 @@ Creatures.attachSchema(CreatureSchema);
|
|||||||
|
|
||||||
const insertCreature = new ValidatedMethod({
|
const insertCreature = new ValidatedMethod({
|
||||||
|
|
||||||
name: 'Creatures.methods.insertCreature',
|
name: 'creatures.insertCreature',
|
||||||
|
|
||||||
validate: null,
|
validate: null,
|
||||||
|
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
if (!this.userId) {
|
if (!this.userId) {
|
||||||
throw new Meteor.Error('Creatures.methods.insert.denied',
|
throw new Meteor.Error('Creatures.methods.insert.denied',
|
||||||
'You need to be logged in to insert a creature');
|
'You need to be logged in to insert a creature');
|
||||||
}
|
}
|
||||||
|
assertUserHasPaidBenefits(this.userId);
|
||||||
|
|
||||||
// Create the creature document
|
// Create the creature document
|
||||||
let charId = Creatures.insert({
|
let charId = Creatures.insert({
|
||||||
@@ -120,22 +160,41 @@ const insertCreature = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const updateCreature = new ValidatedMethod({
|
const updateCreature = new ValidatedMethod({
|
||||||
name: 'Creatures.methods.update',
|
name: 'creatures.update',
|
||||||
validate({_id, path}){
|
validate({_id, path}){
|
||||||
if (!_id) return false;
|
if (!_id) return false;
|
||||||
// Allowed fields
|
// Allowed fields
|
||||||
let allowedFields = ['name', 'alignment', 'gender', 'picture', 'avatarPicture', 'settings'];
|
let allowedFields = [
|
||||||
|
'name',
|
||||||
|
'alignment',
|
||||||
|
'gender',
|
||||||
|
'picture',
|
||||||
|
'avatarPicture',
|
||||||
|
'color',
|
||||||
|
'settings',
|
||||||
|
];
|
||||||
if (!allowedFields.includes(path[0])){
|
if (!allowedFields.includes(path[0])){
|
||||||
throw new Meteor.Error('Creatures.methods.update.denied',
|
throw new Meteor.Error('Creatures.methods.update.denied',
|
||||||
'This field can\'t be updated using this method');
|
'This field can\'t be updated using this method');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, path, value}) {
|
run({_id, path, value}) {
|
||||||
let creature = Creatures.findOne(_id);
|
let creature = Creatures.findOne(_id);
|
||||||
assertEditPermission(creature, this.userId);
|
assertEditPermission(creature, this.userId);
|
||||||
Creatures.update(_id, {
|
if (value === undefined || value === null){
|
||||||
$set: {[path.join('.')]: value},
|
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
|
// The computation memo is an in-memory data structure used only during the
|
||||||
// computation process
|
// computation process
|
||||||
export default class ComputationMemo {
|
export default class ComputationMemo {
|
||||||
constructor(props){
|
constructor(props, creature){
|
||||||
this.statsByVariableName = {};
|
this.statsByVariableName = {};
|
||||||
this.extraStatsByVariableName = {};
|
this.extraStatsByVariableName = {};
|
||||||
this.statsById = {};
|
this.statsById = {};
|
||||||
@@ -15,6 +15,10 @@ export default class ComputationMemo {
|
|||||||
this.classes = {};
|
this.classes = {};
|
||||||
this.togglesById = {};
|
this.togglesById = {};
|
||||||
this.toggleIds = new Set();
|
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
|
// First note all the ids of all the toggles
|
||||||
props.forEach((prop) => {
|
props.forEach((prop) => {
|
||||||
if (
|
if (
|
||||||
@@ -38,6 +42,10 @@ export default class ComputationMemo {
|
|||||||
) {
|
) {
|
||||||
// Add all the stats
|
// Add all the stats
|
||||||
this.addStat(prop);
|
this.addStat(prop);
|
||||||
|
} else if (
|
||||||
|
prop.type === 'item'
|
||||||
|
) {
|
||||||
|
this.addEquipment(prop);
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -49,8 +57,19 @@ export default class ComputationMemo {
|
|||||||
this.addProficiency(prop);
|
this.addProficiency(prop);
|
||||||
} else if (prop.type === 'classLevel'){
|
} else if (prop.type === 'classLevel'){
|
||||||
this.addClassLevel(prop);
|
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){
|
registerProperty(prop){
|
||||||
this.originalPropsById[prop._id] = cloneDeep(prop);
|
this.originalPropsById[prop._id] = cloneDeep(prop);
|
||||||
@@ -63,46 +82,6 @@ export default class ComputationMemo {
|
|||||||
});
|
});
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
storeHighestClassLevel(name, prop, isBaseClass){
|
|
||||||
// Only store the highest level classLevel
|
|
||||||
let stat = this.statsByVariableName[name]
|
|
||||||
if (!stat){
|
|
||||||
this.statsByVariableName[name] = prop;
|
|
||||||
if (isBaseClass){
|
|
||||||
this.classes[name] = prop;
|
|
||||||
}
|
|
||||||
} else if (!has(stat, 'level')){
|
|
||||||
// Stat is overriden by an attribute
|
|
||||||
return;
|
|
||||||
} else if (stat.level < prop.level) {
|
|
||||||
this.statsByVariableName[name] = prop;
|
|
||||||
if (isBaseClass){
|
|
||||||
this.classes[name] = prop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.updateLevel();
|
|
||||||
}
|
|
||||||
updateLevel(){
|
|
||||||
let currentLevel = this.statsByVariableName['level'];
|
|
||||||
if (!currentLevel){
|
|
||||||
currentLevel = {
|
|
||||||
value: 0,
|
|
||||||
computationDetails: {
|
|
||||||
builtIn: true,
|
|
||||||
computed: true,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.statsByVariableName['level'] = currentLevel;
|
|
||||||
}
|
|
||||||
// bail out if overriden by an attribute
|
|
||||||
if (!currentLevel.computationDetails.builtIn) return;
|
|
||||||
let level = 0;
|
|
||||||
for (let name in this.classes){
|
|
||||||
level += this.classes[name].level || 0;
|
|
||||||
}
|
|
||||||
this.statsByVariableName['level'].value = level;
|
|
||||||
}*/
|
|
||||||
addToggle(prop){
|
addToggle(prop){
|
||||||
prop = this.registerProperty(prop);
|
prop = this.registerProperty(prop);
|
||||||
this.togglesById[prop._id] = prop;
|
this.togglesById[prop._id] = prop;
|
||||||
@@ -212,6 +191,14 @@ export default class ComputationMemo {
|
|||||||
});
|
});
|
||||||
return targets;
|
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){
|
function isAbility(prop){
|
||||||
@@ -237,10 +224,17 @@ function isSkillOperation(prop){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function propDetails(prop){
|
function propDetails(prop){
|
||||||
return propDetailsByType[prop.type]() || {};
|
return propDetailsByType[prop.type] && propDetailsByType[prop.type]() ||
|
||||||
|
propDetailsByType.default();
|
||||||
}
|
}
|
||||||
|
|
||||||
const propDetailsByType = {
|
const propDetailsByType = {
|
||||||
|
default(){
|
||||||
|
return {
|
||||||
|
toggleAncestors: [],
|
||||||
|
disabledByToggle: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
toggle(){
|
toggle(){
|
||||||
return {
|
return {
|
||||||
computed: false,
|
computed: false,
|
||||||
@@ -291,4 +285,10 @@ const propDetailsByType = {
|
|||||||
disabledByToggle: false,
|
disabledByToggle: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
denormalizedStat(){
|
||||||
|
return {
|
||||||
|
toggleAncestors: [],
|
||||||
|
disabledByToggle: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,14 @@ import evaluateCalculation from '/imports/api/creature/computation/evaluateCalcu
|
|||||||
|
|
||||||
export default class EffectAggregator{
|
export default class EffectAggregator{
|
||||||
constructor(stat, memo){
|
constructor(stat, memo){
|
||||||
|
delete this.baseValueErrors;
|
||||||
if (stat.baseValueCalculation){
|
if (stat.baseValueCalculation){
|
||||||
this.statBaseValue = evaluateCalculation(stat.baseValueCalculation, memo);
|
let {value, errors} = evaluateCalculation(stat.baseValueCalculation, memo);
|
||||||
this.base = +this.statBaseValue;
|
this.statBaseValue = value;
|
||||||
|
if (errors.length){
|
||||||
|
this.baseValueErrors = errors;
|
||||||
|
}
|
||||||
|
this.base = this.statBaseValue;
|
||||||
} else {
|
} else {
|
||||||
this.base = 0;
|
this.base = 0;
|
||||||
}
|
}
|
||||||
@@ -16,17 +21,22 @@ export default class EffectAggregator{
|
|||||||
this.disadvantage = 0;
|
this.disadvantage = 0;
|
||||||
this.passiveAdd = 0;
|
this.passiveAdd = 0;
|
||||||
this.fail = 0;
|
this.fail = 0;
|
||||||
|
this.set = undefined;
|
||||||
this.conditional = [];
|
this.conditional = [];
|
||||||
this.rollBonus = [];
|
this.rollBonus = [];
|
||||||
|
this.hasNoEffects = true;
|
||||||
}
|
}
|
||||||
addEffect(effect){
|
addEffect(effect){
|
||||||
let result = effect.result;
|
let result = effect.result;
|
||||||
|
if (this.hasNoEffects) this.hasNoEffects = false;
|
||||||
switch(effect.operation){
|
switch(effect.operation){
|
||||||
case 'base':
|
case 'base':
|
||||||
// Take the largest base value
|
// Take the largest base value
|
||||||
this.base = result > this.base ? result : this.base;
|
this.base = result > this.base ? result : this.base;
|
||||||
if (effect.statBase){
|
if (effect.statBase){
|
||||||
this.statBaseValue = result > this.statBaseValue ? result : this.statBaseValue;
|
if (this.statBaseValue === undefined || result > this.statBaseValue){
|
||||||
|
this.statBaseValue = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'add':
|
case 'add':
|
||||||
@@ -45,6 +55,10 @@ export default class EffectAggregator{
|
|||||||
// Take the smallest max value
|
// Take the smallest max value
|
||||||
this.max = result < this.max ? result : this.max;
|
this.max = result < this.max ? result : this.max;
|
||||||
break;
|
break;
|
||||||
|
case 'set':
|
||||||
|
// Take the highest set value
|
||||||
|
this.set = this.set === undefined || result > this.set ? result : this.set;
|
||||||
|
break;
|
||||||
case 'advantage':
|
case 'advantage':
|
||||||
// Sum number of advantages
|
// Sum number of advantages
|
||||||
this.advantage++;
|
this.advantage++;
|
||||||
|
|||||||
@@ -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 computeStat from '/imports/api/creature/computation/computeStat.js';
|
||||||
import applyToggles from '/imports/api/creature/computation/applyToggles.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){
|
export default function combineStat(stat, aggregator, memo){
|
||||||
if (stat.type === 'attribute'){
|
if (stat.type === 'attribute'){
|
||||||
combineAttribute(stat, aggregator);
|
combineAttribute(stat, aggregator, memo);
|
||||||
} else if (stat.type === 'skill'){
|
} else if (stat.type === 'skill'){
|
||||||
combineSkill(stat, aggregator, memo);
|
combineSkill(stat, aggregator, memo);
|
||||||
} else if (stat.type === 'damageMultiplier'){
|
} else if (stat.type === 'damageMultiplier'){
|
||||||
@@ -11,17 +12,39 @@ export default function combineStat(stat, aggregator, memo){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function combineAttribute(stat, aggregator){
|
function getAggregatorResult(stat, aggregator){
|
||||||
let result = (aggregator.base + aggregator.add) * aggregator.mul;
|
let result = (aggregator.base + aggregator.add) * aggregator.mul;
|
||||||
if (result < aggregator.min) result = aggregator.min;
|
if (result < aggregator.min) {
|
||||||
if (result > aggregator.max) result = aggregator.max;
|
result = aggregator.min;
|
||||||
if (!stat.decimal) result = Math.floor(result);
|
}
|
||||||
stat.value = result;
|
if (result > aggregator.max) {
|
||||||
|
result = aggregator.max;
|
||||||
|
}
|
||||||
|
if (aggregator.set !== undefined) {
|
||||||
|
result = aggregator.set;
|
||||||
|
}
|
||||||
|
if (!stat.decimal && Number.isFinite(result)){
|
||||||
|
result = Math.floor(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function combineAttribute(stat, aggregator, memo){
|
||||||
|
stat.value = getAggregatorResult(stat, aggregator);
|
||||||
stat.baseValue = aggregator.statBaseValue;
|
stat.baseValue = aggregator.statBaseValue;
|
||||||
|
stat.baseValueErrors = aggregator.baseValueErrors;
|
||||||
if (stat.attributeType === 'ability') {
|
if (stat.attributeType === 'ability') {
|
||||||
stat.modifier = Math.floor((result - 10) / 2);
|
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.currentValue = stat.value - (stat.damage || 0);
|
||||||
|
stat.hide = aggregator.hasNoEffects &&
|
||||||
|
stat.baseValue === undefined ||
|
||||||
|
undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
function combineSkill(stat, aggregator, memo){
|
function combineSkill(stat, aggregator, memo){
|
||||||
@@ -51,16 +74,23 @@ function combineSkill(stat, aggregator, memo){
|
|||||||
|
|
||||||
if (typeof profBonus !== 'number' && memo.statsByVariableName['level']){
|
if (typeof profBonus !== 'number' && memo.statsByVariableName['level']){
|
||||||
let level = memo.statsByVariableName['level'].value;
|
let level = memo.statsByVariableName['level'].value;
|
||||||
profBonus = Math.floor(level / 4 + 1.75);
|
profBonus = Math.ceil(level / 4) + 1;
|
||||||
}
|
}
|
||||||
// Multiply the proficiency bonus by the actual proficiency
|
// Multiply the proficiency bonus by the actual proficiency
|
||||||
profBonus *= stat.proficiency;
|
profBonus *= stat.proficiency;
|
||||||
|
// Base value
|
||||||
|
stat.baseValue = aggregator.statBaseValue;
|
||||||
|
stat.baseValueErrors = aggregator.baseValueErrors;
|
||||||
// Combine everything to get the final result
|
// 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.min) result = aggregator.min;
|
||||||
if (result > aggregator.max) result = aggregator.max;
|
if (result > aggregator.max) result = aggregator.max;
|
||||||
result = Math.floor(result);
|
if (aggregator.set !== undefined) {
|
||||||
if (aggregator.base > result) result = aggregator.base;
|
result = aggregator.set;
|
||||||
|
}
|
||||||
|
if (Number.isFinite(result)){
|
||||||
|
result = Math.floor(result);
|
||||||
|
}
|
||||||
stat.value = result;
|
stat.value = result;
|
||||||
// Advantage/disadvantage
|
// Advantage/disadvantage
|
||||||
if (aggregator.advantage && !aggregator.disadvantage){
|
if (aggregator.advantage && !aggregator.disadvantage){
|
||||||
@@ -80,6 +110,11 @@ function combineSkill(stat, aggregator, memo){
|
|||||||
stat.fail = aggregator.fail;
|
stat.fail = aggregator.fail;
|
||||||
// Rollbonus
|
// Rollbonus
|
||||||
stat.rollBonuses = aggregator.rollBonus;
|
stat.rollBonuses = aggregator.rollBonus;
|
||||||
|
// Hide
|
||||||
|
stat.hide = aggregator.hasNoEffects &&
|
||||||
|
stat.baseValue === undefined &&
|
||||||
|
stat.proficiency == 0 ||
|
||||||
|
undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function combineDamageMultiplier(stat){
|
function combineDamageMultiplier(stat){
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ export default function computeEffect(effect, memo){
|
|||||||
applyToggles(effect, memo);
|
applyToggles(effect, memo);
|
||||||
|
|
||||||
// Determine result of effect calculation
|
// Determine result of effect calculation
|
||||||
|
delete effect.errors;
|
||||||
if (!effect.calculation){
|
if (!effect.calculation){
|
||||||
if(effect.operation === 'add' || effect.operation === 'base'){
|
if(effect.operation === 'add' || effect.operation === 'base'){
|
||||||
effect.result = 0;
|
effect.result = 0;
|
||||||
|
} else {
|
||||||
|
delete effect.result
|
||||||
}
|
}
|
||||||
} else if (Number.isFinite(+effect.calculation)){
|
} else if (Number.isFinite(+effect.calculation)){
|
||||||
effect.result = +effect.calculation;
|
effect.result = +effect.calculation;
|
||||||
@@ -31,7 +34,11 @@ export default function computeEffect(effect, memo){
|
|||||||
} else if(_.contains(['advantage', 'disadvantage', 'fail'], effect.operation)){
|
} else if(_.contains(['advantage', 'disadvantage', 'fail'], effect.operation)){
|
||||||
effect.result = 1;
|
effect.result = 1;
|
||||||
} else {
|
} else {
|
||||||
effect.result = evaluateCalculation(effect.calculation, memo);
|
let {value, errors} = evaluateCalculation(effect.calculation, memo);
|
||||||
|
effect.result = value;
|
||||||
|
if (errors.length){
|
||||||
|
effect.errors = errors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
effect.computationDetails.computed = true;
|
effect.computationDetails.computed = true;
|
||||||
effect.computationDetails.busyComputing = false;
|
effect.computationDetails.busyComputing = false;
|
||||||
|
|||||||
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 computeStat from '/imports/api/creature/computation/computeStat.js';
|
||||||
import computeEffect from '/imports/api/creature/computation/computeEffect.js';
|
import computeEffect from '/imports/api/creature/computation/computeEffect.js';
|
||||||
import computeToggle from '/imports/api/creature/computation/computeToggle.js';
|
import computeToggle from '/imports/api/creature/computation/computeToggle.js';
|
||||||
|
import computeEndStepProperty from '/imports/api/creature/computation/computeEndStepProperty.js';
|
||||||
|
|
||||||
export default function computeMemo(memo){
|
export default function computeMemo(memo){
|
||||||
// Compute level
|
// Compute level
|
||||||
@@ -15,8 +16,12 @@ export default function computeMemo(memo){
|
|||||||
each(memo.unassignedEffects, effect => {
|
each(memo.unassignedEffects, effect => {
|
||||||
computeEffect(effect, memo);
|
computeEffect(effect, memo);
|
||||||
});
|
});
|
||||||
|
// Compute toggles which didn't already get computed by dependencies
|
||||||
forOwn(memo.togglesById, toggle => {
|
forOwn(memo.togglesById, toggle => {
|
||||||
computeToggle(toggle, memo);
|
computeToggle(toggle, memo);
|
||||||
});
|
});
|
||||||
// Compute class levels
|
// Compute end step properties
|
||||||
|
forOwn(memo.endStepPropsById, prop => {
|
||||||
|
computeEndStepProperty(prop, memo);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export default function computeToggle(toggle, memo){
|
|||||||
toggle.computationDetails.busyComputing = true;
|
toggle.computationDetails.busyComputing = true;
|
||||||
|
|
||||||
// Do work
|
// Do work
|
||||||
|
delete toggle.errors;
|
||||||
if (toggle.enabled){
|
if (toggle.enabled){
|
||||||
toggle.toggleResult = true;
|
toggle.toggleResult = true;
|
||||||
} else if (toggle.disabled){
|
} else if (toggle.disabled){
|
||||||
@@ -25,7 +26,11 @@ export default function computeToggle(toggle, memo){
|
|||||||
} else if (Number.isFinite(+toggle.condition)){
|
} else if (Number.isFinite(+toggle.condition)){
|
||||||
toggle.toggleResult = !!+toggle.condition;
|
toggle.toggleResult = !!+toggle.condition;
|
||||||
} else {
|
} else {
|
||||||
toggle.toggleResult = evaluateCalculation(toggle.condition, memo);
|
let {value, errors} = evaluateCalculation(toggle.condition, memo);
|
||||||
|
toggle.toggleResult = value;
|
||||||
|
if (errors.length){
|
||||||
|
toggle.errors = errors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
toggle.computationDetails.computed = true;
|
toggle.computationDetails.computed = true;
|
||||||
toggle.computationDetails.busyComputing = false;
|
toggle.computationDetails.busyComputing = false;
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
import bareSymbolSubtitutor from '/imports/api/creature/computation/utility/bareSymbolSubtitutor.js';
|
|
||||||
import computeStat from '/imports/api/creature/computation/computeStat.js';
|
import computeStat from '/imports/api/creature/computation/computeStat.js';
|
||||||
import math from '/imports/math.js';
|
import math from '/imports/math.js';
|
||||||
|
|
||||||
|
/* Convert a calculation into a constant output and errors*/
|
||||||
export default function evaluateCalculation(string, memo){
|
export default function evaluateCalculation(string, memo){
|
||||||
if (!string) return string;
|
if (!string) return {errors: [], value: string};
|
||||||
|
let errors = [];
|
||||||
// Parse the string using mathjs
|
// Parse the string using mathjs
|
||||||
let calc;
|
let calc;
|
||||||
try {
|
try {
|
||||||
calc = math.parse(string);
|
calc = math.parse(string);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return string;
|
errors.push({
|
||||||
|
type: 'parsing',
|
||||||
|
message: e.message || e
|
||||||
|
});
|
||||||
|
return {errors, value: string};
|
||||||
}
|
}
|
||||||
// Ensure all symbol nodes are defined and coputed
|
// Ensure all symbol nodes are defined and coputed
|
||||||
calc.traverse(node => {
|
calc.traverse(node => {
|
||||||
@@ -20,12 +25,74 @@ export default function evaluateCalculation(string, memo){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Ensure any bare symbols are value accessors instead
|
// Replace all symbols with their subtitution
|
||||||
let substitutedCalc = calc.transform(bareSymbolSubtitutor(memo.statsByVariableName));
|
let substitutedCalc = calc.transform(
|
||||||
|
symbolSubtitutor(memo.statsByVariableName, errors)
|
||||||
|
);
|
||||||
// Evaluate the expression to a number or return with substitutions
|
// Evaluate the expression to a number or return with substitutions
|
||||||
try {
|
try {
|
||||||
return substitutedCalc.evaluate(memo.statsByVariableName);
|
let value = substitutedCalc.evaluate(memo.statsByVariableName);
|
||||||
|
if (typeof value === 'object') value = value.toString();
|
||||||
|
return {errors, value};
|
||||||
} catch (e){
|
} catch (e){
|
||||||
return substitutedCalc.toString();
|
errors.push({
|
||||||
|
type: 'evaluation',
|
||||||
|
message: e.message || e
|
||||||
|
});
|
||||||
|
let value = substitutedCalc.toString();
|
||||||
|
return {errors, value};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns a function to replace all symbols with either their resolved value
|
||||||
|
// or zero, keeping the errors
|
||||||
|
function symbolSubtitutor(scope, errors){
|
||||||
|
return function(node){
|
||||||
|
// mark symbol nodes that are children of function nodes to be skipped
|
||||||
|
if (node.isFunctionNode){
|
||||||
|
let fn = node.fn;
|
||||||
|
if (fn && fn.isSymbolNode){
|
||||||
|
fn.skipReplacement = true;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
} else if (node.isSymbolNode && node.skipReplacement !== true){
|
||||||
|
//bare symbols of name "stat", should search for stat.value
|
||||||
|
let stat = scope[node.name];
|
||||||
|
if (stat){
|
||||||
|
if (stat.value === undefined){
|
||||||
|
errors.push({
|
||||||
|
type: 'subsitution',
|
||||||
|
message: `${node.name} does not have a value, set to 0`
|
||||||
|
});
|
||||||
|
return new math.ConstantNode(0);
|
||||||
|
} else {
|
||||||
|
return new math.ConstantNode(stat.value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return new math.ConstantNode(node.evaluate(scope));
|
||||||
|
} catch (e) {
|
||||||
|
errors.push({
|
||||||
|
type: 'subsitution',
|
||||||
|
message: `${node.name} not found, set to 0`
|
||||||
|
});
|
||||||
|
return new math.ConstantNode(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (node.isAccessorNode && node.object.isSymbolNode){
|
||||||
|
try {
|
||||||
|
let value = node.evaluate(scope);
|
||||||
|
if (value === undefined) throw 'Not found';
|
||||||
|
return new math.ConstantNode(value);
|
||||||
|
} catch (e) {
|
||||||
|
errors.push({
|
||||||
|
type: 'subsitution',
|
||||||
|
message: `${node.toString()} not found, set to 0`
|
||||||
|
});
|
||||||
|
return new math.ConstantNode(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||||
import ComputationMemo from '/imports/api/creature/computation/ComputationMemo.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 getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||||
import writeAlteredProperties from '/imports/api/creature/computation/writeAlteredProperties.js';
|
import writeAlteredProperties from '/imports/api/creature/computation/writeAlteredProperties.js';
|
||||||
import writeCreatureVariables from '/imports/api/creature/computation/writeCreatureVariables.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({
|
export const recomputeCreature = new ValidatedMethod({
|
||||||
|
|
||||||
name: 'Creatures.methods.recomputeCreature',
|
name: 'creatures.recomputeCreature',
|
||||||
|
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
charId: { type: String }
|
charId: { type: String }
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
|
||||||
run({charId}) {
|
run({charId}) {
|
||||||
|
let creature = Creatures.findOne(charId);
|
||||||
// Permission
|
// Permission
|
||||||
assertEditPermission(charId, this.userId);
|
assertEditPermission(creature, this.userId);
|
||||||
// Work, call this direcly if you are already in a method that has checked
|
// Work, call this direcly if you are already in a method that has checked
|
||||||
// for permission to edit a given character
|
// for permission to edit a given character
|
||||||
recomputeCreatureById(charId);
|
recomputeCreatureById(charId);
|
||||||
@@ -33,8 +42,21 @@ const calculationPropertyTypes = [
|
|||||||
'proficiency',
|
'proficiency',
|
||||||
'classLevel',
|
'classLevel',
|
||||||
'toggle',
|
'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,
|
* 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
|
* distilling down effects and proficiencies into the final stats that make up
|
||||||
@@ -71,17 +93,18 @@ const calculationPropertyTypes = [
|
|||||||
* - Mark the stat as computed
|
* - Mark the stat as computed
|
||||||
* - Write the computed results back to the database
|
* - Write the computed results back to the database
|
||||||
*/
|
*/
|
||||||
export function recomputeCreatureById(creatureId){
|
export function recomputeCreatureByDoc(creature){
|
||||||
|
const creatureId = creature._id;
|
||||||
let props = getActiveProperties({
|
let props = getActiveProperties({
|
||||||
ancestorId: creatureId,
|
ancestorId: creatureId,
|
||||||
filter: {type: {$in: calculationPropertyTypes}},
|
filter: {type: {$in: calculationPropertyTypes}},
|
||||||
includeUntoggled: true,
|
includeUntoggled: true,
|
||||||
|
// TODO filter out expensive fields, particularly icon field
|
||||||
});
|
});
|
||||||
let computationMemo = new ComputationMemo(props);
|
let computationMemo = new ComputationMemo(props, creature);
|
||||||
computeMemo(computationMemo);
|
computeMemo(computationMemo);
|
||||||
writeAlteredProperties(computationMemo);
|
writeAlteredProperties(computationMemo);
|
||||||
writeCreatureVariables(computationMemo, creatureId);
|
writeCreatureVariables(computationMemo, creatureId);
|
||||||
// if(Meteor.isClient) console.log(computationMemo);
|
|
||||||
recomputeDamageMultipliersById(creatureId);
|
recomputeDamageMultipliersById(creatureId);
|
||||||
return computationMemo;
|
return computationMemo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,31 @@
|
|||||||
import { Meteor } from 'meteor/meteor'
|
import { Meteor } from 'meteor/meteor'
|
||||||
import { isEqual, forOwn } from 'lodash';
|
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 { ComputedOnlySkillSchema } from '/imports/api/properties/Skills.js';
|
||||||
import { ComputedOnlyAttributeSchema } from '/imports/api/properties/Attributes.js';
|
import { ComputedOnlyAttributeSchema } from '/imports/api/properties/Attributes.js';
|
||||||
import { ComputedOnlyEffectSchema } from '/imports/api/properties/Effects.js';
|
import { ComputedOnlyEffectSchema } from '/imports/api/properties/Effects.js';
|
||||||
import { ComputedOnlyToggleSchema } from '/imports/api/properties/Toggles.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 = {
|
const schemasByType = {
|
||||||
'skill': ComputedOnlySkillSchema,
|
'skill': ComputedOnlySkillSchema,
|
||||||
'attribute': ComputedOnlyAttributeSchema,
|
'attribute': ComputedOnlyAttributeSchema,
|
||||||
'effect': ComputedOnlyEffectSchema,
|
'effect': ComputedOnlyEffectSchema,
|
||||||
'toggle': ComputedOnlyToggleSchema,
|
'toggle': ComputedOnlyToggleSchema,
|
||||||
|
'action': ComputedOnlyActionSchema,
|
||||||
|
'attack': ComputedOnlyAttackSchema,
|
||||||
|
'savingThrow': ComputedOnlySavingThrowSchema,
|
||||||
|
'spellList': ComputedOnlySpellListSchema,
|
||||||
|
'spell': ComputedOnlySpellSchema,
|
||||||
|
'propertySlot': ComputedOnlySlotSchema,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function writeAlteredProperties(memo){
|
export default function writeAlteredProperties(memo){
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.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({
|
export const recomputeDamageMultipliers = new ValidatedMethod({
|
||||||
|
|
||||||
name: 'Creatures.methods.recomputeDamageMultipliers',
|
name: 'creatures.recomputeDamageMultipliers',
|
||||||
|
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
creatureId: { type: String }
|
creatureId: { type: String }
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
|
||||||
run({creatureId}) {
|
run({creatureId}) {
|
||||||
// Permission
|
// Permission
|
||||||
assertEditPermission(creatureId, this.userId);
|
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,8 +4,30 @@ import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
|||||||
export default function getActiveProperties({
|
export default function getActiveProperties({
|
||||||
ancestorId,
|
ancestorId,
|
||||||
filter = {},
|
filter = {},
|
||||||
options,
|
options = {sort: {order: 1}},
|
||||||
includeUntoggled = false
|
includeUntoggled = false,
|
||||||
|
includeUnprepared = false,
|
||||||
|
includeUnequipped = false,
|
||||||
|
excludeAncestors,
|
||||||
|
}){
|
||||||
|
filter = getActivePropertyFilter({
|
||||||
|
ancestorId,
|
||||||
|
filter,
|
||||||
|
includeUntoggled,
|
||||||
|
includeUnprepared,
|
||||||
|
includeUnequipped,
|
||||||
|
excludeAncestors,
|
||||||
|
});
|
||||||
|
return CreatureProperties.find(filter, options).fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getActivePropertyFilter({
|
||||||
|
ancestorId,
|
||||||
|
filter = {},
|
||||||
|
includeUntoggled = false,
|
||||||
|
includeUnprepared = false,
|
||||||
|
includeUnequipped = false,
|
||||||
|
excludeAncestors = [],
|
||||||
}){
|
}){
|
||||||
if (!ancestorId){
|
if (!ancestorId){
|
||||||
throw 'Ancestor Id is required to get active properties'
|
throw 'Ancestor Id is required to get active properties'
|
||||||
@@ -14,14 +36,23 @@ export default function getActiveProperties({
|
|||||||
let disabledAncestorsFilter = {
|
let disabledAncestorsFilter = {
|
||||||
'ancestors.id': ancestorId,
|
'ancestors.id': ancestorId,
|
||||||
$or: [
|
$or: [
|
||||||
{disabled: true},
|
{disabled: true}, // Everything can be disabled
|
||||||
{equipped: false},
|
{applied: false}, // Buffs can be applied
|
||||||
{applied: false},
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
if (!includeUnequipped){
|
||||||
|
disabledAncestorsFilter.$or.push({type: 'item', equipped: {$ne: true}});
|
||||||
|
}
|
||||||
if (!includeUntoggled){
|
if (!includeUntoggled){
|
||||||
disabledAncestorsFilter.$or.push({toggleResult: false});
|
disabledAncestorsFilter.$or.push({toggleResult: false});
|
||||||
}
|
}
|
||||||
|
if (!includeUnprepared){
|
||||||
|
disabledAncestorsFilter.$or.push({
|
||||||
|
type: 'spell',
|
||||||
|
prepared: {$ne: true},
|
||||||
|
alwaysPrepared: {$ne: true}
|
||||||
|
});
|
||||||
|
}
|
||||||
let disabledAncestorIds = CreatureProperties.find(disabledAncestorsFilter, {
|
let disabledAncestorIds = CreatureProperties.find(disabledAncestorsFilter, {
|
||||||
fields: {_id: 1},
|
fields: {_id: 1},
|
||||||
}).map(prop => prop._id);
|
}).map(prop => prop._id);
|
||||||
@@ -38,9 +69,12 @@ export default function getActiveProperties({
|
|||||||
|
|
||||||
// Get all the properties that are decendents of the ancestor of interest but
|
// Get all the properties that are decendents of the ancestor of interest but
|
||||||
// aren't from the excluded decendents
|
// aren't from the excluded decendents
|
||||||
|
if (filter['ancestors.id'] && Meteor.isClient){
|
||||||
|
console.warn('Filtering on ancestor id is ignored')
|
||||||
|
}
|
||||||
filter['ancestors.id'] = {
|
filter['ancestors.id'] = {
|
||||||
$eq: ancestorId,
|
$eq: ancestorId,
|
||||||
$nin: disabledAncestorIds,
|
$nin: disabledAncestorIds.concat(excludeAncestors),
|
||||||
};
|
};
|
||||||
// Get properties that aren't removed
|
// Get properties that aren't removed
|
||||||
filter.removed = {$ne: true};
|
filter.removed = {$ne: true};
|
||||||
@@ -48,5 +82,5 @@ export default function getActiveProperties({
|
|||||||
filter._id = {
|
filter._id = {
|
||||||
$nin: disabledAncestorIds,
|
$nin: disabledAncestorIds,
|
||||||
}
|
}
|
||||||
return CreatureProperties.find(filter, options).fetch();
|
return filter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
|
||||||
let ExperienceSchema = new SimpleSchema({
|
let ExperienceSchema = new SimpleSchema({
|
||||||
name: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
@@ -10,11 +10,6 @@ let ExperienceSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
// The amount of XP this experience gives
|
|
||||||
value: {
|
|
||||||
type: SimpleSchema.Integer,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
// The real-world date that it occured
|
// The real-world date that it occured
|
||||||
date: {
|
date: {
|
||||||
type: Date,
|
type: Date,
|
||||||
@@ -30,6 +25,20 @@ let ExperienceSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
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 };
|
export { ExperienceSchema };
|
||||||
@@ -1,20 +1,29 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
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 Creatures from '/imports/api/creature/Creatures.js';
|
||||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js'
|
import CreatureProperties from '/imports/api/creature/CreatureProperties.js'
|
||||||
import { assertOwnership } from '/imports/api/creature/creaturePermissions.js';
|
import { assertOwnership } from '/imports/api/creature/creaturePermissions.js';
|
||||||
|
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
||||||
|
|
||||||
function removeRelatedDocuments(charId){
|
function removeRelatedDocuments(creatureId){
|
||||||
CreatureProperties.remove({'ancestors.id': charId});
|
CreatureProperties.remove({'ancestors.id': creatureId});
|
||||||
};
|
Experiences.remove({creatureId});
|
||||||
|
}
|
||||||
|
|
||||||
const removeCreature = new ValidatedMethod({
|
const removeCreature = new ValidatedMethod({
|
||||||
name: "Creatures.methods.removeCreature", // DDP method name
|
name: 'Creatures.methods.removeCreature', // DDP method name
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
charId: {
|
charId: {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({charId}) {
|
run({charId}) {
|
||||||
assertOwnership(charId, this.userId)
|
assertOwnership(charId, this.userId)
|
||||||
Creatures.remove(charId);
|
Creatures.remove(charId);
|
||||||
|
|||||||
112
app/imports/api/creature/restCreature.js
Normal file
112
app/imports/api/creature/restCreature.js
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
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 { recomputeCreatureById } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||||
|
|
||||||
|
const restCreature = new ValidatedMethod({
|
||||||
|
name: 'creature.methods.longRest',
|
||||||
|
validate: new SimpleSchema({
|
||||||
|
creatureId: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
},
|
||||||
|
restType: {
|
||||||
|
type: String,
|
||||||
|
allowedValues: ['shortRest', 'longRest'],
|
||||||
|
},
|
||||||
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({creatureId, restType}) {
|
||||||
|
let creature = Creatures.findOne(creatureId, {
|
||||||
|
fields: {
|
||||||
|
owner: 1,
|
||||||
|
writers: 1,
|
||||||
|
settings: 1,
|
||||||
|
}
|
||||||
|
}) ;
|
||||||
|
// Need edit permissions
|
||||||
|
assertEditPermission(creature, this.userId);
|
||||||
|
|
||||||
|
// Long rests reset short rest properties as well
|
||||||
|
let resetFilter;
|
||||||
|
if (restType === 'shortRest'){
|
||||||
|
resetFilter = 'shortRest'
|
||||||
|
} else {
|
||||||
|
resetFilter = {$in: ['shortRest', 'longRest']}
|
||||||
|
}
|
||||||
|
// Only apply to active properties
|
||||||
|
let filter = getActivePropertyFilter({
|
||||||
|
filter: {reset: resetFilter},
|
||||||
|
ancestorId: creatureId,
|
||||||
|
includeUntoggled: true,
|
||||||
|
});
|
||||||
|
// update all attribute's damage
|
||||||
|
filter.type = 'attribute';
|
||||||
|
CreatureProperties.update(filter, {
|
||||||
|
$set: {damage: 0}
|
||||||
|
}, {
|
||||||
|
selector: {type: 'attribute'},
|
||||||
|
multi: true,
|
||||||
|
});
|
||||||
|
// Update all action-like properties' usesUsed
|
||||||
|
filter.type = {$in: [
|
||||||
|
'action',
|
||||||
|
'attack',
|
||||||
|
'spell'
|
||||||
|
]};
|
||||||
|
CreatureProperties.update(filter, {
|
||||||
|
$set: {usesUsed: 0}
|
||||||
|
}, {
|
||||||
|
selector: {type: 'action'},
|
||||||
|
multi: true,
|
||||||
|
});
|
||||||
|
// Reset half hit dice on a long rest, starting with the highest dice
|
||||||
|
if (restType === 'longRest'){
|
||||||
|
let hitDice = getActiveProperties({
|
||||||
|
ancestorId: creatureId,
|
||||||
|
filter: {type: 'attribute', attributeType: 'hitDice'},
|
||||||
|
options: {fields: {
|
||||||
|
hitDiceSize: 1,
|
||||||
|
damage: 1,
|
||||||
|
value: 1,
|
||||||
|
}},
|
||||||
|
});
|
||||||
|
// Use a collator to do sorting in natural order
|
||||||
|
let collator = new Intl.Collator('en', {
|
||||||
|
numeric: true, sensitivity: 'base'
|
||||||
|
});
|
||||||
|
// Get the hit dice in decending order of hitDiceSize
|
||||||
|
let compare = (a, b) => collator.compare(b.hitDiceSize, a.hitDiceSize)
|
||||||
|
hitDice.sort(compare);
|
||||||
|
// Get the total number of hit dice that can be recovered this rest
|
||||||
|
let totalHd = hitDice.reduce((sum, hd) => sum + (hd.value || 0), 0);
|
||||||
|
let resetMultiplier = creature.settings.hitDiceResetMultiplier || 0.5;
|
||||||
|
let recoverableHd = Math.max(Math.floor(totalHd*resetMultiplier), 1);
|
||||||
|
// recover each hit dice in turn until the recoverable amount is used up
|
||||||
|
let amountToRecover, resultingDamage;
|
||||||
|
hitDice.forEach(hd => {
|
||||||
|
if (!recoverableHd) return;
|
||||||
|
amountToRecover = Math.min(recoverableHd, hd.damage || 0);
|
||||||
|
if (!amountToRecover) return;
|
||||||
|
recoverableHd -= amountToRecover;
|
||||||
|
resultingDamage = hd.damage - amountToRecover;
|
||||||
|
CreatureProperties.update(hd._id, {
|
||||||
|
$set: {damage: resultingDamage}
|
||||||
|
}, {
|
||||||
|
selector: {type: 'attribute'},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
recomputeCreatureById(creatureId);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default restCreature;
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
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');
|
let Icons = new Mongo.Collection('icons');
|
||||||
|
|
||||||
iconsSchema = new SimpleSchema({
|
let iconsSchema = new SimpleSchema({
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
unique: true,
|
unique: true,
|
||||||
@@ -33,21 +36,62 @@ if (Meteor.isServer) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const storedIconsSchema = new SimpleSchema({
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
shape: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
Icons.attachSchema(iconsSchema);
|
Icons.attachSchema(iconsSchema);
|
||||||
|
|
||||||
/*
|
// This method does not validate icons against the schema, use wisely;
|
||||||
console.warn("Write Icons is not secure, disable before deployment")
|
|
||||||
const writeIcons = new ValidatedMethod({
|
const writeIcons = new ValidatedMethod({
|
||||||
name: 'writeIcons',
|
name: 'icons.write',
|
||||||
validate: null,
|
validate: null,
|
||||||
run(icons){
|
run(icons){
|
||||||
|
assertAdmin(this.userId);
|
||||||
if (Meteor.isServer){
|
if (Meteor.isServer){
|
||||||
this.unblock();
|
this.unblock();
|
||||||
Icons.rawCollection().insert(icons, {ordered: false});
|
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;
|
export default Icons;
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
||||||
import simpleSchemaMixin from '/imports/api/creature/mixins/simpleSchemaMixin.js';
|
import simpleSchemaMixin from '/imports/api/creature/mixins/simpleSchemaMixin.js';
|
||||||
import { assertEditPermission, assertOwnership } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission, assertOwnership } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||||
|
import { getUserTier } from '/imports/api/users/patreon/tiers.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Libraries are trees of library nodes where each node represents a character
|
* Libraries are trees of library nodes where each node represents a character
|
||||||
@@ -32,19 +35,28 @@ Libraries.attachSchema(LibrarySchema);
|
|||||||
export default Libraries;
|
export default Libraries;
|
||||||
|
|
||||||
const insertLibrary = new ValidatedMethod({
|
const insertLibrary = new ValidatedMethod({
|
||||||
name: 'Libraries.methods.insert',
|
name: 'libraries.insert',
|
||||||
mixins: [
|
mixins: [
|
||||||
simpleSchemaMixin,
|
simpleSchemaMixin,
|
||||||
],
|
],
|
||||||
schema: LibrarySchema.omit('owner', 'isDefault'),
|
schema: LibrarySchema.omit('owner', 'isDefault'),
|
||||||
run(library) {
|
run(library) {
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('Libraries.methods.insert.denied',
|
||||||
|
'You need to be logged in to insert a library');
|
||||||
|
}
|
||||||
|
let tier = getUserTier(this.userId);
|
||||||
|
if (!tier.paidBenefits){
|
||||||
|
throw new Meteor.Error('Libraries.methods.insert.denied',
|
||||||
|
`The ${tier.name} tier does not allow you to insert a library`);
|
||||||
|
}
|
||||||
library.owner = this.userId;
|
library.owner = this.userId;
|
||||||
return Libraries.insert(library);
|
return Libraries.insert(library);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateLibraryName = new ValidatedMethod({
|
const updateLibraryName = new ValidatedMethod({
|
||||||
name: 'Libraries.methods.updateName',
|
name: 'libraries.updateName',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
_id: {
|
_id: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -54,6 +66,11 @@ const updateLibraryName = new ValidatedMethod({
|
|||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, name}){
|
run({_id, name}){
|
||||||
let library = Libraries.findOne(_id);
|
let library = Libraries.findOne(_id);
|
||||||
assertEditPermission(library, this.userId);
|
assertEditPermission(library, this.userId);
|
||||||
@@ -62,7 +79,7 @@ const updateLibraryName = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const setLibraryDefault = new ValidatedMethod({
|
const setLibraryDefault = new ValidatedMethod({
|
||||||
name: 'Libraries.methods.makeLibraryDefault',
|
name: 'libraries.makeLibraryDefault',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
_id: {
|
_id: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -72,6 +89,11 @@ const setLibraryDefault = new ValidatedMethod({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, isDefault}) {
|
run({_id, isDefault}) {
|
||||||
if (!Meteor.users.isAdmin()){
|
if (!Meteor.users.isAdmin()){
|
||||||
throw new Meteor.Error('Permission denied', 'User must be admin to set libraries as default');
|
throw new Meteor.Error('Permission denied', 'User must be admin to set libraries as default');
|
||||||
@@ -81,13 +103,18 @@ const setLibraryDefault = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const removeLibrary = new ValidatedMethod({
|
const removeLibrary = new ValidatedMethod({
|
||||||
name: 'Libraries.methods.remove',
|
name: 'libraries.remove',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
_id: {
|
_id: {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.id
|
regEx: SimpleSchema.RegEx.id
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id}){
|
run({_id}){
|
||||||
let library = Libraries.findOne(_id);
|
let library = Libraries.findOne(_id);
|
||||||
assertOwnership(library, this.userId);
|
assertOwnership(library, this.userId);
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { Mongo } from 'meteor/mongo';
|
import { Mongo } from 'meteor/mongo';
|
||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
||||||
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
||||||
import propertySchemasIndex from '/imports/api/properties/propertySchemasIndex.js';
|
import propertySchemasIndex from '/imports/api/properties/propertySchemasIndex.js';
|
||||||
import Libraries from '/imports/api/library/Libraries.js';
|
import Libraries from '/imports/api/library/Libraries.js';
|
||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import { softRemove } from '/imports/api/parenting/softRemove.js';
|
import { softRemove } from '/imports/api/parenting/softRemove.js';
|
||||||
import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js';
|
import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js';
|
||||||
|
import { storedIconsSchema } from '/imports/api/icons/Icons.js';
|
||||||
|
|
||||||
let LibraryNodes = new Mongo.Collection('libraryNodes');
|
let LibraryNodes = new Mongo.Collection('libraryNodes');
|
||||||
|
|
||||||
@@ -23,11 +26,16 @@ let LibraryNodeSchema = new SimpleSchema({
|
|||||||
'tags.$': {
|
'tags.$': {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
icon: {
|
||||||
|
type: storedIconsSchema,
|
||||||
|
optional: true,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let key in propertySchemasIndex){
|
for (let key in propertySchemasIndex){
|
||||||
let schema = new SimpleSchema({});
|
let schema = new SimpleSchema({});
|
||||||
schema.extend(LibraryNodeSchema);
|
schema.extend(LibraryNodeSchema);
|
||||||
|
schema.extend(ColorSchema);
|
||||||
schema.extend(propertySchemasIndex[key]);
|
schema.extend(propertySchemasIndex[key]);
|
||||||
schema.extend(ChildSchema);
|
schema.extend(ChildSchema);
|
||||||
schema.extend(SoftRemovableSchema);
|
schema.extend(SoftRemovableSchema);
|
||||||
@@ -49,16 +57,43 @@ function assertNodeEditPermission(node, userId){
|
|||||||
}
|
}
|
||||||
|
|
||||||
const insertNode = new ValidatedMethod({
|
const insertNode = new ValidatedMethod({
|
||||||
name: 'LibraryNodes.methods.insert',
|
name: 'libraryNodes.insert',
|
||||||
validate: null,
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run(libraryNode) {
|
run(libraryNode) {
|
||||||
|
delete libraryNode._id;
|
||||||
assertNodeEditPermission(libraryNode, this.userId);
|
assertNodeEditPermission(libraryNode, this.userId);
|
||||||
return LibraryNodes.insert(libraryNode);
|
return LibraryNodes.insert(libraryNode);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const duplicateNode = new ValidatedMethod({
|
||||||
|
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);
|
||||||
|
delete libraryNode._id;
|
||||||
|
return LibraryNodes.insert(libraryNode);
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const updateLibraryNode = new ValidatedMethod({
|
const updateLibraryNode = new ValidatedMethod({
|
||||||
name: 'LibraryNodes.methods.update',
|
name: 'libraryNodes.update',
|
||||||
validate({_id, path}){
|
validate({_id, path}){
|
||||||
if (!_id) return false;
|
if (!_id) return false;
|
||||||
// We cannot change these fields with a simple update
|
// We cannot change these fields with a simple update
|
||||||
@@ -70,6 +105,11 @@ const updateLibraryNode = new ValidatedMethod({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, path, value}) {
|
run({_id, path, value}) {
|
||||||
let node = LibraryNodes.findOne(_id);
|
let node = LibraryNodes.findOne(_id);
|
||||||
assertNodeEditPermission(node, this.userId);
|
assertNodeEditPermission(node, this.userId);
|
||||||
@@ -88,8 +128,13 @@ const updateLibraryNode = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pushToLibraryNode = new ValidatedMethod({
|
const pushToLibraryNode = new ValidatedMethod({
|
||||||
name: 'LibraryNodes.methods.push',
|
name: 'libraryNodes.push',
|
||||||
validate: null,
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, path, value}){
|
run({_id, path, value}){
|
||||||
let node = LibraryNodes.findOne(_id);
|
let node = LibraryNodes.findOne(_id);
|
||||||
assertNodeEditPermission(node, this.userId);
|
assertNodeEditPermission(node, this.userId);
|
||||||
@@ -102,8 +147,13 @@ const pushToLibraryNode = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pullFromLibraryNode = new ValidatedMethod({
|
const pullFromLibraryNode = new ValidatedMethod({
|
||||||
name: 'LibraryNodes.methods.pull',
|
name: 'libraryNodes.pull',
|
||||||
validate: null,
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id, path, itemId}){
|
run({_id, path, itemId}){
|
||||||
let node = LibraryNodes.findOne(_id);
|
let node = LibraryNodes.findOne(_id);
|
||||||
assertNodeEditPermission(node, this.userId);
|
assertNodeEditPermission(node, this.userId);
|
||||||
@@ -117,10 +167,15 @@ const pullFromLibraryNode = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const softRemoveLibraryNode = new ValidatedMethod({
|
const softRemoveLibraryNode = new ValidatedMethod({
|
||||||
name: 'LibraryNodes.methods.softRemove',
|
name: 'libraryNodes.softRemove',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
_id: SimpleSchema.RegEx.Id
|
_id: SimpleSchema.RegEx.Id
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({_id}){
|
run({_id}){
|
||||||
let node = LibraryNodes.findOne(_id);
|
let node = LibraryNodes.findOne(_id);
|
||||||
assertNodeEditPermission(node, this.userId);
|
assertNodeEditPermission(node, this.userId);
|
||||||
@@ -132,6 +187,7 @@ export default LibraryNodes;
|
|||||||
export {
|
export {
|
||||||
LibraryNodeSchema,
|
LibraryNodeSchema,
|
||||||
insertNode,
|
insertNode,
|
||||||
|
duplicateNode,
|
||||||
updateLibraryNode,
|
updateLibraryNode,
|
||||||
pullFromLibraryNode,
|
pullFromLibraryNode,
|
||||||
pushToLibraryNode,
|
pushToLibraryNode,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ let ChildSchema = new SimpleSchema({
|
|||||||
ancestors: {
|
ancestors: {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
|
max: 100,
|
||||||
},
|
},
|
||||||
'ancestors.$': {
|
'ancestors.$': {
|
||||||
type: RefSchema,
|
type: RefSchema,
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export function reorderDocs({collection, ancestorId}){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (Meteor.isServer){
|
if (Meteor.isServer && bulkWrite.length){
|
||||||
collection.rawCollection().bulkWrite(
|
collection.rawCollection().bulkWrite(
|
||||||
bulkWrite,
|
bulkWrite,
|
||||||
{ordered : false},
|
{ordered : false},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import { union } from 'lodash';
|
import { union } from 'lodash';
|
||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import { updateParent } from '/imports/api/parenting/parenting.js';
|
import { updateParent } from '/imports/api/parenting/parenting.js';
|
||||||
import { reorderDocs, safeUpdateDocOrder } from '/imports/api/parenting/order.js';
|
import { reorderDocs, safeUpdateDocOrder } from '/imports/api/parenting/order.js';
|
||||||
import { RefSchema } from '/imports/api/parenting/ChildSchema.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';
|
import { recomputeCreatureById } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||||
|
|
||||||
const organizeDoc = new ValidatedMethod({
|
const organizeDoc = new ValidatedMethod({
|
||||||
name: 'organize.methods.organizeDoc',
|
name: 'organize.organizeDoc',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
docRef: RefSchema,
|
docRef: RefSchema,
|
||||||
parentRef: RefSchema,
|
parentRef: RefSchema,
|
||||||
@@ -19,6 +20,11 @@ const organizeDoc = new ValidatedMethod({
|
|||||||
// Should end in 0.5 to place it reliably between two existing documents
|
// Should end in 0.5 to place it reliably between two existing documents
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({docRef, parentRef, order}) {
|
run({docRef, parentRef, order}) {
|
||||||
let doc = fetchDocByRef(docRef);
|
let doc = fetchDocByRef(docRef);
|
||||||
let collection = getCollectionByName(docRef.collection);
|
let collection = getCollectionByName(docRef.collection);
|
||||||
@@ -54,7 +60,7 @@ const organizeDoc = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const reorderDoc = new ValidatedMethod({
|
const reorderDoc = new ValidatedMethod({
|
||||||
name: 'organize.methods.reorderDoc',
|
name: 'organize.reorderDoc',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
docRef: RefSchema,
|
docRef: RefSchema,
|
||||||
order: {
|
order: {
|
||||||
@@ -62,6 +68,11 @@ const reorderDoc = new ValidatedMethod({
|
|||||||
// Should end in 0.5 to place it reliably between two existing documents
|
// Should end in 0.5 to place it reliably between two existing documents
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({docRef, order}) {
|
run({docRef, order}) {
|
||||||
let doc = fetchDocByRef(docRef);
|
let doc = fetchDocByRef(docRef);
|
||||||
assertDocEditPermission(doc, this.userId);
|
assertDocEditPermission(doc, this.userId);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export function renewDocIds({docArray, collectionMap}){
|
|||||||
const remapReference = ref => {
|
const remapReference = ref => {
|
||||||
if (idMap[ref.id]){
|
if (idMap[ref.id]){
|
||||||
ref.id = 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 => {
|
docArray.forEach(doc => {
|
||||||
@@ -154,6 +154,14 @@ export function updateParent({docRef, parentRef}){
|
|||||||
// Get the parent and its ancestry
|
// Get the parent and its ancestry
|
||||||
let {parentDoc, parent, ancestors} = getAncestry({parentRef});
|
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
|
// If the doc and its parent are in the same collection, apply the allowed
|
||||||
// parent rules based on type
|
// parent rules based on type
|
||||||
if (docRef.collection === parentRef.collection){
|
if (docRef.collection === parentRef.collection){
|
||||||
@@ -204,17 +212,11 @@ export function getName(doc){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function nodesToTree({collection, ancestorId, filter, options}){
|
export function nodeArrayToTree(nodes){
|
||||||
// Store a dict of all the nodes
|
// Store a dict and list of all the nodes
|
||||||
let nodeIndex = {};
|
let nodeIndex = {};
|
||||||
let nodeList = [];
|
let nodeList = [];
|
||||||
if (!options) options = {};
|
nodes.forEach( node => {
|
||||||
options.sort = {order: 1};
|
|
||||||
collection.find({
|
|
||||||
'ancestors.id': ancestorId,
|
|
||||||
removed: {$ne: true},
|
|
||||||
...filter,
|
|
||||||
}, options).forEach( node => {
|
|
||||||
let treeNode = {
|
let treeNode = {
|
||||||
node: node,
|
node: node,
|
||||||
children: [],
|
children: [],
|
||||||
@@ -238,3 +240,12 @@ export function nodesToTree({collection, ancestorId, filter, options}){
|
|||||||
});
|
});
|
||||||
return forest;
|
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 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
|
* Actions are things a character can do
|
||||||
@@ -12,6 +13,10 @@ let ActionSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
summary: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
@@ -40,13 +45,60 @@ let ActionSchema = new SimpleSchema({
|
|||||||
'tags.$': {
|
'tags.$': {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
// Duplicate the ResourceSchema here so we can extend it elegantly.
|
||||||
resources: {
|
resources: {
|
||||||
type: ResourcesSchema,
|
type: Object,
|
||||||
defaultValue: {},
|
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
|
// Calculation of how many times this action can be used
|
||||||
// Only set if this action tracks its own uses, rather than adjusting
|
|
||||||
// resources
|
|
||||||
uses: {
|
uses: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
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({
|
const AdjustmentSchema = new SimpleSchema({
|
||||||
// The roll that determines how much to change the attribute
|
// The roll that determines how much to change the attribute
|
||||||
|
// This can be simplified, but should only compute when activated
|
||||||
amount: {
|
amount: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
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
|
// Attacks are special instances of actions
|
||||||
let AttackSchema = new SimpleSchema()
|
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 };
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
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';
|
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -13,7 +14,7 @@ let AttributeSchema = new SimpleSchema({
|
|||||||
variableName: {
|
variableName: {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: VARIABLE_NAME_REGEX,
|
regEx: VARIABLE_NAME_REGEX,
|
||||||
min: 3,
|
min: 2,
|
||||||
defaultValue: 'newAttribute',
|
defaultValue: 'newAttribute',
|
||||||
},
|
},
|
||||||
// How it is displayed and computed is determined by type
|
// How it is displayed and computed is determined by type
|
||||||
@@ -38,6 +39,11 @@ let AttributeSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
allowedValues: ['d4', 'd6', 'd8', 'd10', 'd12', 'd20'],
|
allowedValues: ['d4', 'd6', 'd8', 'd10', 'd12', 'd20'],
|
||||||
optional: true,
|
optional: true,
|
||||||
|
},
|
||||||
|
// For type spellSlot, the level needs to be stored separately
|
||||||
|
spellSlotLevelCalculation: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
},
|
},
|
||||||
// The starting value, before effects
|
// The starting value, before effects
|
||||||
baseValueCalculation: {
|
baseValueCalculation: {
|
||||||
@@ -73,18 +79,48 @@ let ComputedOnlyAttributeSchema = new SimpleSchema({
|
|||||||
baseValue: {
|
baseValue: {
|
||||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||||
optional: true,
|
optional: true,
|
||||||
|
},
|
||||||
|
baseValueErrors: {
|
||||||
|
type: Array,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
'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
|
// The computed value of the attribute
|
||||||
value: {
|
value: {
|
||||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
},
|
||||||
|
// The computed value of the attribute minus the damage
|
||||||
|
currentValue: {
|
||||||
|
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||||
|
defaultValue: 0,
|
||||||
|
optional: true,
|
||||||
},
|
},
|
||||||
// The computed modifier, provided the attribute type is `ability`
|
// The computed modifier, provided the attribute type is `ability`
|
||||||
modifier: {
|
modifier: {
|
||||||
type: SimpleSchema.Integer,
|
type: SimpleSchema.Integer,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
// Should this attribute hide
|
||||||
|
hide: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const ComputedAttributeSchema = new SimpleSchema()
|
const ComputedAttributeSchema = new SimpleSchema()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ let ClassLevelSchema = new SimpleSchema({
|
|||||||
// The name of this class level's variable
|
// The name of this class level's variable
|
||||||
variableName: {
|
variableName: {
|
||||||
type: String,
|
type: String,
|
||||||
|
min: 2,
|
||||||
regEx: VARIABLE_NAME_REGEX,
|
regEx: VARIABLE_NAME_REGEX,
|
||||||
},
|
},
|
||||||
level: {
|
level: {
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ let ContainerSchema = new SimpleSchema({
|
|||||||
weight: {
|
weight: {
|
||||||
type: Number,
|
type: Number,
|
||||||
min: 0,
|
min: 0,
|
||||||
defaultValue: 0
|
optional: true,
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
type: Number,
|
type: Number,
|
||||||
min: 0,
|
min: 0,
|
||||||
defaultValue: 0
|
optional: true,
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
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 };
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ let DamageMultiplierSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
// Tags which must be present to be affected by this multiplier (AND)
|
// Tags which must be present to be affected by this multiplier (AND)
|
||||||
targetTags: {
|
includeTags: {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
},
|
},
|
||||||
'targetTags.$': {
|
'includeTags.$': {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import DAMAGE_TYPES from '/imports/constants/DAMAGE_TYPES.js';
|
|||||||
|
|
||||||
const DamageSchema = new SimpleSchema({
|
const DamageSchema = new SimpleSchema({
|
||||||
// The roll that determines how much to damage the attribute
|
// The roll that determines how much to damage the attribute
|
||||||
|
// This can be simplified, but only computed when applied
|
||||||
amount: {
|
amount: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||||
/*
|
/*
|
||||||
* Effects are reason-value attached to skills and abilities
|
* Effects are reason-value attached to skills and abilities
|
||||||
* that modify their final value or presentation in some way
|
* that modify their final value or presentation in some way
|
||||||
@@ -18,6 +18,7 @@ let EffectSchema = new SimpleSchema({
|
|||||||
'mul',
|
'mul',
|
||||||
'min',
|
'min',
|
||||||
'max',
|
'max',
|
||||||
|
'set',
|
||||||
'advantage',
|
'advantage',
|
||||||
'disadvantage',
|
'disadvantage',
|
||||||
'passiveAdd',
|
'passiveAdd',
|
||||||
@@ -37,7 +38,6 @@ let EffectSchema = new SimpleSchema({
|
|||||||
},
|
},
|
||||||
'stats.$': {
|
'stats.$': {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,7 +47,15 @@ const ComputedOnlyEffectSchema = new SimpleSchema({
|
|||||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
})
|
// The errors encountered while computing the result
|
||||||
|
errors: {
|
||||||
|
type: Array,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
'errors.$':{
|
||||||
|
type: ErrorSchema,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const ComputedEffectSchema = new SimpleSchema()
|
const ComputedEffectSchema = new SimpleSchema()
|
||||||
.extend(ComputedOnlyEffectSchema)
|
.extend(ComputedOnlyEffectSchema)
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ const ItemSchema = new SimpleSchema({
|
|||||||
weight: {
|
weight: {
|
||||||
type: Number,
|
type: Number,
|
||||||
min: 0,
|
min: 0,
|
||||||
defaultValue: 0,
|
optional: true,
|
||||||
},
|
},
|
||||||
// Value per item in the stack, in gold pieces
|
// Value per item in the stack, in gold pieces
|
||||||
value: {
|
value: {
|
||||||
type: Number,
|
type: Number,
|
||||||
min: 0,
|
min: 0,
|
||||||
defaultValue: 0,
|
optional: true,
|
||||||
},
|
},
|
||||||
// If this item is equipped, it requires attunement
|
// If this item is equipped, it requires attunement
|
||||||
// Being equipped is `enabled === true`
|
// Being equipped is `enabled === true`
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ let ProficiencySchema = new SimpleSchema({
|
|||||||
},
|
},
|
||||||
'stats.$': {
|
'stats.$': {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
|
||||||
},
|
},
|
||||||
// A number representing how proficient the character is
|
// A number representing how proficient the character is
|
||||||
value: {
|
value: {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import SimpleSchema from 'simpl-schema';
|
|||||||
* child rolls are applied
|
* child rolls are applied
|
||||||
*/
|
*/
|
||||||
let RollSchema = new SimpleSchema({
|
let RollSchema = new SimpleSchema({
|
||||||
// The roll
|
// The roll, can be simplified, but only computed in context
|
||||||
roll: {
|
roll: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||||
|
|
||||||
// These are the rolls made when saves are called for
|
// These are the rolls made when saves are called for
|
||||||
// For the saving throw bonus or proficiency, see ./Skills.js
|
// For the saving throw bonus or proficiency, see ./Skills.js
|
||||||
let SavingThrowSchema = new SimpleSchema ({
|
let SavingThrowSchema = new SimpleSchema ({
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
dc: {
|
dc: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
@@ -14,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,4 +1,6 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
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
|
* Skills are anything that results in a modifier to be added to a D20
|
||||||
@@ -13,7 +15,8 @@ let SkillSchema = new SimpleSchema({
|
|||||||
// Ignored for skilltype = save
|
// Ignored for skilltype = save
|
||||||
variableName: {
|
variableName: {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: /^\w*[a-z]\w*$/i,
|
regEx: VARIABLE_NAME_REGEX,
|
||||||
|
min: 2,
|
||||||
},
|
},
|
||||||
// The variable name of the ability this skill relies on
|
// The variable name of the ability this skill relies on
|
||||||
ability: {
|
ability: {
|
||||||
@@ -35,9 +38,9 @@ let SkillSchema = new SimpleSchema({
|
|||||||
],
|
],
|
||||||
defaultValue: 'skill',
|
defaultValue: 'skill',
|
||||||
},
|
},
|
||||||
// If the baseValue is higher than the computed value, it will be used as `value`
|
// The starting value, before effects
|
||||||
baseValue: {
|
baseValueCalculation: {
|
||||||
type: Number,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
// The base proficiency of this skill
|
// The base proficiency of this skill
|
||||||
@@ -57,6 +60,18 @@ let ComputedOnlySkillSchema = new SimpleSchema({
|
|||||||
value: {
|
value: {
|
||||||
type: Number,
|
type: Number,
|
||||||
defaultValue: 0,
|
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
|
// Computed value added by the ability
|
||||||
abilityMod: {
|
abilityMod: {
|
||||||
@@ -101,6 +116,11 @@ let ComputedOnlySkillSchema = new SimpleSchema({
|
|||||||
type: SimpleSchema.Integer,
|
type: SimpleSchema.Integer,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
// Should this attribute hide
|
||||||
|
hide: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const ComputedSkillSchema = new SimpleSchema()
|
const ComputedSkillSchema = new SimpleSchema()
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||||
|
|
||||||
let SlotSchema = new SimpleSchema({
|
let SlotSchema = new SimpleSchema({
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
slotType: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
slotTags: {
|
slotTags: {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
@@ -8,6 +21,43 @@ let SlotSchema = new SimpleSchema({
|
|||||||
'slotTags.$': {
|
'slotTags.$': {
|
||||||
type: String,
|
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 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({
|
let SpellListSchema = new SimpleSchema({
|
||||||
name: {
|
name: {
|
||||||
@@ -9,6 +11,12 @@ let SpellListSchema = new SimpleSchema({
|
|||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
variableName: {
|
||||||
|
type: String,
|
||||||
|
regEx: VARIABLE_NAME_REGEX,
|
||||||
|
min: 2,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
// Calculation of how many spells in this list can be prepared
|
// Calculation of how many spells in this list can be prepared
|
||||||
maxPrepared: {
|
maxPrepared: {
|
||||||
type: String,
|
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 SimpleSchema from 'simpl-schema';
|
||||||
|
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||||
|
|
||||||
const magicSchools = [
|
const magicSchools = [
|
||||||
'abjuration',
|
'abjuration',
|
||||||
@@ -25,6 +26,10 @@ let SpellSchema = new SimpleSchema({})
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
prepared: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
// This spell ignores spell slot rules
|
// This spell ignores spell slot rules
|
||||||
castWithoutSpellSlots: {
|
castWithoutSpellSlots: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -33,14 +38,6 @@ let SpellSchema = new SimpleSchema({})
|
|||||||
hasAttackRoll: {
|
hasAttackRoll: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
|
||||||
// Spell lists that this spell appears on
|
|
||||||
spellLists: {
|
|
||||||
type: Array,
|
|
||||||
defaultValue: [],
|
|
||||||
},
|
|
||||||
'spellLists.$': {
|
|
||||||
type: String,
|
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
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,4 +1,5 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||||
|
|
||||||
const ToggleSchema = new SimpleSchema({
|
const ToggleSchema = new SimpleSchema({
|
||||||
name: {
|
name: {
|
||||||
@@ -27,6 +28,14 @@ const ComputedOnlyToggleSchema = new SimpleSchema({
|
|||||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
// The errors encountered while computing the result
|
||||||
|
errors: {
|
||||||
|
type: Array,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
'errors.$': {
|
||||||
|
type: ErrorSchema,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const ComputedToggleSchema = new SimpleSchema()
|
const ComputedToggleSchema = new SimpleSchema()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
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 { 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 { ComputedAttributeSchema } from '/imports/api/properties/Attributes.js';
|
||||||
import { BuffSchema } from '/imports/api/properties/Buffs.js';
|
import { BuffSchema } from '/imports/api/properties/Buffs.js';
|
||||||
import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.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 { DamageSchema } from '/imports/api/properties/Damages.js';
|
||||||
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
|
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
|
||||||
import { ComputedEffectSchema } from '/imports/api/properties/Effects.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 { FeatureSchema } from '/imports/api/properties/Features.js';
|
||||||
import { FolderSchema } from '/imports/api/properties/Folders.js';
|
import { FolderSchema } from '/imports/api/properties/Folders.js';
|
||||||
import { ItemSchema } from '/imports/api/properties/Items.js';
|
import { ItemSchema } from '/imports/api/properties/Items.js';
|
||||||
import { NoteSchema } from '/imports/api/properties/Notes.js';
|
import { NoteSchema } from '/imports/api/properties/Notes.js';
|
||||||
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
|
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
|
||||||
import { RollSchema } from '/imports/api/properties/Rolls.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 { ComputedSkillSchema } from '/imports/api/properties/Skills.js';
|
||||||
import { SlotSchema } from '/imports/api/properties/Slots.js';
|
import { ComputedSlotSchema } from '/imports/api/properties/Slots.js';
|
||||||
import { SpellSchema } from '/imports/api/properties/Spells.js';
|
import { ComputedSpellSchema } from '/imports/api/properties/Spells.js';
|
||||||
import { SpellListSchema } from '/imports/api/properties/SpellLists.js';
|
import { ComputedSpellListSchema } from '/imports/api/properties/SpellLists.js';
|
||||||
import { ToggleSchema } from '/imports/api/properties/Toggles.js';
|
import { ToggleSchema } from '/imports/api/properties/Toggles.js';
|
||||||
|
|
||||||
const propertySchemasIndex = {
|
const propertySchemasIndex = {
|
||||||
action: ActionSchema,
|
action: ComputedActionSchema,
|
||||||
adjustment: AdjustmentSchema,
|
adjustment: AdjustmentSchema,
|
||||||
attack: AttackSchema,
|
attack: ComputedAttackSchema,
|
||||||
attribute: ComputedAttributeSchema,
|
attribute: ComputedAttributeSchema,
|
||||||
buff: BuffSchema,
|
buff: BuffSchema,
|
||||||
classLevel: ClassLevelSchema,
|
classLevel: ClassLevelSchema,
|
||||||
damage: DamageSchema,
|
damage: DamageSchema,
|
||||||
damageMultiplier: DamageMultiplierSchema,
|
damageMultiplier: DamageMultiplierSchema,
|
||||||
effect: ComputedEffectSchema,
|
effect: ComputedEffectSchema,
|
||||||
experience: ExperienceSchema,
|
|
||||||
feature: FeatureSchema,
|
feature: FeatureSchema,
|
||||||
folder: FolderSchema,
|
folder: FolderSchema,
|
||||||
note: NoteSchema,
|
note: NoteSchema,
|
||||||
proficiency: ProficiencySchema,
|
proficiency: ProficiencySchema,
|
||||||
roll: RollSchema,
|
roll: RollSchema,
|
||||||
savingThrow: SavingThrowSchema,
|
savingThrow: ComputedSavingThrowSchema,
|
||||||
skill: ComputedSkillSchema,
|
skill: ComputedSkillSchema,
|
||||||
slot: SlotSchema,
|
propertySlot: ComputedSlotSchema,
|
||||||
spellList: SpellListSchema,
|
spellList: ComputedSpellListSchema,
|
||||||
spell: SpellSchema,
|
spell: ComputedSpellSchema,
|
||||||
toggle: ToggleSchema,
|
toggle: ToggleSchema,
|
||||||
container: ContainerSchema,
|
container: ContainerSchema,
|
||||||
item: ItemSchema,
|
item: ItemSchema,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.js';
|
|||||||
import { DamageSchema } from '/imports/api/properties/Damages.js';
|
import { DamageSchema } from '/imports/api/properties/Damages.js';
|
||||||
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
|
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
|
||||||
import { EffectSchema } from '/imports/api/properties/Effects.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 { FeatureSchema } from '/imports/api/properties/Features.js';
|
||||||
import { FolderSchema } from '/imports/api/properties/Folders.js';
|
import { FolderSchema } from '/imports/api/properties/Folders.js';
|
||||||
import { NoteSchema } from '/imports/api/properties/Notes.js';
|
import { NoteSchema } from '/imports/api/properties/Notes.js';
|
||||||
@@ -33,7 +32,6 @@ const propertySchemasIndex = {
|
|||||||
damage: DamageSchema,
|
damage: DamageSchema,
|
||||||
damageMultiplier: DamageMultiplierSchema,
|
damageMultiplier: DamageMultiplierSchema,
|
||||||
effect: EffectSchema,
|
effect: EffectSchema,
|
||||||
experience: ExperienceSchema,
|
|
||||||
feature: FeatureSchema,
|
feature: FeatureSchema,
|
||||||
folder: FolderSchema,
|
folder: FolderSchema,
|
||||||
note: NoteSchema,
|
note: NoteSchema,
|
||||||
@@ -41,7 +39,7 @@ const propertySchemasIndex = {
|
|||||||
roll: RollSchema,
|
roll: RollSchema,
|
||||||
savingThrow: SavingThrowSchema,
|
savingThrow: SavingThrowSchema,
|
||||||
skill: SkillSchema,
|
skill: SkillSchema,
|
||||||
slot: SlotSchema,
|
propertySlot: SlotSchema,
|
||||||
spellList: SpellListSchema,
|
spellList: SpellListSchema,
|
||||||
spell: SpellSchema,
|
spell: SpellSchema,
|
||||||
toggle: ToggleSchema,
|
toggle: ToggleSchema,
|
||||||
|
|||||||
12
app/imports/api/properties/subSchemas/ErrorSchema.js
Normal file
12
app/imports/api/properties/subSchemas/ErrorSchema.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
|
||||||
|
const ErrorSchema = new SimpleSchema({
|
||||||
|
message: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ErrorSchema;
|
||||||
@@ -17,6 +17,10 @@ const ItemConsumedSchema = new SimpleSchema({
|
|||||||
type: Number,
|
type: Number,
|
||||||
defaultValue: 1,
|
defaultValue: 1,
|
||||||
},
|
},
|
||||||
|
itemId: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default ItemConsumedSchema;
|
export default ItemConsumedSchema;
|
||||||
|
|||||||
@@ -4,13 +4,19 @@ import fetchDocByRef from '/imports/api/parenting/fetchDocByRef.js';
|
|||||||
import getCollectionByName from '/imports/api/parenting/getCollectionByName.js';
|
import getCollectionByName from '/imports/api/parenting/getCollectionByName.js';
|
||||||
import { RefSchema } from '/imports/api/parenting/ChildSchema.js';
|
import { RefSchema } from '/imports/api/parenting/ChildSchema.js';
|
||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
|
||||||
const setPublic = new ValidatedMethod({
|
const setPublic = new ValidatedMethod({
|
||||||
name: 'sharing.methods.setPublic',
|
name: 'sharing.setPublic',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
docRef: RefSchema,
|
docRef: RefSchema,
|
||||||
isPublic: { type: Boolean },
|
isPublic: { type: Boolean },
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({docRef, isPublic}){
|
run({docRef, isPublic}){
|
||||||
let doc = fetchDocByRef(docRef);
|
let doc = fetchDocByRef(docRef);
|
||||||
assertOwnership(doc, this.userId);
|
assertOwnership(doc, this.userId);
|
||||||
@@ -21,7 +27,7 @@ const setPublic = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const updateUserSharePermissions = new ValidatedMethod({
|
const updateUserSharePermissions = new ValidatedMethod({
|
||||||
name: 'sharing.methods.updateUserSharePermissions',
|
name: 'sharing.updateUserSharePermissions',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
docRef: RefSchema,
|
docRef: RefSchema,
|
||||||
userId: {
|
userId: {
|
||||||
@@ -33,6 +39,11 @@ const updateUserSharePermissions = new ValidatedMethod({
|
|||||||
allowedValues: ['reader', 'writer', 'none'],
|
allowedValues: ['reader', 'writer', 'none'],
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({docRef, userId, role}){
|
run({docRef, userId, role}){
|
||||||
let doc = fetchDocByRef(docRef);
|
let doc = fetchDocByRef(docRef);
|
||||||
if (role === 'none'){
|
if (role === 'none'){
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import { _ } from 'meteor/underscore';
|
import { _ } from 'meteor/underscore';
|
||||||
import fetchDocByRef from '/imports/api/parenting/fetchDocByRef.js';
|
import fetchDocByRef from '/imports/api/parenting/fetchDocByRef.js';
|
||||||
|
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||||
|
|
||||||
function assertIdValid(userId){
|
function assertIdValid(userId){
|
||||||
if (!userId || typeof userId !== 'string'){
|
if (!userId || typeof userId !== 'string'){
|
||||||
throw new Meteor.Error("Permission denied",
|
throw new Meteor.Error('Permission denied',
|
||||||
"No user ID given for edit permission check");
|
'No user ID given for edit permission check');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertdocExists(doc){
|
function assertdocExists(doc){
|
||||||
if (!doc){
|
if (!doc){
|
||||||
throw new Meteor.Error("Permission denied",
|
throw new Meteor.Error('Permission denied',
|
||||||
`No such document exists`);
|
'No such document exists');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,8 +22,8 @@ export function assertOwnership(doc, userId){
|
|||||||
if (doc.owner === userId ){
|
if (doc.owner === userId ){
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Meteor.Error("Permission denied",
|
throw new Meteor.Error('Permission denied',
|
||||||
`You are not the owner of this document`);
|
'You are not the owner of this document');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,11 +36,34 @@ export function assertOwnership(doc, userId){
|
|||||||
export function assertEditPermission(doc, userId) {
|
export function assertEditPermission(doc, userId) {
|
||||||
assertIdValid(userId);
|
assertIdValid(userId);
|
||||||
assertdocExists(doc);
|
assertdocExists(doc);
|
||||||
if (doc.owner === userId || _.contains(doc.writers, userId)){
|
let user = Meteor.users.findOne(userId, {
|
||||||
|
fields: {
|
||||||
|
'services.patreon': 1,
|
||||||
|
'roles': 1,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Admin override
|
||||||
|
if (user.roles && user.roles.includes('admin')){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the user is of a tier with paid benefits
|
||||||
|
let tier = getUserTier(user);
|
||||||
|
if (!tier.paidBenefits){
|
||||||
|
throw new Meteor.Error('Edit permission denied',
|
||||||
|
`The ${tier.name} tier does not allow you to edit this document`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the user is authorized for this specific document
|
||||||
|
if (
|
||||||
|
doc.owner === userId ||
|
||||||
|
_.contains(doc.writers, userId)
|
||||||
|
){
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Meteor.Error("Edit permission denied",
|
throw new Meteor.Error('Edit permission denied',
|
||||||
`You do not have permission to edit this document`);
|
'You do not have permission to edit this document');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +98,8 @@ export function assertViewPermission(doc, userId) {
|
|||||||
){
|
){
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Meteor.Error("View permission denied",
|
throw new Meteor.Error('View permission denied',
|
||||||
`You do not have permission to view this character`);
|
'You do not have permission to view this character');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,3 +113,17 @@ export function assertDocViewPermission(doc, userId){
|
|||||||
let root = getRoot(doc);
|
let root = getRoot(doc);
|
||||||
assertViewPermission(root, userId);
|
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 SimpleSchema from 'simpl-schema';
|
||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||||
|
|
||||||
let Invites= new Mongo.Collection('invites');
|
let Invites= new Mongo.Collection('invites');
|
||||||
@@ -85,13 +86,18 @@ function alignInvitesWithPatreonTier(user){
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getInviteToken = new ValidatedMethod({
|
const getInviteToken = new ValidatedMethod({
|
||||||
name: 'Invites.methods.getToken',
|
name: 'invites.getToken',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
inviteId: {
|
inviteId: {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({inviteId}) {
|
run({inviteId}) {
|
||||||
let invite = Invites.findOne(inviteId);
|
let invite = Invites.findOne(inviteId);
|
||||||
if (this.userId !== invite.inviter) {
|
if (this.userId !== invite.inviter) {
|
||||||
@@ -109,12 +115,17 @@ const getInviteToken = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const acceptInviteToken = new ValidatedMethod({
|
const acceptInviteToken = new ValidatedMethod({
|
||||||
name: 'Invites.methods.acceptToken',
|
name: 'invites.acceptToken',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
inviteToken: {
|
inviteToken: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({inviteToken}) {
|
run({inviteToken}) {
|
||||||
if (!this.userId) {
|
if (!this.userId) {
|
||||||
throw new Meteor.Error('Invites.methods.acceptToken.denied',
|
throw new Meteor.Error('Invites.methods.acceptToken.denied',
|
||||||
@@ -146,13 +157,18 @@ const acceptInviteToken = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const revokeInvite = new ValidatedMethod({
|
const revokeInvite = new ValidatedMethod({
|
||||||
name: 'Invites.methods.revokeInvite',
|
name: 'invites.revokeInvite',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
inviteId: {
|
inviteId: {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({inviteId}) {
|
run({inviteId}) {
|
||||||
if (!this.userId) {
|
if (!this.userId) {
|
||||||
throw new Meteor.Error('Invites.methods.revokeInvite.denied',
|
throw new Meteor.Error('Invites.methods.revokeInvite.denied',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
|
||||||
const userSchema = new SimpleSchema({
|
const userSchema = new SimpleSchema({
|
||||||
username: {
|
username: {
|
||||||
@@ -80,14 +81,29 @@ const userSchema = new SimpleSchema({
|
|||||||
profile: {
|
profile: {
|
||||||
type: Object,
|
type: Object,
|
||||||
blackbox: true,
|
blackbox: true,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
preferences: {
|
||||||
|
type: Object,
|
||||||
|
optional: true,
|
||||||
|
defaultValue: {},
|
||||||
|
},
|
||||||
|
'preferences.swapAbilityScoresAndModifiers': {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Meteor.users.attachSchema(userSchema);
|
Meteor.users.attachSchema(userSchema);
|
||||||
|
|
||||||
Meteor.users.generateApiKey = new ValidatedMethod({
|
Meteor.users.generateApiKey = new ValidatedMethod({
|
||||||
name: 'Users.methods.generateApiKey',
|
name: 'users.generateApiKey',
|
||||||
validate: null,
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run(){
|
run(){
|
||||||
if(Meteor.isClient) return;
|
if(Meteor.isClient) return;
|
||||||
var user = Meteor.users.findOne(this.userId);
|
var user = Meteor.users.findOne(this.userId);
|
||||||
@@ -99,10 +115,15 @@ Meteor.users.generateApiKey = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Meteor.users.setDarkMode = new ValidatedMethod({
|
Meteor.users.setDarkMode = new ValidatedMethod({
|
||||||
name: 'Users.methods.setDarkMode',
|
name: 'users.setDarkMode',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
darkMode: { type: Boolean },
|
darkMode: { type: Boolean },
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({darkMode}){
|
run({darkMode}){
|
||||||
if (!this.userId) return;
|
if (!this.userId) return;
|
||||||
Meteor.users.update(this.userId, {$set: {darkMode}});
|
Meteor.users.update(this.userId, {$set: {darkMode}});
|
||||||
@@ -110,7 +131,7 @@ Meteor.users.setDarkMode = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Meteor.users.sendVerificationEmail = new ValidatedMethod({
|
Meteor.users.sendVerificationEmail = new ValidatedMethod({
|
||||||
name: 'Users.methods.sendVerificationEmail',
|
name: 'users.sendVerificationEmail',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
userId:{
|
userId:{
|
||||||
type: String,
|
type: String,
|
||||||
@@ -120,6 +141,11 @@ Meteor.users.sendVerificationEmail = new ValidatedMethod({
|
|||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({userId, address}){
|
run({userId, address}){
|
||||||
userId = this.userId || userId;
|
userId = this.userId || userId;
|
||||||
let user = Meteor.users.findOne(userId);
|
let user = Meteor.users.findOne(userId);
|
||||||
@@ -142,8 +168,13 @@ Meteor.users.isAdmin = function(userId){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Meteor.users.canPickUsername = new ValidatedMethod({
|
Meteor.users.canPickUsername = new ValidatedMethod({
|
||||||
name: 'Users.methods.canPickUsername',
|
name: 'users.canPickUsername',
|
||||||
validate: userSchema.pick('username').validator(),
|
validate: userSchema.pick('username').validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({username}){
|
run({username}){
|
||||||
if (Meteor.isClient) return;
|
if (Meteor.isClient) return;
|
||||||
let user = Accounts.findUserByUsername(username);
|
let user = Accounts.findUserByUsername(username);
|
||||||
@@ -156,8 +187,13 @@ Meteor.users.canPickUsername = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Meteor.users.setUsername = new ValidatedMethod({
|
Meteor.users.setUsername = new ValidatedMethod({
|
||||||
name: 'Users.methods.setUsername',
|
name: 'users.setUsername',
|
||||||
validate: userSchema.pick('username').validator(),
|
validate: userSchema.pick('username').validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({username}){
|
run({username}){
|
||||||
if (!this.userId) throw 'Can only set your username if logged in';
|
if (!this.userId) throw 'Can only set your username if logged in';
|
||||||
if (Meteor.isClient) return;
|
if (Meteor.isClient) return;
|
||||||
@@ -165,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({
|
Meteor.users.subscribeToLibrary = new ValidatedMethod({
|
||||||
name: 'Users.methods.subscribeToLibrary',
|
name: 'users.subscribeToLibrary',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
libraryId:{
|
libraryId:{
|
||||||
type: String,
|
type: String,
|
||||||
@@ -176,6 +242,11 @@ Meteor.users.subscribeToLibrary = new ValidatedMethod({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({libraryId, subscribe}){
|
run({libraryId, subscribe}){
|
||||||
if (!this.userId) throw 'Can only subscribe if logged in';
|
if (!this.userId) throw 'Can only subscribe if logged in';
|
||||||
if (subscribe){
|
if (subscribe){
|
||||||
@@ -191,12 +262,17 @@ Meteor.users.subscribeToLibrary = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({
|
Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({
|
||||||
name: 'Users.methods.findUserByUsernameOrEmail',
|
name: 'users.findUserByUsernameOrEmail',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
usernameOrEmail:{
|
usernameOrEmail:{
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
run({usernameOrEmail}){
|
run({usernameOrEmail}){
|
||||||
if (Meteor.isClient) return;
|
if (Meteor.isClient) return;
|
||||||
let user = Accounts.findUserByUsername(usernameOrEmail) ||
|
let user = Accounts.findUserByUsername(usernameOrEmail) ||
|
||||||
|
|||||||
@@ -59,7 +59,11 @@ export function getTierByEntitledCents(entitledCents = 0){
|
|||||||
export function getUserTier(user){
|
export function getUserTier(user){
|
||||||
if (!user) throw 'user must be provided';
|
if (!user) throw 'user must be provided';
|
||||||
if (typeof user === 'string'){
|
if (typeof user === 'string'){
|
||||||
user = Meteor.users.findOne(user);
|
user = Meteor.users.findOne(user, {
|
||||||
|
fields: {
|
||||||
|
'services.patreon': 1,
|
||||||
|
}
|
||||||
|
});
|
||||||
if (!user) throw 'User not found';
|
if (!user) throw 'User not found';
|
||||||
}
|
}
|
||||||
const entitledCents = getEntitledCents(user);
|
const entitledCents = getEntitledCents(user);
|
||||||
@@ -73,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 default TIERS;
|
||||||
export { GUEST_TIER };
|
export { GUEST_TIER };
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
const DAMAGE_TYPES = Object.freeze([
|
const DAMAGE_TYPES = Object.freeze([
|
||||||
"bludgeoning",
|
'healing',
|
||||||
"piercing",
|
'bludgeoning',
|
||||||
"slashing",
|
'piercing',
|
||||||
"acid",
|
'slashing',
|
||||||
"cold",
|
'acid',
|
||||||
"fire",
|
'cold',
|
||||||
"force",
|
'fire',
|
||||||
"lightning",
|
'force',
|
||||||
"necrotic",
|
'lightning',
|
||||||
"poison",
|
'necrotic',
|
||||||
"psychic",
|
'poison',
|
||||||
"radiant",
|
'psychic',
|
||||||
"thunder",
|
'radiant',
|
||||||
|
'thunder',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export default DAMAGE_TYPES;
|
export default DAMAGE_TYPES;
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
const PROPERTIES = Object.freeze({
|
const PROPERTIES = Object.freeze({
|
||||||
action: {
|
action: {
|
||||||
icon: 'offline_bolt',
|
icon: '$vuetify.icons.action',
|
||||||
name: 'Action'
|
name: 'Action'
|
||||||
},
|
},
|
||||||
adjustment: {
|
|
||||||
icon: 'warning',
|
|
||||||
name: 'Attribute damage'
|
|
||||||
},
|
|
||||||
attack: {
|
attack: {
|
||||||
icon: 'bolt',
|
icon: '$vuetify.icons.attack',
|
||||||
name: 'Attack'
|
name: 'Attack'
|
||||||
},
|
},
|
||||||
attribute: {
|
attribute: {
|
||||||
icon: 'donut_small',
|
icon: '$vuetify.icons.attribute',
|
||||||
name: 'Attribute'
|
name: 'Attribute'
|
||||||
},
|
},
|
||||||
|
adjustment: {
|
||||||
|
icon: '$vuetify.icons.attribute_damage',
|
||||||
|
name: 'Attribute damage'
|
||||||
|
},
|
||||||
buff: {
|
buff: {
|
||||||
icon: 'star',
|
icon: '$vuetify.icons.buff',
|
||||||
name: 'Buff'
|
name: 'Buff'
|
||||||
},
|
},
|
||||||
classLevel: {
|
classLevel: {
|
||||||
icon: 'school',
|
icon: '$vuetify.icons.class_level',
|
||||||
name: 'Class level'
|
name: 'Class level'
|
||||||
},
|
},
|
||||||
|
container: {
|
||||||
|
icon: 'work',
|
||||||
|
name: 'Container'
|
||||||
|
},
|
||||||
damage: {
|
damage: {
|
||||||
icon: 'report',
|
icon: '$vuetify.icons.damage',
|
||||||
name: 'Damage'
|
name: 'Damage'
|
||||||
},
|
},
|
||||||
damageMultiplier: {
|
damageMultiplier: {
|
||||||
icon: 'layers',
|
icon: '$vuetify.icons.damage_multiplier',
|
||||||
name: 'Damage multiplier'
|
name: 'Damage multiplier'
|
||||||
},
|
},
|
||||||
effect: {
|
effect: {
|
||||||
icon: 'show_chart',
|
icon: '$vuetify.icons.effect',
|
||||||
name: 'Effect'
|
name: 'Effect'
|
||||||
},
|
},
|
||||||
experience: {
|
|
||||||
icon: 'add',
|
|
||||||
name: 'Experience'
|
|
||||||
},
|
|
||||||
feature: {
|
feature: {
|
||||||
icon: 'subject',
|
icon: 'subject',
|
||||||
name: 'Feature'
|
name: 'Feature'
|
||||||
@@ -47,6 +47,10 @@ const PROPERTIES = Object.freeze({
|
|||||||
icon: 'folder',
|
icon: 'folder',
|
||||||
name: 'Folder'
|
name: 'Folder'
|
||||||
},
|
},
|
||||||
|
item: {
|
||||||
|
icon: '$vuetify.icons.item',
|
||||||
|
name: 'Item'
|
||||||
|
},
|
||||||
note: {
|
note: {
|
||||||
icon: 'note',
|
icon: 'note',
|
||||||
name: 'Note'
|
name: 'Note'
|
||||||
@@ -56,35 +60,31 @@ const PROPERTIES = Object.freeze({
|
|||||||
name: 'Proficiency'
|
name: 'Proficiency'
|
||||||
},
|
},
|
||||||
roll: {
|
roll: {
|
||||||
icon: 'flare',
|
icon: '$vuetify.icons.roll',
|
||||||
name: 'Roll'
|
name: 'Roll'
|
||||||
},
|
},
|
||||||
savingThrow: {
|
savingThrow: {
|
||||||
icon: 'all_out',
|
icon: '$vuetify.icons.saving_throw',
|
||||||
name: 'Saving throw'
|
name: 'Saving throw'
|
||||||
},
|
},
|
||||||
skill: {
|
skill: {
|
||||||
icon: 'check_box',
|
icon: '$vuetify.icons.skill',
|
||||||
name: 'Skill'
|
name: 'Skill'
|
||||||
},
|
},
|
||||||
|
propertySlot: {
|
||||||
|
icon: 'tab_unselected',
|
||||||
|
name: 'Slot'
|
||||||
|
},
|
||||||
spellList: {
|
spellList: {
|
||||||
icon: 'list',
|
icon: '$vuetify.icons.spell_list',
|
||||||
name: 'Spell list'
|
name: 'Spell list'
|
||||||
},
|
},
|
||||||
spell: {
|
spell: {
|
||||||
icon: 'whatshot',
|
icon: '$vuetify.icons.spell',
|
||||||
name: 'Spell'
|
name: 'Spell'
|
||||||
},
|
},
|
||||||
container: {
|
|
||||||
icon: 'work',
|
|
||||||
name: 'Container'
|
|
||||||
},
|
|
||||||
item: {
|
|
||||||
icon: 'category',
|
|
||||||
name: 'Item'
|
|
||||||
},
|
|
||||||
toggle: {
|
toggle: {
|
||||||
icon: 'power_settings_new',
|
icon: '$vuetify.icons.toggle',
|
||||||
name: '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';
|
import { create, all } from 'mathjs';
|
||||||
|
|
||||||
const math = create(all);
|
const math = create(all);
|
||||||
math.import({
|
math.import({
|
||||||
'if': function(pred, a, b) {
|
'if': function(pred, a, b) {
|
||||||
return 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 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
|
* Deletes all soft removed documents that were removed more than 30 minutes ago
|
||||||
* and were not restored
|
* and were not restored
|
||||||
|
* @return {Number} Number of documents removed
|
||||||
*/
|
*/
|
||||||
const deleteOldSoftRemovedDocs = function(){
|
const deleteOldSoftRemovedDocs = function(){
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
@@ -14,30 +21,30 @@ if (Meteor.isServer) Meteor.startup(() => {
|
|||||||
collection.remove({
|
collection.remove({
|
||||||
removed: true,
|
removed: true,
|
||||||
removedAt: {$lt: thirtyMinutesAgo} // dates *before* 30 minutes ago
|
removedAt: {$lt: thirtyMinutesAgo} // dates *before* 30 minutes ago
|
||||||
}, error => {
|
}, function(error){
|
||||||
if (error) console.error(error);
|
if (error){
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SyncedCron.add({
|
SyncedCron.add({
|
||||||
name: "Delete all soft removed items that haven't been restored",
|
name: 'deleteSoftRemovedDocs',
|
||||||
schedule: function(parser) {
|
schedule: function(parser) {
|
||||||
return parser.text('every 6 hours');
|
return parser.text('every 2 hours');
|
||||||
},
|
},
|
||||||
job: function() {
|
job: deleteOldSoftRemovedDocs,
|
||||||
deleteOldSoftRemovedDocs();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SyncedCron.start();
|
||||||
|
|
||||||
// Add a method to manually trigger removal
|
// Add a method to manually trigger removal
|
||||||
Meteor.methods({
|
Meteor.methods({
|
||||||
deleteOldSoftRemovedDocs() {
|
deleteOldSoftRemovedDocs() {
|
||||||
const user = Meteor.users.findOne(this.userId);
|
assertAdmin(this.userId);
|
||||||
if (user && _.contains(user.roles, "admin")){
|
this.unblock();
|
||||||
return deleteOldSoftRemovedDocs();
|
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,38 +1,42 @@
|
|||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
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(){
|
Meteor.publish('characterList', function(){
|
||||||
var userId = this.userId;
|
this.autorun(function (){
|
||||||
if (!userId) {
|
var userId = this.userId;
|
||||||
return [];
|
if (!userId) {
|
||||||
}
|
return this.ready();
|
||||||
const user = Meteor.user();
|
}
|
||||||
const subs = user && user.subscribedCharacters || [];
|
const user = Meteor.users.findOne(this.userId, {
|
||||||
return [
|
fields: {subscribedCharacters: 1}
|
||||||
Creatures.find({
|
});
|
||||||
$or: [
|
const subs = user && user.subscribedCharacters || [];
|
||||||
{readers: userId},
|
return [
|
||||||
{writers: userId},
|
Creatures.find({
|
||||||
{owner: userId},
|
$or: [
|
||||||
{_id: {$in: subs}},
|
{readers: userId},
|
||||||
],
|
{writers: userId},
|
||||||
type: 'pc',
|
{owner: userId},
|
||||||
}, {
|
{_id: {$in: subs}},
|
||||||
fields: {
|
],
|
||||||
name: 1,
|
type: 'pc',
|
||||||
initial: 1,
|
}, {
|
||||||
alignment: 1,
|
fields: {
|
||||||
gender: 1,
|
name: 1,
|
||||||
readers: 1,
|
initial: 1,
|
||||||
writers:1,
|
alignment: 1,
|
||||||
owner: 1,
|
gender: 1,
|
||||||
color: 1,
|
readers: 1,
|
||||||
picture: 1,
|
writers:1,
|
||||||
avatarPicture: 1,
|
owner: 1,
|
||||||
public: 1,
|
color: 1,
|
||||||
}
|
picture: 1,
|
||||||
}
|
avatarPicture: 1,
|
||||||
),
|
public: 1,
|
||||||
Parties.find({owner: userId}),
|
}
|
||||||
];
|
}
|
||||||
|
),
|
||||||
|
Parties.find({owner: userId}),
|
||||||
|
];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
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/characterList.js';
|
||||||
import '/imports/server/publications/library.js';
|
import '/imports/server/publications/library.js';
|
||||||
import '/imports/server/publications/singleCharacter.js';
|
import '/imports/server/publications/singleCharacter.js';
|
||||||
|
import '/imports/server/publications/experiences.js';
|
||||||
import '/imports/server/publications/users.js';
|
import '/imports/server/publications/users.js';
|
||||||
import '/imports/server/publications/icons.js';
|
import '/imports/server/publications/icons.js';
|
||||||
|
import '/imports/server/publications/tabletops.js';
|
||||||
|
|||||||
@@ -1,44 +1,68 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
import Libraries from '/imports/api/library/Libraries.js';
|
import Libraries from '/imports/api/library/Libraries.js';
|
||||||
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||||
|
|
||||||
const standardLibraryIds = [
|
const standardLibraryIds = [
|
||||||
'SRDLibraryGA3XWsd',
|
'SRDLibraryGA3XWsd',
|
||||||
];
|
];
|
||||||
|
|
||||||
Meteor.publish('standardLibraries', function(){
|
Meteor.publish('standardLibraries', function(){
|
||||||
return Libraries.find({_id: {$in: standardLibraryIds}});
|
return Libraries.find({_id: {$in: standardLibraryIds}});
|
||||||
});
|
});
|
||||||
|
|
||||||
Meteor.publish('libraries', function(){
|
Meteor.publish('libraries', function(){
|
||||||
if (!this.userId) return [];
|
this.autorun(function (){
|
||||||
const user = Meteor.user();
|
if (!this.userId) {
|
||||||
const subs = user && user.subscribedLibraries || [];
|
return this.ready();
|
||||||
return Libraries.find({
|
}
|
||||||
$or: [
|
const user = Meteor.users.findOne(this.userId, {
|
||||||
{owner: this.userId},
|
fields: {subscribedLibraries: 1}
|
||||||
{writers: this.userId},
|
});
|
||||||
{readers: this.userId},
|
const subs = user && user.subscribedLibraries || [];
|
||||||
{_id: {$in: subs}},
|
return Libraries.find({
|
||||||
]
|
$or: [
|
||||||
});
|
{owner: this.userId},
|
||||||
|
{writers: this.userId},
|
||||||
|
{readers: this.userId},
|
||||||
|
{_id: {$in: subs}},
|
||||||
|
]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let libraryIdSchema = new SimpleSchema({
|
||||||
|
libraryId: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Meteor.publish('library', function(libraryId){
|
Meteor.publish('library', function(libraryId){
|
||||||
if (!this.userId) return [];
|
libraryIdSchema.validate({libraryId});
|
||||||
let libraryCursor = Libraries.find({
|
this.autorun(function (){
|
||||||
_id: libraryId,
|
let libraryCursor
|
||||||
$or: [
|
if (this.userId) {
|
||||||
{owner: this.userId},
|
libraryCursor = Libraries.find({
|
||||||
{writers: this.userId},
|
_id: libraryId,
|
||||||
{readers: this.userId},
|
$or: [
|
||||||
{public: true},
|
{owner: this.userId},
|
||||||
],
|
{writers: this.userId},
|
||||||
});
|
{readers: this.userId},
|
||||||
if (!libraryCursor.count()) return [];
|
{public: true},
|
||||||
return [
|
],
|
||||||
libraryCursor,
|
});
|
||||||
LibraryNodes.find({
|
} else {
|
||||||
'ancestors.id': libraryId,
|
libraryCursor = Libraries.find({
|
||||||
}),
|
_id: libraryId,
|
||||||
];
|
public: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!libraryCursor.count()) return this.ready();
|
||||||
|
return [
|
||||||
|
libraryCursor,
|
||||||
|
LibraryNodes.find({
|
||||||
|
'ancestors.id': libraryId,
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
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);
|
||||||
@@ -1,25 +1,33 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/Creatures.js';
|
||||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||||
|
|
||||||
Meteor.publish('singleCharacter', function(charId){
|
let schema = new SimpleSchema({
|
||||||
let userId = this.userId;
|
creatureId: {
|
||||||
var char = Creatures.findOne({
|
type: String,
|
||||||
_id: charId,
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
$or: [
|
},
|
||||||
{readers: userId},
|
});
|
||||||
{writers: userId},
|
|
||||||
{owner: userId},
|
Meteor.publish('singleCharacter', function(creatureId){
|
||||||
{public: true},
|
schema.validate({ creatureId });
|
||||||
],
|
this.autorun(function (){
|
||||||
});
|
let userId = this.userId;
|
||||||
if (char){
|
let creatureCursor = Creatures.find({
|
||||||
return [
|
_id: creatureId,
|
||||||
Creatures.find({_id: charId}),
|
$or: [
|
||||||
CreatureProperties.find({
|
{readers: userId},
|
||||||
'ancestors.id': charId,
|
{writers: userId},
|
||||||
}),
|
{owner: userId},
|
||||||
];
|
{public: true},
|
||||||
} else {
|
],
|
||||||
return [];
|
});
|
||||||
}
|
if (!creatureCursor.count()) return this.ready();
|
||||||
|
return [
|
||||||
|
creatureCursor,
|
||||||
|
CreatureProperties.find({
|
||||||
|
'ancestors.id': creatureId,
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
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]
|
||||||
|
})
|
||||||
|
});
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
import '/imports/api/users/Users.js';
|
import '/imports/api/users/Users.js';
|
||||||
import Invites from '/imports/api/users/Invites.js';
|
import Invites from '/imports/api/users/Invites.js';
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ Meteor.publish('user', function(){
|
|||||||
darkMode: 1,
|
darkMode: 1,
|
||||||
subscribedLibraries: 1,
|
subscribedLibraries: 1,
|
||||||
profile: 1,
|
profile: 1,
|
||||||
|
preferences: 1,
|
||||||
'services.patreon.id': 1,
|
'services.patreon.id': 1,
|
||||||
'services.patreon.entitledCents': 1,
|
'services.patreon.entitledCents': 1,
|
||||||
'services.patreon.entitledCentsOverride': 1,
|
'services.patreon.entitledCentsOverride': 1,
|
||||||
@@ -32,8 +34,20 @@ Meteor.publish('user', function(){
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let userIdsSchema = new SimpleSchema({
|
||||||
|
ids: {
|
||||||
|
type: Array,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
'ids.$':{
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
Meteor.publish('userPublicProfiles', function(ids){
|
Meteor.publish('userPublicProfiles', function(ids){
|
||||||
if (!this.userId || !Array.isArray(ids)) return [];
|
userIdsSchema.validate({ids});
|
||||||
|
if (!this.userId || !ids) return this.ready();
|
||||||
return Meteor.users.find({
|
return Meteor.users.find({
|
||||||
_id: {$in: ids}
|
_id: {$in: ids}
|
||||||
},{
|
},{
|
||||||
|
|||||||
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>
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<template lang="html">
|
|
||||||
<v-layout justify-center>
|
|
||||||
<color-picker v-model="color"/>
|
|
||||||
</v-layout>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import ColorPicker from '/imports/ui/components/ColorPicker.vue';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
data(){ return {
|
|
||||||
color: '#CE93D8',
|
|
||||||
}},
|
|
||||||
components: {
|
|
||||||
ColorPicker,
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
color(newColor){
|
|
||||||
console.log(`%c${newColor}`, `background: ${newColor};`);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="css" scoped>
|
|
||||||
</style>
|
|
||||||
@@ -1,193 +1,230 @@
|
|||||||
<template lang="html">
|
<template lang="html">
|
||||||
<v-menu
|
<v-menu
|
||||||
:close-on-content-click="false"
|
v-model="opened"
|
||||||
|
:close-on-content-click="false"
|
||||||
transition="slide-y-transition"
|
transition="slide-y-transition"
|
||||||
lazy
|
lazy
|
||||||
v-model="opened"
|
left
|
||||||
>
|
>
|
||||||
<v-btn
|
<v-btn
|
||||||
slot="activator"
|
slot="activator"
|
||||||
icon
|
icon
|
||||||
>
|
>
|
||||||
<v-icon>format_paint</v-icon>
|
<v-icon>format_paint</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
<v-card class="overflow-hidden">
|
<v-card class="overflow-hidden">
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<v-item-group v-model="color" mandatory>
|
<v-layout
|
||||||
<v-layout row wrap>
|
row
|
||||||
<v-item
|
wrap
|
||||||
v-for="kebabColorOption in colors"
|
>
|
||||||
:key="kebabColorOption"
|
<div
|
||||||
:value="kebabToCamelCase(kebabColorOption)"
|
v-for="colorOption in colors"
|
||||||
>
|
:key="colorOption"
|
||||||
<div
|
:class="[colorOption, shade]"
|
||||||
slot-scope="{ active, toggle }"
|
class="color-swatch d-flex align-center"
|
||||||
:class="[kebabColorOption, kebabShade]"
|
@click="color = colorOption"
|
||||||
class="color-swatch d-flex align-center"
|
>
|
||||||
@click="toggle"
|
<v-scroll-y-transition>
|
||||||
>
|
<v-icon
|
||||||
<v-scroll-y-transition>
|
v-if="kebabColor === colorOption"
|
||||||
<v-icon
|
:class="{dark: isDark(colorOption, shade)}"
|
||||||
v-if="active"
|
>
|
||||||
:class="{dark: isDark(kebabColorOption, kebabShade)}"
|
check
|
||||||
>check</v-icon>
|
</v-icon>
|
||||||
</v-scroll-y-transition>
|
</v-scroll-y-transition>
|
||||||
</div>
|
</div>
|
||||||
</v-item>
|
<div
|
||||||
<div class="spacer" v-for="i in 8"/>
|
v-for="i in 8"
|
||||||
</v-layout>
|
:key="i"
|
||||||
</v-item-group>
|
class="spacer"
|
||||||
<v-item-group class="mt-2" v-model="shade" mandatory>
|
/>
|
||||||
<v-layout wrap>
|
</v-layout>
|
||||||
<v-item
|
<v-fade-transition>
|
||||||
v-for="kebabShadeOption in shades"
|
<v-layout
|
||||||
:key="kebabShadeOption"
|
v-show="color"
|
||||||
:value="kebabToCamelCase(kebabShadeOption)"
|
wrap
|
||||||
>
|
class="mt-2"
|
||||||
<div
|
>
|
||||||
slot-scope="{ active, toggle }"
|
<div
|
||||||
:class="[kebabColor, kebabShadeOption]"
|
v-for="shadeOption in shades"
|
||||||
class="shade-swatch d-flex align-center"
|
:key="shadeOption"
|
||||||
@click="toggle"
|
:class="[kebabColor, shadeOption]"
|
||||||
>
|
class="shade-swatch d-flex align-center"
|
||||||
<v-scroll-y-transition>
|
@click="shade = shadeOption"
|
||||||
<v-icon
|
>
|
||||||
v-if="active"
|
<v-scroll-y-transition>
|
||||||
:class="{dark: isDark(kebabColor, kebabShadeOption)}"
|
<v-icon
|
||||||
>check</v-icon>
|
v-if="kebabShade === shadeOption"
|
||||||
</v-scroll-y-transition>
|
:class="isDark(color, shade) ? 'dark' : 'light'"
|
||||||
</div>
|
>
|
||||||
</v-item>
|
check
|
||||||
<div class="spacer" v-for="i in 8"/>
|
</v-icon>
|
||||||
</v-layout>
|
</v-scroll-y-transition>
|
||||||
</v-item-group>
|
</div>
|
||||||
</v-card-text>
|
<div
|
||||||
<v-card-actions>
|
v-for="i in 8"
|
||||||
<v-spacer/>
|
:key="i"
|
||||||
<v-btn flat @click="opened = false">Done</v-btn>
|
class="spacer"
|
||||||
</v-card-actions>
|
/>
|
||||||
</v-card>
|
</v-layout>
|
||||||
|
</v-fade-transition>
|
||||||
|
</v-card-text>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-btn
|
||||||
|
flat
|
||||||
|
@click="$emit('input')"
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</v-btn>
|
||||||
|
<v-spacer />
|
||||||
|
<v-btn
|
||||||
|
flat
|
||||||
|
@click="opened = false"
|
||||||
|
>
|
||||||
|
Done
|
||||||
|
</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
</v-menu>
|
</v-menu>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import isDarkColor from '/imports/ui/utility/isDarkColor.js';
|
import isDarkColor from '/imports/ui/utility/isDarkColor.js';
|
||||||
import vuetifyColors from 'vuetify/es5/util/colors';
|
import vuetifyColors from 'vuetify/es5/util/colors';
|
||||||
import { kebabToCamelCase, camelToKebabCase } from '/imports/ui/utility/swapCase.js';
|
import { kebabToCamelCase, camelToKebabCase } from '/imports/ui/utility/swapCase.js';
|
||||||
|
|
||||||
function colorToHex(color, shade = 'base'){
|
function colorToHex(color, shade = 'base'){
|
||||||
color = kebabToCamelCase(color);
|
if (!color) return;
|
||||||
shade = kebabToCamelCase(shade);
|
color = kebabToCamelCase(color);
|
||||||
return vuetifyColors[color][shade];
|
shade = kebabToCamelCase(shade);
|
||||||
};
|
return vuetifyColors[color] && vuetifyColors[color][shade];
|
||||||
|
}
|
||||||
|
|
||||||
// Create an index of hex colors and what color/shade combination makes them
|
// Create an index of hex colors and what color/shade combination makes them
|
||||||
let colorIndex = {};
|
let colorIndex = {};
|
||||||
for (let color in vuetifyColors){
|
for (let color in vuetifyColors){
|
||||||
for (let shade in vuetifyColors[color]){
|
color = kebabToCamelCase(color);
|
||||||
colorIndex[vuetifyColors[color][shade]] = {color, shade};
|
for (let shade in vuetifyColors[color]){
|
||||||
}
|
shade = kebabToCamelCase(shade);
|
||||||
}
|
colorIndex[vuetifyColors[color][shade]] = {color, shade};
|
||||||
function hexToColor(hex){
|
}
|
||||||
return colorIndex[hex.toLowerCase()];
|
}
|
||||||
};
|
function hexToColor(hex){
|
||||||
|
if (!hex) return undefined;
|
||||||
|
return colorIndex[hex.toLowerCase()];
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
value: String, //hex string
|
//hex string
|
||||||
},
|
value: {
|
||||||
data(){ return {
|
type: String,
|
||||||
colors: [
|
default: undefined,
|
||||||
'red',
|
},
|
||||||
'pink',
|
},
|
||||||
'purple',
|
data(){ return {
|
||||||
'deep-purple',
|
colors: [
|
||||||
'indigo',
|
'red',
|
||||||
'blue',
|
'pink',
|
||||||
'light-blue',
|
'purple',
|
||||||
'cyan',
|
'deep-purple',
|
||||||
'teal',
|
'indigo',
|
||||||
'green',
|
'blue',
|
||||||
'light-green',
|
'light-blue',
|
||||||
'lime',
|
'cyan',
|
||||||
'yellow',
|
'teal',
|
||||||
'amber',
|
'green',
|
||||||
'orange',
|
'light-green',
|
||||||
'deep-orange',
|
'lime',
|
||||||
'brown',
|
'yellow',
|
||||||
'grey',
|
'amber',
|
||||||
],
|
'orange',
|
||||||
shades: [
|
'deep-orange',
|
||||||
'lighten-4',
|
'brown',
|
||||||
'lighten-3',
|
'grey',
|
||||||
'lighten-2',
|
],
|
||||||
'lighten-1',
|
shades: [
|
||||||
'base',
|
'lighten-4',
|
||||||
'darken-1',
|
'lighten-3',
|
||||||
'darken-2',
|
'lighten-2',
|
||||||
'darken-3',
|
'lighten-1',
|
||||||
'darken-4',
|
'base',
|
||||||
],
|
'darken-1',
|
||||||
opened: false,
|
'darken-2',
|
||||||
}},
|
'darken-3',
|
||||||
methods: {
|
'darken-4',
|
||||||
isDark(kebabColor, kebabShade){
|
],
|
||||||
color = colorToHex(kebabColor, kebabShade);
|
opened: false,
|
||||||
return isDarkColor(color);
|
}},
|
||||||
},
|
computed: {
|
||||||
kebabToCamelCase,
|
combination (){
|
||||||
},
|
if (!this.value) return;
|
||||||
computed: {
|
return hexToColor(this.value) || {};
|
||||||
combination (){
|
},
|
||||||
return hexToColor(this.value) || {};
|
color: {
|
||||||
},
|
get(){
|
||||||
color: {
|
return this.combination && this.combination.color;
|
||||||
get(){
|
},
|
||||||
return this.combination.color;
|
set(newColor){
|
||||||
},
|
this.$emit('input', colorToHex(newColor, this.shade));
|
||||||
set(newColor){
|
},
|
||||||
this.$emit('input', colorToHex(newColor, this.shade));
|
},
|
||||||
},
|
shade: {
|
||||||
},
|
get(){
|
||||||
shade: {
|
return this.combination && this.combination.shade;
|
||||||
get(){
|
},
|
||||||
return this.combination.shade;
|
set(newShade){
|
||||||
},
|
this.$emit('input', colorToHex(this.color, newShade));
|
||||||
set(newShade){
|
},
|
||||||
this.$emit('input', colorToHex(this.color, newShade));
|
},
|
||||||
},
|
kebabColor(){
|
||||||
},
|
return camelToKebabCase(this.color);
|
||||||
kebabColor(){
|
},
|
||||||
return camelToKebabCase(this.color);
|
kebabShade(){
|
||||||
},
|
return camelToKebabCase(this.shade);
|
||||||
kebabShade(){
|
},
|
||||||
return camelToKebabCase(this.shade);
|
},
|
||||||
},
|
methods: {
|
||||||
},
|
isDark(kebabColor, kebabShade){
|
||||||
};
|
let color = colorToHex(kebabColor, kebabShade);
|
||||||
|
return isDarkColor(color);
|
||||||
|
},
|
||||||
|
kebabToCamelCase,
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
.color-swatch, .shade-swatch {
|
.color-swatch, .shade-swatch {
|
||||||
height: 30px;
|
height: 30px;
|
||||||
width: 30px;
|
width: 30px;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
cursor: pointer;
|
||||||
.v-icon {
|
transition: all 0.2s linear;
|
||||||
height: 30px;
|
}
|
||||||
}
|
.color-swatch:hover{
|
||||||
.v-icon {
|
z-index: 1;
|
||||||
color: black;
|
transform: scale(1.1);
|
||||||
}
|
box-shadow: 0px 2px 1px -1px rgba(0,0,0,0.2),
|
||||||
.dark.v-icon {
|
0px 1px 1px 0px rgba(0,0,0,0.14),
|
||||||
color: white;
|
0px 1px 3px 0px rgba(0,0,0,0.12);
|
||||||
}
|
}
|
||||||
.layout {
|
.v-icon {
|
||||||
max-width: 270px;
|
height: 30px;
|
||||||
}
|
}
|
||||||
.spacer {
|
.v-icon {
|
||||||
width: 30px;
|
color: black;
|
||||||
height: 0;
|
}
|
||||||
flex-grow: 1;
|
.dark.v-icon {
|
||||||
}
|
color: white;
|
||||||
|
}
|
||||||
|
.layout {
|
||||||
|
max-width: 270px;
|
||||||
|
}
|
||||||
|
.spacer {
|
||||||
|
width: 30px;
|
||||||
|
height: 0;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
<template lang="html">
|
|
||||||
<column-layout>
|
|
||||||
<div v-for="(height, n) in cardHeights" :key="n">
|
|
||||||
<v-card :height="height"/>
|
|
||||||
</div >
|
|
||||||
</column-layout>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import ColumnLayout from "/imports/ui/components/ColumnLayout.vue";
|
|
||||||
import { _ } from "meteor/underscore";
|
|
||||||
export default {
|
|
||||||
dontWrap: true,
|
|
||||||
data(){return{
|
|
||||||
cardHeights: _.times(12, n => `${_.random(100, 500)}px`),
|
|
||||||
}},
|
|
||||||
components: {
|
|
||||||
ColumnLayout,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="css" scoped>
|
|
||||||
</style>
|
|
||||||
@@ -40,6 +40,7 @@ export default {
|
|||||||
Table and width set because firefox does not support break-inside: avoid
|
Table and width set because firefox does not support break-inside: avoid
|
||||||
*/
|
*/
|
||||||
display: table;
|
display: table;
|
||||||
|
table-layout: fixed;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
-webkit-backface-visibility: hidden;
|
-webkit-backface-visibility: hidden;
|
||||||
-webkit-transform: translateX(0);
|
-webkit-transform: translateX(0);
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
<template lang="html">
|
|
||||||
<icon-search/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import IconSearch from '/imports/ui/components/IconSearch.vue';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
components: {
|
|
||||||
IconSearch,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="css" scoped>
|
|
||||||
</style>
|
|
||||||
@@ -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;' : ''}`"
|
:style="`transform: none; ${hasToolbarClickListener ? 'cursor: pointer;' : ''}`"
|
||||||
:color="color"
|
:color="color"
|
||||||
:dark="isDark"
|
:dark="isDark"
|
||||||
|
:light="!isDark"
|
||||||
@click="$emit('toolbarclick')"
|
@click="$emit('toolbarclick')"
|
||||||
>
|
>
|
||||||
<slot name="toolbar" />
|
<slot name="toolbar" />
|
||||||
|
|||||||
43
app/imports/ui/components/TreeDetailLayout.vue
Normal file
43
app/imports/ui/components/TreeDetailLayout.vue
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<template lang="html">
|
||||||
|
<div
|
||||||
|
class="layout row"
|
||||||
|
style="height: 100%;"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="layout column justify-start"
|
||||||
|
:style="computedTreeStyle"
|
||||||
|
>
|
||||||
|
<slot name="tree" />
|
||||||
|
</div>
|
||||||
|
<template v-if="$vuetify.breakpoint.mdAndUp">
|
||||||
|
<v-divider vertical />
|
||||||
|
<div
|
||||||
|
class="flex layout column"
|
||||||
|
style="background-color: inherit; overflow: hidden;"
|
||||||
|
data-id="selected-node-card"
|
||||||
|
>
|
||||||
|
<slot name="detail" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
computed:{
|
||||||
|
computedTreeStyle(){
|
||||||
|
if (this.$vuetify.breakpoint.smAndDown) return;
|
||||||
|
let style = 'flex-shrink: 0; flex-grow: 0; ';
|
||||||
|
if (this.$vuetify.breakpoint.xlOnly){
|
||||||
|
style += 'width: 400px;'
|
||||||
|
} else {
|
||||||
|
style += 'width: 320px;'
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="css" scoped>
|
||||||
|
</style>
|
||||||
@@ -11,7 +11,7 @@ import Computed from '/imports/ui/components/computation/Computed.vue';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
inject: {
|
inject: {
|
||||||
computationContext: { default: {} }
|
context: { default: {} }
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
Computed,
|
Computed,
|
||||||
@@ -24,8 +24,8 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
scope(){
|
scope(){
|
||||||
return this.computationContext.creature &&
|
return this.context.creature &&
|
||||||
this.computationContext.creature.variables;
|
this.context.creature.variables;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template lang="html">
|
<template lang="html">
|
||||||
<v-menu
|
<v-menu
|
||||||
v-model="menu"
|
v-model="menu"
|
||||||
:close-on-content-click="false"
|
:close-on-content-click="false"
|
||||||
lazy
|
lazy
|
||||||
@@ -7,21 +7,25 @@
|
|||||||
full-width
|
full-width
|
||||||
min-width="290px"
|
min-width="290px"
|
||||||
>
|
>
|
||||||
<template v-slot:activator="{ on }">
|
<template #activator="{ on }">
|
||||||
<v-text-field
|
<v-text-field
|
||||||
:value="formattedSafeValue"
|
:value="formattedSafeValue"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
prepend-icon="event"
|
prepend-icon="event"
|
||||||
readonly
|
readonly
|
||||||
v-on="on"
|
:loading="loading"
|
||||||
:loading="loading"
|
|
||||||
:error-messages="errors"
|
:error-messages="errors"
|
||||||
@focus="focused = true"
|
:disabled="isDisabled"
|
||||||
@blur="focused = false"
|
box
|
||||||
box
|
v-on="on"
|
||||||
></v-text-field>
|
@focus="focused = true"
|
||||||
|
@blur="focused = false"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
<v-date-picker :value="formattedSafeValue" @input="dateInput"></v-date-picker>
|
<v-date-picker
|
||||||
|
:value="formattedSafeValue"
|
||||||
|
@input="dateInput"
|
||||||
|
/>
|
||||||
</v-menu>
|
</v-menu>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -34,17 +38,17 @@ export default {
|
|||||||
data(){return {
|
data(){return {
|
||||||
menu: false,
|
menu: false,
|
||||||
};},
|
};},
|
||||||
|
computed: {
|
||||||
|
formattedSafeValue(){
|
||||||
|
return format(this.safeValue, 'YYYY-MM-DD')
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
dateInput(e){
|
dateInput(e){
|
||||||
this.menu = false;
|
this.menu = false;
|
||||||
this.input(e);
|
this.input(e);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
formattedSafeValue(){
|
|
||||||
return format(this.safeValue, 'YYYY-MM-DD')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
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>
|
||||||
18
app/imports/ui/components/global/SmartCheckbox.vue
Normal file
18
app/imports/ui/components/global/SmartCheckbox.vue
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<template lang="html">
|
||||||
|
<v-checkbox
|
||||||
|
v-bind="$attrs"
|
||||||
|
:loading="loading"
|
||||||
|
:error-messages="errors"
|
||||||
|
:input-value="safeValue"
|
||||||
|
:disabled="isDisabled"
|
||||||
|
@change="change"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import SmartInput from '/imports/ui/components/global/SmartInputMixin.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mixins: [SmartInput],
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
:value="safeValue"
|
:value="safeValue"
|
||||||
:menu-props="{auto: true, lazy: true}"
|
:menu-props="{auto: true, lazy: true}"
|
||||||
:search-input.sync="searchInput"
|
:search-input.sync="searchInput"
|
||||||
|
:disabled="isDisabled"
|
||||||
box
|
box
|
||||||
@change="customChange"
|
@change="customChange"
|
||||||
@focus="focused = true"
|
@focus="focused = true"
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
<template lang="html">
|
|
||||||
<v-container grid-list-lg>
|
|
||||||
<v-layout row wrap align-center>
|
|
||||||
|
|
||||||
<v-flex xs6>
|
|
||||||
<text-field
|
|
||||||
:value="value1"
|
|
||||||
@change="value1Change"
|
|
||||||
/>
|
|
||||||
</v-flex>
|
|
||||||
<v-flex xs6>
|
|
||||||
<div class="flex">
|
|
||||||
{{value1}}
|
|
||||||
</div>
|
|
||||||
</v-flex>
|
|
||||||
|
|
||||||
<v-flex xs6>
|
|
||||||
<text-field
|
|
||||||
:value="changingValue"
|
|
||||||
@change="(val, ack) => {changingValue = val; ack()}"
|
|
||||||
/>
|
|
||||||
</v-flex>
|
|
||||||
<v-flex xs6>
|
|
||||||
{{changingValue}}
|
|
||||||
</v-flex>
|
|
||||||
|
|
||||||
<v-flex xs6>
|
|
||||||
<text-area
|
|
||||||
:value="value2"
|
|
||||||
@change="value2Change"
|
|
||||||
label="text-area"
|
|
||||||
/>
|
|
||||||
</v-flex>
|
|
||||||
<v-flex xs6>
|
|
||||||
{{value2}}
|
|
||||||
</v-flex>
|
|
||||||
|
|
||||||
<v-flex xs6>
|
|
||||||
<smart-select
|
|
||||||
:value="value3"
|
|
||||||
:items="['meep', 'moop', 'maap']"
|
|
||||||
label="select"
|
|
||||||
@change="(val, ack) => {setTimeout(() => {value3 = val; ack()}, 700)}"
|
|
||||||
/>
|
|
||||||
</v-flex>
|
|
||||||
<v-flex xs6>
|
|
||||||
{{value3}}
|
|
||||||
</v-flex>
|
|
||||||
|
|
||||||
</v-layout>
|
|
||||||
</v-container>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
data(){ return {
|
|
||||||
value1: 'Five letters minimum, always trimmed',
|
|
||||||
value2: 'Takes 2s to write',
|
|
||||||
value3: 'meep',
|
|
||||||
changingValue: `Changes every 3s ${Math.random().toFixed(4)}`,
|
|
||||||
}},
|
|
||||||
methods: {
|
|
||||||
value1Change(val, ack){
|
|
||||||
let error;
|
|
||||||
val = val.trim();
|
|
||||||
if (!val || val.length < 5){
|
|
||||||
error = "Too short";
|
|
||||||
} else {
|
|
||||||
this.value1 = val;
|
|
||||||
}
|
|
||||||
ack(error);
|
|
||||||
},
|
|
||||||
value2Change(val, ack){
|
|
||||||
setTimeout(() => {
|
|
||||||
this.value2 = val;
|
|
||||||
ack();
|
|
||||||
}, 2000);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
setInterval(() => {
|
|
||||||
this.changingValue = `Changes every 3s ${Math.random().toFixed(4)}`;
|
|
||||||
}, 3000);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="css" scoped>
|
|
||||||
.layout {
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user