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,
|
type: Number,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
},
|
},
|
||||||
|
// Version of computation engine that was last used to compute this creature
|
||||||
|
computeVersion: {
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
defaultValue: 'pc',
|
defaultValue: 'pc',
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ function computeAction(prop, memo){
|
|||||||
if (prop.usesUsed >= prop.usesResult){
|
if (prop.usesUsed >= prop.usesResult){
|
||||||
prop.insufficientResources = true;
|
prop.insufficientResources = true;
|
||||||
}
|
}
|
||||||
|
if (!prop.resources) return;
|
||||||
// Attributes consumed
|
// Attributes consumed
|
||||||
prop.resources.attributesConsumed.forEach((attConsumed, i) => {
|
prop.resources.attributesConsumed.forEach((attConsumed, i) => {
|
||||||
if (attConsumed.variableName){
|
if (attConsumed.variableName){
|
||||||
|
|||||||
@@ -102,12 +102,12 @@ export function recomputeCreatureByDoc(creature){
|
|||||||
'ancestors.id': creatureId,
|
'ancestors.id': creatureId,
|
||||||
inactive: {$ne: true},
|
inactive: {$ne: true},
|
||||||
type: {$in: calculationPropertyTypes},
|
type: {$in: calculationPropertyTypes},
|
||||||
|
// TODO filter out expensive fields, particularly icon field
|
||||||
}).fetch();
|
}).fetch();
|
||||||
/*getActiveProperties({
|
/*getActiveProperties({
|
||||||
ancestorId: creatureId,
|
ancestorId: creatureId,
|
||||||
filter: {type: {$in: calculationPropertyTypes}},
|
filter: {type: {$in: calculationPropertyTypes}},
|
||||||
includeUntoggled: true,
|
includeUntoggled: true,
|
||||||
// TODO filter out expensive fields, particularly icon field
|
|
||||||
});*/
|
});*/
|
||||||
let computationMemo = new ComputationMemo(props, creature);
|
let computationMemo = new ComputationMemo(props, creature);
|
||||||
computeMemo(computationMemo);
|
computeMemo(computationMemo);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
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.js';
|
||||||
|
import VERSION from '/imports/constants/VERSION.js';
|
||||||
|
|
||||||
export default function writeCreatureVariables(memo, creatureId) {
|
export default function writeCreatureVariables(memo, creatureId) {
|
||||||
const fields = [
|
const fields = [
|
||||||
@@ -31,5 +32,8 @@ export default function writeCreatureVariables(memo, creatureId) {
|
|||||||
let condensedStat = pick(stat, fields);
|
let condensedStat = pick(stat, fields);
|
||||||
memo.creatureVariables[variableName] = condensedStat;
|
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 CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||||
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
||||||
import { assertViewPermission } from '/imports/api/creature/creaturePermissions.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({
|
let schema = new SimpleSchema({
|
||||||
creatureId: {
|
creatureId: {
|
||||||
@@ -28,8 +30,13 @@ Meteor.publish('singleCharacter', function(creatureId){
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
assertViewPermission(creatureCursor.fetch()[0], userId);
|
let creature = creatureCursor.fetch()[0];
|
||||||
|
assertViewPermission(creature, userId);
|
||||||
|
if (creature.computeVersion !== VERSION){
|
||||||
|
recomputeCreatureById(creatureId)
|
||||||
|
}
|
||||||
} catch (e){
|
} catch (e){
|
||||||
|
console.error(e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="px-3 pb-3">
|
<div class="px-3 pb-3">
|
||||||
<template
|
<template
|
||||||
v-if="model.resources.attributesConsumed.length ||
|
v-if="model.resources && model.resources.attributesConsumed.length ||
|
||||||
model.resources.itemsConsumed.length"
|
model.resources.itemsConsumed.length"
|
||||||
>
|
>
|
||||||
<attribute-consumed-view
|
<attribute-consumed-view
|
||||||
|
|||||||
Reference in New Issue
Block a user