Characters now recompute on subscribe if they haven't been computed in the current version
This commit is contained in:
@@ -96,6 +96,11 @@ let CreatureSchema = new SimpleSchema({
|
||||
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',
|
||||
|
||||
@@ -34,6 +34,7 @@ function computeAction(prop, memo){
|
||||
if (prop.usesUsed >= prop.usesResult){
|
||||
prop.insufficientResources = true;
|
||||
}
|
||||
if (!prop.resources) return;
|
||||
// Attributes consumed
|
||||
prop.resources.attributesConsumed.forEach((attConsumed, i) => {
|
||||
if (attConsumed.variableName){
|
||||
|
||||
@@ -102,12 +102,12 @@ export function recomputeCreatureByDoc(creature){
|
||||
'ancestors.id': creatureId,
|
||||
inactive: {$ne: true},
|
||||
type: {$in: calculationPropertyTypes},
|
||||
// TODO filter out expensive fields, particularly icon field
|
||||
}).fetch();
|
||||
/*getActiveProperties({
|
||||
ancestorId: creatureId,
|
||||
filter: {type: {$in: calculationPropertyTypes}},
|
||||
includeUntoggled: true,
|
||||
// TODO filter out expensive fields, particularly icon field
|
||||
});*/
|
||||
let computationMemo = new ComputationMemo(props, creature);
|
||||
computeMemo(computationMemo);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { pick, forOwn } from 'lodash';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import VERSION from '/imports/constants/VERSION.js';
|
||||
|
||||
export default function writeCreatureVariables(memo, creatureId) {
|
||||
const fields = [
|
||||
@@ -31,5 +32,8 @@ export default function writeCreatureVariables(memo, creatureId) {
|
||||
let condensedStat = pick(stat, fields);
|
||||
memo.creatureVariables[variableName] = condensedStat;
|
||||
});
|
||||
Creatures.update(creatureId, {$set: {variables: memo.creatureVariables}});
|
||||
Creatures.update(creatureId, {$set: {
|
||||
variables: memo.creatureVariables,
|
||||
computeVersion: VERSION,
|
||||
}});
|
||||
}
|
||||
|
||||
6
app/imports/constants/VERSION.js
Normal file
6
app/imports/constants/VERSION.js
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
const VERSION = Meteor.isClient ? 'CLIENT' : process.env.SOURCE_VERSION || require('child_process')
|
||||
.execSync('git rev-parse --short HEAD')
|
||||
.toString().trim();
|
||||
|
||||
export default VERSION;
|
||||
@@ -3,6 +3,8 @@ import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
||||
import { assertViewPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import { recomputeCreatureById } from '/imports/api/creature/computation/recomputeCreature.js';
|
||||
import VERSION from '/imports/constants/VERSION.js';
|
||||
|
||||
let schema = new SimpleSchema({
|
||||
creatureId: {
|
||||
@@ -28,8 +30,13 @@ Meteor.publish('singleCharacter', function(creatureId){
|
||||
],
|
||||
});
|
||||
try {
|
||||
assertViewPermission(creatureCursor.fetch()[0], userId);
|
||||
let creature = creatureCursor.fetch()[0];
|
||||
assertViewPermission(creature, userId);
|
||||
if (creature.computeVersion !== VERSION){
|
||||
recomputeCreatureById(creatureId)
|
||||
}
|
||||
} catch (e){
|
||||
console.error(e);
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
</div>
|
||||
<div class="px-3 pb-3">
|
||||
<template
|
||||
v-if="model.resources.attributesConsumed.length ||
|
||||
v-if="model.resources && model.resources.attributesConsumed.length ||
|
||||
model.resources.itemsConsumed.length"
|
||||
>
|
||||
<attribute-consumed-view
|
||||
|
||||
Reference in New Issue
Block a user