Merge branch 'version-2' into version-2-dev

This commit is contained in:
Stefan Zermatten
2022-05-09 12:46:09 +02:00
9 changed files with 127 additions and 34 deletions

View File

@@ -47,3 +47,4 @@ ostrio:files
simple:rest-bearer-token-parser
simple:rest-json-error-handler
littledata:synced-cron
mdg:meteor-apm-agent

View File

@@ -52,8 +52,10 @@ inter-process-messaging@0.1.1
lai:collection-extensions@0.3.0
launch-screen@1.3.0
littledata:synced-cron@1.5.1
livedata@1.0.18
localstorage@1.2.0
logging@1.3.1
mdg:meteor-apm-agent@3.5.0
mdg:validated-method@1.2.0
meteor@1.10.0
meteor-base@1.5.1
@@ -73,6 +75,7 @@ mongo@1.14.6
mongo-decimal@0.1.2
mongo-dev-server@1.1.0
mongo-id@1.0.8
mongo-livedata@1.0.12
npm-mongo@4.3.1
oauth@2.1.1
oauth2@1.3.1

View File

@@ -2,7 +2,7 @@ import { EJSON } from 'meteor/ejson';
import createGraph from 'ngraph.graph';
export default class CreatureComputation {
constructor(properties){
constructor(properties, creature){
// Set up fields
this.originalPropsById = {};
this.propsById = {};
@@ -11,6 +11,7 @@ export default class CreatureComputation {
this.props = properties;
this.dependencyGraph = createGraph();
this.errors = [];
this.creature = creature;
// Store properties for easy access later
properties.forEach(prop => {

View File

@@ -73,7 +73,7 @@ function getCreature(creatureId){
export function buildComputationFromProps(properties, creature){
const computation = new CreatureComputation(properties);
const computation = new CreatureComputation(properties, creature);
// Dependency graph where edge(a, b) means a depends on b
// The graph includes all dependencies even of inactive properties
// such that any properties changing without changing their dependencies

View File

@@ -1,10 +1,31 @@
import Creatures from '/imports/api/creature/creatures/Creatures.js';
import { EJSON } from 'meteor/ejson';
export default function writeScope(creatureId, scope){
// Remove large properties that aren't likely to be accessed
export default function writeScope(creatureId, computation) {
const scope = computation.scope;
const variables = computation.creature.variables || {};
let $set;
for (const key in scope){
// Remove large properties that aren't likely to be accessed
delete scope[key].parent;
delete scope[key].ancestors;
// Remove empty keys
for (const subKey in scope[key]) {
if (scope[key][subKey] === undefined) {
delete scope[key][subKey]
}
}
// Only update changed fields
if (!EJSON.equals(variables[key], scope[key])) {
if (!$set) $set = {};
// Set the changed key in the creature variables
$set[`variables.${key}`] = scope[key];
}
}
if ($set) {
Creatures.update(creatureId, {$set});
}
Creatures.update(creatureId, {$set: {variables: scope}});
}

View File

@@ -20,8 +20,8 @@ function computeComputation(computation, creatureId) {
try {
computeCreatureComputation(computation);
writeAlteredProperties(computation);
writeScope(creatureId, computation.scope);
} catch (e) {
writeScope(creatureId, computation);
} catch (e){
const errorText = e.reason || e.message || e.toString();
computation.errors.push({
type: 'crash',

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import Libraries from '/imports/api/library/Libraries.js';
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
import { assertViewPermission } from '/imports/api/sharing/sharingPermissions.js';
import { assertViewPermission, assertDocViewPermission } from '/imports/api/sharing/sharingPermissions.js';
Meteor.publish('libraries', function(){
this.autorun(function (){
@@ -63,12 +63,64 @@ Meteor.publish('libraryNodes', function(libraryId){
LibraryNodes.find({
'ancestors.id': libraryId,
}, {
sort: {order: 1},
sort: { order: 1 },
fields: {
_id: 1,
name: 1,
type: 1,
icon: 1,
color: 1,
order: 1,
parent: 1,
ancestors: 1,
// Effect
operation: 1,
targetTags: 1,
stats: 1,
// Item
quantity: 1,
plural: 1,
equipped: 1,
// Branch
branchType: 1,
// Damage:
damageType: 1,
stat: 1,
amount: 1,
// Class level
level: 1,
// Proficiency
value: 1,
// Reference
cache: 1,
}
}),
];
});
});
const nodeIdSchema = new SimpleSchema({
libraryNodeId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
},
});
Meteor.publish('libraryNode', function (libraryNodeId) {
if (!libraryNodeId) return [];
nodeIdSchema.validate({ libraryNodeId });
this.autorun(function () {
const userId = this.userId;
const nodeCursor = LibraryNodes.find({_id: libraryNodeId});
let node = nodeCursor.fetch()[0];
try { assertDocViewPermission(node, userId) }
catch (e) {
return this.error(e);
}
return [ nodeCursor ];
});
});
Meteor.publish('softRemovedLibraryNodes', function(libraryId){
if (!libraryId) return [];
libraryIdSchema.validate({libraryId});

View File

@@ -5,6 +5,7 @@
:model="model"
:editing="editing"
:flat="flat"
:embedded="embedded"
@duplicate="duplicate"
@move="move"
@remove="remove"
@@ -12,32 +13,41 @@
@color-changed="value => change({path: ['color'], value})"
/>
</template>
<template v-if="model">
<v-fade-transition
mode="out-in"
<v-fade-transition
mode="out-in"
>
<div v-if="!_id" />
<div
v-else-if="!$subReady.libraryNode"
class="fill-height layout justify-center align-center"
>
<component
:is="model.type + 'Form'"
v-if="editing"
:key="_id"
class="library-node-form"
:model="model"
@change="change"
@push="push"
@pull="pull"
<v-progress-circular
indeterminate
color="primary"
size="64"
/>
<component
:is="model.type + 'Viewer'"
v-else-if="!editing && $options.components[model.type + 'Viewer']"
:key="_id"
class="creature-property-viewer"
:model="model"
/>
<p v-else>
This property can't be viewed yet.
</p>
</v-fade-transition>
</template>
</div>
<component
:is="model.type + 'Form'"
v-else-if="model && editing"
:key="_id"
class="library-node-form"
:model="model"
@change="change"
@push="push"
@pull="pull"
/>
<component
:is="model.type + 'Viewer'"
v-else-if="model && !editing && $options.components[model.type + 'Viewer']"
:key="_id"
class="creature-property-viewer"
:model="model"
/>
<p v-else>
This property can't be viewed yet.
</p>
</v-fade-transition>
<div
v-if="!embedded"
slot="actions"
@@ -136,6 +146,11 @@
},
},
meteor: {
$subscribe: {
'libraryNode'(){
return [this._id];
}
},
model(){
return LibraryNodes.findOne(this.currentId);
},

View File

@@ -21,7 +21,7 @@
</span>
</template>
<template v-else>
{{ model.stat || 'Attribute' }} damage
<span>{{ model.stat || 'Attribute' }} damage</span>
</template>
</div>
</div>