Compare commits
219 Commits
2.0-beta.1
...
2.0-beta.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8162c76185 | ||
|
|
e21586e9ce | ||
|
|
4c2155d8ff | ||
|
|
44cc46ed22 | ||
|
|
d2b5d5f01d | ||
|
|
4492c47b00 | ||
|
|
6600cea9fa | ||
|
|
741a9b080a | ||
|
|
b041db22e4 | ||
|
|
a465e2ce87 | ||
|
|
8ecefb03ad | ||
|
|
9f62a78eb0 | ||
|
|
16e2b1249f | ||
|
|
a35f9221a2 | ||
|
|
6364549d50 | ||
|
|
d999fb46a7 | ||
|
|
ec01a2adb5 | ||
|
|
1f64558100 | ||
|
|
19a2798bf7 | ||
|
|
a5f2c2e0d2 | ||
|
|
ee174210fd | ||
|
|
1e38295164 | ||
|
|
758cb2f8bc | ||
|
|
36bb3c3181 | ||
|
|
02434de34c | ||
|
|
0dc0bea53e | ||
|
|
c392119430 | ||
|
|
4e2e0ca364 | ||
|
|
4a8b72f163 | ||
|
|
d916dc2b78 | ||
|
|
56860ba96d | ||
|
|
b607755f9f | ||
|
|
86d8fa4325 | ||
|
|
2b08249e5e | ||
|
|
3133e664d5 | ||
|
|
48f32e0a8d | ||
|
|
c72785c9e7 | ||
|
|
421ff2aa7d | ||
|
|
9a9e6491b9 | ||
|
|
332258705c | ||
|
|
73ef109d4d | ||
|
|
fc240a34c4 | ||
|
|
8ac4028f38 | ||
|
|
2849df1974 | ||
|
|
3fa2cca7ae | ||
|
|
a0b53af6d7 | ||
|
|
51c709f7a5 | ||
|
|
28d67409aa | ||
|
|
7e97bcb6d8 | ||
|
|
4e87737a3e | ||
|
|
822fa4619f | ||
|
|
80ba44a28f | ||
|
|
c3c079731e | ||
|
|
039b7046b2 | ||
|
|
8eaad3600f | ||
|
|
5cf78932e6 | ||
|
|
d43d364175 | ||
|
|
0ad4c71189 | ||
|
|
e8c6f26a0b | ||
|
|
8804c80a56 | ||
|
|
0d21ab758e | ||
|
|
2ecb0e2671 | ||
|
|
f3b9b62486 | ||
|
|
29a4575760 | ||
|
|
a6fbf71b36 | ||
|
|
86d9383af0 | ||
|
|
3db589f775 | ||
|
|
e96755927f | ||
|
|
66dc0ee34f | ||
|
|
54bf21c57c | ||
|
|
5f5fe801f6 | ||
|
|
a451afcbaf | ||
|
|
848e961e3b | ||
|
|
c5aca81131 | ||
|
|
814e371148 | ||
|
|
69f4bbf360 | ||
|
|
6b2d74a165 | ||
|
|
cf05aea80a | ||
|
|
1a2d4b22bb | ||
|
|
81d52a1847 | ||
|
|
e3fc56a844 | ||
|
|
64fceb9c38 | ||
|
|
9994c1f32a | ||
|
|
7056c5b37b | ||
|
|
1ad1d1f23d | ||
|
|
c65c8f3299 | ||
|
|
4faea42371 | ||
|
|
9825872576 | ||
|
|
85b536bc46 | ||
|
|
9aa8203dcc | ||
|
|
217133137b | ||
|
|
aef7dbcbb3 | ||
|
|
6ff750417f | ||
|
|
a9eacfab03 | ||
|
|
1f633621b7 | ||
|
|
9f3c8bef34 | ||
|
|
8a83e7d8a1 | ||
|
|
a28182f3e9 | ||
|
|
3d122e062f | ||
|
|
e9a273244a | ||
|
|
1de3122254 | ||
|
|
298db01e5b | ||
|
|
727101cd63 | ||
|
|
d4d002cf31 | ||
|
|
2150bd6da4 | ||
|
|
e1df145675 | ||
|
|
1eb78756ac | ||
|
|
ce9b9199ec | ||
|
|
cfb1414494 | ||
|
|
4abd689c9f | ||
|
|
f0e443fba2 | ||
|
|
52e7deedc6 | ||
|
|
15d593db79 | ||
|
|
e30754ef26 | ||
|
|
255ac529b3 | ||
|
|
c8b5ada5b9 | ||
|
|
0c24238069 | ||
|
|
66847430ad | ||
|
|
bfb860605f | ||
|
|
d87524418a | ||
|
|
5f97592ed3 | ||
|
|
562991216f | ||
|
|
109b89022e | ||
|
|
d4ca07ce9c | ||
|
|
885607f685 | ||
|
|
81460f8835 | ||
|
|
cce5f9b926 | ||
|
|
7d3a51de9d | ||
|
|
fc774fcc5e | ||
|
|
0f37a49b95 | ||
|
|
9814e20091 | ||
|
|
d89cb77040 | ||
|
|
8590d29abf | ||
|
|
9298754dc9 | ||
|
|
e2d6d40bb3 | ||
|
|
152677b023 | ||
|
|
838e2ed35f | ||
|
|
60ae1ef604 | ||
|
|
ecfe5f1360 | ||
|
|
292d3c3f37 | ||
|
|
3c26bb2fc6 | ||
|
|
ada1355c29 | ||
|
|
2662af8ea2 | ||
|
|
26b68dccef | ||
|
|
0717f8e8d7 | ||
|
|
5cf0330e03 | ||
|
|
1978a2e4c7 | ||
|
|
5a2e500348 | ||
|
|
7d4356592a | ||
|
|
2c448d1748 | ||
|
|
4f96d817d5 | ||
|
|
f9998eabc4 | ||
|
|
623cff584c | ||
|
|
aa34508cb3 | ||
|
|
6678bc1cea | ||
|
|
0324b9f7c3 | ||
|
|
ccac142ec6 | ||
|
|
fe3fa56541 | ||
|
|
480da6fc7d | ||
|
|
6ffb48b7b6 | ||
|
|
82150df5e0 | ||
|
|
9a120a6e9a | ||
|
|
f385c2857e | ||
|
|
11a2851ac4 | ||
|
|
313382fb82 | ||
|
|
b9ae337a64 | ||
|
|
4dc0a6159b | ||
|
|
e00dfe1532 | ||
|
|
28e1fcabd5 | ||
|
|
2c0496b44b | ||
|
|
89adda60ec | ||
|
|
8c3710cda3 | ||
|
|
b501b9d830 | ||
|
|
574f8373e7 | ||
|
|
a7ecdecec1 | ||
|
|
0aa59a4bfc | ||
|
|
8f0ff3245e | ||
|
|
9a2d10b7ed | ||
|
|
a8aa1923a8 | ||
|
|
57fa162c89 | ||
|
|
4d548c901c | ||
|
|
a97be2f93a | ||
|
|
1276f872a0 | ||
|
|
7daab97297 | ||
|
|
2e3704d096 | ||
|
|
7283a27727 | ||
|
|
3517636b8b | ||
|
|
e617ef9b75 | ||
|
|
cd45ae1442 | ||
|
|
bcedd548c7 | ||
|
|
dc53e38efe | ||
|
|
e381b3b24d | ||
|
|
111d971bc2 | ||
|
|
bf4ce4f9f7 | ||
|
|
2a983b0a94 | ||
|
|
a5460bba0b | ||
|
|
df361236f5 | ||
|
|
e1d670fe9f | ||
|
|
1e9f0515e5 | ||
|
|
0404020335 | ||
|
|
c248d8f4a0 | ||
|
|
8d95da8b7a | ||
|
|
e11ab39864 | ||
|
|
331fcef9ad | ||
|
|
7e3bff9677 | ||
|
|
1b650b26b6 | ||
|
|
5925605962 | ||
|
|
dee1265b69 | ||
|
|
3d3ec3bcf2 | ||
|
|
dce2c92516 | ||
|
|
0fe2780983 | ||
|
|
e126cdd3cb | ||
|
|
d69ada0db4 | ||
|
|
858915b25b | ||
|
|
d10a7eca14 | ||
|
|
671d17018c | ||
|
|
f2883d320f | ||
|
|
aad0c7249e | ||
|
|
612fcca68c |
19
README.md
19
README.md
@@ -66,5 +66,24 @@ You should see this:
|
|||||||
=> App running at: http://localhost:3000/
|
=> App running at: http://localhost:3000/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Environmental Variables
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
```
|
||||||
|
MAIL_URL=smtp://<your smtp mail url>
|
||||||
|
METEOR_SETTINGS={ "public": { "environment": "production", "patreon": { "clientId": "<your patreon client ID>", "campaignId": "<your campaign id>" } }, "patreon": { "clientSecret": "<your client secret>", "creatorAccessToken": "<your creator access token>" } }
|
||||||
|
MONGO_OPLOG_URL=mongodb+srv://<your url for the oplog account of your mongo database>
|
||||||
|
MONGO_URL=mongodb+srv://<your url for the read/write account of your mongo database>
|
||||||
|
NPM_CONFIG_PRODUCTION=true
|
||||||
|
PROJECT_DIR=app
|
||||||
|
ROOT_URL=https://<url of your DiceCloud instance>
|
||||||
|
DEFAULT_LIBRARIES=<comma separated list of library ids that will be subscribed by default: "abc123,def456">
|
||||||
|
```
|
||||||
|
|
||||||
|
To disable Patreon features and unlock all paid restrictions for all users of your deployment, replace
|
||||||
|
`"patreon": { "clientId": ... }"` with `"disablePatreon": true` in the public key of the METEOR_SETTINGS environment variable.
|
||||||
|
|
||||||
|
Alternatively run `meteor run --settings exampleMeteorSettings.json` to start the app with the example settings that disable Patreon by default.
|
||||||
|
|
||||||
Now, visiting [](http://localhost:3000/) should show you an empty instance of
|
Now, visiting [](http://localhost:3000/) should show you an empty instance of
|
||||||
DiceCloud running.
|
DiceCloud running.
|
||||||
|
|||||||
@@ -3,50 +3,44 @@
|
|||||||
# 'meteor add' and 'meteor remove' will edit this file for you,
|
# 'meteor add' and 'meteor remove' will edit this file for you,
|
||||||
# but you can also edit it by hand.
|
# but you can also edit it by hand.
|
||||||
|
|
||||||
accounts-password@1.6.2
|
accounts-password
|
||||||
accounts-ui@1.3.1
|
random
|
||||||
random@1.2.0
|
|
||||||
dburles:collection-helpers
|
dburles:collection-helpers
|
||||||
reactive-var@1.0.11
|
reactive-var
|
||||||
underscore@1.0.10
|
underscore
|
||||||
momentjs:moment
|
momentjs:moment
|
||||||
dburles:mongo-collection-instances
|
dburles:mongo-collection-instances
|
||||||
percolate:migrations
|
accounts-google
|
||||||
accounts-google@1.3.3
|
email
|
||||||
email@2.0.0
|
|
||||||
meteorhacks:subs-manager
|
meteorhacks:subs-manager
|
||||||
chuangbo:marked
|
chuangbo:marked
|
||||||
meteor-base@1.4.0
|
meteor-base
|
||||||
mobile-experience@1.1.0
|
mobile-experience
|
||||||
mongo@1.10.0
|
mongo
|
||||||
session@1.2.0
|
session
|
||||||
jquery@1.11.10
|
tracker
|
||||||
tracker@1.2.0
|
logging
|
||||||
logging@1.1.20
|
reload
|
||||||
reload@1.3.0
|
ejson
|
||||||
ejson@1.1.1
|
check
|
||||||
check@1.3.1
|
standard-minifier-js
|
||||||
standard-minifier-js@2.6.0
|
shell-server
|
||||||
shell-server@0.5.0
|
|
||||||
seba:minifiers-autoprefixer
|
|
||||||
templates:array
|
templates:array
|
||||||
ecmascript@0.14.3
|
ecmascript
|
||||||
es5-shim@4.8.0
|
es5-shim
|
||||||
reactive-dict@1.3.0
|
reactive-dict
|
||||||
percolate:synced-cron
|
percolate:synced-cron
|
||||||
ongoworks:speakingurl
|
ongoworks:speakingurl
|
||||||
service-configuration@1.0.11
|
service-configuration
|
||||||
google-config-ui@1.0.1
|
dynamic-import
|
||||||
dynamic-import@0.5.2
|
ddp-rate-limiter
|
||||||
ddp-rate-limiter@1.0.9
|
rate-limit
|
||||||
rate-limit@1.0.9
|
|
||||||
meteortesting:mocha
|
|
||||||
mdg:validated-method
|
mdg:validated-method
|
||||||
akryum:vue-router2
|
akryum:vue-router2
|
||||||
static-html
|
static-html
|
||||||
aldeed:collection2@3.0.0
|
aldeed:collection2
|
||||||
aldeed:schema-index
|
aldeed:schema-index
|
||||||
akryum:vue-component
|
zer0th:meteor-vuetify-loader
|
||||||
accounts-patreon
|
accounts-patreon
|
||||||
bozhao:link-accounts
|
bozhao:link-accounts
|
||||||
peerlibrary:reactive-publish
|
peerlibrary:reactive-publish
|
||||||
@@ -54,3 +48,6 @@ simple:rest
|
|||||||
simple:rest-method-mixin
|
simple:rest-method-mixin
|
||||||
mikowals:batch-insert
|
mikowals:batch-insert
|
||||||
peerlibrary:subscription-data
|
peerlibrary:subscription-data
|
||||||
|
seba:minifiers-autoprefixer
|
||||||
|
akryum:vue-component
|
||||||
|
akryum:vue-sass
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
METEOR@1.11.1
|
METEOR@2.2.1
|
||||||
|
|||||||
@@ -1,29 +1,27 @@
|
|||||||
accounts-base@1.7.0
|
accounts-base@1.9.0
|
||||||
accounts-google@1.3.3
|
accounts-google@1.3.3
|
||||||
accounts-oauth@1.2.0
|
accounts-oauth@1.2.0
|
||||||
accounts-password@1.6.2
|
accounts-password@1.7.1
|
||||||
accounts-patreon@0.1.0
|
accounts-patreon@0.1.0
|
||||||
accounts-ui@1.3.1
|
|
||||||
accounts-ui-unstyled@1.4.2
|
|
||||||
akryum:npm-check@0.1.2
|
akryum:npm-check@0.1.2
|
||||||
akryum:vue-component@0.15.2
|
akryum:vue-component@0.15.2
|
||||||
akryum:vue-component-dev-client@0.4.7
|
akryum:vue-component-dev-client@0.4.7
|
||||||
akryum:vue-component-dev-server@0.1.4
|
akryum:vue-component-dev-server@0.1.4
|
||||||
akryum:vue-router2@0.2.3
|
akryum:vue-router2@0.2.3
|
||||||
aldeed:collection2@3.2.1
|
akryum:vue-sass@0.1.2
|
||||||
|
aldeed:collection2@3.4.1
|
||||||
aldeed:schema-index@3.0.0
|
aldeed:schema-index@3.0.0
|
||||||
allow-deny@1.1.0
|
allow-deny@1.1.0
|
||||||
autoupdate@1.6.0
|
autoupdate@1.7.0
|
||||||
babel-compiler@7.5.3
|
babel-compiler@7.6.2
|
||||||
babel-runtime@1.5.0
|
babel-runtime@1.5.0
|
||||||
base64@1.0.12
|
base64@1.0.12
|
||||||
binary-heap@1.0.11
|
binary-heap@1.0.11
|
||||||
blaze@2.3.4
|
blaze-tools@1.1.2
|
||||||
blaze-tools@1.0.10
|
|
||||||
boilerplate-generator@1.7.1
|
boilerplate-generator@1.7.1
|
||||||
bozhao:link-accounts@2.2.1
|
bozhao:link-accounts@2.4.0
|
||||||
caching-compiler@1.2.2
|
caching-compiler@1.2.2
|
||||||
caching-html-compiler@1.1.3
|
caching-html-compiler@1.2.1
|
||||||
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
|
||||||
@@ -32,65 +30,56 @@ 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
|
||||||
ddp-client@2.3.3
|
ddp-client@2.4.1
|
||||||
ddp-common@1.4.0
|
ddp-common@1.4.0
|
||||||
ddp-rate-limiter@1.0.9
|
ddp-rate-limiter@1.0.9
|
||||||
ddp-server@2.3.2
|
ddp-server@2.3.3
|
||||||
deps@1.0.12
|
deps@1.0.12
|
||||||
diff-sequence@1.1.1
|
diff-sequence@1.1.1
|
||||||
dynamic-import@0.5.3
|
dynamic-import@0.6.0
|
||||||
ecmascript@0.14.3
|
ecmascript@0.15.1
|
||||||
ecmascript-runtime@0.7.0
|
ecmascript-runtime@0.7.0
|
||||||
ecmascript-runtime-client@0.11.0
|
ecmascript-runtime-client@0.11.1
|
||||||
ecmascript-runtime-server@0.10.0
|
ecmascript-runtime-server@0.10.1
|
||||||
ejson@1.1.1
|
ejson@1.1.1
|
||||||
email@2.0.0
|
email@2.0.0
|
||||||
es5-shim@4.8.0
|
es5-shim@4.8.0
|
||||||
fetch@0.1.1
|
fetch@0.1.1
|
||||||
geojson-utils@1.0.10
|
geojson-utils@1.0.10
|
||||||
google-config-ui@1.0.1
|
|
||||||
google-oauth@1.3.0
|
google-oauth@1.3.0
|
||||||
hot-code-push@1.0.4
|
hot-code-push@1.0.4
|
||||||
html-tools@1.0.11
|
html-tools@1.1.2
|
||||||
htmljs@1.0.11
|
htmljs@1.1.1
|
||||||
http@1.4.2
|
http@1.4.4
|
||||||
id-map@1.1.0
|
id-map@1.1.1
|
||||||
inter-process-messaging@0.1.1
|
inter-process-messaging@0.1.1
|
||||||
jquery@1.11.11
|
|
||||||
lai:collection-extensions@0.2.1_1
|
lai:collection-extensions@0.2.1_1
|
||||||
launch-screen@1.2.0
|
launch-screen@1.2.1
|
||||||
less@2.8.0
|
|
||||||
livedata@1.0.18
|
livedata@1.0.18
|
||||||
lmieulet:meteor-coverage@1.1.4
|
|
||||||
localstorage@1.2.0
|
localstorage@1.2.0
|
||||||
logging@1.1.20
|
logging@1.2.0
|
||||||
mdg:validated-method@1.2.0
|
mdg:validated-method@1.2.0
|
||||||
meteor@1.9.3
|
meteor@1.9.3
|
||||||
meteor-base@1.4.0
|
meteor-base@1.4.0
|
||||||
meteorhacks:picker@1.0.3
|
|
||||||
meteorhacks:subs-manager@1.6.4
|
meteorhacks:subs-manager@1.6.4
|
||||||
meteortesting:browser-tests@1.3.4
|
|
||||||
meteortesting:mocha@1.1.5
|
|
||||||
meteortesting:mocha-core@7.0.1
|
|
||||||
mikowals:batch-insert@1.2.0
|
mikowals:batch-insert@1.2.0
|
||||||
minifier-css@1.5.3
|
minifier-css@1.5.4
|
||||||
minifier-js@2.6.0
|
minifier-js@2.6.1
|
||||||
minimongo@1.6.0
|
minimongo@1.6.2
|
||||||
mobile-experience@1.1.0
|
mobile-experience@1.1.0
|
||||||
mobile-status-bar@1.1.0
|
mobile-status-bar@1.1.0
|
||||||
modern-browsers@0.1.5
|
modern-browsers@0.1.5
|
||||||
modules@0.15.0
|
modules@0.16.0
|
||||||
modules-runtime@0.12.0
|
modules-runtime@0.12.0
|
||||||
momentjs:moment@2.29.1
|
momentjs:moment@2.29.1
|
||||||
mongo@1.10.0
|
mongo@1.11.1
|
||||||
mongo-decimal@0.1.1
|
mongo-decimal@0.1.2
|
||||||
mongo-dev-server@1.1.0
|
mongo-dev-server@1.1.0
|
||||||
mongo-id@1.0.7
|
mongo-id@1.0.8
|
||||||
npm-bcrypt@0.9.3
|
npm-bcrypt@0.9.4
|
||||||
npm-mongo@3.8.1
|
npm-mongo@3.9.0
|
||||||
oauth@1.3.2
|
oauth@1.3.2
|
||||||
oauth2@1.3.0
|
oauth2@1.3.0
|
||||||
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
|
||||||
@@ -104,18 +93,18 @@ peerlibrary:reactive-mongo@0.4.0
|
|||||||
peerlibrary:reactive-publish@0.10.0
|
peerlibrary:reactive-publish@0.10.0
|
||||||
peerlibrary:server-autorun@0.8.0
|
peerlibrary:server-autorun@0.8.0
|
||||||
peerlibrary:subscription-data@0.8.0
|
peerlibrary:subscription-data@0.8.0
|
||||||
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
|
||||||
raix:eventemitter@0.1.3
|
raix:eventemitter@1.0.0
|
||||||
random@1.2.0
|
random@1.2.0
|
||||||
rate-limit@1.0.9
|
rate-limit@1.0.9
|
||||||
|
react-fast-refresh@0.1.1
|
||||||
reactive-dict@1.3.0
|
reactive-dict@1.3.0
|
||||||
reactive-var@1.0.11
|
reactive-var@1.0.11
|
||||||
reload@1.3.0
|
reload@1.3.1
|
||||||
retry@1.1.0
|
retry@1.1.0
|
||||||
routepolicy@1.1.0
|
routepolicy@1.1.0
|
||||||
seba:minifiers-autoprefixer@1.2.1
|
seba:minifiers-autoprefixer@2.0.1
|
||||||
service-configuration@1.0.11
|
service-configuration@1.0.11
|
||||||
session@1.2.0
|
session@1.2.0
|
||||||
sha@1.0.9
|
sha@1.0.9
|
||||||
@@ -123,20 +112,18 @@ shell-server@0.5.0
|
|||||||
simple:json-routes@2.1.0
|
simple:json-routes@2.1.0
|
||||||
simple:rest@1.1.1
|
simple:rest@1.1.1
|
||||||
simple:rest-method-mixin@1.0.1
|
simple:rest-method-mixin@1.0.1
|
||||||
socket-stream-client@0.3.1
|
socket-stream-client@0.3.3
|
||||||
spacebars@1.0.15
|
spacebars-compiler@1.3.0
|
||||||
spacebars-compiler@1.1.3
|
|
||||||
srp@1.1.0
|
srp@1.1.0
|
||||||
standard-minifier-js@2.6.0
|
standard-minifier-js@2.6.1
|
||||||
static-html@1.2.2
|
static-html@1.3.2
|
||||||
templates:array@1.0.3
|
templates:array@1.0.3
|
||||||
templating@1.3.2
|
templating-tools@1.2.1
|
||||||
templating-compiler@1.3.3
|
tmeasday:check-npm-versions@1.0.2
|
||||||
templating-runtime@1.3.2
|
|
||||||
templating-tools@1.1.2
|
|
||||||
tmeasday:check-npm-versions@0.3.2
|
|
||||||
tracker@1.2.0
|
tracker@1.2.0
|
||||||
|
typescript@4.2.2
|
||||||
underscore@1.0.10
|
underscore@1.0.10
|
||||||
url@1.3.1
|
url@1.3.2
|
||||||
webapp@1.9.1
|
webapp@1.10.1
|
||||||
webapp-hashing@1.0.9
|
webapp-hashing@1.1.0
|
||||||
|
zer0th:meteor-vuetify-loader@0.1.30
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet">
|
||||||
<meta name="viewport" content="width=device-width initial-scale=1.0, user-scalable=no">
|
<meta name="viewport" content="width=device-width initial-scale=1.0, user-scalable=no">
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
import '/imports/ui/vueSetup.js';
|
import '/imports/ui/vueSetup.js';
|
||||||
import '/imports/ui/styles/stylesIndex.js';
|
import '/imports/ui/styles/stylesIndex.js';
|
||||||
import '/imports/client/config.js';
|
import '/imports/client/config.js';
|
||||||
|
import '/imports/client/serviceWorker.js';
|
||||||
|
|||||||
6
app/exampleMeteorSettings.json
Normal file
6
app/exampleMeteorSettings.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"public": {
|
||||||
|
"environment": "production",
|
||||||
|
"disablePatreon": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,227 +0,0 @@
|
|||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
|
||||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
|
||||||
import SimpleSchema from 'simpl-schema';
|
|
||||||
import deathSaveSchema from '/imports/api/properties/subSchemas/DeathSavesSchema.js'
|
|
||||||
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
|
||||||
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.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/restCreature.js';
|
|
||||||
|
|
||||||
//set up the collection for creatures
|
|
||||||
let Creatures = new Mongo.Collection('creatures');
|
|
||||||
|
|
||||||
let CreatureSettingsSchema = new SimpleSchema({
|
|
||||||
//slowed down by carrying too much?
|
|
||||||
useVariantEncumbrance: {
|
|
||||||
type: Boolean,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
//hide spellcasting tab
|
|
||||||
hideSpellcasting: {
|
|
||||||
type: Boolean,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
// Swap around the modifier and stat
|
|
||||||
swapStatAndModifier: {
|
|
||||||
type: Boolean,
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
discordWebhook: {
|
|
||||||
type: String,
|
|
||||||
optional: true,
|
|
||||||
max: 200,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
let CreatureSchema = new SimpleSchema({
|
|
||||||
// Strings
|
|
||||||
name: {
|
|
||||||
type: String,
|
|
||||||
defaultValue: '',
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
alignment: {
|
|
||||||
type: String,
|
|
||||||
optional: true
|
|
||||||
},
|
|
||||||
gender: {
|
|
||||||
type: String,
|
|
||||||
optional: true
|
|
||||||
},
|
|
||||||
picture: {
|
|
||||||
type: String,
|
|
||||||
optional: true
|
|
||||||
},
|
|
||||||
avatarPicture: {
|
|
||||||
type: String,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
// Mechanics
|
|
||||||
deathSave: {
|
|
||||||
type: deathSaveSchema,
|
|
||||||
defaultValue: {},
|
|
||||||
},
|
|
||||||
// Stats that are computed and denormalised outside of recomputation
|
|
||||||
denormalizedStats: {
|
|
||||||
type: Object,
|
|
||||||
defaultValue: {},
|
|
||||||
},
|
|
||||||
// Sum of all XP gained by this character
|
|
||||||
'denormalizedStats.xp': {
|
|
||||||
type: SimpleSchema.Integer,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
// Sum of all levels granted by milestone XP
|
|
||||||
'denormalizedStats.milestoneLevels': {
|
|
||||||
type: SimpleSchema.Integer,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
// Sum of all weights of items and containers that are carried
|
|
||||||
'denormalizedStats.weightCarried': {
|
|
||||||
type: Number,
|
|
||||||
defaultValue: 0,
|
|
||||||
},
|
|
||||||
// Version of computation engine that was last used to compute this creature
|
|
||||||
computeVersion: {
|
|
||||||
type: String,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
defaultValue: 'pc',
|
|
||||||
allowedValues: ['pc', 'npc', 'monster'],
|
|
||||||
},
|
|
||||||
damageMultipliers: {
|
|
||||||
type: Object,
|
|
||||||
blackbox: true,
|
|
||||||
defaultValue: {}
|
|
||||||
},
|
|
||||||
variables: {
|
|
||||||
type: Object,
|
|
||||||
blackbox: true,
|
|
||||||
defaultValue: {}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Tabletop
|
|
||||||
tabletop: {
|
|
||||||
type: String,
|
|
||||||
regEx: SimpleSchema.RegEx.id,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
initiativeRoll: {
|
|
||||||
type: SimpleSchema.Integer,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
// Settings
|
|
||||||
settings: {
|
|
||||||
type: CreatureSettingsSchema,
|
|
||||||
defaultValue: {},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
CreatureSchema.extend(ColorSchema);
|
|
||||||
CreatureSchema.extend(SharingSchema);
|
|
||||||
|
|
||||||
Creatures.attachSchema(CreatureSchema);
|
|
||||||
|
|
||||||
const insertCreature = new ValidatedMethod({
|
|
||||||
|
|
||||||
name: 'creatures.insertCreature',
|
|
||||||
|
|
||||||
validate: null,
|
|
||||||
|
|
||||||
mixins: [RateLimiterMixin],
|
|
||||||
rateLimit: {
|
|
||||||
numRequests: 5,
|
|
||||||
timeInterval: 5000,
|
|
||||||
},
|
|
||||||
|
|
||||||
run() {
|
|
||||||
if (!this.userId) {
|
|
||||||
throw new Meteor.Error('Creatures.methods.insert.denied',
|
|
||||||
'You need to be logged in to insert a creature');
|
|
||||||
}
|
|
||||||
assertUserHasPaidBenefits(this.userId);
|
|
||||||
|
|
||||||
// Create the creature document
|
|
||||||
let creatureId = Creatures.insert({
|
|
||||||
owner: this.userId,
|
|
||||||
});
|
|
||||||
CreatureProperties.insert({
|
|
||||||
slotTags: ['base'],
|
|
||||||
quantityExpected: 1,
|
|
||||||
type: 'propertySlot',
|
|
||||||
name: 'Base',
|
|
||||||
description: 'Choose a starting point for your character, this will define the basic setup of your character sheet. Without a base, your sheet will be empty.',
|
|
||||||
hideWhenFull: true,
|
|
||||||
parent: {collection: 'creatures', id: creatureId},
|
|
||||||
ancestors: [{collection: 'creatures', id: creatureId}],
|
|
||||||
order: 0,
|
|
||||||
tags: [],
|
|
||||||
spaceLeft: 1,
|
|
||||||
totalFilled: 0,
|
|
||||||
});
|
|
||||||
this.unblock();
|
|
||||||
return creatureId;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
const updateCreature = new ValidatedMethod({
|
|
||||||
name: 'creatures.update',
|
|
||||||
validate({_id, path}){
|
|
||||||
if (!_id) return false;
|
|
||||||
// Allowed fields
|
|
||||||
let allowedFields = [
|
|
||||||
'name',
|
|
||||||
'alignment',
|
|
||||||
'gender',
|
|
||||||
'picture',
|
|
||||||
'avatarPicture',
|
|
||||||
'color',
|
|
||||||
'settings',
|
|
||||||
];
|
|
||||||
if (!allowedFields.includes(path[0])){
|
|
||||||
throw new Meteor.Error('Creatures.methods.update.denied',
|
|
||||||
'This field can\'t be updated using this method');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mixins: [RateLimiterMixin],
|
|
||||||
rateLimit: {
|
|
||||||
numRequests: 5,
|
|
||||||
timeInterval: 5000,
|
|
||||||
},
|
|
||||||
run({_id, path, value}) {
|
|
||||||
let creature = Creatures.findOne(_id);
|
|
||||||
assertEditPermission(creature, this.userId);
|
|
||||||
if (value === undefined || value === null){
|
|
||||||
Creatures.update(_id, {
|
|
||||||
$unset: {[path.join('.')]: 1},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Creatures.update(_id, {
|
|
||||||
$set: {[path.join('.')]: value},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Creatures;
|
|
||||||
export { CreatureSchema, insertCreature, updateCreature };
|
|
||||||
@@ -1,28 +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,
|
|
||||||
},
|
|
||||||
creatures: {
|
|
||||||
type: Array,
|
|
||||||
defaultValue: [],
|
|
||||||
},
|
|
||||||
'creatures.$': {
|
|
||||||
type: String,
|
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
|
||||||
},
|
|
||||||
owner: {
|
|
||||||
type: String,
|
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
Parties.attachSchema(partySchema);
|
|
||||||
|
|
||||||
export default Parties;
|
|
||||||
@@ -4,7 +4,7 @@ import embedInlineCalculations from '/imports/api/creature/computation/afterComp
|
|||||||
export default function applyAction({prop, log}){
|
export default function applyAction({prop, log}){
|
||||||
let content = { name: prop.name };
|
let content = { name: prop.name };
|
||||||
if (prop.summary){
|
if (prop.summary){
|
||||||
content.description = embedInlineCalculations(
|
content.value = embedInlineCalculations(
|
||||||
prop.summary, prop.summaryCalculations
|
prop.summary, prop.summaryCalculations
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,42 +13,43 @@ export default function applyAdjustment({
|
|||||||
...creature.variables,
|
...creature.variables,
|
||||||
...actionContext,
|
...actionContext,
|
||||||
};
|
};
|
||||||
try {
|
var {result, context} = evaluateString({
|
||||||
var {result, errors} = evaluateString(prop.amount, scope, 'reduce');
|
string: prop.amount,
|
||||||
if (typeof result !== 'number') {
|
scope,
|
||||||
log.content.push({
|
fn: 'reduce'
|
||||||
name: 'Attribute damage',
|
});
|
||||||
error: errors.join(', ') || 'Something went wrong',
|
context.errors.forEach(e => {
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e){
|
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: 'Attribute damage',
|
name: 'Attribute damage error',
|
||||||
error: e.toString(),
|
value: e.message || e.toString(),
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
if (damageTargets) {
|
if (damageTargets) {
|
||||||
damageTargets.forEach(target => {
|
damageTargets.forEach(target => {
|
||||||
if (prop.target === 'each'){
|
if (prop.target === 'each'){
|
||||||
result = evaluateString(prop.amount, scope, 'reduce');
|
({result} = evaluateString({
|
||||||
|
string: prop.amount,
|
||||||
|
scope,
|
||||||
|
fn: 'reduce'
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
damagePropertiesByName.call({
|
damagePropertiesByName.call({
|
||||||
creatureId: target._id,
|
creatureId: target._id,
|
||||||
variableName: prop.stat,
|
variableName: prop.stat,
|
||||||
operation: prop.operation || 'increment',
|
operation: prop.operation || 'increment',
|
||||||
value: result
|
value: result.value,
|
||||||
});
|
});
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: 'Attribute damage',
|
name: 'Attribute damage',
|
||||||
resultPrefix: `${prop.stat} ${prop.operation === 'set' ? 'set to' : ''}`,
|
value: `${prop.stat}${prop.operation === 'set' ? ' set to' : ''}` +
|
||||||
result: `${-result}`,
|
` ${result.isNumber ? -result.value : result.toString()}`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: 'Attribute damage',
|
name: 'Attribute damage',
|
||||||
resultPrefix: `${prop.stat} ${prop.operation === 'set' ? 'set to' : ''}`,
|
value: `${prop.stat}${prop.operation === 'set' ? ' set to' : ''}` +
|
||||||
result: `${-result}`,
|
` ${result.isNumber ? -result.value : result.toString()}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ export default function applyAttack({
|
|||||||
|
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: criticalHit ? 'Critical Hit!' : 'To Hit',
|
name: criticalHit ? 'Critical Hit!' : 'To Hit',
|
||||||
resultPrefix: `1d20 [${value}] + ${prop.rollBonusResult} = `,
|
value: `1d20 [${value}] + ${prop.rollBonusResult} = ` + result,
|
||||||
result,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,75 +15,101 @@ export default function applyDamage({
|
|||||||
...creature.variables,
|
...creature.variables,
|
||||||
...actionContext,
|
...actionContext,
|
||||||
};
|
};
|
||||||
|
// Add the target's variables to the scope
|
||||||
if (targets.length === 1){
|
if (targets.length === 1){
|
||||||
scope.target = targets[0].variables;
|
scope.target = targets[0].variables;
|
||||||
}
|
}
|
||||||
|
// Determine if the hit is critical
|
||||||
let criticalHit = !!(
|
let criticalHit = !!(
|
||||||
actionContext.criticalHit &&
|
actionContext.criticalHit &&
|
||||||
actionContext.criticalHit.value &&
|
actionContext.criticalHit.value &&
|
||||||
prop.damageType !== 'healing' // Can't critically heal
|
prop.damageType !== 'healing' // Can't critically heal
|
||||||
);
|
);
|
||||||
|
// Double the damage rolls if the hit is critical
|
||||||
let context = new CompilationContext({
|
let context = new CompilationContext({
|
||||||
doubleRolls: criticalHit,
|
doubleRolls: criticalHit,
|
||||||
});
|
});
|
||||||
try {
|
|
||||||
var {result, errors} = evaluateString(prop.amount, scope, 'reduce', context);
|
// Compute the roll the first time, logging any errors
|
||||||
if (typeof result !== 'number') {
|
var {result} = evaluateString({
|
||||||
log.content.push({
|
string: prop.amount,
|
||||||
error: errors.join(', '),
|
scope,
|
||||||
});
|
fn: 'reduce',
|
||||||
}
|
context
|
||||||
} catch (e){
|
});
|
||||||
|
|
||||||
|
// If the result is an error bail out now
|
||||||
|
if (result.constructor.name === 'ErrorNode'){
|
||||||
log.content.push({
|
log.content.push({
|
||||||
error: e.toString(),
|
name: 'Damage error',
|
||||||
|
value: result.toString(),
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
let suffix = (criticalHit ? ' critical ' : '') +
|
|
||||||
|
// Memoise the damage suffix for the log
|
||||||
|
let suffix = (criticalHit ? ' critical ' : ' ') +
|
||||||
prop.damageType +
|
prop.damageType +
|
||||||
(prop.damageType !== 'healing' ? ' damage': '');
|
(prop.damageType !== ' healing ' ? ' damage ': '');
|
||||||
|
|
||||||
if (damageTargets && damageTargets.length) {
|
if (damageTargets && damageTargets.length) {
|
||||||
|
// Iterate through all the targets
|
||||||
damageTargets.forEach(target => {
|
damageTargets.forEach(target => {
|
||||||
let name = prop.damageType === 'healing' ? 'Healing' : 'Damage';
|
let name = prop.damageType === 'healing' ? 'Healing' : 'Damage';
|
||||||
|
|
||||||
|
// Reroll the damage if needed
|
||||||
if (prop.target === 'each'){
|
if (prop.target === 'each'){
|
||||||
result = evaluateString(prop.amount, scope, 'reduce');
|
({result, context} = evaluateString({
|
||||||
|
string: prop.amount,
|
||||||
|
scope,
|
||||||
|
fn: 'reduce'
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
// If the result is an error or not a number bail out now
|
||||||
|
if (result.constructor.name === 'ErrorNode' || !result.isNumber){
|
||||||
|
log.content.push({
|
||||||
|
name: 'Damage error',
|
||||||
|
value: result.toString(),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal the damage to the target
|
||||||
let damageDealt = dealDamage.call({
|
let damageDealt = dealDamage.call({
|
||||||
creatureId: target._id,
|
creatureId: target._id,
|
||||||
damageType: prop.damageType,
|
damageType: prop.damageType,
|
||||||
amount: result,
|
amount: result.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Log the damage done
|
||||||
if (target._id === creature._id){
|
if (target._id === creature._id){
|
||||||
|
// Target is same as self, log damage as such
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name,
|
name,
|
||||||
result: damageDealt,
|
value: damageDealt + suffix + ' to self',
|
||||||
details: suffix + 'to self',
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name,
|
name,
|
||||||
resultPrefix: 'Dealt ',
|
value: 'Dealt ' + damageDealt + suffix + ` ${target.name && ' to '}${target.name}`,
|
||||||
result: damageDealt,
|
|
||||||
details: suffix + `${target.name && ' to '}${target.name}`,
|
|
||||||
});
|
});
|
||||||
|
// Log the damage received on that creature's log as well
|
||||||
insertCreatureLog.call({
|
insertCreatureLog.call({
|
||||||
log: {
|
log: {
|
||||||
|
creatureId: target._id,
|
||||||
content: [{
|
content: [{
|
||||||
name,
|
name,
|
||||||
resultPrefix: 'Recieved ',
|
value: 'Recieved ' + damageDealt + suffix,
|
||||||
result: damageDealt,
|
|
||||||
details: suffix,
|
|
||||||
}],
|
}],
|
||||||
creatureId: target._id,
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// There are no targets, just log the result
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: prop.damageType === 'healing' ? 'Healing' : 'Damage',
|
name: prop.damageType === 'healing' ? 'Healing' : 'Damage',
|
||||||
result,
|
value: result.toString() + suffix,
|
||||||
details: suffix,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import applySave from '/imports/api/creature/actions/applySave.js';
|
|||||||
function applyProperty(options){
|
function applyProperty(options){
|
||||||
let prop = options.prop;
|
let prop = options.prop;
|
||||||
if (prop.type === 'buff'){
|
if (prop.type === 'buff'){
|
||||||
// ignore only applied buffs
|
// ignore only applied buffs, don't apply them again
|
||||||
if (prop.applied === true){
|
if (prop.applied === true){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ function applyProperty(options){
|
|||||||
break;
|
break;
|
||||||
case 'buff':
|
case 'buff':
|
||||||
applyBuff(options);
|
applyBuff(options);
|
||||||
break;
|
return false;
|
||||||
case 'toggle':
|
case 'toggle':
|
||||||
return applyToggle(options);
|
return applyToggle(options);
|
||||||
case 'roll':
|
case 'roll':
|
||||||
@@ -52,23 +52,25 @@ function applyProperty(options){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyPropertyAndWalkChildren({prop, child, targets, ...options}){
|
function applyPropertyAndWalkChildren({prop, children, targets, ...options}){
|
||||||
let shouldKeepWalking = applyProperty({ prop, targets, ...options });
|
let shouldKeepWalking = applyProperty({ prop, children, targets, ...options });
|
||||||
if (shouldKeepWalking){
|
if (shouldKeepWalking){
|
||||||
applyProperties({ forest: child.children, targets, ...options,});
|
applyProperties({ forest: children, targets, ...options,});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function applyProperties({ forest, targets, ...options}){
|
export default function applyProperties({ forest, targets, ...options}){
|
||||||
forest.forEach(child => {
|
forest.forEach(node => {
|
||||||
let prop = child.node;
|
let prop = node.node;
|
||||||
if (shouldSplit(prop)){
|
options.actionContext[`#${prop.type}`] = prop;
|
||||||
|
let children = node.children;
|
||||||
|
if (shouldSplit(prop) && targets.length){
|
||||||
targets.forEach(target => {
|
targets.forEach(target => {
|
||||||
let targets = [target]
|
let targets = [target]
|
||||||
applyPropertyAndWalkChildren({ targets, prop, child, ...options});
|
applyPropertyAndWalkChildren({ targets, prop, children, ...options});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
applyPropertyAndWalkChildren({prop, child, targets, ...options});
|
applyPropertyAndWalkChildren({prop, children, targets, ...options});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,23 +10,16 @@ export default function applyRoll({
|
|||||||
...creature.variables,
|
...creature.variables,
|
||||||
...actionContext,
|
...actionContext,
|
||||||
};
|
};
|
||||||
try {
|
var {result} = evaluateString({
|
||||||
var {result, errors} = evaluateString(prop.roll, scope, 'reduce');
|
string: prop.roll,
|
||||||
actionContext[prop.variableName] = result;
|
scope,
|
||||||
log.content.push({
|
fn: 'reduce'
|
||||||
name: prop.name,
|
});
|
||||||
resultPrefix: prop.variableName + ' = ' + prop.roll + ' = ',
|
if (result.isNumber){
|
||||||
result,
|
actionContext[prop.variableName] = result.value;
|
||||||
});
|
|
||||||
if (errors.length) {
|
|
||||||
log.content.push({
|
|
||||||
error: errors.join(', '),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e){
|
|
||||||
log.content.push({
|
|
||||||
error: e.toString(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
log.content.push({
|
||||||
|
name: prop.name,
|
||||||
|
value: prop.variableName + ' = ' + prop.roll + ' = ' + result.toString(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,19 +14,16 @@ export default function applySave({
|
|||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
// Calculate the DC
|
// Calculate the DC
|
||||||
var {result, errors} = evaluateString(prop.dc, scope, 'reduce');
|
var {result} = evaluateString({
|
||||||
let dc = result;
|
string: prop.dc,
|
||||||
|
scope,
|
||||||
|
fn: 'reduce'
|
||||||
|
});
|
||||||
|
let dc = result.value;
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: prop.name,
|
name: prop.name,
|
||||||
resultPrefix: ' DC ',
|
value: ' DC ' + result.toString(),
|
||||||
result,
|
|
||||||
});
|
});
|
||||||
if (errors.length) {
|
|
||||||
log.content.push({
|
|
||||||
error: errors.join(', '),
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (prop.target === 'self'){
|
if (prop.target === 'self'){
|
||||||
let save = CreaturesProperties.findOne({
|
let save = CreaturesProperties.findOne({
|
||||||
'ancestors.id': creature._id,
|
'ancestors.id': creature._id,
|
||||||
@@ -38,7 +35,8 @@ export default function applySave({
|
|||||||
});
|
});
|
||||||
if (!save){
|
if (!save){
|
||||||
log.content.push({
|
log.content.push({
|
||||||
error: 'No saving throw found: ' + prop.stat,
|
name: 'Saving throw error',
|
||||||
|
value: 'No saving throw found: ' + prop.stat,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -62,9 +60,7 @@ export default function applySave({
|
|||||||
let saveSuccess = result >= dc;
|
let saveSuccess = result >= dc;
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: 'Save',
|
name: 'Save',
|
||||||
resultPrefix,
|
value: resultPrefix + result + (saveSuccess ? 'Passed' : 'Failed')
|
||||||
result,
|
|
||||||
details: saveSuccess ? 'Passed' : 'Failed'
|
|
||||||
});
|
});
|
||||||
return !saveSuccess;
|
return !saveSuccess;
|
||||||
} else {
|
} else {
|
||||||
@@ -73,7 +69,8 @@ export default function applySave({
|
|||||||
}
|
}
|
||||||
} catch (e){
|
} catch (e){
|
||||||
log.content.push({
|
log.content.push({
|
||||||
error: e.toString(),
|
name: 'Save error',
|
||||||
|
value: e.toString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,23 +13,21 @@ export default function applyToggle({
|
|||||||
if (Number.isFinite(+prop.condition)){
|
if (Number.isFinite(+prop.condition)){
|
||||||
return !!+prop.condition;
|
return !!+prop.condition;
|
||||||
}
|
}
|
||||||
try {
|
var {result} = evaluateString({
|
||||||
var {result, errors} = evaluateString(prop.condition, scope, 'reduce');
|
string: prop.condition,
|
||||||
if (typeof result !== 'number' && typeof result !== 'boolean') {
|
scope,
|
||||||
log.content.push({
|
fn: 'reduce'
|
||||||
error: errors.join(', '),
|
});
|
||||||
});
|
if (result.constructor.name === 'ErrorNode') {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: prop.name,
|
name: 'Toggle error',
|
||||||
resultPrefix: prop.condition + ' = ',
|
value: result.toString(),
|
||||||
result,
|
|
||||||
});
|
|
||||||
return !!result;
|
|
||||||
} catch (e){
|
|
||||||
log.content.push({
|
|
||||||
error: e.toString(),
|
|
||||||
});
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
log.content.push({
|
||||||
|
name: prop.name || 'Toggle',
|
||||||
|
value: prop.condition + ' = ' + result.toString(),
|
||||||
|
});
|
||||||
|
return !!result.value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ 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 { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import { damagePropertyWork } from '/imports/api/creature/creatureProperties/methods/damageProperty.js';
|
import { damagePropertyWork } from '/imports/api/creature/creatureProperties/methods/damageProperty.js';
|
||||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
import { doActionWork } from '/imports/api/creature/actions/doAction.js';
|
import { doActionWork } from '/imports/api/creature/actions/doAction.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
|
import getAncestorContext from '/imports/api/creature/actions/getAncestorContext.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory';
|
||||||
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties';
|
||||||
|
|
||||||
const castSpellWithSlot = new ValidatedMethod({
|
const castSpellWithSlot = new ValidatedMethod({
|
||||||
name: 'creatureProperties.castSpellWithSlot',
|
name: 'creatureProperties.castSpellWithSlot',
|
||||||
@@ -61,16 +64,26 @@ const castSpellWithSlot = new ValidatedMethod({
|
|||||||
value: 1,
|
value: 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
doActionWork({
|
let actionContext = getAncestorContext(spell);
|
||||||
|
|
||||||
|
doActionWork({
|
||||||
action: spell,
|
action: spell,
|
||||||
context: {slotLevel},
|
actionContext: {slotLevel, ...actionContext},
|
||||||
creature,
|
creature,
|
||||||
target,
|
targets: target ? [target] : [],
|
||||||
method: this,
|
method: this,
|
||||||
});
|
});
|
||||||
// Note this only recomputes the top-level creature, not the nearest one
|
|
||||||
recomputeCreatureByDoc(creature);
|
// Note these lines only recompute the top-level creature, not the nearest one
|
||||||
|
// The acting creature might have a new item
|
||||||
|
recomputeInventory(creature._id);
|
||||||
|
// The spell might add properties which need to be activated
|
||||||
|
recomputeInactiveProperties(creature._id);
|
||||||
|
recomputeCreatureByDoc(creature);
|
||||||
|
|
||||||
if (target){
|
if (target){
|
||||||
|
recomputeInventory(target._id);
|
||||||
|
recomputeInactiveProperties(target._id);
|
||||||
recomputeCreatureByDoc(target);
|
recomputeCreatureByDoc(target);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ 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 { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import { CreatureLogSchema, insertCreatureLogWork } from '/imports/api/creature/log/CreatureLogs.js';
|
import { CreatureLogSchema, insertCreatureLogWork } from '/imports/api/creature/log/CreatureLogs.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
import { nodesToTree } from '/imports/api/parenting/parenting.js';
|
import nodesToTree from '/imports/api/parenting/nodesToTree.js';
|
||||||
import applyProperties from '/imports/api/creature/actions/applyProperties.js';
|
import applyProperties from '/imports/api/creature/actions/applyProperties.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
|
import getAncestorContext from '/imports/api/creature/actions/getAncestorContext.js';
|
||||||
|
|
||||||
const doAction = new ValidatedMethod({
|
const doAction = new ValidatedMethod({
|
||||||
name: 'creatureProperties.doAction',
|
name: 'creatureProperties.doAction',
|
||||||
@@ -34,6 +37,10 @@ const doAction = new ValidatedMethod({
|
|||||||
let action = CreatureProperties.findOne(actionId);
|
let action = CreatureProperties.findOne(actionId);
|
||||||
// Check permissions
|
// Check permissions
|
||||||
let creature = getRootCreatureAncestor(action);
|
let creature = getRootCreatureAncestor(action);
|
||||||
|
|
||||||
|
// Build ancestor context
|
||||||
|
let actionContext = getAncestorContext(action);
|
||||||
|
|
||||||
assertEditPermission(creature, this.userId);
|
assertEditPermission(creature, this.userId);
|
||||||
let targets = [];
|
let targets = [];
|
||||||
targetIds.forEach(targetId => {
|
targetIds.forEach(targetId => {
|
||||||
@@ -41,11 +48,18 @@ const doAction = new ValidatedMethod({
|
|||||||
assertEditPermission(target, this.userId);
|
assertEditPermission(target, this.userId);
|
||||||
targets.push(target);
|
targets.push(target);
|
||||||
});
|
});
|
||||||
doActionWork({action, creature, targets, method: this});
|
doActionWork({action, creature, targets, actionContext, method: this});
|
||||||
|
|
||||||
|
// The acting creature might have used ammo
|
||||||
|
recomputeInventory(creature._id);
|
||||||
|
|
||||||
|
// The action might add properties which need to be activated
|
||||||
|
recomputeInactiveProperties(creature._id);
|
||||||
|
|
||||||
// recompute creatures
|
// recompute creatures
|
||||||
recomputeCreatureByDoc(creature);
|
recomputeCreatureByDoc(creature);
|
||||||
targets.forEach(target => {
|
targets.forEach(target => {
|
||||||
|
recomputeInactiveProperties(target._id);
|
||||||
recomputeCreatureByDoc(target);
|
recomputeCreatureByDoc(target);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -55,7 +69,7 @@ export function doActionWork({
|
|||||||
action,
|
action,
|
||||||
creature,
|
creature,
|
||||||
targets,
|
targets,
|
||||||
context = {},
|
actionContext = {},
|
||||||
method
|
method
|
||||||
}){
|
}){
|
||||||
// Create the log
|
// Create the log
|
||||||
@@ -74,7 +88,7 @@ export function doActionWork({
|
|||||||
}];
|
}];
|
||||||
applyProperties({
|
applyProperties({
|
||||||
forest: startingForest,
|
forest: startingForest,
|
||||||
actionContext: context,
|
actionContext,
|
||||||
creature,
|
creature,
|
||||||
targets,
|
targets,
|
||||||
log,
|
log,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
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 { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
import roll from '/imports/parser/roll.js';
|
import roll from '/imports/parser/roll.js';
|
||||||
|
|
||||||
const doCheck = new ValidatedMethod({
|
const doCheck = new ValidatedMethod({
|
||||||
|
|||||||
15
app/imports/api/creature/actions/getAncestorContext.js
Normal file
15
app/imports/api/creature/actions/getAncestorContext.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
|
||||||
|
export default function getAncestorContext(prop){
|
||||||
|
// Build ancestor context
|
||||||
|
const actionContext = {};
|
||||||
|
let ancestorIds = prop.ancestors.map(ref => ref.id);
|
||||||
|
CreatureProperties.find({
|
||||||
|
_id: {$in: ancestorIds}
|
||||||
|
}, {
|
||||||
|
sort: {order: 1},
|
||||||
|
}).forEach(ancestor => {
|
||||||
|
actionContext[`#${ancestor.type}`] = ancestor;
|
||||||
|
});
|
||||||
|
return actionContext;
|
||||||
|
}
|
||||||
@@ -61,7 +61,7 @@ export default function spendResources({prop, log}){
|
|||||||
});
|
});
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: 'Uses left',
|
name: 'Uses left',
|
||||||
result: prop.usesResult - prop.usesUsed - 1,
|
value: prop.usesResult - (prop.usesUsed || 0) - 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,10 +84,10 @@ export default function spendResources({prop, log}){
|
|||||||
// Log all the spending
|
// Log all the spending
|
||||||
if (gainLog.length) log.content.push({
|
if (gainLog.length) log.content.push({
|
||||||
name: 'Gained',
|
name: 'Gained',
|
||||||
description: gainLog.join('\n'),
|
value: gainLog.join('\n'),
|
||||||
});
|
});
|
||||||
if (spendLog.length) log.content.push({
|
if (spendLog.length) log.content.push({
|
||||||
name: 'Spent',
|
name: 'Spent',
|
||||||
description: spendLog.join('\n'),
|
value: spendLog.join('\n'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
57
app/imports/api/creature/archive/ArchivedCreatures.js
Normal file
57
app/imports/api/creature/archive/ArchivedCreatures.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
|
||||||
|
// Archived creatures is an immutable collection of creatures that are no longer
|
||||||
|
// in use and can be safely archived by the mongoDB hosting service.
|
||||||
|
// It keeps the working datasets like creatureProperties much smaller
|
||||||
|
// than they would otherwise be.
|
||||||
|
let ArchivedCreatures = new Mongo.Collection('archivedCreatures');
|
||||||
|
|
||||||
|
// We use blackbox objects for everything:
|
||||||
|
// - saves time checking every object against a schema
|
||||||
|
// - doesn't accidentaly create indices defined in subschemas
|
||||||
|
// - The objects we are archiving have already been checked against their
|
||||||
|
// own schemas
|
||||||
|
let ArchivedCreatureSchema = new SimpleSchema({
|
||||||
|
owner: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
// The primary index on this collection
|
||||||
|
index: 1,
|
||||||
|
},
|
||||||
|
archiveDate: {
|
||||||
|
type: Date,
|
||||||
|
// Indexed so the archiving system can archive documents when they
|
||||||
|
// get to a certain age
|
||||||
|
index: 1,
|
||||||
|
},
|
||||||
|
creature: {
|
||||||
|
type: Object,
|
||||||
|
blackbox: true,
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
type: Array,
|
||||||
|
},
|
||||||
|
'properties.$': {
|
||||||
|
type: Object,
|
||||||
|
blackbox: true,
|
||||||
|
},
|
||||||
|
experiences: {
|
||||||
|
type: Array,
|
||||||
|
},
|
||||||
|
'experiences.$': {
|
||||||
|
type: Object,
|
||||||
|
blackbox: true,
|
||||||
|
},
|
||||||
|
logs: {
|
||||||
|
type: Array,
|
||||||
|
},
|
||||||
|
'logs.$': {
|
||||||
|
type: Object,
|
||||||
|
blackbox: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
ArchivedCreatures.attachSchema(ArchivedCreatureSchema);
|
||||||
|
|
||||||
|
import '/imports/api/creature/archive/methods/index.js';
|
||||||
|
export default ArchivedCreatures;
|
||||||
66
app/imports/api/creature/archive/methods/archiveCreatures.js
Normal file
66
app/imports/api/creature/archive/methods/archiveCreatures.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
import { assertOwnership } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
||||||
|
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
||||||
|
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature.js';
|
||||||
|
import ArchivedCreatures from '/imports/api/creature/archive/ArchivedCreatures.js';
|
||||||
|
|
||||||
|
function archiveCreature(creatureId){
|
||||||
|
// Build the archive document
|
||||||
|
const creature = Creatures.findOne(creatureId);
|
||||||
|
const properties = CreatureProperties.find({'ancestors.id': creatureId}).fetch();
|
||||||
|
const experiences = Experiences.find({creatureId}).fetch();
|
||||||
|
const logs = CreatureLogs.find({creatureId}).fetch();
|
||||||
|
let archiveCreature = {
|
||||||
|
owner: creature.owner,
|
||||||
|
archiveDate: new Date(),
|
||||||
|
creature,
|
||||||
|
properties,
|
||||||
|
experiences,
|
||||||
|
logs,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Insert it
|
||||||
|
let id = ArchivedCreatures.insert(archiveCreature);
|
||||||
|
|
||||||
|
// Remove the original creature
|
||||||
|
removeCreatureWork(creatureId);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const archiveCreatures = new ValidatedMethod({
|
||||||
|
name: 'Creatures.methods.archiveCreatures',
|
||||||
|
validate: new SimpleSchema({
|
||||||
|
creatureIds: {
|
||||||
|
type: Array,
|
||||||
|
max: 10,
|
||||||
|
},
|
||||||
|
'creatureIds.$': {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
},
|
||||||
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 1,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({creatureIds}) {
|
||||||
|
for (let id of creatureIds){
|
||||||
|
assertOwnership(id, this.userId)
|
||||||
|
}
|
||||||
|
let archivedIds = [];
|
||||||
|
for (let id of creatureIds){
|
||||||
|
let archivedId = archiveCreature(id);
|
||||||
|
archivedIds.push(archivedId);
|
||||||
|
}
|
||||||
|
return archivedIds;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default archiveCreatures;
|
||||||
2
app/imports/api/creature/archive/methods/index.js
Normal file
2
app/imports/api/creature/archive/methods/index.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import '/imports/api/creature/archive/methods/archiveCreatures.js';
|
||||||
|
import '/imports/api/creature/archive/methods/restoreCreatures.js';
|
||||||
77
app/imports/api/creature/archive/methods/restoreCreatures.js
Normal file
77
app/imports/api/creature/archive/methods/restoreCreatures.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
import { assertOwnership } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
||||||
|
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
||||||
|
import ArchivedCreatures from '/imports/api/creature/archive/ArchivedCreatures.js';
|
||||||
|
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature.js';
|
||||||
|
|
||||||
|
function restoreCreature(archiveId){
|
||||||
|
// Get the archive
|
||||||
|
const archivedCreature = ArchivedCreatures.findOne(archiveId);
|
||||||
|
|
||||||
|
// Insert the creature sub documents
|
||||||
|
// They still have their original _id's
|
||||||
|
Creatures.insert(archivedCreature.creature);
|
||||||
|
try {
|
||||||
|
// Add all the properties
|
||||||
|
if (archivedCreature.properties && archivedCreature.properties.length){
|
||||||
|
CreatureProperties.batchInsert(archivedCreature.properties);
|
||||||
|
}
|
||||||
|
if (archivedCreature.experiences && archivedCreature.experiences.length){
|
||||||
|
Experiences.batchInsert(archivedCreature.experiences);
|
||||||
|
}
|
||||||
|
if (archivedCreature.logs && archivedCreature.logs.length){
|
||||||
|
CreatureLogs.batchInsert(archivedCreature.logs);
|
||||||
|
}
|
||||||
|
// Remove the archived creature
|
||||||
|
ArchivedCreatures.remove(archiveId);
|
||||||
|
} catch (e) {
|
||||||
|
// If the above fails, delete the inserted creature
|
||||||
|
removeCreatureWork(archivedCreature.creature._id);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not recompute. The creature was in a computed and ordered state when
|
||||||
|
// we archived it, just restore everything as-is
|
||||||
|
|
||||||
|
return archivedCreature.creature._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const restoreCreatures = new ValidatedMethod({
|
||||||
|
name: 'Creatures.methods.restoreCreatures',
|
||||||
|
validate: new SimpleSchema({
|
||||||
|
archiveIds: {
|
||||||
|
type: Array,
|
||||||
|
max: 10,
|
||||||
|
},
|
||||||
|
'archiveIds.$': {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
},
|
||||||
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 1,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({archiveIds}) {
|
||||||
|
for (let id of archiveIds){
|
||||||
|
let archivedCreature = ArchivedCreatures.findOne(id, {
|
||||||
|
fields: {owner: 1}
|
||||||
|
});
|
||||||
|
assertOwnership(archivedCreature, this.userId)
|
||||||
|
}
|
||||||
|
let creatureIds = [];
|
||||||
|
for (let id of archiveIds){
|
||||||
|
let creatureId = restoreCreature(id);
|
||||||
|
creatureIds.push(creatureId);
|
||||||
|
}
|
||||||
|
return creatureIds;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default restoreCreatures;
|
||||||
@@ -4,8 +4,8 @@ export default function embedInlineCalculations(string, calculations){
|
|||||||
if (!string) return '';
|
if (!string) return '';
|
||||||
if (!calculations) return string;
|
if (!calculations) return string;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
return string.replace(INLINE_CALCULATION_REGEX, () => {
|
return string.replace(INLINE_CALCULATION_REGEX, substring => {
|
||||||
let comp = calculations && calculations[index++];
|
let comp = calculations && calculations[index++];
|
||||||
return comp && comp.result ? comp.result : string;
|
return (comp && 'result' in comp) ? comp.result : substring;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,67 @@
|
|||||||
import { parse, CompilationContext } from '/imports/parser/parser.js';
|
import { parse, CompilationContext } from '/imports/parser/parser.js';
|
||||||
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
|
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
|
||||||
|
import SymbolNode from '/imports/parser/parseTree/SymbolNode.js';
|
||||||
|
import ErrorNode from '/imports/parser/parseTree/ErrorNode.js';
|
||||||
|
|
||||||
export default function evaluateString(string, scope, fn = 'compile', context){
|
//TODO replace constants with their parsed node
|
||||||
let errors = [];
|
|
||||||
|
export default function evaluateString({string, scope, fn = 'compile', context}){
|
||||||
|
if (!context){
|
||||||
|
context = new CompilationContext({});
|
||||||
|
}
|
||||||
if (!string){
|
if (!string){
|
||||||
errors.push('No string provided');
|
context.storeError('No string provided');
|
||||||
return {result: string, errors};
|
return {result: {value: string}, context};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!scope) errors.push('No scope provided');
|
if (!scope) context.storeError('No scope provided');
|
||||||
|
|
||||||
// Parse the string using mathjs
|
// Parse the string using mathjs
|
||||||
let node;
|
let node;
|
||||||
try {
|
try {
|
||||||
node = parse(string);
|
node = parse(string);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errors.push(e);
|
context.storeError(e);
|
||||||
return {result: string, errors};
|
return {result: {value: string}, context};
|
||||||
}
|
|
||||||
if (!context){
|
|
||||||
context = new CompilationContext({});
|
|
||||||
}
|
}
|
||||||
|
node = replaceConstants({calc: node, context, scope});
|
||||||
let result = node[fn](scope, context);
|
let result = node[fn](scope, context);
|
||||||
if (result instanceof ConstantNode){
|
return {result, context};
|
||||||
return {result: result.value, errors: context.errors}
|
}
|
||||||
} else {
|
|
||||||
return {result: result.toString(), errors: context.errors};
|
// Replace constants in the calc with the right ParseNodes
|
||||||
}
|
function replaceConstants({calc, context, scope}){
|
||||||
|
let constFailed = [];
|
||||||
|
calc = calc.replaceNodes(node => {
|
||||||
|
if (!(node instanceof SymbolNode)) return;
|
||||||
|
let constant = scope[node.name];
|
||||||
|
// replace constants that aren't overridden by stats or disabled by a toggle
|
||||||
|
if (constant && constant.type === 'constant'){
|
||||||
|
// Fail if the constant has errors
|
||||||
|
if (constant.errors && constant.errors.length){
|
||||||
|
constFailed.push(node.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let parsedConstantNode;
|
||||||
|
try {
|
||||||
|
parsedConstantNode = parse(constant.calculation);
|
||||||
|
} catch(e){
|
||||||
|
constFailed.push(node.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!parsedConstantNode) constFailed.push(node.name);
|
||||||
|
return parsedConstantNode;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
constFailed.forEach(name => {
|
||||||
|
context.storeError({
|
||||||
|
type: 'error',
|
||||||
|
message: `${name} is a constant property with parsing errors`
|
||||||
|
});
|
||||||
|
});
|
||||||
|
let failed = !!constFailed.length;
|
||||||
|
if (failed){
|
||||||
|
calc = new ErrorNode({error: 'Failed to replace constants'});
|
||||||
|
}
|
||||||
|
return calc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
|
|
||||||
|
|
||||||
// Strings can have computations in bracers like so: {computation}
|
|
||||||
export default function evalutateStringWithEmbeddedCalculations(string, scope){
|
|
||||||
console.warn('evalutateStringWithEmbeddedCalculations should be replaced with ' +
|
|
||||||
'fetching the result from the compuations on the property doc');
|
|
||||||
if (!string) return string;
|
|
||||||
// Compute everything inside bracers
|
|
||||||
return string.replace(/\{([^{}]*)\}/g, function(match, p1){
|
|
||||||
let {result} = evaluateString(p1, scope);
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -7,6 +7,7 @@ export default class ComputationMemo {
|
|||||||
constructor(props, creature){
|
constructor(props, creature){
|
||||||
this.statsByVariableName = {};
|
this.statsByVariableName = {};
|
||||||
this.constantsByVariableName = {};
|
this.constantsByVariableName = {};
|
||||||
|
this.constantsById = {};
|
||||||
this.extraStatsByVariableName = {};
|
this.extraStatsByVariableName = {};
|
||||||
this.statsById = {};
|
this.statsById = {};
|
||||||
this.originalPropsById = {};
|
this.originalPropsById = {};
|
||||||
@@ -77,11 +78,7 @@ export default class ComputationMemo {
|
|||||||
}
|
}
|
||||||
addConstant(prop){
|
addConstant(prop){
|
||||||
prop = this.registerProperty(prop);
|
prop = this.registerProperty(prop);
|
||||||
if (
|
this.constantsById[prop._id] = prop;
|
||||||
!this.constantsByVariableName[prop.variableName]
|
|
||||||
){
|
|
||||||
this.constantsByVariableName[prop.variableName] = prop
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
registerProperty(prop){
|
registerProperty(prop){
|
||||||
this.originalPropsById[prop._id] = cloneDeep(prop);
|
this.originalPropsById[prop._id] = cloneDeep(prop);
|
||||||
@@ -107,31 +104,10 @@ export default class ComputationMemo {
|
|||||||
let variableName = prop.variableName;
|
let variableName = prop.variableName;
|
||||||
if (!variableName) return;
|
if (!variableName) return;
|
||||||
let existingStat = this.statsByVariableName[variableName];
|
let existingStat = this.statsByVariableName[variableName];
|
||||||
|
prop = this.registerProperty(prop);
|
||||||
if (existingStat){
|
if (existingStat){
|
||||||
existingStat.computationDetails.idsOfSameName.push(prop._id);
|
existingStat.computationDetails.idsOfSameName.push(prop._id);
|
||||||
this.originalPropsById[prop._id] = cloneDeep(prop);
|
|
||||||
if (prop.baseValueCalculation){
|
|
||||||
existingStat.computationDetails.effects.push({
|
|
||||||
operation: 'base',
|
|
||||||
calculation: prop.baseValueCalculation,
|
|
||||||
stats: [variableName],
|
|
||||||
computationDetails: propDetailsByType.effect(),
|
|
||||||
statBase: true,
|
|
||||||
dependencies: [],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (prop.baseProficiency){
|
|
||||||
existingStat.computationDetails.proficiencies.push({
|
|
||||||
value: prop.baseProficiency,
|
|
||||||
stats: [variableName],
|
|
||||||
computationDetails: propDetailsByType.proficiency(),
|
|
||||||
type: 'proficiency',
|
|
||||||
statBase: true,
|
|
||||||
dependencies: [],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
prop = this.registerProperty(prop);
|
|
||||||
this.statsById[prop._id] = prop;
|
this.statsById[prop._id] = prop;
|
||||||
this.statsByVariableName[variableName] = prop;
|
this.statsByVariableName[variableName] = prop;
|
||||||
if (
|
if (
|
||||||
@@ -193,7 +169,9 @@ export default class ComputationMemo {
|
|||||||
prop = this.registerProperty(prop);
|
prop = this.registerProperty(prop);
|
||||||
let targets = this.getProficiencyTargets(prop);
|
let targets = this.getProficiencyTargets(prop);
|
||||||
targets.forEach(target => {
|
targets.forEach(target => {
|
||||||
target.computationDetails.proficiencies.push(prop);
|
if(target.computationDetails.proficiencies){
|
||||||
|
target.computationDetails.proficiencies.push(prop);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getProficiencyTargets(prop){
|
getProficiencyTargets(prop){
|
||||||
@@ -256,7 +234,6 @@ const propDetailsByType = {
|
|||||||
default(){
|
default(){
|
||||||
return {
|
return {
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
toggle(){
|
toggle(){
|
||||||
@@ -264,7 +241,6 @@ const propDetailsByType = {
|
|||||||
computed: false,
|
computed: false,
|
||||||
busyComputing: false,
|
busyComputing: false,
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
attribute(){
|
attribute(){
|
||||||
@@ -272,8 +248,8 @@ const propDetailsByType = {
|
|||||||
computed: false,
|
computed: false,
|
||||||
busyComputing: false,
|
busyComputing: false,
|
||||||
effects: [],
|
effects: [],
|
||||||
|
proficiencies: [],
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
idsOfSameName: [],
|
idsOfSameName: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -284,7 +260,6 @@ const propDetailsByType = {
|
|||||||
effects: [],
|
effects: [],
|
||||||
proficiencies: [],
|
proficiencies: [],
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
idsOfSameName: [],
|
idsOfSameName: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -293,26 +268,22 @@ const propDetailsByType = {
|
|||||||
computed: false,
|
computed: false,
|
||||||
busyComputing: false,
|
busyComputing: false,
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
classLevel(){
|
classLevel(){
|
||||||
return {
|
return {
|
||||||
computed: true,
|
computed: true,
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
proficiency(){
|
proficiency(){
|
||||||
return {
|
return {
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
denormalizedStat(){
|
denormalizedStat(){
|
||||||
return {
|
return {
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,6 @@
|
|||||||
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
|
||||||
import { union } from 'lodash';
|
|
||||||
|
|
||||||
export default class EffectAggregator{
|
export default class EffectAggregator{
|
||||||
constructor(stat, memo){
|
constructor(){
|
||||||
delete this.baseValueErrors;
|
this.base = undefined;
|
||||||
if (stat.baseValueCalculation){
|
|
||||||
let {
|
|
||||||
result,
|
|
||||||
context,
|
|
||||||
dependencies
|
|
||||||
} = evaluateCalculation({
|
|
||||||
string: stat.baseValueCalculation,
|
|
||||||
prop: stat,
|
|
||||||
memo
|
|
||||||
});
|
|
||||||
this.statBaseValue = result.value;
|
|
||||||
stat.dependencies = union(
|
|
||||||
stat.dependencies,
|
|
||||||
dependencies,
|
|
||||||
);
|
|
||||||
if (context.errors.length){
|
|
||||||
this.baseValueErrors = context.errors;
|
|
||||||
}
|
|
||||||
this.base = this.statBaseValue;
|
|
||||||
} else {
|
|
||||||
this.base = 0;
|
|
||||||
}
|
|
||||||
this.add = 0;
|
this.add = 0;
|
||||||
this.mul = 1;
|
this.mul = 1;
|
||||||
this.min = Number.NEGATIVE_INFINITY;
|
this.min = Number.NEGATIVE_INFINITY;
|
||||||
@@ -45,10 +20,11 @@ export default class EffectAggregator{
|
|||||||
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;
|
if (Number.isFinite(result)){
|
||||||
if (effect.statBase){
|
if(Number.isFinite(this.base)){
|
||||||
if (this.statBaseValue === undefined || result > this.statBaseValue){
|
this.base = Math.max(this.base, result);
|
||||||
this.statBaseValue = result;
|
} else {
|
||||||
|
this.base = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ import computeToggle from '/imports/api/creature/computation/engine/computeToggl
|
|||||||
import { union } from 'lodash';
|
import { union } from 'lodash';
|
||||||
|
|
||||||
export default function applyToggles(prop, memo){
|
export default function applyToggles(prop, memo){
|
||||||
|
// If it used to be inactive delete those fields
|
||||||
|
if (prop.inactive) prop.inactive = undefined;
|
||||||
|
if (prop.deactivatedByAncestor) prop.deactivatedByAncestor = undefined;
|
||||||
|
if (prop.deactivatedByToggle) prop.deactivatedByToggle = undefined;
|
||||||
|
// Iterate through the toggle ancestors from oldest to nearest
|
||||||
prop.computationDetails.toggleAncestors.forEach(toggleId => {
|
prop.computationDetails.toggleAncestors.forEach(toggleId => {
|
||||||
let toggle = memo.togglesById[toggleId];
|
let toggle = memo.togglesById[toggleId];
|
||||||
computeToggle(toggle, memo);
|
computeToggle(toggle, memo);
|
||||||
@@ -10,8 +15,11 @@ export default function applyToggles(prop, memo){
|
|||||||
[toggle._id],
|
[toggle._id],
|
||||||
toggle.dependencies,
|
toggle.dependencies,
|
||||||
);
|
);
|
||||||
|
// Deactivate if the toggle is false
|
||||||
if (!toggle.toggleResult){
|
if (!toggle.toggleResult){
|
||||||
prop.computationDetails.disabledByToggle = true;
|
prop.inactive = true;
|
||||||
|
prop.deactivatedByAncestor = true;
|
||||||
|
prop.deactivatedByToggle = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import computeStat from '/imports/api/creature/computation/engine/computeStat.js';
|
import computeStat from '/imports/api/creature/computation/engine/computeStat.js';
|
||||||
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
import computeProficiency from '/imports/api/creature/computation/engine/computeProficiency.js';
|
||||||
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
||||||
|
import stripFloatingPointOddities from '/imports/ui/utility/stripFloatingPointOddities.js';
|
||||||
import { union } from 'lodash';
|
import { union } from 'lodash';
|
||||||
|
|
||||||
export default function combineStat(stat, aggregator, memo){
|
export default function combineStat(stat, aggregator, memo){
|
||||||
@@ -14,7 +15,15 @@ export default function combineStat(stat, aggregator, memo){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getAggregatorResult(stat, aggregator){
|
function getAggregatorResult(stat, aggregator){
|
||||||
let result = (aggregator.base + aggregator.add) * aggregator.mul;
|
let base;
|
||||||
|
if (!Number.isFinite(aggregator.base)){
|
||||||
|
base = stat.baseValue || 0;
|
||||||
|
} else if (!Number.isFinite(stat.baseValue)){
|
||||||
|
base = aggregator.base || 0;
|
||||||
|
} else {
|
||||||
|
base = Math.max(aggregator.base, stat.baseValue);
|
||||||
|
}
|
||||||
|
let result = (base + aggregator.add) * aggregator.mul;
|
||||||
if (result < aggregator.min) {
|
if (result < aggregator.min) {
|
||||||
result = aggregator.min;
|
result = aggregator.min;
|
||||||
}
|
}
|
||||||
@@ -26,14 +35,14 @@ function getAggregatorResult(stat, aggregator){
|
|||||||
}
|
}
|
||||||
if (!stat.decimal && Number.isFinite(result)){
|
if (!stat.decimal && Number.isFinite(result)){
|
||||||
result = Math.floor(result);
|
result = Math.floor(result);
|
||||||
|
} else if (Number.isFinite(result)){
|
||||||
|
result = stripFloatingPointOddities(result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function combineAttribute(stat, aggregator, memo){
|
function combineAttribute(stat, aggregator, memo){
|
||||||
stat.value = getAggregatorResult(stat, aggregator);
|
stat.value = getAggregatorResult(stat, aggregator);
|
||||||
stat.baseValue = aggregator.statBaseValue;
|
|
||||||
stat.baseValueErrors = aggregator.baseValueErrors;
|
|
||||||
if (stat.attributeType === 'spellSlot'){
|
if (stat.attributeType === 'spellSlot'){
|
||||||
let {
|
let {
|
||||||
result,
|
result,
|
||||||
@@ -78,9 +87,7 @@ function combineSkill(stat, aggregator, memo){
|
|||||||
// Skills are based on some ability Modifier
|
// Skills are based on some ability Modifier
|
||||||
let ability = stat.ability && memo.statsByVariableName[stat.ability]
|
let ability = stat.ability && memo.statsByVariableName[stat.ability]
|
||||||
if (stat.ability && ability){
|
if (stat.ability && ability){
|
||||||
if (!ability.computationDetails.computed){
|
computeStat(ability, memo);
|
||||||
computeStat(ability, memo);
|
|
||||||
}
|
|
||||||
stat.abilityMod = ability.modifier;
|
stat.abilityMod = ability.modifier;
|
||||||
stat.dependencies = union(
|
stat.dependencies = union(
|
||||||
stat.dependencies,
|
stat.dependencies,
|
||||||
@@ -91,12 +98,12 @@ function combineSkill(stat, aggregator, memo){
|
|||||||
stat.abilityMod = 0;
|
stat.abilityMod = 0;
|
||||||
}
|
}
|
||||||
// Combine all the child proficiencies
|
// Combine all the child proficiencies
|
||||||
stat.proficiency = stat.baseProficiency || 0;
|
stat.proficiency = 0;
|
||||||
for (let i in stat.computationDetails.proficiencies){
|
for (let i in stat.computationDetails.proficiencies){
|
||||||
let prof = stat.computationDetails.proficiencies[i];
|
let prof = stat.computationDetails.proficiencies[i];
|
||||||
applyToggles(prof, memo);
|
computeProficiency(prof, memo);
|
||||||
if (
|
if (
|
||||||
!prof.computationDetails.disabledByToggle &&
|
!prof.deactivatedByToggle &&
|
||||||
prof.value > stat.proficiency
|
prof.value > stat.proficiency
|
||||||
){
|
){
|
||||||
stat.proficiency = prof.value;
|
stat.proficiency = prof.value;
|
||||||
@@ -111,29 +118,37 @@ function combineSkill(stat, aggregator, memo){
|
|||||||
let profBonusStat = memo.statsByVariableName['proficiencyBonus'];
|
let profBonusStat = memo.statsByVariableName['proficiencyBonus'];
|
||||||
let profBonus = profBonusStat && profBonusStat.value;
|
let profBonus = profBonusStat && profBonusStat.value;
|
||||||
|
|
||||||
if (typeof profBonus !== 'number' && memo.statsByVariableName['level']){
|
if (profBonusStat){
|
||||||
let level = memo.statsByVariableName['level'].value;
|
|
||||||
profBonus = Math.ceil(level / 4) + 1;
|
|
||||||
if (level._id){
|
|
||||||
stat.dependencies = union(stat.dependencies, [level._id]);
|
|
||||||
}
|
|
||||||
if (level.dependencies){
|
|
||||||
stat.dependencies = union(stat.dependencies, level.dependencies);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stat.dependencies = union(
|
stat.dependencies = union(
|
||||||
stat.dependencies,
|
stat.dependencies,
|
||||||
[profBonusStat._id],
|
[profBonusStat._id],
|
||||||
profBonusStat.dependencies,
|
profBonusStat.dependencies,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof profBonus !== 'number' && memo.statsByVariableName['level']){
|
||||||
|
let levelProp = memo.statsByVariableName['level'];
|
||||||
|
let level = levelProp.value;
|
||||||
|
profBonus = Math.ceil(level / 4) + 1;
|
||||||
|
if (levelProp._id){
|
||||||
|
stat.dependencies = union(stat.dependencies, [levelProp._id]);
|
||||||
|
}
|
||||||
|
if (levelProp.dependencies){
|
||||||
|
stat.dependencies = union(stat.dependencies, levelProp.dependencies);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Multiply the proficiency bonus by the actual proficiency
|
// Multiply the proficiency bonus by the actual proficiency
|
||||||
profBonus *= stat.proficiency;
|
if(stat.proficiency === 0.49){
|
||||||
// Base value
|
// Round down proficiency bonus in the special case
|
||||||
stat.baseValue = aggregator.statBaseValue;
|
profBonus = Math.floor(profBonus * 0.5);
|
||||||
stat.baseValueErrors = aggregator.baseValueErrors;
|
} else {
|
||||||
|
profBonus = Math.ceil(profBonus * stat.proficiency);
|
||||||
|
}
|
||||||
|
|
||||||
// Combine everything to get the final result
|
// Combine everything to get the final result
|
||||||
let result = (aggregator.base + stat.abilityMod + profBonus + aggregator.add) * aggregator.mul;
|
let base = aggregator.base || 0;
|
||||||
|
let result = (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;
|
||||||
if (aggregator.set !== undefined) {
|
if (aggregator.set !== undefined) {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||||
|
|
||||||
|
export default function computeConstant(constant, memo){
|
||||||
|
// Apply any toggles
|
||||||
|
applyToggles(constant, memo);
|
||||||
|
if (constant.deactivatedByToggle) return;
|
||||||
|
if (
|
||||||
|
!memo.constantsByVariableName[constant.variableName]
|
||||||
|
){
|
||||||
|
memo.constantsByVariableName[constant.variableName] = constant
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
||||||
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
|
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
|
||||||
|
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||||
import { union } from 'lodash';
|
import { union } from 'lodash';
|
||||||
|
|
||||||
export default function computeEndStepProperty(prop, memo){
|
export default function computeEndStepProperty(prop, memo){
|
||||||
|
applyToggles(prop, memo);
|
||||||
|
|
||||||
switch (prop.type){
|
switch (prop.type){
|
||||||
case 'action':
|
case 'action':
|
||||||
case 'spell':
|
case 'spell':
|
||||||
@@ -14,16 +17,22 @@ export default function computeEndStepProperty(prop, memo){
|
|||||||
break;
|
break;
|
||||||
case 'attack':
|
case 'attack':
|
||||||
computeAction(prop, memo);
|
computeAction(prop, memo);
|
||||||
computeAttack(prop, memo);
|
computePropertyField(prop, memo, 'rollBonus');
|
||||||
break;
|
break;
|
||||||
case 'savingThrow':
|
case 'savingThrow':
|
||||||
computeSavingThrow(prop, memo);
|
computePropertyField(prop, memo, 'dc');
|
||||||
break;
|
break;
|
||||||
case 'spellList':
|
case 'spellList':
|
||||||
computeSpellList(prop, memo);
|
computePropertyField(prop, memo, 'maxPrepared');
|
||||||
|
computePropertyField(prop, memo, 'attackRollBonus');
|
||||||
|
computePropertyField(prop, memo, 'dc');
|
||||||
break;
|
break;
|
||||||
case 'propertySlot':
|
case 'propertySlot':
|
||||||
computeSlot(prop, memo);
|
computePropertyField(prop, memo, 'quantityExpected');
|
||||||
|
computePropertyField(prop, memo, 'slotCondition');
|
||||||
|
break;
|
||||||
|
case 'roll':
|
||||||
|
computePropertyField(prop, memo, 'roll', 'compile');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,26 +78,33 @@ function computeAction(prop, memo){
|
|||||||
});
|
});
|
||||||
// Items consumed
|
// Items consumed
|
||||||
prop.resources.itemsConsumed.forEach((itemConsumed, i) => {
|
prop.resources.itemsConsumed.forEach((itemConsumed, i) => {
|
||||||
let item = itemConsumed.itemId && memo.equipmentById[itemConsumed.itemId];
|
let item = itemConsumed.itemId ?
|
||||||
prop.resources.itemsConsumed[i].itemId = item && item._id;
|
memo.equipmentById[itemConsumed.itemId] :
|
||||||
let available = item && item.quantity || 0;
|
undefined;
|
||||||
|
let available = item ? item.quantity : 0;
|
||||||
prop.resources.itemsConsumed[i].available = available;
|
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){
|
if (!item || available < itemConsumed.quantity){
|
||||||
prop.insufficientResources = true;
|
prop.insufficientResources = true;
|
||||||
}
|
}
|
||||||
if (item){
|
if (item){
|
||||||
|
prop.resources.itemsConsumed[i].itemId = item._id;
|
||||||
|
let name = item.name;
|
||||||
|
if (item.quantity !== 1 && item.plural){
|
||||||
|
name = item.plural;
|
||||||
|
}
|
||||||
|
if (name) prop.resources.itemsConsumed[i].itemName = name;
|
||||||
|
if (item.icon) prop.resources.itemsConsumed[i].itemIcon = item.icon;
|
||||||
|
if (item.color) prop.resources.itemsConsumed[i].itemColor = item.color;
|
||||||
prop.dependencies = union(
|
prop.dependencies = union(
|
||||||
prop.dependencies,
|
prop.dependencies,
|
||||||
[item._id],
|
[item._id],
|
||||||
item.dependencies
|
item.dependencies
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
delete prop.resources.itemsConsumed[i].itemId;
|
||||||
|
delete prop.resources.itemsConsumed[i].itemName;
|
||||||
|
delete prop.resources.itemsConsumed[i].itemIcon;
|
||||||
|
delete prop.resources.itemsConsumed[i].itemColor;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -111,19 +127,3 @@ function computePropertyField(prop, memo, fieldName, fn){
|
|||||||
delete prop[`${fieldName}Errors`];
|
delete prop[`${fieldName}Errors`];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeAttack(prop, memo){
|
|
||||||
computePropertyField(prop, memo, 'rollBonus');
|
|
||||||
}
|
|
||||||
|
|
||||||
function computeSavingThrow(prop, memo){
|
|
||||||
computePropertyField(prop, memo, 'dc');
|
|
||||||
}
|
|
||||||
|
|
||||||
function computeSpellList(prop, memo){
|
|
||||||
computePropertyField(prop, memo, 'maxPrepared');
|
|
||||||
}
|
|
||||||
|
|
||||||
function computeSlot(prop, memo){
|
|
||||||
computePropertyField(prop, memo, 'slotCondition');
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { forOwn, has, union } from 'lodash';
|
import { forOwn, has, union } from 'lodash';
|
||||||
|
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||||
|
|
||||||
export default function computeLevels(memo){
|
export default function computeLevels(memo){
|
||||||
computeClassLevels(memo);
|
computeClassLevels(memo);
|
||||||
@@ -7,11 +8,13 @@ export default function computeLevels(memo){
|
|||||||
|
|
||||||
function computeClassLevels(memo){
|
function computeClassLevels(memo){
|
||||||
forOwn(memo.classLevelsById, classLevel => {
|
forOwn(memo.classLevelsById, classLevel => {
|
||||||
|
applyToggles(classLevel, memo);
|
||||||
// class levels are mutually dependent
|
// class levels are mutually dependent
|
||||||
classLevel.dependencies = union(
|
classLevel.dependencies = union(
|
||||||
classLevel.dependencies,
|
classLevel.dependencies,
|
||||||
Object.keys(memo.classLevelsById)
|
Object.keys(memo.classLevelsById)
|
||||||
);
|
);
|
||||||
|
if (classLevel.deactivatedByToggle) return;
|
||||||
let name = classLevel.variableName;
|
let name = classLevel.variableName;
|
||||||
let stat = memo.statsByVariableName[name];
|
let stat = memo.statsByVariableName[name];
|
||||||
if (!stat){
|
if (!stat){
|
||||||
@@ -29,7 +32,7 @@ function computeClassLevels(memo){
|
|||||||
|
|
||||||
function computeTotalLevel(memo){
|
function computeTotalLevel(memo){
|
||||||
let currentLevel = memo.statsByVariableName['level'];
|
let currentLevel = memo.statsByVariableName['level'];
|
||||||
if (!currentLevel){
|
if (!currentLevel || currentLevel.deactivatedByToggle){
|
||||||
currentLevel = {
|
currentLevel = {
|
||||||
value: 0,
|
value: 0,
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
|
|||||||
@@ -5,10 +5,15 @@ import computeEffect from '/imports/api/creature/computation/engine/computeEffec
|
|||||||
import computeToggle from '/imports/api/creature/computation/engine/computeToggle.js';
|
import computeToggle from '/imports/api/creature/computation/engine/computeToggle.js';
|
||||||
import computeEndStepProperty from '/imports/api/creature/computation/engine/computeEndStepProperty.js';
|
import computeEndStepProperty from '/imports/api/creature/computation/engine/computeEndStepProperty.js';
|
||||||
import computeInlineCalculations from '/imports/api/creature/computation/engine/computeInlineCalculations.js';
|
import computeInlineCalculations from '/imports/api/creature/computation/engine/computeInlineCalculations.js';
|
||||||
|
import computeConstant from '/imports/api/creature/computation/engine/computeConstant.js';
|
||||||
|
|
||||||
export default function computeMemo(memo){
|
export default function computeMemo(memo){
|
||||||
// Compute level
|
// Compute level
|
||||||
computeLevels(memo);
|
computeLevels(memo);
|
||||||
|
// Compute all constants that could be used
|
||||||
|
forOwn(memo.constantsById, constant => {
|
||||||
|
computeConstant (constant, memo);
|
||||||
|
});
|
||||||
// Compute all stats, even if they are overriden
|
// Compute all stats, even if they are overriden
|
||||||
forOwn(memo.statsById, stat => {
|
forOwn(memo.statsById, stat => {
|
||||||
computeStat (stat, memo);
|
computeStat (stat, memo);
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||||
|
|
||||||
|
export default function computeEffect(proficiency, memo){
|
||||||
|
if (proficiency.computationDetails.computed) return;
|
||||||
|
if (proficiency.computationDetails.busyComputing){
|
||||||
|
// Trying to compute this proficiency again while it is already computing.
|
||||||
|
// We must be in a dependency loop.
|
||||||
|
proficiency.computationDetails.computed = true;
|
||||||
|
proficiency.result = NaN;
|
||||||
|
proficiency.computationDetails.busyComputing = false;
|
||||||
|
proficiency.computationDetails.error = 'dependencyLoop';
|
||||||
|
if (Meteor.isClient) console.warn('dependencyLoop', proficiency);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Before doing any work, mark this proficiency as busy
|
||||||
|
proficiency.computationDetails.busyComputing = true;
|
||||||
|
|
||||||
|
// Apply any toggles
|
||||||
|
applyToggles(proficiency, memo);
|
||||||
|
|
||||||
|
proficiency.computationDetails.computed = true;
|
||||||
|
proficiency.computationDetails.busyComputing = false;
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import combineStat from '/imports/api/creature/computation/engine/combineStat.js';
|
import combineStat from '/imports/api/creature/computation/engine/combineStat.js';
|
||||||
import computeEffect from '/imports/api/creature/computation/engine/computeEffect.js';
|
import computeEffect from '/imports/api/creature/computation/engine/computeEffect.js';
|
||||||
import EffectAggregator from '/imports/api/creature/computation/engine/EffectAggregator.js';
|
import EffectAggregator from '/imports/api/creature/computation/engine/EffectAggregator.js';
|
||||||
|
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
||||||
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||||
import { each, union } from 'lodash';
|
import { each, union, without } from 'lodash';
|
||||||
|
|
||||||
export default function computeStat(stat, memo){
|
export default function computeStat(stat, memo){
|
||||||
// If the stat is already computed, skip it
|
// If the stat is already computed, skip it
|
||||||
@@ -19,32 +20,143 @@ export default function computeStat(stat, memo){
|
|||||||
}
|
}
|
||||||
// Before doing any work, mark this stat as busy
|
// Before doing any work, mark this stat as busy
|
||||||
stat.computationDetails.busyComputing = true;
|
stat.computationDetails.busyComputing = true;
|
||||||
// Apply any toggles
|
|
||||||
applyToggles(stat, memo);
|
|
||||||
|
|
||||||
if (!stat.computationDetails.disabledByToggle){
|
let effects = stat.computationDetails.effects || [];
|
||||||
// Compute and aggregate all the effects
|
let proficiencies = stat.computationDetails.proficiencies || [];
|
||||||
let aggregator = new EffectAggregator(stat, memo)
|
|
||||||
each(stat.computationDetails.effects, (effect) => {
|
// Get references to all the stats that share the variable name
|
||||||
computeEffect(effect, memo);
|
let sameNameStats
|
||||||
if (effect._id){
|
|
||||||
stat.dependencies = union(
|
if (stat.computationDetails.idsOfSameName){
|
||||||
stat.dependencies,
|
sameNameStats = stat.computationDetails.idsOfSameName.map(
|
||||||
[effect._id]
|
id => memo.propsById[id]
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
stat.dependencies = union(
|
sameNameStats = [];
|
||||||
stat.dependencies,
|
|
||||||
effect.dependencies
|
|
||||||
)
|
|
||||||
if (!effect.computationDetails.disabledByToggle){
|
|
||||||
aggregator.addEffect(effect);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Conglomerate all the effects to compute the final stat values
|
|
||||||
combineStat(stat, aggregator, memo);
|
|
||||||
}
|
}
|
||||||
// Mark the attribute as computed
|
|
||||||
stat.computationDetails.computed = true;
|
let allStats = [stat, ...sameNameStats];
|
||||||
stat.computationDetails.busyComputing = false;
|
|
||||||
|
// Decide which stat is the last active stat
|
||||||
|
// The last active stat is considered the cannonical stat
|
||||||
|
let lastActiveStat;
|
||||||
|
allStats.forEach(candidateStat => {
|
||||||
|
applyToggles(candidateStat, memo);
|
||||||
|
if (!candidateStat.inactive) lastActiveStat = candidateStat;
|
||||||
|
candidateStat.overridden = undefined;
|
||||||
|
});
|
||||||
|
if (!lastActiveStat){
|
||||||
|
delete memo.statsByVariableName[stat.variableName];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Make sure the active stat has all the effects and proficiencies
|
||||||
|
lastActiveStat.computationDetails.effects = effects;
|
||||||
|
lastActiveStat.computationDetails.proficiencies = proficiencies;
|
||||||
|
|
||||||
|
// Update the memo's stat with the chosen stat
|
||||||
|
memo.statsByVariableName[stat.variableName] = lastActiveStat;
|
||||||
|
|
||||||
|
// Recreate list of the non-cannonical stats
|
||||||
|
sameNameStats = without(allStats, lastActiveStat);
|
||||||
|
|
||||||
|
sameNameStats.forEach(statInstance => {
|
||||||
|
// Mark the non-cannonical stats as overridden
|
||||||
|
statInstance.overridden = true;
|
||||||
|
|
||||||
|
// Apply the cannonical damage
|
||||||
|
statInstance.damage = lastActiveStat.damage;
|
||||||
|
});
|
||||||
|
|
||||||
|
let baseDependencies = [];
|
||||||
|
allStats.forEach(statInstance => {
|
||||||
|
// Add this stat and its deps to the dependencies
|
||||||
|
baseDependencies = union(
|
||||||
|
baseDependencies,
|
||||||
|
[statInstance._id],
|
||||||
|
statInstance.dependencies,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Apply all the base proficiencies
|
||||||
|
if (statInstance.baseProficiency && !statInstance.inactive){
|
||||||
|
proficiencies.push({
|
||||||
|
value: statInstance.baseProficiency,
|
||||||
|
stats: [statInstance.variableName],
|
||||||
|
type: 'proficiency',
|
||||||
|
dependencies: statInstance.overridden ?
|
||||||
|
union(statInstance.dependencies, [statInstance._id]) :
|
||||||
|
[],
|
||||||
|
computationDetails: {
|
||||||
|
computed: true,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute each active stat's baseValue calculation and apply it
|
||||||
|
if (!statInstance.inactive) {
|
||||||
|
delete statInstance.baseValueErrors;
|
||||||
|
let {
|
||||||
|
result,
|
||||||
|
context,
|
||||||
|
dependencies
|
||||||
|
} = evaluateCalculation({
|
||||||
|
string: statInstance.baseValueCalculation,
|
||||||
|
prop: statInstance,
|
||||||
|
memo
|
||||||
|
});
|
||||||
|
result.value = +result.value;
|
||||||
|
if (!isNaN(result.value)){
|
||||||
|
statInstance.baseValue = result.value;
|
||||||
|
} else {
|
||||||
|
statInstance.baseValue = undefined;
|
||||||
|
}
|
||||||
|
statInstance.dependencies = union(statInstance.dependencies, dependencies);
|
||||||
|
if (context.errors.length){
|
||||||
|
statInstance.baseValueErrors = context.errors;
|
||||||
|
}
|
||||||
|
// Apply all the base values
|
||||||
|
if (Number.isFinite(statInstance.baseValue)){
|
||||||
|
effects.push({
|
||||||
|
operation: 'base',
|
||||||
|
calculation: statInstance.baseValueCalculation,
|
||||||
|
result: statInstance.baseValue,
|
||||||
|
stats: [statInstance.variableName],
|
||||||
|
dependencies: statInstance.overridden ?
|
||||||
|
union(statInstance.dependencies, [statInstance._id]) :
|
||||||
|
[],
|
||||||
|
computationDetails: {
|
||||||
|
computed: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Compute and aggregate all the effects
|
||||||
|
let aggregator = new EffectAggregator();
|
||||||
|
let effectDeps = [];
|
||||||
|
each(effects, (effect) => {
|
||||||
|
// Compute
|
||||||
|
computeEffect(effect, memo);
|
||||||
|
if (effect.deactivatedByToggle) return;
|
||||||
|
|
||||||
|
// dependencies
|
||||||
|
if (effect._id) effectDeps = union(effectDeps, [effect._id]);
|
||||||
|
effectDeps = union(effectDeps, effect.dependencies);
|
||||||
|
|
||||||
|
// Add computed effect to aggregator
|
||||||
|
aggregator.addEffect(effect);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Combine the effects into the stats
|
||||||
|
allStats.forEach(statInstance => {
|
||||||
|
// Conglomerate all the effects to compute the final stat values
|
||||||
|
combineStat(statInstance, aggregator, memo);
|
||||||
|
// Mark the stats as computed
|
||||||
|
statInstance.computationDetails.computed = true;
|
||||||
|
statInstance.computationDetails.busyComputing = false;
|
||||||
|
// Only the active stat instance depeneds on the effects
|
||||||
|
if (!statInstance.overridden){
|
||||||
|
statInstance.dependencies = union(statInstance.dependencies, effectDeps);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
||||||
|
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||||
import { union } from 'lodash';
|
import { union } from 'lodash';
|
||||||
|
|
||||||
export default function computeToggle(toggle, memo){
|
export default function computeToggle(toggle, memo){
|
||||||
@@ -16,6 +17,9 @@ export default function computeToggle(toggle, memo){
|
|||||||
// Before doing any work, mark this toggle as busy
|
// Before doing any work, mark this toggle as busy
|
||||||
toggle.computationDetails.busyComputing = true;
|
toggle.computationDetails.busyComputing = true;
|
||||||
|
|
||||||
|
// Apply any parent toggles
|
||||||
|
applyToggles(toggle, memo);
|
||||||
|
|
||||||
// Do work
|
// Do work
|
||||||
delete toggle.errors;
|
delete toggle.errors;
|
||||||
if (toggle.enabled){
|
if (toggle.enabled){
|
||||||
@@ -41,6 +45,11 @@ export default function computeToggle(toggle, memo){
|
|||||||
toggle.errors = context.errors;
|
toggle.errors = context.errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!toggle.toggleResult){
|
||||||
|
toggle.inactive = true;
|
||||||
|
toggle.deactivatedBySelf = true;
|
||||||
|
toggle.deactivatedByToggle = true;
|
||||||
|
}
|
||||||
toggle.computationDetails.computed = true;
|
toggle.computationDetails.computed = true;
|
||||||
toggle.computationDetails.busyComputing = false;
|
toggle.computationDetails.busyComputing = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ export default function evaluateCalculation({
|
|||||||
context,
|
context,
|
||||||
dependencies,
|
dependencies,
|
||||||
};
|
};
|
||||||
|
if (typeof string !== 'string'){
|
||||||
|
string = string.toString();
|
||||||
|
}
|
||||||
// Parse the string
|
// Parse the string
|
||||||
let calc;
|
let calc;
|
||||||
try {
|
try {
|
||||||
@@ -68,8 +71,8 @@ function replaceConstants({calc, memo, prop, dependencies, context}){
|
|||||||
} else if (node.name === '#constant'){
|
} else if (node.name === '#constant'){
|
||||||
constant = findAncestorByType({type: 'constant', prop, memo});
|
constant = findAncestorByType({type: 'constant', prop, memo});
|
||||||
}
|
}
|
||||||
// replace constants that aren't overridden by stats
|
// replace constants that aren't overridden by stats or disabled by a toggle
|
||||||
if (constant && !stat){
|
if (constant && !constant.deactivatedByToggle && !stat){
|
||||||
dependencies = union(dependencies, [
|
dependencies = union(dependencies, [
|
||||||
constant._id,
|
constant._id,
|
||||||
...constant.dependencies
|
...constant.dependencies
|
||||||
@@ -119,10 +122,14 @@ function computeSymbols({calc, memo, prop, dependencies}){
|
|||||||
computeStat(stat, memo);
|
computeStat(stat, memo);
|
||||||
}
|
}
|
||||||
if (stat){
|
if (stat){
|
||||||
dependencies = union(dependencies, [
|
if (stat.dependencies){
|
||||||
stat._id || node.name,
|
dependencies = union(dependencies, [
|
||||||
...stat.dependencies
|
stat._id || node.name,
|
||||||
]);
|
...stat.dependencies
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
dependencies = union(dependencies, [stat._id || node.name]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,6 @@
|
|||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
|
||||||
export default function getComputationProperties(creatureId){
|
export default function getComputationProperties(creatureId){
|
||||||
// find ids of all toggles that have conditions, even if they are inactive
|
|
||||||
let toggleIds = CreatureProperties.find({
|
|
||||||
'ancestors.id': creatureId,
|
|
||||||
type: 'toggle',
|
|
||||||
removed: {$ne: true},
|
|
||||||
condition: { $exists: true },
|
|
||||||
}, {
|
|
||||||
fields: {_id: 1},
|
|
||||||
}).map(t => t._id);
|
|
||||||
// Find all the relevant properties
|
// Find all the relevant properties
|
||||||
return CreatureProperties.find({
|
return CreatureProperties.find({
|
||||||
'ancestors.id': creatureId,
|
'ancestors.id': creatureId,
|
||||||
@@ -17,17 +8,15 @@ export default function getComputationProperties(creatureId){
|
|||||||
$or: [
|
$or: [
|
||||||
// All active properties
|
// All active properties
|
||||||
{inactive: {$ne: true}},
|
{inactive: {$ne: true}},
|
||||||
// All active and inactive toggles with conditions
|
// Unless they were deactivated because of a toggle
|
||||||
// Same as {$in: toggleIds}, but should be slightly faster
|
{deactivatedByToggle: true},
|
||||||
{type: 'toggle', condition: { $exists: true }},
|
|
||||||
// All decendents of the above toggles
|
|
||||||
{'ancestors.id': {$in: toggleIds}},
|
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
// Filter out fields never used by calculations
|
// Filter out fields never used by calculations
|
||||||
fields: {
|
fields: {
|
||||||
icon: 0,
|
icon: 0,
|
||||||
},
|
},
|
||||||
|
// Obey tree order
|
||||||
sort: {
|
sort: {
|
||||||
order: 1,
|
order: 1,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,23 +8,26 @@ export default function writeAlteredProperties(memo){
|
|||||||
// Loop through all properties on the memo
|
// Loop through all properties on the memo
|
||||||
forOwn(memo.propsById, changed => {
|
forOwn(memo.propsById, changed => {
|
||||||
let schema = propertySchemasIndex[changed.type];
|
let schema = propertySchemasIndex[changed.type];
|
||||||
if (!schema) return;
|
if (!schema){
|
||||||
let extraIds = changed.computationDetails.idsOfSameName;
|
console.warn('No schema for ' + changed.type);
|
||||||
let ids;
|
return;
|
||||||
if (extraIds && extraIds.length){
|
}
|
||||||
ids = [changed._id, ...extraIds];
|
let id = changed._id;
|
||||||
} else {
|
let op = undefined;
|
||||||
ids = [changed._id];
|
let original = memo.originalPropsById[id];
|
||||||
|
let keys = [
|
||||||
|
'dependencies',
|
||||||
|
'inactive',
|
||||||
|
'deactivatedBySelf',
|
||||||
|
'deactivatedByAncestor',
|
||||||
|
'deactivatedByToggle',
|
||||||
|
'damage',
|
||||||
|
...schema.objectKeys(),
|
||||||
|
];
|
||||||
|
op = addChangedKeysToOp(op, keys, original, changed);
|
||||||
|
if (op){
|
||||||
|
bulkWriteOperations.push(op);
|
||||||
}
|
}
|
||||||
ids.forEach(id => {
|
|
||||||
let op = undefined;
|
|
||||||
let original = memo.originalPropsById[id];
|
|
||||||
let keys = ['dependencies', ...schema.objectKeys()];
|
|
||||||
op = addChangedKeysToOp(op, keys, original, changed);
|
|
||||||
if (op){
|
|
||||||
bulkWriteOperations.push(op);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
writePropertiesSequentially(bulkWriteOperations);
|
writePropertiesSequentially(bulkWriteOperations);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,49 @@
|
|||||||
import { pick, forOwn } from 'lodash';
|
import { pick, forOwn } from 'lodash';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import VERSION from '/imports/constants/VERSION.js';
|
import VERSION from '/imports/constants/VERSION.js';
|
||||||
|
|
||||||
export default function writeCreatureVariables(memo, creatureId, fullRecompute = true) {
|
export default function writeCreatureVariables(memo, creatureId, fullRecompute = true) {
|
||||||
const fields = [
|
const fields = [
|
||||||
'name',
|
|
||||||
'attributeType',
|
|
||||||
'baseValue',
|
|
||||||
'spellSlotLevelValue',
|
|
||||||
'damage',
|
|
||||||
'decimal',
|
|
||||||
'reset',
|
|
||||||
'resetMultiplier',
|
|
||||||
'value',
|
|
||||||
'currentValue',
|
|
||||||
'modifier',
|
|
||||||
'ability',
|
'ability',
|
||||||
'skillType',
|
|
||||||
'baseProficiency',
|
|
||||||
'abilityMod',
|
'abilityMod',
|
||||||
'advantage',
|
'advantage',
|
||||||
'passiveBonus',
|
'attributeType',
|
||||||
'proficiency',
|
'baseProficiency',
|
||||||
|
'baseValue',
|
||||||
|
'calculation',
|
||||||
'conditionalBenefits',
|
'conditionalBenefits',
|
||||||
'rollBonuses',
|
'currentValue',
|
||||||
|
'damage',
|
||||||
|
'decimal',
|
||||||
'fail',
|
'fail',
|
||||||
'level',
|
'level',
|
||||||
|
'modifier',
|
||||||
|
'name',
|
||||||
|
'passiveBonus',
|
||||||
|
'proficiency',
|
||||||
|
'reset',
|
||||||
|
'resetMultiplier',
|
||||||
|
'rollBonuses',
|
||||||
|
'skillType',
|
||||||
|
'spellSlotLevelValue',
|
||||||
|
'type',
|
||||||
|
'value',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (fullRecompute){
|
if (fullRecompute){
|
||||||
memo.creatureVariables = {};
|
memo.creatureVariables = {};
|
||||||
forOwn(memo.statsByVariableName, (stat, variableName) => {
|
forOwn(memo.statsByVariableName, (stat, variableName) => {
|
||||||
|
// Don't save context variables
|
||||||
|
if (variableName[0] === '#') return;
|
||||||
let condensedStat = pick(stat, fields);
|
let condensedStat = pick(stat, fields);
|
||||||
memo.creatureVariables[variableName] = condensedStat;
|
memo.creatureVariables[variableName] = condensedStat;
|
||||||
});
|
});
|
||||||
|
forOwn(memo.constantsByVariableName, (stat, variableName) => {
|
||||||
|
let condensedStat = pick(stat, fields);
|
||||||
|
if (!memo.creatureVariables[variableName]){
|
||||||
|
memo.creatureVariables[variableName] = condensedStat;
|
||||||
|
}
|
||||||
|
});
|
||||||
Creatures.update(creatureId, {$set: {
|
Creatures.update(creatureId, {$set: {
|
||||||
variables: memo.creatureVariables,
|
variables: memo.creatureVariables,
|
||||||
computeVersion: VERSION,
|
computeVersion: VERSION,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
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/creatures/creaturePermissions.js';
|
||||||
import ComputationMemo from '/imports/api/creature/computation/engine/ComputationMemo.js';
|
import ComputationMemo from '/imports/api/creature/computation/engine/ComputationMemo.js';
|
||||||
import getComputationProperties from '/imports/api/creature/computation/engine/getComputationProperties.js';
|
import getComputationProperties from '/imports/api/creature/computation/engine/getComputationProperties.js';
|
||||||
import computeMemo from '/imports/api/creature/computation/engine/computeMemo.js';
|
import computeMemo from '/imports/api/creature/computation/engine/computeMemo.js';
|
||||||
@@ -11,7 +11,7 @@ import { recomputeDamageMultipliersById } from '/imports/api/creature/denormalis
|
|||||||
import recomputeSlotFullness from '/imports/api/creature/denormalise/recomputeSlotFullness.js';
|
import recomputeSlotFullness from '/imports/api/creature/denormalise/recomputeSlotFullness.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
import getDependentProperties from '/imports/api/creature/computation/engine/getDependentProperties.js';
|
import getDependentProperties from '/imports/api/creature/computation/engine/getDependentProperties.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
|
|
||||||
export const recomputeCreature = new ValidatedMethod({
|
export const recomputeCreature = new ValidatedMethod({
|
||||||
@@ -89,7 +89,6 @@ export function recomputeCreatureByDoc(creature){
|
|||||||
writeCreatureVariables(computationMemo, creatureId);
|
writeCreatureVariables(computationMemo, creatureId);
|
||||||
recomputeDamageMultipliersById(creatureId);
|
recomputeDamageMultipliersById(creatureId);
|
||||||
recomputeSlotFullness(creatureId);
|
recomputeSlotFullness(creatureId);
|
||||||
recomputeInactiveProperties(creatureId);
|
|
||||||
return computationMemo;
|
return computationMemo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
39
app/imports/api/creature/creatureFolders/CreatureFolders.js
Normal file
39
app/imports/api/creature/creatureFolders/CreatureFolders.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
|
let CreatureFolders = new Mongo.Collection('creatureFolders');
|
||||||
|
|
||||||
|
let creatureFolderSchema = new SimpleSchema({
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
trim: false,
|
||||||
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
|
},
|
||||||
|
creatures: {
|
||||||
|
type: Array,
|
||||||
|
defaultValue: [],
|
||||||
|
},
|
||||||
|
'creatures.$': {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
},
|
||||||
|
owner: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
index: 1,
|
||||||
|
},
|
||||||
|
archived: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
type: Number,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
CreatureFolders.attachSchema(creatureFolderSchema);
|
||||||
|
|
||||||
|
import '/imports/api/creature/creatureFolders/methods.js/index.js';
|
||||||
|
export default CreatureFolders;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import '/imports/api/creature/creatureFolders/methods.js/insertCreatureFolder.js';
|
||||||
|
import '/imports/api/creature/creatureFolders/methods.js/updateCreatureFolderName.js';
|
||||||
|
import '/imports/api/creature/creatureFolders/methods.js/removeCreatureFolder.js';
|
||||||
|
import '/imports/api/creature/creatureFolders/methods.js/moveCreatureToFolder.js';
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import CreatureFolders from '/imports/api/creature/creatureFolders/CreatureFolders.js';
|
||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
|
||||||
|
const insertCreatureFolder = new ValidatedMethod({
|
||||||
|
name: 'creatureFolders.methods.insert',
|
||||||
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run() {
|
||||||
|
// Ensure logged in
|
||||||
|
let userId = this.userId;
|
||||||
|
if (!userId) {
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.insert.denied',
|
||||||
|
'You need to be logged in to insert a folder');
|
||||||
|
}
|
||||||
|
// Limit folders to 50 per user
|
||||||
|
let existingFolders = CreatureFolders.find({
|
||||||
|
owner: userId
|
||||||
|
}, {
|
||||||
|
fields: {order: 1},
|
||||||
|
sort: {order :-1}
|
||||||
|
});
|
||||||
|
if (existingFolders.count() >= 50){
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.insert.denied',
|
||||||
|
'You can not have more than 50 folders');
|
||||||
|
}
|
||||||
|
// Make the new folder the last in the order
|
||||||
|
let order = 0;
|
||||||
|
let lastFolder = existingFolders.fetch()[0];
|
||||||
|
if (lastFolder){
|
||||||
|
order = (lastFolder.order || 0) + 1;
|
||||||
|
}
|
||||||
|
// Insert
|
||||||
|
return CreatureFolders.insert({
|
||||||
|
name: 'Folder',
|
||||||
|
owner: userId,
|
||||||
|
order,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default insertCreatureFolder;
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import CreatureFolders from '/imports/api/creature/creatureFolders/CreatureFolders.js';
|
||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
|
||||||
|
const moveCreatureToFolder = new ValidatedMethod({
|
||||||
|
name: 'creatureFolders.methods.moveCreatureToFolder',
|
||||||
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({creatureId, folderId}) {
|
||||||
|
// Ensure logged in
|
||||||
|
let userId = this.userId;
|
||||||
|
if (!userId) {
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.updateName.denied',
|
||||||
|
'You need to be logged in to remove a folder');
|
||||||
|
}
|
||||||
|
// Check that this folder is owned by the user
|
||||||
|
if (folderId){
|
||||||
|
let existingFolder = CreatureFolders.findOne(folderId);
|
||||||
|
if (existingFolder.owner !== userId){
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.updateName.denied',
|
||||||
|
'This folder does not belong to you');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Remove from other folders
|
||||||
|
CreatureFolders.update({
|
||||||
|
owner: userId
|
||||||
|
}, {
|
||||||
|
$pull: {creatures: creatureId},
|
||||||
|
}, {
|
||||||
|
multi: true,
|
||||||
|
});
|
||||||
|
if (folderId){
|
||||||
|
// Add to this folder
|
||||||
|
CreatureFolders.update(folderId, {
|
||||||
|
$addToSet: {creatures: creatureId},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default moveCreatureToFolder;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import CreatureFolders from '/imports/api/creature/creatureFolders/CreatureFolders.js';
|
||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
|
||||||
|
const removeCreatureFolder = new ValidatedMethod({
|
||||||
|
name: 'creatureFolders.methods.remove',
|
||||||
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({_id}) {
|
||||||
|
// Ensure logged in
|
||||||
|
let userId = this.userId;
|
||||||
|
if (!userId) {
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.updateName.denied',
|
||||||
|
'You need to be logged in to remove a folder');
|
||||||
|
}
|
||||||
|
// Check that this folder is owned by the user
|
||||||
|
let existingFolder = CreatureFolders.findOne(_id);
|
||||||
|
if (existingFolder.owner !== userId){
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.updateName.denied',
|
||||||
|
'This folder does not belong to you');
|
||||||
|
}
|
||||||
|
// Remove
|
||||||
|
return CreatureFolders.remove(_id);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default removeCreatureFolder;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import CreatureFolders from '/imports/api/creature/creatureFolders/CreatureFolders.js';
|
||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
|
||||||
|
const reorderCreatureFolder = new ValidatedMethod({
|
||||||
|
name: 'creatureFolders.methods.reorder',
|
||||||
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({_id, order}) {
|
||||||
|
// Ensure logged in
|
||||||
|
let userId = this.userId;
|
||||||
|
if (!userId) {
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.reorder.denied',
|
||||||
|
'You need to be logged in to reorder a folder');
|
||||||
|
}
|
||||||
|
// Check that this folder is owned by the user
|
||||||
|
let existingFolder = CreatureFolders.findOne(_id);
|
||||||
|
if (existingFolder.owner !== userId){
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.reorder.denied',
|
||||||
|
'This folder does not belong to you');
|
||||||
|
}
|
||||||
|
// First give it the new order, it should end in 0.5 putting it between two other docs
|
||||||
|
CreatureFolders.update(_id, {$set: {order}});
|
||||||
|
this.unblock();
|
||||||
|
// Reorder all the folders with integer numbers in this new order
|
||||||
|
CreatureFolders.find({
|
||||||
|
owner: userId
|
||||||
|
}, {
|
||||||
|
fields: {order: 1,},
|
||||||
|
sort: {order: -1}
|
||||||
|
}).forEach((folder, index) => {
|
||||||
|
if (folder.order !== index){
|
||||||
|
CreatureFolders.update(_id, {$set: {order: index}})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default reorderCreatureFolder;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import CreatureFolders from '/imports/api/creature/creatureFolders/CreatureFolders.js';
|
||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
|
||||||
|
const updateCreatureFolderName = new ValidatedMethod({
|
||||||
|
name: 'creatureFolders.methods.updateName',
|
||||||
|
validate: null,
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({_id, name}) {
|
||||||
|
// Ensure logged in
|
||||||
|
let userId = this.userId;
|
||||||
|
if (!userId) {
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.updateName.denied',
|
||||||
|
'You need to be logged in to update a folder');
|
||||||
|
}
|
||||||
|
// Check that this folder is owned by the user
|
||||||
|
let existingFolder = CreatureFolders.findOne(_id);
|
||||||
|
if (existingFolder.owner !== userId){
|
||||||
|
throw new Meteor.Error('creatureFolders.methods.updateName.denied',
|
||||||
|
'This folder does not belong to you');
|
||||||
|
}
|
||||||
|
// Update
|
||||||
|
return CreatureFolders.update(_id, {$set: {name}});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default updateCreatureFolderName;
|
||||||
@@ -5,6 +5,7 @@ import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
|||||||
import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js';
|
import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js';
|
||||||
import propertySchemasIndex from '/imports/api/properties/computedPropertySchemasIndex.js';
|
import propertySchemasIndex from '/imports/api/properties/computedPropertySchemasIndex.js';
|
||||||
import { storedIconsSchema } from '/imports/api/icons/Icons.js';
|
import { storedIconsSchema } from '/imports/api/icons/Icons.js';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
let CreatureProperties = new Mongo.Collection('creatureProperties');
|
let CreatureProperties = new Mongo.Collection('creatureProperties');
|
||||||
|
|
||||||
@@ -16,9 +17,11 @@ let CreaturePropertySchema = new SimpleSchema({
|
|||||||
tags: {
|
tags: {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
|
maxCount: STORAGE_LIMITS.tagCount,
|
||||||
},
|
},
|
||||||
'tags.$': {
|
'tags.$': {
|
||||||
type: String,
|
type: String,
|
||||||
|
max: STORAGE_LIMITS.tagLength,
|
||||||
},
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -27,6 +30,13 @@ let CreaturePropertySchema = new SimpleSchema({
|
|||||||
icon: {
|
icon: {
|
||||||
type: storedIconsSchema,
|
type: storedIconsSchema,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.icon,
|
||||||
|
},
|
||||||
|
// Reference to the library node that this property was copied from
|
||||||
|
libraryNodeId: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
optional: true,
|
||||||
},
|
},
|
||||||
// Denormalised flag if this property is inactive on the sheet for any reason
|
// Denormalised flag if this property is inactive on the sheet for any reason
|
||||||
// Including being disabled, or a decendent of a disabled property
|
// Including being disabled, or a decendent of a disabled property
|
||||||
@@ -50,6 +60,13 @@ let CreaturePropertySchema = new SimpleSchema({
|
|||||||
optional: true,
|
optional: true,
|
||||||
index: 1,
|
index: 1,
|
||||||
},
|
},
|
||||||
|
// Denormalised flag if this property was made inactive because of a toggle
|
||||||
|
// calculation. Either an ancestor toggle calculation or its own.
|
||||||
|
deactivatedByToggle: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
index: 1,
|
||||||
|
},
|
||||||
// Denormalised list of all properties or creatures this property depends on
|
// Denormalised list of all properties or creatures this property depends on
|
||||||
dependencies: {
|
dependencies: {
|
||||||
type: Array,
|
type: Array,
|
||||||
@@ -58,7 +75,6 @@ let CreaturePropertySchema = new SimpleSchema({
|
|||||||
},
|
},
|
||||||
'dependencies.$': {
|
'dependencies.$': {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
|
|
||||||
export default function getRootCreatureAncestor(property){
|
export default function getRootCreatureAncestor(property){
|
||||||
return Creatures.findOne(property.ancestors[0].id);
|
return Creatures.findOne(property.ancestors[0].id);
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import SimpleSchema from 'simpl-schema';
|
|||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import { recomputePropertyDependencies } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
|
||||||
const adjustQuantity = new ValidatedMethod({
|
const adjustQuantity = new ValidatedMethod({
|
||||||
name: 'creatureProperties.adjustQuantity',
|
name: 'creatureProperties.adjustQuantity',
|
||||||
@@ -30,8 +31,10 @@ const adjustQuantity = new ValidatedMethod({
|
|||||||
// Do work
|
// Do work
|
||||||
adjustQuantityWork({property, operation, value});
|
adjustQuantityWork({property, operation, value});
|
||||||
|
|
||||||
// Changing quantity does not change dependencies, recompute deps
|
// Changing quantity does not change dependencies, but recomputing the
|
||||||
recomputePropertyDependencies(property);
|
// inventory changes many deps at once, so recompute fully
|
||||||
|
recomputeCreatureByDoc(rootCreature);
|
||||||
|
recomputeInventory(rootCreature._id);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
|||||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import { damagePropertyWork } from '/imports/api/creature/creatureProperties/methods/damageProperty.js';
|
import { damagePropertyWork } from '/imports/api/creature/creatureProperties/methods/damageProperty.js';
|
||||||
import { recomputePropertyDependencies } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputePropertyDependencies } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
@@ -50,7 +50,7 @@ const damagePropertiesByName = new ValidatedMethod({
|
|||||||
damagePropertyWork({property, operation, value});
|
damagePropertyWork({property, operation, value});
|
||||||
lastProperty = property;
|
lastProperty = property;
|
||||||
});
|
});
|
||||||
recomputePropertyDependencies(lastProperty);
|
if (lastProperty) recomputePropertyDependencies(lastProperty);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ const damageProperty = new ValidatedMethod({
|
|||||||
run({_id, operation, value}) {
|
run({_id, operation, value}) {
|
||||||
// Check permissions
|
// Check permissions
|
||||||
let property = CreatureProperties.findOne(_id);
|
let property = CreatureProperties.findOne(_id);
|
||||||
|
if (!property) throw new Meteor.Error(
|
||||||
|
'Damage property failed', 'Property doesn\'t exist'
|
||||||
|
);
|
||||||
let rootCreature = getRootCreatureAncestor(property);
|
let rootCreature = getRootCreatureAncestor(property);
|
||||||
assertEditPermission(rootCreature, this.userId);
|
assertEditPermission(rootCreature, this.userId);
|
||||||
// Check if property can take damage
|
// Check if property can take damage
|
||||||
@@ -34,9 +37,10 @@ const damageProperty = new ValidatedMethod({
|
|||||||
`Property of type "${property.type}" can't be damaged`
|
`Property of type "${property.type}" can't be damaged`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
damagePropertyWork({property, operation, value});
|
let result = damagePropertyWork({property, operation, value});
|
||||||
// Dependencies can't be changed through damage, only recompute deps
|
// Dependencies can't be changed through damage, only recompute deps
|
||||||
recomputePropertyDependencies(property);
|
recomputePropertyDependencies(property);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
|||||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import { damagePropertyWork } from '/imports/api/creature/creatureProperties/methods/damageProperty.js';
|
import { damagePropertyWork } from '/imports/api/creature/creatureProperties/methods/damageProperty.js';
|
||||||
import { recomputeCreatureByDependencies } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureByDependencies } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
|||||||
@@ -2,9 +2,24 @@ 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 { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
|
||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import { insertPropertyWork } from '/imports/api/creature/creatureProperties/methods/insertProperty.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
|
import {
|
||||||
|
setLineageOfDocs,
|
||||||
|
renewDocIds
|
||||||
|
} from '/imports/api/parenting/parenting.js';
|
||||||
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
|
import { reorderDocs } from '/imports/api/parenting/order.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
var snackbar;
|
||||||
|
if (Meteor.isClient){
|
||||||
|
snackbar = require(
|
||||||
|
'/imports/ui/components/snackbars/SnackbarQueue.js'
|
||||||
|
).snackbar
|
||||||
|
}
|
||||||
|
|
||||||
|
const DUPLICATE_CHILDREN_LIMIT = 50;
|
||||||
|
|
||||||
const duplicateProperty = new ValidatedMethod({
|
const duplicateProperty = new ValidatedMethod({
|
||||||
name: 'creatureProperties.duplicate',
|
name: 'creatureProperties.duplicate',
|
||||||
@@ -20,13 +35,70 @@ const duplicateProperty = new ValidatedMethod({
|
|||||||
timeInterval: 5000,
|
timeInterval: 5000,
|
||||||
},
|
},
|
||||||
run({_id}) {
|
run({_id}) {
|
||||||
let creatureProperty = CreatureProperties.findOne(_id);
|
let property = CreatureProperties.findOne(_id);
|
||||||
let rootCreature = getRootCreatureAncestor(creatureProperty);
|
let creature = getRootCreatureAncestor(property);
|
||||||
assertEditPermission(rootCreature, this.userId);
|
|
||||||
insertPropertyWork({
|
assertEditPermission(creature, this.userId);
|
||||||
property: creatureProperty,
|
|
||||||
creature: rootCreature,
|
// Renew the doc ID
|
||||||
|
let randomSrc = DDP.randomStream('duplicateProperty');
|
||||||
|
let propertyId = randomSrc.id();
|
||||||
|
property._id = propertyId;
|
||||||
|
|
||||||
|
// Get all the descendants
|
||||||
|
let nodes = CreatureProperties.find({
|
||||||
|
'ancestors.id': _id,
|
||||||
|
removed: {$ne: true},
|
||||||
|
}, {
|
||||||
|
limit: DUPLICATE_CHILDREN_LIMIT + 1,
|
||||||
|
sort: {order: 1},
|
||||||
|
}).fetch();
|
||||||
|
|
||||||
|
// Alert the user if the limit was hit
|
||||||
|
if (nodes.length > DUPLICATE_CHILDREN_LIMIT){
|
||||||
|
nodes.pop();
|
||||||
|
if (Meteor.isClient){
|
||||||
|
snackbar({
|
||||||
|
text: `Only the first ${DUPLICATE_CHILDREN_LIMIT} children were duplicated`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-map all the ancestors
|
||||||
|
setLineageOfDocs({
|
||||||
|
docArray: nodes,
|
||||||
|
newAncestry : [
|
||||||
|
...property.ancestors,
|
||||||
|
{id: propertyId, collection: 'creatureProperties'}
|
||||||
|
],
|
||||||
|
oldParent : {id: _id, collection: 'creatureProperties'},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Give the docs new IDs without breaking internal references
|
||||||
|
renewDocIds({docArray: nodes});
|
||||||
|
|
||||||
|
// Order the root node
|
||||||
|
property.order += 0.5;
|
||||||
|
|
||||||
|
// Insert the properties
|
||||||
|
CreatureProperties.batchInsert([property, ...nodes]);
|
||||||
|
|
||||||
|
// Tree structure changed by inserts, reorder the tree
|
||||||
|
reorderDocs({
|
||||||
|
collection: CreatureProperties,
|
||||||
|
ancestorId: property.ancestors[0].id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Inserting the active status of the property needs to be denormalised
|
||||||
|
recomputeInactiveProperties(creature._id);
|
||||||
|
|
||||||
|
// Recompute the inventory
|
||||||
|
recomputeInventory(creature._id);
|
||||||
|
|
||||||
|
// Inserting a creature property invalidates dependencies: full recompute
|
||||||
|
recomputeCreatureByDoc(creature);
|
||||||
|
|
||||||
|
return propertyId;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,23 +4,11 @@ import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
|||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import { organizeDoc } from '/imports/api/parenting/organizeMethods.js';
|
import { organizeDoc } from '/imports/api/parenting/organizeMethods.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
import INVENTORY_TAGS from '/imports/constants/INVENTORY_TAGS.js';
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
export function getParentRefByTag(creatureId, tag){
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
let prop = CreatureProperties.findOne({
|
import BUILT_IN_TAGS from '/imports/constants/BUILT_IN_TAGS.js';
|
||||||
'ancestors.id': creatureId,
|
import getParentRefByTag from '/imports/api/creature/creatureProperties/methods/getParentRefByTag.js';
|
||||||
removed: {$ne: true},
|
|
||||||
inactive: {$ne: true},
|
|
||||||
tags: tag,
|
|
||||||
}, {
|
|
||||||
sort: {order: 1},
|
|
||||||
});
|
|
||||||
if (prop){
|
|
||||||
return {id: prop._id, collection: 'creatureProperties'};
|
|
||||||
} else {
|
|
||||||
return {id: creatureId, collection: 'creatures'};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Equipping or unequipping an item will also change its parent
|
// Equipping or unequipping an item will also change its parent
|
||||||
const equipItem = new ValidatedMethod({
|
const equipItem = new ValidatedMethod({
|
||||||
@@ -47,9 +35,10 @@ const equipItem = new ValidatedMethod({
|
|||||||
}, {
|
}, {
|
||||||
selector: {type: 'item'},
|
selector: {type: 'item'},
|
||||||
});
|
});
|
||||||
let tag = equipped ? INVENTORY_TAGS.equipment : INVENTORY_TAGS.carried;
|
let tag = equipped ? BUILT_IN_TAGS.equipment : BUILT_IN_TAGS.carried;
|
||||||
let parentRef = getParentRefByTag(creature._id, tag);
|
let parentRef = getParentRefByTag(creature._id, tag);
|
||||||
// organizeDoc handles recompuation
|
if (!parentRef) parentRef = {id: creature._id, collection: 'creatures'};
|
||||||
|
|
||||||
organizeDoc.call({
|
organizeDoc.call({
|
||||||
docRef: {
|
docRef: {
|
||||||
id: _id,
|
id: _id,
|
||||||
@@ -57,7 +46,12 @@ const equipItem = new ValidatedMethod({
|
|||||||
},
|
},
|
||||||
parentRef,
|
parentRef,
|
||||||
order: Number.MAX_SAFE_INTEGER,
|
order: Number.MAX_SAFE_INTEGER,
|
||||||
|
skipRecompute: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
recomputeInactiveProperties(creature._id);
|
||||||
|
recomputeInventory(creature._id);
|
||||||
|
recomputeCreatureByDoc(creature);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
|
||||||
|
export default function getParentRefByTag(creatureId, tag){
|
||||||
|
let prop = CreatureProperties.findOne({
|
||||||
|
'ancestors.id': creatureId,
|
||||||
|
removed: {$ne: true},
|
||||||
|
inactive: {$ne: true},
|
||||||
|
tags: tag,
|
||||||
|
}, {
|
||||||
|
sort: {order: 1},
|
||||||
|
});
|
||||||
|
return prop && {id: prop._id, collection: 'creatureProperties'};
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
export default function getSlotFillFilter({slot, libraryIds}){
|
||||||
|
let filter = {
|
||||||
|
removed: {$ne: true},
|
||||||
|
$and: []
|
||||||
|
};
|
||||||
|
if (libraryIds){
|
||||||
|
filter['ancestors.id'] = {$in: libraryIds};
|
||||||
|
}
|
||||||
|
if (slot.slotType){
|
||||||
|
filter.$and.push({
|
||||||
|
$or: [{
|
||||||
|
type: slot.slotType
|
||||||
|
},{
|
||||||
|
type: 'slotFiller',
|
||||||
|
slotFillerType: slot.slotType,
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let tagsOr = [];
|
||||||
|
let tagsNor = [];
|
||||||
|
if (slot.slotTags && slot.slotTags.length){
|
||||||
|
tagsOr.push({tags: {$all: slot.slotTags}});
|
||||||
|
}
|
||||||
|
if (slot.extraTags && slot.extraTags.length){
|
||||||
|
slot.extraTags.forEach(extra => {
|
||||||
|
if (!extra.tags || !extra.tags.length) return;
|
||||||
|
if (extra.operation === 'OR'){
|
||||||
|
tagsOr.push({tags: {$all: extra.tags}});
|
||||||
|
} else if (extra.operation === 'NOT'){
|
||||||
|
tagsNor.push({tags: {$all: extra.tags}});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (tagsOr.length){
|
||||||
|
filter.$and.push({$or: tagsOr});
|
||||||
|
}
|
||||||
|
if (tagsNor.length){
|
||||||
|
filter.$and.push({$nor: tagsNor});
|
||||||
|
}
|
||||||
|
if (!filter.$and.length){
|
||||||
|
delete filter.$and;
|
||||||
|
}
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import '//imports/api/creature/creatureProperties/methods/adjustQuantity.js';
|
import '/imports/api/creature/creatureProperties/methods/adjustQuantity.js';
|
||||||
import '/imports/api/creature/creatureProperties/methods/damagePropertiesByName.js';
|
import '/imports/api/creature/creatureProperties/methods/damagePropertiesByName.js';
|
||||||
import '/imports/api/creature/creatureProperties/methods/damageProperty.js';
|
import '/imports/api/creature/creatureProperties/methods/damageProperty.js';
|
||||||
import '/imports/api/creature/creatureProperties/methods/dealDamage.js';
|
import '/imports/api/creature/creatureProperties/methods/dealDamage.js';
|
||||||
|
|||||||
@@ -2,22 +2,129 @@ import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
|||||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import { reorderDocs } from '/imports/api/parenting/order.js';
|
import { reorderDocs } from '/imports/api/parenting/order.js';
|
||||||
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
import { getAncestry } from '/imports/api/parenting/parenting.js';
|
||||||
|
import getParentRefByTag from '/imports/api/creature/creatureProperties/methods/getParentRefByTag.js';
|
||||||
|
import { RefSchema } from '/imports/api/parenting/ChildSchema.js';
|
||||||
|
import { getHighestOrder } from '/imports/api/parenting/order.js';
|
||||||
|
|
||||||
const insertProperty = new ValidatedMethod({
|
const insertProperty = new ValidatedMethod({
|
||||||
name: 'creatureProperties.insert',
|
name: 'creatureProperties.insert',
|
||||||
validate: null,
|
validate: new SimpleSchema({
|
||||||
|
creatureProperty: {
|
||||||
|
type: Object,
|
||||||
|
blackbox: true,
|
||||||
|
},
|
||||||
|
parentRef: RefSchema,
|
||||||
|
}).validator(),
|
||||||
mixins: [RateLimiterMixin],
|
mixins: [RateLimiterMixin],
|
||||||
rateLimit: {
|
rateLimit: {
|
||||||
numRequests: 5,
|
numRequests: 5,
|
||||||
timeInterval: 5000,
|
timeInterval: 5000,
|
||||||
},
|
},
|
||||||
run({creatureProperty}) {
|
run({creatureProperty, parentRef}) {
|
||||||
let rootCreature = getRootCreatureAncestor(creatureProperty);
|
// get the new ancestry for the properties
|
||||||
|
let {parentDoc, ancestors} = getAncestry({parentRef});
|
||||||
|
|
||||||
|
// Check permission to edit
|
||||||
|
let rootCreature;
|
||||||
|
if (parentRef.collection === 'creatures'){
|
||||||
|
rootCreature = parentDoc;
|
||||||
|
} else if (parentRef.collection === 'creatureProperties'){
|
||||||
|
rootCreature = getRootCreatureAncestor(parentDoc);
|
||||||
|
} else {
|
||||||
|
throw `${parentRef.collection} is not a valid parent collection`
|
||||||
|
}
|
||||||
assertEditPermission(rootCreature, this.userId);
|
assertEditPermission(rootCreature, this.userId);
|
||||||
|
|
||||||
|
creatureProperty.parent = parentRef;
|
||||||
|
creatureProperty.ancestors = ancestors;
|
||||||
|
|
||||||
|
return insertPropertyWork({
|
||||||
|
property: creatureProperty,
|
||||||
|
creature: rootCreature,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const insertPropertyAsChildOfTag = new ValidatedMethod({
|
||||||
|
name: 'creatureProperties.insertAsChildOfTag',
|
||||||
|
validate: new SimpleSchema({
|
||||||
|
creatureProperty: {
|
||||||
|
type: Object,
|
||||||
|
blackbox: true,
|
||||||
|
},
|
||||||
|
creatureId: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
},
|
||||||
|
tag: {
|
||||||
|
type: String,
|
||||||
|
max: 20,
|
||||||
|
},
|
||||||
|
tagDefaultName: {
|
||||||
|
type: String,
|
||||||
|
max: 20,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({creatureProperty, creatureId, tag, tagDefaultName}) {
|
||||||
|
let parentRef = getParentRefByTag(creatureId, tag);
|
||||||
|
|
||||||
|
if (!parentRef){
|
||||||
|
// Use the creature as the parent and mark that we need to insert the folder first later
|
||||||
|
var insertFolderFirst = true;
|
||||||
|
parentRef = {id: creatureId, collection: 'creatures'};
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the new ancestry for the properties
|
||||||
|
let {parentDoc, ancestors} = getAncestry({parentRef});
|
||||||
|
|
||||||
|
// Check permission to edit
|
||||||
|
let rootCreature;
|
||||||
|
if (parentRef.collection === 'creatures'){
|
||||||
|
rootCreature = parentDoc;
|
||||||
|
} else if (parentRef.collection === 'creatureProperties'){
|
||||||
|
rootCreature = getRootCreatureAncestor(parentDoc);
|
||||||
|
} else {
|
||||||
|
throw `${parentRef.collection} is not a valid parent collection`
|
||||||
|
}
|
||||||
|
assertEditPermission(rootCreature, this.userId);
|
||||||
|
|
||||||
|
// Add the folder first if we need to
|
||||||
|
if (insertFolderFirst){
|
||||||
|
let order = getHighestOrder({
|
||||||
|
collection: CreatureProperties,
|
||||||
|
ancestorId: parentRef.id,
|
||||||
|
}) + 1;
|
||||||
|
let id = CreatureProperties.insert({
|
||||||
|
type: 'folder',
|
||||||
|
name: tagDefaultName || (tag.charAt(0).toUpperCase() + tag.slice(1)),
|
||||||
|
tags: [tag],
|
||||||
|
parent: parentRef,
|
||||||
|
ancestors: [parentRef],
|
||||||
|
order,
|
||||||
|
});
|
||||||
|
// Make the folder our new parent
|
||||||
|
let newParentRef = {id, collection: 'creatureProperties'};
|
||||||
|
ancestors = [parentRef, newParentRef];
|
||||||
|
parentRef = newParentRef;
|
||||||
|
creatureProperty.order = order + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
creatureProperty.parent = parentRef;
|
||||||
|
creatureProperty.ancestors = ancestors;
|
||||||
|
|
||||||
return insertPropertyWork({
|
return insertPropertyWork({
|
||||||
property: creatureProperty,
|
property: creatureProperty,
|
||||||
creature: rootCreature,
|
creature: rootCreature,
|
||||||
@@ -35,9 +142,15 @@ export function insertPropertyWork({property, creature}){
|
|||||||
});
|
});
|
||||||
// Inserting the active status of the property needs to be denormalised
|
// Inserting the active status of the property needs to be denormalised
|
||||||
recomputeInactiveProperties(creature._id);
|
recomputeInactiveProperties(creature._id);
|
||||||
|
|
||||||
|
// Recompute the inventory if it has changed
|
||||||
|
if (property.type === 'item' || property.type === 'container'){
|
||||||
|
recomputeInventory(creature._id);
|
||||||
|
}
|
||||||
// Inserting a creature property invalidates dependencies: full recompute
|
// Inserting a creature property invalidates dependencies: full recompute
|
||||||
recomputeCreatureByDoc(creature);
|
recomputeCreatureByDoc(creature);
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default insertProperty;
|
export default insertProperty;
|
||||||
|
export { insertPropertyAsChildOfTag };
|
||||||
|
|||||||
@@ -15,24 +15,34 @@ import {
|
|||||||
} from '/imports/api/parenting/parenting.js';
|
} from '/imports/api/parenting/parenting.js';
|
||||||
import { reorderDocs } from '/imports/api/parenting/order.js';
|
import { reorderDocs } from '/imports/api/parenting/order.js';
|
||||||
import { setDocToLastOrder } from '/imports/api/parenting/order.js';
|
import { setDocToLastOrder } from '/imports/api/parenting/order.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
import fetchDocByRef from '/imports/api/parenting/fetchDocByRef.js';
|
||||||
|
|
||||||
const insertPropertyFromLibraryNode = new ValidatedMethod({
|
const insertPropertyFromLibraryNode = new ValidatedMethod({
|
||||||
name: 'creatureProperties.insertPropertyFromLibraryNode',
|
name: 'creatureProperties.insertPropertyFromLibraryNode',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
nodeId: {
|
nodeIds: {
|
||||||
|
type: Array,
|
||||||
|
max: 20,
|
||||||
|
},
|
||||||
|
'nodeIds.$': {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
},
|
},
|
||||||
parentRef: {
|
parentRef: {
|
||||||
type: RefSchema,
|
type: RefSchema,
|
||||||
},
|
},
|
||||||
|
order: {
|
||||||
|
type: Number,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
}).validator(),
|
}).validator(),
|
||||||
mixins: [RateLimiterMixin],
|
mixins: [RateLimiterMixin],
|
||||||
rateLimit: {
|
rateLimit: {
|
||||||
numRequests: 5,
|
numRequests: 5,
|
||||||
timeInterval: 5000,
|
timeInterval: 5000,
|
||||||
},
|
},
|
||||||
run({nodeId, parentRef}) {
|
run({nodeIds, parentRef, order}) {
|
||||||
// get the new ancestry for the properties
|
// get the new ancestry for the properties
|
||||||
let {parentDoc, ancestors} = getAncestry({parentRef});
|
let {parentDoc, ancestors} = getAncestry({parentRef});
|
||||||
|
|
||||||
@@ -47,46 +57,15 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
|||||||
}
|
}
|
||||||
assertEditPermission(rootCreature, this.userId);
|
assertEditPermission(rootCreature, this.userId);
|
||||||
|
|
||||||
// Fetch the library node and its decendents, provided they have not been
|
// {libraryId: hasViewPermission}
|
||||||
// removed
|
//let libraryPermissionMemoir = {};
|
||||||
let node = LibraryNodes.findOne({
|
let node;
|
||||||
_id: nodeId,
|
nodeIds.forEach(nodeId => {
|
||||||
removed: {$ne: true},
|
// TODO: Check library view permission for each node before starting
|
||||||
});
|
node = insertPropertyFromNode(nodeId, ancestors, order);
|
||||||
if (!node) throw `Node not found for nodeId: ${nodeId}`;
|
});
|
||||||
let oldParent = node.parent;
|
|
||||||
let nodes = LibraryNodes.find({
|
|
||||||
'ancestors.id': nodeId,
|
|
||||||
removed: {$ne: true},
|
|
||||||
}).fetch();
|
|
||||||
|
|
||||||
// The root node is first in the array of nodes
|
// get one of the root inserted docs
|
||||||
// It must get the first generated ID to prevent flickering
|
|
||||||
nodes = [node, ...nodes];
|
|
||||||
|
|
||||||
// re-map all the ancestors
|
|
||||||
setLineageOfDocs({
|
|
||||||
docArray: nodes,
|
|
||||||
newAncestry: ancestors,
|
|
||||||
oldParent,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Give the docs new IDs without breaking internal references
|
|
||||||
renewDocIds({
|
|
||||||
docArray: nodes,
|
|
||||||
collectionMap: {'libraryNodes': 'creatureProperties'}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Order the root node
|
|
||||||
setDocToLastOrder({
|
|
||||||
collection: CreatureProperties,
|
|
||||||
doc: node,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Insert the creature properties
|
|
||||||
CreatureProperties.batchInsert(nodes);
|
|
||||||
|
|
||||||
// get the root inserted doc
|
|
||||||
let rootId = node._id;
|
let rootId = node._id;
|
||||||
|
|
||||||
// Tree structure changed by inserts, reorder the tree
|
// Tree structure changed by inserts, reorder the tree
|
||||||
@@ -96,7 +75,9 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// The library properties need to denormalise which of them are inactive
|
// The library properties need to denormalise which of them are inactive
|
||||||
recomputeInactiveProperties(rootId);
|
recomputeInactiveProperties(rootCreature._id);
|
||||||
|
// Some of the library properties may be items or containers
|
||||||
|
recomputeInventory(rootCreature._id);
|
||||||
// Inserting a creature property invalidates dependencies: full recompute
|
// Inserting a creature property invalidates dependencies: full recompute
|
||||||
recomputeCreatureByDoc(rootCreature);
|
recomputeCreatureByDoc(rootCreature);
|
||||||
// Return the docId of the last property, the inserted root property
|
// Return the docId of the last property, the inserted root property
|
||||||
@@ -104,4 +85,158 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function insertPropertyFromNode(nodeId, ancestors, order){
|
||||||
|
// Fetch the library node and its decendents, provided they have not been
|
||||||
|
// removed
|
||||||
|
// TODO: Check permission to read the library this node is in
|
||||||
|
let node = LibraryNodes.findOne({
|
||||||
|
_id: nodeId,
|
||||||
|
removed: {$ne: true},
|
||||||
|
});
|
||||||
|
if (!node) throw `Node not found for nodeId: ${nodeId}`;
|
||||||
|
let oldParent = node.parent;
|
||||||
|
let nodes = LibraryNodes.find({
|
||||||
|
'ancestors.id': nodeId,
|
||||||
|
removed: {$ne: true},
|
||||||
|
}).fetch();
|
||||||
|
|
||||||
|
// Convert all references into actual nodes
|
||||||
|
nodes = reifyNodeReferences(nodes);
|
||||||
|
|
||||||
|
// The root node is first in the array of nodes
|
||||||
|
// It must get the first generated ID to prevent flickering
|
||||||
|
nodes = [node, ...nodes];
|
||||||
|
|
||||||
|
// set libraryNodeIds
|
||||||
|
storeLibraryNodeReferences(nodes, nodeId);
|
||||||
|
|
||||||
|
// re-map all the ancestors
|
||||||
|
setLineageOfDocs({
|
||||||
|
docArray: nodes,
|
||||||
|
newAncestry: ancestors,
|
||||||
|
oldParent,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Give the docs new IDs without breaking internal references
|
||||||
|
renewDocIds({
|
||||||
|
docArray: nodes,
|
||||||
|
collectionMap: {'libraryNodes': 'creatureProperties'}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Order the root node
|
||||||
|
if (order === undefined){
|
||||||
|
setDocToLastOrder({
|
||||||
|
collection: CreatureProperties,
|
||||||
|
doc: node,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
node.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert the creature properties
|
||||||
|
CreatureProperties.batchInsert(nodes);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function storeLibraryNodeReferences(nodes){
|
||||||
|
nodes.forEach(node => {
|
||||||
|
node.libraryNodeId = node._id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Covert node references into actual nodes
|
||||||
|
// TODO: check permissions for each library a reference node references
|
||||||
|
function reifyNodeReferences(nodes, visitedRefs = new Set(), depth = 0){
|
||||||
|
depth += 1;
|
||||||
|
// New nodes added this function
|
||||||
|
let newNodes = [];
|
||||||
|
|
||||||
|
// Filter out the reference nodes we replace
|
||||||
|
let resultingNodes = nodes.filter(node => {
|
||||||
|
|
||||||
|
// We have already visited this ref and replaced it
|
||||||
|
if (visitedRefs.has(node._id)) return false;
|
||||||
|
|
||||||
|
// Already replaced an ancestor node
|
||||||
|
for (let i; i < node.ancestors.length; i++){
|
||||||
|
if (visitedRefs.has(node.ancestors[i].id)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This isn't a reference node, continue as normal
|
||||||
|
if (node.type !== 'reference') return true;
|
||||||
|
|
||||||
|
// We have gone too deep, keep the reference node as an error
|
||||||
|
if (depth > 10){
|
||||||
|
if (Meteor.isClient) console.warn('Reference depth limit exceeded');
|
||||||
|
node.cache = {error: 'Reference depth limit exceeded'};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let referencedNode
|
||||||
|
try {
|
||||||
|
referencedNode = fetchDocByRef(node.ref);
|
||||||
|
referencedNode.order = node.order;
|
||||||
|
// We are definitely replacing this node, so add it to the list
|
||||||
|
visitedRefs.add(node._id);
|
||||||
|
} catch (e){
|
||||||
|
node.cache = {error: e.reason || e.message || e.toString()};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all the descendants of the referenced node
|
||||||
|
let descendents = LibraryNodes.find({
|
||||||
|
'ancestors.id': referencedNode._id,
|
||||||
|
removed: {$ne: true},
|
||||||
|
}, {
|
||||||
|
sort: {order: 1},
|
||||||
|
}).fetch();
|
||||||
|
|
||||||
|
// We are adding the referenced node and its descendants
|
||||||
|
let addedNodes = [referencedNode, ...descendents];
|
||||||
|
|
||||||
|
// re-map all the ancestors to parent the new sub-tree into our existing
|
||||||
|
// node tree
|
||||||
|
setLineageOfDocs({
|
||||||
|
docArray: addedNodes,
|
||||||
|
newAncestry: node.ancestors,
|
||||||
|
oldParent: referencedNode.parent,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove all the looped references and descendents from the new nodes
|
||||||
|
// We can't rely on the reify recursion to do this, since the IDs are
|
||||||
|
// getting renewed before it is called
|
||||||
|
addedNodes = addedNodes.filter(node => {
|
||||||
|
// Exclude removed referenced
|
||||||
|
if (visitedRefs.has(node._id)) return false;
|
||||||
|
|
||||||
|
// Exclude descendants of removed references
|
||||||
|
for (let i; i < node.ancestors.length; i++){
|
||||||
|
if (visitedRefs.has(node.ancestors[i].id)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Force the referencedNode to take the old id of the reference
|
||||||
|
// such that the reference's children can be kept
|
||||||
|
|
||||||
|
// Give the new referenced sub-tree new ids
|
||||||
|
renewDocIds({
|
||||||
|
docArray: addedNodes,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reify the subtree as well with recursion
|
||||||
|
addedNodes = reifyNodeReferences(addedNodes, visitedRefs, depth);
|
||||||
|
|
||||||
|
// Store the new nodes from this inner loop without altering the array
|
||||||
|
// we are looping over
|
||||||
|
newNodes.push(...addedNodes);
|
||||||
|
});
|
||||||
|
|
||||||
|
// We are done filtering the array, we can add the new nodes to it
|
||||||
|
resultingNodes.push(...newNodes);
|
||||||
|
|
||||||
|
return resultingNodes;
|
||||||
|
}
|
||||||
|
|
||||||
export default insertPropertyFromLibraryNode;
|
export default insertPropertyFromLibraryNode;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import CreatureProperties from '/imports/api/creature/creatureProperties/Creatur
|
|||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
import { get } from 'lodash';
|
||||||
|
|
||||||
const pushToProperty = new ValidatedMethod({
|
const pushToProperty = new ValidatedMethod({
|
||||||
name: 'creatureProperties.push',
|
name: 'creatureProperties.push',
|
||||||
@@ -19,9 +20,26 @@ const pushToProperty = new ValidatedMethod({
|
|||||||
let rootCreature = getRootCreatureAncestor(property);
|
let rootCreature = getRootCreatureAncestor(property);
|
||||||
assertEditPermission(rootCreature, this.userId);
|
assertEditPermission(rootCreature, this.userId);
|
||||||
|
|
||||||
|
let joinedPath = path.join('.');
|
||||||
|
|
||||||
|
// Respect maxCount
|
||||||
|
let schema = CreatureProperties.simpleSchema(property);
|
||||||
|
let maxCount = schema.get(joinedPath, 'maxCount');
|
||||||
|
|
||||||
|
if (Number.isFinite(maxCount)){
|
||||||
|
let array = get(property, path);
|
||||||
|
let currentCount = array ? array.length : 0;
|
||||||
|
if (currentCount >= maxCount){
|
||||||
|
throw new Meteor.Error(
|
||||||
|
'Array is full',
|
||||||
|
`Cannot have more than ${maxCount} values`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Do work
|
// Do work
|
||||||
CreatureProperties.update(_id, {
|
CreatureProperties.update(_id, {
|
||||||
$push: {[path.join('.')]: value},
|
$push: {[joinedPath]: value},
|
||||||
}, {
|
}, {
|
||||||
selector: {type: property.type},
|
selector: {type: property.type},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { restore } from '/imports/api/parenting/softRemove.js';
|
|||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
|
||||||
const restoreProperty = new ValidatedMethod({
|
const restoreProperty = new ValidatedMethod({
|
||||||
name: 'creatureProperties.restore',
|
name: 'creatureProperties.restore',
|
||||||
@@ -27,6 +28,8 @@ const restoreProperty = new ValidatedMethod({
|
|||||||
// Do work
|
// Do work
|
||||||
restore({_id, collection: CreatureProperties});
|
restore({_id, collection: CreatureProperties});
|
||||||
|
|
||||||
|
// Items and containers might be restored
|
||||||
|
recomputeInventory(rootCreature._id);
|
||||||
// Parents active status may have changed while it was deleted
|
// Parents active status may have changed while it was deleted
|
||||||
recomputeInactiveProperties(rootCreature._id);
|
recomputeInactiveProperties(rootCreature._id);
|
||||||
// Changes dependency tree by restoring children
|
// Changes dependency tree by restoring children
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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 getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
|
||||||
const softRemoveProperty = new ValidatedMethod({
|
const softRemoveProperty = new ValidatedMethod({
|
||||||
name: 'creatureProperties.softRemove',
|
name: 'creatureProperties.softRemove',
|
||||||
@@ -26,6 +27,8 @@ const softRemoveProperty = new ValidatedMethod({
|
|||||||
// Do work
|
// Do work
|
||||||
softRemove({_id, collection: CreatureProperties});
|
softRemove({_id, collection: CreatureProperties});
|
||||||
|
|
||||||
|
// Potentially changes items and containers
|
||||||
|
recomputeInventory(rootCreature._id);
|
||||||
// Changes dependency tree by removing children
|
// Changes dependency tree by removing children
|
||||||
recomputeCreatureByDoc(rootCreature);
|
recomputeCreatureByDoc(rootCreature);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
|||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureById } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||||
|
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||||
|
|
||||||
const updateCreatureProperty = new ValidatedMethod({
|
const updateCreatureProperty = new ValidatedMethod({
|
||||||
name: 'creatureProperties.update',
|
name: 'creatureProperties.update',
|
||||||
@@ -52,8 +53,14 @@ const updateCreatureProperty = new ValidatedMethod({
|
|||||||
].includes(path[0])){
|
].includes(path[0])){
|
||||||
recomputeInactiveProperties(rootCreature._id);
|
recomputeInactiveProperties(rootCreature._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property.type === 'item' || property.type === 'container'){
|
||||||
|
// Potentially changes items and containers
|
||||||
|
recomputeInventory(rootCreature._id);
|
||||||
|
}
|
||||||
// Updating a property is likely to change dependencies, do a full recompute
|
// Updating a property is likely to change dependencies, do a full recompute
|
||||||
recomputeCreatureByDoc(rootCreature);
|
// denormalised stats might change, so fetch the creature again
|
||||||
|
recomputeCreatureById(rootCreature._id);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
180
app/imports/api/creature/creatures/Creatures.js
Normal file
180
app/imports/api/creature/creatures/Creatures.js
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import deathSaveSchema from '/imports/api/properties/subSchemas/DeathSavesSchema.js'
|
||||||
|
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
||||||
|
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
|
//set up the collection for creatures
|
||||||
|
let Creatures = new Mongo.Collection('creatures');
|
||||||
|
|
||||||
|
let CreatureSettingsSchema = new SimpleSchema({
|
||||||
|
//slowed down by carrying too much?
|
||||||
|
useVariantEncumbrance: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
//hide spellcasting tab
|
||||||
|
hideSpellcasting: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
// Swap around the modifier and stat
|
||||||
|
swapStatAndModifier: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
// Hide all the unused stats
|
||||||
|
hideUnusedStats: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
// Show the tree tab
|
||||||
|
showTreeTab: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
// Hide the spells tab
|
||||||
|
hideSpellsTab: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
// How much each hitDice resets on a long rest
|
||||||
|
hitDiceResetMultiplier: {
|
||||||
|
type: Number,
|
||||||
|
optional: true,
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
},
|
||||||
|
discordWebhook: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.url,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let CreatureSchema = new SimpleSchema({
|
||||||
|
// Strings
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
defaultValue: '',
|
||||||
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
|
},
|
||||||
|
alignment: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
|
},
|
||||||
|
gender: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
|
},
|
||||||
|
picture: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.url,
|
||||||
|
},
|
||||||
|
avatarPicture: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.url,
|
||||||
|
},
|
||||||
|
// Mechanics
|
||||||
|
deathSave: {
|
||||||
|
type: deathSaveSchema,
|
||||||
|
defaultValue: {},
|
||||||
|
},
|
||||||
|
// Stats that are computed and denormalised outside of recomputation
|
||||||
|
denormalizedStats: {
|
||||||
|
type: Object,
|
||||||
|
defaultValue: {},
|
||||||
|
},
|
||||||
|
// Sum of all XP gained by this character
|
||||||
|
'denormalizedStats.xp': {
|
||||||
|
type: SimpleSchema.Integer,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
// Sum of all levels granted by milestone XP
|
||||||
|
'denormalizedStats.milestoneLevels': {
|
||||||
|
type: SimpleSchema.Integer,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
// Inventory
|
||||||
|
'denormalizedStats.weightTotal': {
|
||||||
|
type: Number,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
'denormalizedStats.weightEquipment': {
|
||||||
|
type: Number,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
'denormalizedStats.weightCarried': {
|
||||||
|
type: Number,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
'denormalizedStats.valueTotal': {
|
||||||
|
type: Number,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
'denormalizedStats.valueEquipment': {
|
||||||
|
type: Number,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
'denormalizedStats.valueCarried': {
|
||||||
|
type: Number,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
'denormalizedStats.itemsAttuned': {
|
||||||
|
type: Number,
|
||||||
|
defaultValue: 0,
|
||||||
|
},
|
||||||
|
// Version of computation engine that was last used to compute this creature
|
||||||
|
computeVersion: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
defaultValue: 'pc',
|
||||||
|
allowedValues: ['pc', 'npc', 'monster'],
|
||||||
|
},
|
||||||
|
damageMultipliers: {
|
||||||
|
type: Object,
|
||||||
|
blackbox: true,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
variables: {
|
||||||
|
type: Object,
|
||||||
|
blackbox: true,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Tabletop
|
||||||
|
tabletop: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.id,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
initiativeRoll: {
|
||||||
|
type: SimpleSchema.Integer,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
settings: {
|
||||||
|
type: CreatureSettingsSchema,
|
||||||
|
defaultValue: {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
CreatureSchema.extend(ColorSchema);
|
||||||
|
CreatureSchema.extend(SharingSchema);
|
||||||
|
|
||||||
|
Creatures.attachSchema(CreatureSchema);
|
||||||
|
|
||||||
|
|
||||||
|
import '/imports/api/creature/creatures/methods/index.js';
|
||||||
|
|
||||||
|
export default Creatures;
|
||||||
|
export { CreatureSchema };
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import {
|
import {
|
||||||
assertEditPermission as editPermission,
|
assertEditPermission as editPermission,
|
||||||
assertViewPermission as viewPermission,
|
assertViewPermission as viewPermission,
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import BUILT_IN_TAGS from '/imports/constants/BUILT_IN_TAGS.js';
|
||||||
|
|
||||||
|
export default function defaultCharacterProperties(creatureId){
|
||||||
|
if (!creatureId) throw 'creatureId is required';
|
||||||
|
const creatureRef = {collection: 'creatures', id: creatureId};
|
||||||
|
let randomSrc = DDP.randomStream('defaultProperties');
|
||||||
|
const inventoryId = randomSrc.id();
|
||||||
|
const inventoryRef = {collection: 'creatureProperties', id: inventoryId};
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: 'propertySlot',
|
||||||
|
name: 'Ruleset',
|
||||||
|
description: 'Choose a starting point for your character, this will define the basic setup of your character sheet. Without a base, your sheet will be empty.',
|
||||||
|
slotTags: ['base'],
|
||||||
|
tags: [],
|
||||||
|
quantityExpected: 1,
|
||||||
|
hideWhenFull: true,
|
||||||
|
spaceLeft: 1,
|
||||||
|
totalFilled: 0,
|
||||||
|
order: 0,
|
||||||
|
parent: creatureRef,
|
||||||
|
ancestors: [creatureRef],
|
||||||
|
}, {
|
||||||
|
_id: inventoryId,
|
||||||
|
type: 'folder',
|
||||||
|
name: 'Inventory',
|
||||||
|
tags: [BUILT_IN_TAGS.inventory],
|
||||||
|
order: 1,
|
||||||
|
parent: creatureRef,
|
||||||
|
ancestors: [creatureRef],
|
||||||
|
}, {
|
||||||
|
type: 'folder',
|
||||||
|
name: 'Equipment',
|
||||||
|
tags: [BUILT_IN_TAGS.equipment],
|
||||||
|
order: 2,
|
||||||
|
parent: inventoryRef,
|
||||||
|
ancestors: [creatureRef, inventoryRef],
|
||||||
|
}, {
|
||||||
|
type: 'folder',
|
||||||
|
name: 'Carried',
|
||||||
|
tags: [BUILT_IN_TAGS.carried],
|
||||||
|
order: 3,
|
||||||
|
parent: inventoryRef,
|
||||||
|
ancestors: [creatureRef, inventoryRef],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
5
app/imports/api/creature/creatures/getCreatureUrlName.js
Normal file
5
app/imports/api/creature/creatures/getCreatureUrlName.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import getSlug from 'speakingurl';
|
||||||
|
|
||||||
|
export default function getCreatureUrlName({name}){
|
||||||
|
return getSlug(name, {maintainCase: true}) || '-';
|
||||||
|
}
|
||||||
4
app/imports/api/creature/creatures/methods/index.js
Normal file
4
app/imports/api/creature/creatures/methods/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import '/imports/api/creature/creatures/methods/insertCreature.js';
|
||||||
|
import '/imports/api/creature/creatures/methods/removeCreature.js';
|
||||||
|
import '/imports/api/creature/creatures/methods/restCreature.js';
|
||||||
|
import '/imports/api/creature/creatures/methods/updateCreature.js';
|
||||||
70
app/imports/api/creature/creatures/methods/insertCreature.js
Normal file
70
app/imports/api/creature/creatures/methods/insertCreature.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||||
|
import defaultCharacterProperties from '/imports/api/creature/creatures/defaultCharacterProperties.js';
|
||||||
|
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode.js';
|
||||||
|
|
||||||
|
const insertCreature = new ValidatedMethod({
|
||||||
|
|
||||||
|
name: 'creatures.insertCreature',
|
||||||
|
|
||||||
|
validate: null,
|
||||||
|
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
|
||||||
|
run() {
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('Creatures.methods.insert.denied',
|
||||||
|
'You need to be logged in to insert a creature');
|
||||||
|
}
|
||||||
|
let tier = getUserTier(this.userId);
|
||||||
|
|
||||||
|
let currentCharacterCount = Creatures.find({
|
||||||
|
owner: this.userId,
|
||||||
|
}, {
|
||||||
|
fields: {_id: 1},
|
||||||
|
}).count();
|
||||||
|
|
||||||
|
if (
|
||||||
|
tier.characterSlots !== -1 &&
|
||||||
|
currentCharacterCount >= tier.characterSlots
|
||||||
|
){
|
||||||
|
throw new Meteor.Error('Creatures.methods.insert.denied',
|
||||||
|
`You are already at your limit of ${tier.characterSlots} characters`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the creature document
|
||||||
|
let creatureId = Creatures.insert({
|
||||||
|
owner: this.userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Insert the default properties
|
||||||
|
// Not batchInsert because we want the properties cleaned by the schema
|
||||||
|
let baseId;
|
||||||
|
defaultCharacterProperties(creatureId).forEach(prop => {
|
||||||
|
let id = CreatureProperties.insert(prop);
|
||||||
|
if (prop.name === 'Ruleset'){
|
||||||
|
baseId = id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Meteor.isServer){
|
||||||
|
// Insert the 5e ruleset as the default base
|
||||||
|
insertPropertyFromLibraryNode.call({
|
||||||
|
nodeIds: ['iHbhfcg3AL5isSWbw'],
|
||||||
|
parentRef: {id: baseId, collection: 'creatureProperties'},
|
||||||
|
order: 0.5,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return creatureId;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default insertCreature;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
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 { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import { assertOwnership } from '/imports/api/creature/creaturePermissions.js';
|
import { assertOwnership } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
||||||
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
import Experiences from '/imports/api/creature/experience/Experiences.js';
|
||||||
@@ -28,10 +28,14 @@ const removeCreature = new ValidatedMethod({
|
|||||||
},
|
},
|
||||||
run({charId}) {
|
run({charId}) {
|
||||||
assertOwnership(charId, this.userId)
|
assertOwnership(charId, this.userId)
|
||||||
Creatures.remove(charId);
|
this.unblock();
|
||||||
this.unblock();
|
removeCreatureWork(charId)
|
||||||
removeRelatedDocuments(charId);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export function removeCreatureWork(creatureId){
|
||||||
|
Creatures.remove(creatureId);
|
||||||
|
removeRelatedDocuments(creatureId);
|
||||||
|
}
|
||||||
|
|
||||||
export default removeCreature;
|
export default removeCreature;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
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 { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
import { recomputeCreatureById } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureById } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
|
||||||
const restCreature = new ValidatedMethod({
|
const restCreature = new ValidatedMethod({
|
||||||
45
app/imports/api/creature/creatures/methods/updateCreature.js
Normal file
45
app/imports/api/creature/creatures/methods/updateCreature.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
|
import {assertEditPermission} from '/imports/api/sharing/sharingPermissions.js';
|
||||||
|
|
||||||
|
const updateCreature = new ValidatedMethod({
|
||||||
|
name: 'creatures.update',
|
||||||
|
validate({_id, path}){
|
||||||
|
if (!_id) return false;
|
||||||
|
// Allowed fields
|
||||||
|
let allowedFields = [
|
||||||
|
'name',
|
||||||
|
'alignment',
|
||||||
|
'gender',
|
||||||
|
'picture',
|
||||||
|
'avatarPicture',
|
||||||
|
'color',
|
||||||
|
'settings',
|
||||||
|
];
|
||||||
|
if (!allowedFields.includes(path[0])){
|
||||||
|
throw new Meteor.Error('Creatures.methods.update.denied',
|
||||||
|
'This field can\'t be updated using this method');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({_id, path, value}) {
|
||||||
|
let creature = Creatures.findOne(_id);
|
||||||
|
assertEditPermission(creature, this.userId);
|
||||||
|
if (value === undefined || value === null){
|
||||||
|
Creatures.update(_id, {
|
||||||
|
$unset: {[path.join('.')]: 1},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Creatures.update(_id, {
|
||||||
|
$set: {[path.join('.')]: value},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default updateCreature;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
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/creatures/creaturePermissions.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
|
||||||
export const recomputeDamageMultipliers = new ValidatedMethod({
|
export const recomputeDamageMultipliers = new ValidatedMethod({
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ export default function recomputeInactiveProperties(ancestorId){
|
|||||||
{disabled: true}, // Everything can be disabled
|
{disabled: true}, // Everything can be disabled
|
||||||
{type: 'buff', applied: false}, // Buffs can be applied
|
{type: 'buff', applied: false}, // Buffs can be applied
|
||||||
{type: 'item', equipped: {$ne: true}},
|
{type: 'item', equipped: {$ne: true}},
|
||||||
{type: 'toggle', toggleResult: false},
|
|
||||||
{type: 'spell', prepared: {$ne: true}, alwaysPrepared: {$ne: true}},
|
{type: 'spell', prepared: {$ne: true}, alwaysPrepared: {$ne: true}},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -56,14 +55,18 @@ export default function recomputeInactiveProperties(ancestorId){
|
|||||||
CreatureProperties.update({
|
CreatureProperties.update({
|
||||||
'ancestors.id': {$eq: ancestorId, $nin: disabledIds},
|
'ancestors.id': {$eq: ancestorId, $nin: disabledIds},
|
||||||
'_id': {$nin: disabledIds},
|
'_id': {$nin: disabledIds},
|
||||||
|
// if it was a toggle responsible, we leave it alone
|
||||||
|
deactivatedByToggle: {$ne: true},
|
||||||
$or: [
|
$or: [
|
||||||
{inactive: true},
|
{inactive: true},
|
||||||
{deactivatedByAncestor: true},
|
{deactivatedByAncestor: true},
|
||||||
|
{deactivatedBySelf: true}
|
||||||
],
|
],
|
||||||
}, {
|
}, {
|
||||||
$unset: {
|
$unset: {
|
||||||
inactive: 1,
|
inactive: 1,
|
||||||
deactivatedByAncestor: 1,
|
deactivatedByAncestor: 1,
|
||||||
|
deactivatedBySelf: 1,
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
multi: true,
|
multi: true,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
import nodesToTree from '/imports/api/parenting/parenting.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
|
import nodesToTree from '/imports/api/parenting/nodesToTree.js';
|
||||||
|
|
||||||
export default function recomputeInventory(creatureId){
|
export default function recomputeInventory(creatureId){
|
||||||
let inventoryForest = nodesToTree({
|
let inventoryForest = nodesToTree({
|
||||||
@@ -10,27 +11,27 @@ export default function recomputeInventory(creatureId){
|
|||||||
},
|
},
|
||||||
deactivatedByAncestor: {$ne: true},
|
deactivatedByAncestor: {$ne: true},
|
||||||
});
|
});
|
||||||
return getChildrenInventoryData(inventoryForest);
|
let containersToWrite = [];
|
||||||
}
|
let data = getChildrenInventoryData(inventoryForest, containersToWrite);
|
||||||
|
containersToWrite.forEach(container => {
|
||||||
function getChildrenInventoryData(forest){
|
CreatureProperties.update(container._id, {$set: {
|
||||||
let data = {
|
contentsWeight: container.contentsWeight,
|
||||||
weightTotal: 0,
|
contentsValue: container.contentsValue,
|
||||||
weightEquipment: 0,
|
}}, {selector: {type: 'container'}});
|
||||||
weightCarried: 0,
|
|
||||||
valueTotal: 0,
|
|
||||||
valueEquipment: 0,
|
|
||||||
valueCarried: 0,
|
|
||||||
}
|
|
||||||
forest.forEach(tree => {
|
|
||||||
let treeData = getInventoryData(tree);
|
|
||||||
for (let key in data){
|
|
||||||
data[key] += treeData[key];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
Creatures.update(creatureId, {$set: {
|
||||||
|
'denormalizedStats.weightTotal': data.weightTotal,
|
||||||
|
'denormalizedStats.weightEquipment': data.weightEquipment,
|
||||||
|
'denormalizedStats.weightCarried': data.weightCarried,
|
||||||
|
'denormalizedStats.valueTotal': data.valueTotal,
|
||||||
|
'denormalizedStats.valueEquipment': data.valueEquipment,
|
||||||
|
'denormalizedStats.valueCarried': data.valueCarried,
|
||||||
|
'denormalizedStats.itemsAttuned': data.itemsAttuned,
|
||||||
|
}});
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInventoryData(tree){
|
function getChildrenInventoryData(forest, containersToWrite){
|
||||||
let data = {
|
let data = {
|
||||||
weightTotal: 0,
|
weightTotal: 0,
|
||||||
weightEquipment: 0,
|
weightEquipment: 0,
|
||||||
@@ -40,24 +41,41 @@ function getInventoryData(tree){
|
|||||||
valueCarried: 0,
|
valueCarried: 0,
|
||||||
itemsAttuned: 0,
|
itemsAttuned: 0,
|
||||||
}
|
}
|
||||||
let childData = getChildrenInventoryData(tree.children);
|
forest.forEach(tree => {
|
||||||
|
let treeData = getInventoryData(tree, containersToWrite);
|
||||||
|
for (let key in data){
|
||||||
|
data[key] += treeData[key] || 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getInventoryData(tree, containersToWrite){
|
||||||
|
let data = {
|
||||||
|
weightTotal: 0,
|
||||||
|
weightEquipment: 0,
|
||||||
|
weightCarried: 0,
|
||||||
|
valueTotal: 0,
|
||||||
|
valueEquipment: 0,
|
||||||
|
valueCarried: 0,
|
||||||
|
itemsAttuned: 0,
|
||||||
|
}
|
||||||
|
let childData = getChildrenInventoryData(tree.children, containersToWrite);
|
||||||
let node = tree.node;
|
let node = tree.node;
|
||||||
if (node.type === 'container'){
|
if (node.type === 'container'){
|
||||||
data.weightTotal += node.weight;
|
data.weightTotal += node.weight || 0;
|
||||||
data.valueTotal += node.value;
|
data.valueTotal += node.value || 0;
|
||||||
if (node.carried){
|
data.weightCarried += node.weight || 0;
|
||||||
data.weightCarried += node.weight;
|
data.valueCarried += node.value || 0;
|
||||||
data.valueCarried += node.valueCarried;
|
storeContentsData(node, childData, containersToWrite);
|
||||||
}
|
|
||||||
storeContentsData(node, childData);
|
|
||||||
} else if (node.type === 'item'){
|
} else if (node.type === 'item'){
|
||||||
data.weightTotal += node.weight * node.quantity;
|
data.weightTotal += (node.weight * node.quantity) || 0;
|
||||||
data.valueTotal += node.value * node.quantity;
|
data.valueTotal += (node.value * node.quantity) || 0;
|
||||||
data.weightCarried += node.weight * node.quantity;
|
data.weightCarried += (node.weight * node.quantity) || 0;
|
||||||
data.valueCarried += node.valueCarried * node.quantity;
|
data.valueCarried += (node.value * node.quantity) || 0;
|
||||||
if (node.equipped){
|
if (node.equipped){
|
||||||
data.weightEquipment += node.weight * node.quantity;
|
data.weightEquipment += (node.weight * node.quantity) || 0;
|
||||||
data.valueEquipment += node.valueCarried * node.quantity;
|
data.valueEquipment += (node.value * node.quantity) || 0;
|
||||||
}
|
}
|
||||||
if (node.attuned){
|
if (node.attuned){
|
||||||
data.itemsAttuned += 1;
|
data.itemsAttuned += 1;
|
||||||
@@ -66,16 +84,18 @@ function getInventoryData(tree){
|
|||||||
for (let key in data){
|
for (let key in data){
|
||||||
data[key] += childData[key];
|
data[key] += childData[key];
|
||||||
}
|
}
|
||||||
|
if (node.contentsWeightless){
|
||||||
|
data.weightCarried = node.weight;
|
||||||
|
}
|
||||||
|
if (node.carried === false){
|
||||||
|
data.weightCarried = 0;
|
||||||
|
data.valueCarried = 0;
|
||||||
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeContentsData(node, childData){
|
function storeContentsData(node, childData, containersToWrite){
|
||||||
let newContentsWeight;
|
let newContentsWeight = childData.weightCarried
|
||||||
if (node.contentsWeightless){
|
|
||||||
newContentsWeight = 0;
|
|
||||||
} else {
|
|
||||||
newContentsWeight = childData.weightCarried
|
|
||||||
}
|
|
||||||
if (node.contentsWeight !== newContentsWeight){
|
if (node.contentsWeight !== newContentsWeight){
|
||||||
node.contentsWeight = newContentsWeight;
|
node.contentsWeight = newContentsWeight;
|
||||||
node.contentsWeightChanged = true;
|
node.contentsWeightChanged = true;
|
||||||
@@ -85,4 +105,7 @@ function storeContentsData(node, childData){
|
|||||||
node.contentsValue = newContentsValue;
|
node.contentsValue = newContentsValue;
|
||||||
node.contentsValueChanged = true;
|
node.contentsValueChanged = true;
|
||||||
}
|
}
|
||||||
|
if (node.contentsWeightChanged || node.contentsValueChanged){
|
||||||
|
containersToWrite.push(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,14 @@ export default function recomputeSlotFullness(ancestorId){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
let spaceLeft;
|
let spaceLeft;
|
||||||
if (slot.quantityExpected === 0){
|
let expected = slot.quantityExpectedResult;
|
||||||
|
if (typeof expected !== 'number'){
|
||||||
|
expected = 1;
|
||||||
|
}
|
||||||
|
if (expected === 0){
|
||||||
spaceLeft = null;
|
spaceLeft = null;
|
||||||
} else {
|
} else {
|
||||||
spaceLeft = slot.quantityExpected - totalFilled;
|
spaceLeft = expected - totalFilled;
|
||||||
}
|
}
|
||||||
if (slot.totalFilled !== totalFilled || slot.spaceLeft !== spaceLeft){
|
if (slot.totalFilled !== totalFilled || slot.spaceLeft !== spaceLeft){
|
||||||
CreatureProperties.update(slot._id, {
|
CreatureProperties.update(slot._id, {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
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 { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
|
||||||
import { recomputeCreatureById } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
import { recomputeCreatureById } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
let Experiences = new Mongo.Collection('experiences');
|
let Experiences = new Mongo.Collection('experiences');
|
||||||
|
|
||||||
@@ -12,6 +12,7 @@ let ExperienceSchema = new SimpleSchema({
|
|||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
},
|
},
|
||||||
// The amount of XP this experience gives
|
// The amount of XP this experience gives
|
||||||
xp: {
|
xp: {
|
||||||
@@ -90,11 +91,6 @@ const insertExperience = new ValidatedMethod({
|
|||||||
throw new Meteor.Error('Experiences.methods.insert.denied',
|
throw new Meteor.Error('Experiences.methods.insert.denied',
|
||||||
'You need to be logged in to insert an experience');
|
'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 = [];
|
let insertedIds = [];
|
||||||
creatureIds.forEach(creatureId => {
|
creatureIds.forEach(creatureId => {
|
||||||
let id = insertExperienceForCreature({experience, creatureId, userId});
|
let id = insertExperienceForCreature({experience, creatureId, userId});
|
||||||
@@ -123,11 +119,6 @@ const removeExperience = new ValidatedMethod({
|
|||||||
throw new Meteor.Error('Experiences.methods.remove.denied',
|
throw new Meteor.Error('Experiences.methods.remove.denied',
|
||||||
'You need to be logged in to remove an experience');
|
'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);
|
let experience = Experiences.findOne(experienceId);
|
||||||
if (!experience) return;
|
if (!experience) return;
|
||||||
let creatureId = experience.creatureId
|
let creatureId = experience.creatureId
|
||||||
@@ -168,11 +159,6 @@ const recomputeExperiences = new ValidatedMethod({
|
|||||||
throw new Meteor.Error('Experiences.methods.recompute.denied',
|
throw new Meteor.Error('Experiences.methods.recompute.denied',
|
||||||
'You need to be logged in to recompute a creature\'s experiences');
|
'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);
|
assertEditPermission(creatureId, userId);
|
||||||
|
|
||||||
let xp = 0;
|
let xp = 0;
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
let ExperienceSchema = new SimpleSchema({
|
let ExperienceSchema = new SimpleSchema({
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
},
|
},
|
||||||
// Potentially long description of the event
|
// Potentially long description of the event
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.description,
|
||||||
},
|
},
|
||||||
// The real-world date that it occured
|
// The real-world date that it occured
|
||||||
date: {
|
date: {
|
||||||
@@ -24,14 +27,17 @@ let ExperienceSchema = new SimpleSchema({
|
|||||||
worldDate: {
|
worldDate: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
},
|
},
|
||||||
// Tags to better find this entry later
|
// Tags to better find this entry later
|
||||||
tags: {
|
tags: {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
|
maxCount: STORAGE_LIMITS.tagCount,
|
||||||
},
|
},
|
||||||
'tags.$': {
|
'tags.$': {
|
||||||
type: String,
|
type: String,
|
||||||
|
max: STORAGE_LIMITS.tagLength,
|
||||||
},
|
},
|
||||||
// ID of the journal this entry belongs to
|
// ID of the journal this entry belongs to
|
||||||
journalId: {
|
journalId: {
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||||
import LogContentSchema from '/imports/api/creature/log/LogContentSchema.js';
|
import LogContentSchema from '/imports/api/creature/log/LogContentSchema.js';
|
||||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import {assertEditPermission} from '/imports/api/creature/creaturePermissions.js';
|
import {assertEditPermission} from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
import {
|
import {
|
||||||
parse,
|
parse,
|
||||||
CompilationContext,
|
CompilationContext,
|
||||||
prettifyParseError
|
prettifyParseError
|
||||||
} from '/imports/parser/parser.js';
|
} from '/imports/parser/parser.js';
|
||||||
const PER_CREATURE_LOG_LIMIT = 100;
|
const PER_CREATURE_LOG_LIMIT = 100;
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
if (Meteor.isServer){
|
if (Meteor.isServer){
|
||||||
var sendWebhookAsCreature = require('/imports/server/discord/sendWebhook.js').sendWebhookAsCreature;
|
var sendWebhookAsCreature = require('/imports/server/discord/sendWebhook.js').sendWebhookAsCreature;
|
||||||
@@ -21,7 +22,7 @@ let CreatureLogSchema = new SimpleSchema({
|
|||||||
content: {
|
content: {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
maxCount: 25,
|
maxCount: STORAGE_LIMITS.logContentCount,
|
||||||
},
|
},
|
||||||
'content.$': {
|
'content.$': {
|
||||||
type: LogContentSchema,
|
type: LogContentSchema,
|
||||||
@@ -45,6 +46,7 @@ let CreatureLogSchema = new SimpleSchema({
|
|||||||
creatureName: {
|
creatureName: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ function removeOldLogs(creatureId){
|
|||||||
sort: {date: -1},
|
sort: {date: -1},
|
||||||
skip: PER_CREATURE_LOG_LIMIT,
|
skip: PER_CREATURE_LOG_LIMIT,
|
||||||
});
|
});
|
||||||
|
if (!firstExpiredLog) return;
|
||||||
// Remove all logs older than the one over the limit
|
// Remove all logs older than the one over the limit
|
||||||
CreatureLogs.remove({
|
CreatureLogs.remove({
|
||||||
creatureId,
|
creatureId,
|
||||||
@@ -69,32 +72,10 @@ function logToMessageData(log){
|
|||||||
let embed = {
|
let embed = {
|
||||||
fields: [],
|
fields: [],
|
||||||
};
|
};
|
||||||
log.content.forEach(c => {
|
log.content.forEach(field => {
|
||||||
let field = {};
|
if (!field.name) field.name = '\u200b';
|
||||||
let descriptionField = {};
|
if (!field.value) field.value = '\u200b';
|
||||||
if (c.name) field.name = c.name;
|
embed.fields.push(field);
|
||||||
let valueArray = [];
|
|
||||||
if (c.error) valueArray.push(`*${c.error}*`);
|
|
||||||
if (c.resultPrefix) valueArray.push(`${c.resultPrefix}`);
|
|
||||||
if (c.result) valueArray.push(`\`${c.result}\``);
|
|
||||||
if (c.details) valueArray.push(c.details);
|
|
||||||
if (valueArray.length) field.value = valueArray.join(' ');
|
|
||||||
if (c.description){
|
|
||||||
if (!field.value){
|
|
||||||
field.value = c.description;
|
|
||||||
} else {
|
|
||||||
descriptionField.value = c.description;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (field.name || field.value){
|
|
||||||
if (!field.name) field.name = '\u200b';
|
|
||||||
if (!field.value) field.value = '\u200b';
|
|
||||||
embed.fields.push(field);
|
|
||||||
}
|
|
||||||
if (descriptionField.value){
|
|
||||||
descriptionField.name = '\u200b';
|
|
||||||
embed.fields.push(descriptionField);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return { embeds: [embed] };
|
return { embeds: [embed] };
|
||||||
}
|
}
|
||||||
@@ -109,7 +90,7 @@ function logWebhook({log, creature}){
|
|||||||
}
|
}
|
||||||
|
|
||||||
const insertCreatureLog = new ValidatedMethod({
|
const insertCreatureLog = new ValidatedMethod({
|
||||||
name: 'creatureLogs.methods.insertCreatureLog',
|
name: 'creatureLogs.methods.insert',
|
||||||
mixins: [RateLimiterMixin],
|
mixins: [RateLimiterMixin],
|
||||||
rateLimit: {
|
rateLimit: {
|
||||||
numRequests: 5,
|
numRequests: 5,
|
||||||
@@ -138,7 +119,7 @@ const insertCreatureLog = new ValidatedMethod({
|
|||||||
export function insertCreatureLogWork({log, creature, method}){
|
export function insertCreatureLogWork({log, creature, method}){
|
||||||
// Build the new log
|
// Build the new log
|
||||||
if (typeof log === 'string'){
|
if (typeof log === 'string'){
|
||||||
log = {text: log};
|
log = {content: [{value: log}]};
|
||||||
}
|
}
|
||||||
log.date = new Date();
|
log.date = new Date();
|
||||||
// Insert it
|
// Insert it
|
||||||
@@ -190,30 +171,30 @@ const logRoll = new ValidatedMethod({
|
|||||||
parsedResult = parse(roll);
|
parsedResult = parse(roll);
|
||||||
} catch (e){
|
} catch (e){
|
||||||
let error = prettifyParseError(e);
|
let error = prettifyParseError(e);
|
||||||
logContent.push({error});
|
logContent.push({name: 'Parse Error', value: error});
|
||||||
}
|
}
|
||||||
if (parsedResult) try {
|
if (parsedResult) try {
|
||||||
let rollContext = new CompilationContext();
|
let rollContext = new CompilationContext();
|
||||||
let compiled = parsedResult.compile(creature.variables, rollContext);
|
let compiled = parsedResult.compile(creature.variables, rollContext);
|
||||||
let compiledString = compiled.toString();
|
let compiledString = compiled.toString();
|
||||||
if (!equalIgnoringWhitespace(compiledString, roll)) logContent.push({
|
if (!equalIgnoringWhitespace(compiledString, roll)) logContent.push({
|
||||||
details: roll
|
value: roll
|
||||||
});
|
});
|
||||||
logContent.push({
|
logContent.push({
|
||||||
details: compiledString
|
value: compiledString
|
||||||
});
|
});
|
||||||
let rolled = compiled.roll(creature.variables, rollContext);
|
let rolled = compiled.roll(creature.variables, rollContext);
|
||||||
let rolledString = rolled.toString();
|
let rolledString = rolled.toString();
|
||||||
if (rolledString !== compiledString) logContent.push({
|
if (rolledString !== compiledString) logContent.push({
|
||||||
result: rolled.toString()
|
value: rolled.toString()
|
||||||
});
|
});
|
||||||
let result = rolled.reduce(creature.variables, rollContext);
|
let result = rolled.reduce(creature.variables, rollContext);
|
||||||
let resultString = result.toString();
|
let resultString = result.toString();
|
||||||
if (resultString !== rolledString) logContent.push({
|
if (resultString !== rolledString) logContent.push({
|
||||||
result: resultString
|
value: resultString
|
||||||
});
|
});
|
||||||
} catch (e){
|
} catch (e){
|
||||||
logContent = [{error: 'Calculation error'}];
|
logContent = [{name: 'Calculation error'}];
|
||||||
}
|
}
|
||||||
const log = {
|
const log = {
|
||||||
content: logContent,
|
content: logContent,
|
||||||
|
|||||||
@@ -1,35 +1,21 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||||
import RollDetailsSchema from '/imports/api/properties/subSchemas/RollDetailsSchema.js';
|
import RollDetailsSchema from '/imports/api/properties/subSchemas/RollDetailsSchema.js';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
let LogContentSchema = new SimpleSchema({
|
let LogContentSchema = new SimpleSchema({
|
||||||
|
// The name of the field, included in discord webhook message
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
},
|
},
|
||||||
error: {
|
// The details of the field, included in discord webhook message
|
||||||
type: String,
|
// Markdown support
|
||||||
optional: true,
|
value: {
|
||||||
},
|
|
||||||
resultPrefix: {
|
|
||||||
type: String,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
result: {
|
|
||||||
type: String,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
expandedResult: {
|
|
||||||
type: String,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
details: {
|
|
||||||
type: String,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.summary,
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -38,6 +24,7 @@ let LogContentSchema = new SimpleSchema({
|
|||||||
'context.errors':{
|
'context.errors':{
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
|
maxCount: STORAGE_LIMITS.errorCount,
|
||||||
},
|
},
|
||||||
'context.errors.$': {
|
'context.errors.$': {
|
||||||
type: ErrorSchema,
|
type: ErrorSchema,
|
||||||
@@ -45,6 +32,7 @@ let LogContentSchema = new SimpleSchema({
|
|||||||
'context.rolls': {
|
'context.rolls': {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
|
maxCount: STORAGE_LIMITS.rollCount,
|
||||||
},
|
},
|
||||||
'context.rolls.$': {
|
'context.rolls.$': {
|
||||||
type: RollDetailsSchema,
|
type: RollDetailsSchema,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
assertEditPermission,
|
assertEditPermission,
|
||||||
assertViewPermission,
|
assertViewPermission,
|
||||||
assertOwnership,
|
assertOwnership,
|
||||||
} from '/imports/api/creature/creaturePermissions.js';
|
} from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||||
|
|
||||||
// Checks if the method has permission to run on the document. If the document
|
// Checks if the method has permission to run on the document. If the document
|
||||||
// has a charId, that creature is checked, otherwise if it has an _id and the
|
// has a charId, that creature is checked, otherwise if it has an _id and the
|
||||||
|
|||||||
12
app/imports/api/creature/v1Migration/migrateCharacter.js
Normal file
12
app/imports/api/creature/v1Migration/migrateCharacter.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { fetch } from 'meteor/fetch'
|
||||||
|
|
||||||
|
export default function importCharacter(url){
|
||||||
|
// Using v1's JSON API to fetch the character data in a usable format
|
||||||
|
// url -> https://dicecloud.com/character/<id>/json?key=<key>
|
||||||
|
fetch(url)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
let character = data.characters[0];
|
||||||
|
console.log(character.name + ' fetched successfuly')
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ 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 { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
import { assertAdmin } from '/imports/api/sharing/sharingPermissions.js';
|
import { assertAdmin } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
let Icons = new Mongo.Collection('icons');
|
let Icons = new Mongo.Collection('icons');
|
||||||
|
|
||||||
@@ -9,22 +10,27 @@ let iconsSchema = new SimpleSchema({
|
|||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
unique: true,
|
unique: true,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
index: 1,
|
index: 1,
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.description,
|
||||||
},
|
},
|
||||||
tags: {
|
tags: {
|
||||||
type: Array,
|
type: Array,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
maxCount: STORAGE_LIMITS.tagCount,
|
||||||
index: 1,
|
index: 1,
|
||||||
},
|
},
|
||||||
'tags.$': {
|
'tags.$': {
|
||||||
type: String,
|
type: String,
|
||||||
|
max: STORAGE_LIMITS.tagLength,
|
||||||
},
|
},
|
||||||
shape: {
|
shape: {
|
||||||
type: String,
|
type: String,
|
||||||
|
max: STORAGE_LIMITS.icon,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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'
|
import { getUserTier } from '/imports/api/users/patreon/tiers.js'
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.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
|
||||||
@@ -21,11 +22,8 @@ let Libraries = new Mongo.Collection('libraries');
|
|||||||
let LibrarySchema = new SimpleSchema({
|
let LibrarySchema = new SimpleSchema({
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
|
max: STORAGE_LIMITS.name,
|
||||||
},
|
},
|
||||||
isDefault: {
|
|
||||||
type: Boolean,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
LibrarySchema.extend(SharingSchema);
|
LibrarySchema.extend(SharingSchema);
|
||||||
@@ -39,7 +37,7 @@ const insertLibrary = new ValidatedMethod({
|
|||||||
mixins: [
|
mixins: [
|
||||||
simpleSchemaMixin,
|
simpleSchemaMixin,
|
||||||
],
|
],
|
||||||
schema: LibrarySchema.omit('owner', 'isDefault'),
|
schema: LibrarySchema.omit('owner'),
|
||||||
run(library) {
|
run(library) {
|
||||||
if (!this.userId) {
|
if (!this.userId) {
|
||||||
throw new Meteor.Error('Libraries.methods.insert.denied',
|
throw new Meteor.Error('Libraries.methods.insert.denied',
|
||||||
@@ -78,30 +76,6 @@ const updateLibraryName = new ValidatedMethod({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const setLibraryDefault = new ValidatedMethod({
|
|
||||||
name: 'libraries.makeLibraryDefault',
|
|
||||||
validate: new SimpleSchema({
|
|
||||||
_id: {
|
|
||||||
type: String,
|
|
||||||
regEx: SimpleSchema.RegEx.id
|
|
||||||
},
|
|
||||||
isDefault: {
|
|
||||||
type: Boolean,
|
|
||||||
},
|
|
||||||
}).validator(),
|
|
||||||
mixins: [RateLimiterMixin],
|
|
||||||
rateLimit: {
|
|
||||||
numRequests: 5,
|
|
||||||
timeInterval: 5000,
|
|
||||||
},
|
|
||||||
run({_id, isDefault}) {
|
|
||||||
if (!Meteor.users.isAdmin()){
|
|
||||||
throw new Meteor.Error('Permission denied', 'User must be admin to set libraries as default');
|
|
||||||
}
|
|
||||||
return Libraries.update(_id, {$set: {isDefault}});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const removeLibrary = new ValidatedMethod({
|
const removeLibrary = new ValidatedMethod({
|
||||||
name: 'libraries.remove',
|
name: 'libraries.remove',
|
||||||
validate: new SimpleSchema({
|
validate: new SimpleSchema({
|
||||||
@@ -118,10 +92,14 @@ const removeLibrary = new ValidatedMethod({
|
|||||||
run({_id}){
|
run({_id}){
|
||||||
let library = Libraries.findOne(_id);
|
let library = Libraries.findOne(_id);
|
||||||
assertOwnership(library, this.userId);
|
assertOwnership(library, this.userId);
|
||||||
Libraries.remove(_id);
|
this.unblock();
|
||||||
this.unblock();
|
removeLibaryWork(_id)
|
||||||
LibraryNodes.remove({'ancestors.id': _id});
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
export { LibrarySchema, insertLibrary, setLibraryDefault, updateLibraryName, removeLibrary };
|
export function removeLibaryWork(libraryId){
|
||||||
|
Libraries.remove(libraryId);
|
||||||
|
LibraryNodes.remove({'ancestors.id': libraryId});
|
||||||
|
}
|
||||||
|
|
||||||
|
export { LibrarySchema, insertLibrary, updateLibraryName, removeLibrary };
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ 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';
|
import { storedIconsSchema } from '/imports/api/icons/Icons.js';
|
||||||
|
import '/imports/api/library/methods/index.js';
|
||||||
|
import { updateReferenceNodeWork } from '/imports/api/library/methods/updateReferenceNode.js';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
let LibraryNodes = new Mongo.Collection('libraryNodes');
|
let LibraryNodes = new Mongo.Collection('libraryNodes');
|
||||||
|
|
||||||
@@ -22,13 +25,16 @@ let LibraryNodeSchema = new SimpleSchema({
|
|||||||
tags: {
|
tags: {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
|
maxCount: STORAGE_LIMITS.tagCount,
|
||||||
},
|
},
|
||||||
'tags.$': {
|
'tags.$': {
|
||||||
type: String,
|
type: String,
|
||||||
|
max: STORAGE_LIMITS.tagLength,
|
||||||
},
|
},
|
||||||
icon: {
|
icon: {
|
||||||
type: storedIconsSchema,
|
type: storedIconsSchema,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
max: STORAGE_LIMITS.icon,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -75,31 +81,15 @@ const insertNode = new ValidatedMethod({
|
|||||||
run(libraryNode) {
|
run(libraryNode) {
|
||||||
delete libraryNode._id;
|
delete libraryNode._id;
|
||||||
assertNodeEditPermission(libraryNode, this.userId);
|
assertNodeEditPermission(libraryNode, this.userId);
|
||||||
return LibraryNodes.insert(libraryNode);
|
let nodeId = LibraryNodes.insert(libraryNode);
|
||||||
|
if (libraryNode.type == 'reference'){
|
||||||
|
libraryNode._id = nodeId;
|
||||||
|
updateReferenceNodeWork(libraryNode, this.userId);
|
||||||
|
}
|
||||||
|
return nodeId;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
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.update',
|
name: 'libraryNodes.update',
|
||||||
validate({_id, path}){
|
validate({_id, path}){
|
||||||
@@ -129,9 +119,14 @@ const updateLibraryNode = new ValidatedMethod({
|
|||||||
} else {
|
} else {
|
||||||
modifier = {$set: {[pathString]: value}};
|
modifier = {$set: {[pathString]: value}};
|
||||||
}
|
}
|
||||||
return LibraryNodes.update(_id, modifier, {
|
let numUpdated = LibraryNodes.update(_id, modifier, {
|
||||||
selector: {type: node.type},
|
selector: {type: node.type},
|
||||||
});
|
});
|
||||||
|
if (node.type == 'reference'){
|
||||||
|
node = LibraryNodes.findOne(_id);
|
||||||
|
updateReferenceNodeWork(node, this.userId);
|
||||||
|
}
|
||||||
|
return numUpdated;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -195,7 +190,6 @@ export default LibraryNodes;
|
|||||||
export {
|
export {
|
||||||
LibraryNodeSchema,
|
LibraryNodeSchema,
|
||||||
insertNode,
|
insertNode,
|
||||||
duplicateNode,
|
|
||||||
updateLibraryNode,
|
updateLibraryNode,
|
||||||
pullFromLibraryNode,
|
pullFromLibraryNode,
|
||||||
pushToLibraryNode,
|
pushToLibraryNode,
|
||||||
|
|||||||
87
app/imports/api/library/methods/duplicateLibraryNode.js
Normal file
87
app/imports/api/library/methods/duplicateLibraryNode.js
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||||
|
import { assertDocEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||||
|
import {
|
||||||
|
setLineageOfDocs,
|
||||||
|
renewDocIds
|
||||||
|
} from '/imports/api/parenting/parenting.js';
|
||||||
|
import { reorderDocs } from '/imports/api/parenting/order.js';
|
||||||
|
|
||||||
|
var snackbar;
|
||||||
|
if (Meteor.isClient){
|
||||||
|
snackbar = require(
|
||||||
|
'/imports/ui/components/snackbars/SnackbarQueue.js'
|
||||||
|
).snackbar
|
||||||
|
}
|
||||||
|
|
||||||
|
const DUPLICATE_CHILDREN_LIMIT = 50;
|
||||||
|
|
||||||
|
const duplicateLibraryNode = 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);
|
||||||
|
assertDocEditPermission(libraryNode, this.userId);
|
||||||
|
|
||||||
|
let randomSrc = DDP.randomStream('duplicateLibraryNode');
|
||||||
|
let libraryNodeId = randomSrc.id();
|
||||||
|
libraryNode._id = libraryNodeId;
|
||||||
|
|
||||||
|
let nodes = LibraryNodes.find({
|
||||||
|
'ancestors.id': _id,
|
||||||
|
removed: {$ne: true},
|
||||||
|
}, {
|
||||||
|
limit: DUPLICATE_CHILDREN_LIMIT + 1,
|
||||||
|
sort: {order: 1},
|
||||||
|
}).fetch();
|
||||||
|
|
||||||
|
if (nodes.length > DUPLICATE_CHILDREN_LIMIT){
|
||||||
|
nodes.pop();
|
||||||
|
if (Meteor.isClient){
|
||||||
|
snackbar({
|
||||||
|
text: `Only the first ${DUPLICATE_CHILDREN_LIMIT} children were duplicated`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-map all the ancestors
|
||||||
|
setLineageOfDocs({
|
||||||
|
docArray: nodes,
|
||||||
|
newAncestry : [
|
||||||
|
...libraryNode.ancestors,
|
||||||
|
{id: libraryNodeId, collection: 'libraryNodes'}
|
||||||
|
],
|
||||||
|
oldParent : {id: _id, collection: 'libraryNodes'},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Give the docs new IDs without breaking internal references
|
||||||
|
renewDocIds({docArray: nodes});
|
||||||
|
|
||||||
|
// Order the root node
|
||||||
|
libraryNode.order += 0.5;
|
||||||
|
|
||||||
|
LibraryNodes.batchInsert([libraryNode, ...nodes]);
|
||||||
|
|
||||||
|
// Tree structure changed by inserts, reorder the tree
|
||||||
|
reorderDocs({
|
||||||
|
collection: LibraryNodes,
|
||||||
|
ancestorId: libraryNode.ancestors[0].id,
|
||||||
|
});
|
||||||
|
|
||||||
|
return libraryNodeId;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default duplicateLibraryNode;
|
||||||
2
app/imports/api/library/methods/index.js
Normal file
2
app/imports/api/library/methods/index.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import '/imports/api/library/methods/duplicateLibraryNode.js';
|
||||||
|
import '/imports/api/library/methods/updateReferenceNode.js';
|
||||||
67
app/imports/api/library/methods/updateReferenceNode.js
Normal file
67
app/imports/api/library/methods/updateReferenceNode.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||||
|
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||||
|
import {
|
||||||
|
assertDocEditPermission,
|
||||||
|
assertViewPermission,
|
||||||
|
} from '/imports/api/sharing/sharingPermissions.js';
|
||||||
|
import fetchDocByRef from '/imports/api/parenting/fetchDocByRef.js';
|
||||||
|
|
||||||
|
const updateReferenceNode = new ValidatedMethod({
|
||||||
|
name: 'libraryNodes.updateReferenceNode',
|
||||||
|
validate: new SimpleSchema({
|
||||||
|
_id: {
|
||||||
|
type: String,
|
||||||
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
}
|
||||||
|
}).validator(),
|
||||||
|
mixins: [RateLimiterMixin],
|
||||||
|
rateLimit: {
|
||||||
|
numRequests: 5,
|
||||||
|
timeInterval: 5000,
|
||||||
|
},
|
||||||
|
run({_id}) {
|
||||||
|
let userId = this.userId;
|
||||||
|
let node = LibraryNodes.findOne(_id);
|
||||||
|
assertDocEditPermission(node, userId);
|
||||||
|
updateReferenceNodeWork(node, userId);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function writeCache(_id, cache){
|
||||||
|
LibraryNodes.update(_id, {$set: {cache}}, {
|
||||||
|
selector: {type: 'reference'},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateReferenceNodeWork(node, userId){
|
||||||
|
let cache = {}
|
||||||
|
if (!node.ref){
|
||||||
|
writeCache(node._id, cache);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let doc, library;
|
||||||
|
try {
|
||||||
|
doc = fetchDocByRef(node.ref);
|
||||||
|
if (doc.removed) throw 'Property has been deleted';
|
||||||
|
if (doc.ancestors[0].id !== node.ancestors[0].id){
|
||||||
|
library = fetchDocByRef(doc.ancestors[0]);
|
||||||
|
assertViewPermission(library, userId)
|
||||||
|
}
|
||||||
|
} catch(e){
|
||||||
|
cache = {error: e.reason || e.message || e.toString()}
|
||||||
|
writeCache(node._id, cache);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cache = {
|
||||||
|
node: doc,
|
||||||
|
};
|
||||||
|
if (library){
|
||||||
|
cache.library = {name: library.name};
|
||||||
|
}
|
||||||
|
writeCache(node._id, cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default updateReferenceNode;
|
||||||
|
export { updateReferenceNodeWork }
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
|
||||||
|
|
||||||
Blacklist = new Mongo.Collection("blacklist");
|
|
||||||
|
|
||||||
Schemas.Blacklist = new SimpleSchema({
|
|
||||||
userId: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
Blacklist.attachSchema(Schemas.Blacklist);
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
|
||||||
|
|
||||||
ChangeLogs = new Mongo.Collection("changeLogs");
|
|
||||||
|
|
||||||
Schemas.ChangeLog = new SimpleSchema({
|
|
||||||
version: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
changes: {
|
|
||||||
type: [String],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
ChangeLogs.attachSchema(Schemas.ChangeLog);
|
|
||||||
|
|
||||||
ChangeLogs.allow({
|
|
||||||
insert: function(userId, doc) {
|
|
||||||
var user = Meteor.users.findOne(userId);
|
|
||||||
if (user) return _.contains(user.roles, "admin");
|
|
||||||
},
|
|
||||||
update: function(userId, doc, fields, modifier) {
|
|
||||||
var user = Meteor.users.findOne(userId);
|
|
||||||
if (user) return _.contains(user.roles, "admin");
|
|
||||||
},
|
|
||||||
remove: function(userId, doc) {
|
|
||||||
var user = Meteor.users.findOne(userId);
|
|
||||||
if (user) return _.contains(user.roles, "admin");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
|
||||||
|
|
||||||
Reports = new Mongo.Collection("reports");
|
|
||||||
|
|
||||||
Schemas.Report = new SimpleSchema({
|
|
||||||
owner: {
|
|
||||||
type: String,
|
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
trim: false,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: String,
|
|
||||||
trim: false,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
allowedValues: ["General Feedback", "Bug", "Suggested Change", "Feature Request"],
|
|
||||||
defaultValue: "General Feedback",
|
|
||||||
},
|
|
||||||
//the immediate impact of doing this action (eg. -1 rages)
|
|
||||||
severity: {
|
|
||||||
type: SimpleSchema.Integer,
|
|
||||||
defaultValue: 5,
|
|
||||||
min: 1,
|
|
||||||
max: 10,
|
|
||||||
},
|
|
||||||
metaData: {
|
|
||||||
type: Object,
|
|
||||||
blackbox: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
Reports.attachSchema(Schemas.Report);
|
|
||||||
|
|
||||||
Meteor.methods({
|
|
||||||
insertReport: function(report) {
|
|
||||||
check(report, {
|
|
||||||
title: String,
|
|
||||||
description: String,
|
|
||||||
type: String,
|
|
||||||
severity: Number,
|
|
||||||
metaData: Object,
|
|
||||||
});
|
|
||||||
report.owner = this.userId;
|
|
||||||
var id = Reports.insert(report);
|
|
||||||
var user = Meteor.users.findOne(this.userId);
|
|
||||||
var sender = user &&
|
|
||||||
user.emails &&
|
|
||||||
user.emails[0] &&
|
|
||||||
user.emails[0].address ||
|
|
||||||
user.services &&
|
|
||||||
user.services.google &&
|
|
||||||
user.services.google.email ||
|
|
||||||
"reports@dicecloud.com";
|
|
||||||
var bodyText = "Report ID: " + id +
|
|
||||||
"\nSeverity: " + report.severity +
|
|
||||||
"\nType: " + report.type +
|
|
||||||
"\n\n" + report.description;
|
|
||||||
Email.send({
|
|
||||||
from: sender,
|
|
||||||
to: "stefan.zermatten@gmail.com",
|
|
||||||
subject: "DiceCloud feedback - " + report.title,
|
|
||||||
text: bodyText,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
deleteReport: function(id) {
|
|
||||||
var user = Meteor.users.findOne(this.userId);
|
|
||||||
if (!_.contains(user.roles, "admin")){
|
|
||||||
throw new Meteor.Error(
|
|
||||||
"not admin",
|
|
||||||
"The user must be an administrator to delete feedback"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Reports.remove(id);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,13 +1,20 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||||
|
|
||||||
const RefSchema = new SimpleSchema({
|
const RefSchema = new SimpleSchema({
|
||||||
id: {
|
id: {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.Id,
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
// TODO: Rather than indexing this field, index `ancestors.0.id` to only
|
||||||
|
// index the root of the ancestor heirarchy to significantly reduce
|
||||||
|
// index size and improve performance
|
||||||
|
// All queries on an ancestor document need to target `ancestors.0.id` first
|
||||||
|
// before targeting a younger ancestor
|
||||||
index: 1
|
index: 1
|
||||||
},
|
},
|
||||||
collection: {
|
collection: {
|
||||||
type: String
|
type: String,
|
||||||
|
max: STORAGE_LIMITS.collectionName,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -22,7 +29,7 @@ let ChildSchema = new SimpleSchema({
|
|||||||
ancestors: {
|
ancestors: {
|
||||||
type: Array,
|
type: Array,
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
max: 100,
|
maxCount: STORAGE_LIMITS.ancestorCount,
|
||||||
},
|
},
|
||||||
'ancestors.$': {
|
'ancestors.$': {
|
||||||
type: RefSchema,
|
type: RefSchema,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user