Tabletop targeted actions now work

This commit is contained in:
Stefan Zermatten
2023-01-15 14:18:17 +02:00
parent 25e6b19b49
commit ceb170cbcf
9 changed files with 188 additions and 201 deletions

View File

@@ -125,33 +125,16 @@ const insertCreatureLog = new ValidatedMethod({
},
});
const insertTabletopLog = new ValidatedMethod({
name: 'creatureLogs.methods.insertTabletopLog',
mixins: [RateLimiterMixin],
rateLimit: {
numRequests: 5,
timeInterval: 5000,
},
validate: new SimpleSchema({
log: CreatureLogSchema.omit('date'),
}).validator(),
run({ log }) {
const tabletopId = log.tabletopId;
assertUserInTabletop(tabletopId, this.userId);
// Build the new log
let id = insertCreatureLogWork({ log, method: this })
return id;
},
});
export function insertCreatureLogWork({ log, creature, method }) {
export function insertCreatureLogWork({ log, creature, tabletopId, method }) {
// Build the new log
if (typeof log === 'string') {
log = { content: [{ value: log }] };
}
if (!log.content?.length) return;
log.date = new Date();
if (creature) log.tabletopId = creature.tabletop;
if (tabletopId) log.tabletopId = tabletopId;
if (creature && creature.tabletop) log.tabletopId = creature.tabletop;
console.log(log.tabletopId);
// Insert it
let id = CreatureLogs.insert(log);
if (Meteor.isServer) {
@@ -185,24 +168,39 @@ const logRoll = new ValidatedMethod({
roll: {
type: String,
},
tabletopId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
optional: true,
},
creatureId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
optional: true,
},
}).validator(),
run({ roll, creatureId }) {
const creature = Creatures.findOne(creatureId, {
fields: {
readers: 1,
writers: 1,
owner: 1,
'settings.discordWebhook': 1,
name: 1,
avatarPicture: 1,
}
});
assertEditPermission(creature, this.userId);
const variables = CreatureVariables.findOne({ _creatureId: creatureId });
run({ roll, tabletopId, creatureId }) {
if (!creatureId && !tabletopId) throw new Meteor.Error('no-id',
'A creature id or tabletop id must be given'
);
let creature;
if (creatureId) {
creature = Creatures.findOne(creatureId, {
fields: {
readers: 1,
writers: 1,
owner: 1,
'settings.discordWebhook': 1,
name: 1,
avatarPicture: 1,
}
});
assertEditPermission(creature, this.userId);
}
if (tabletopId) {
assertUserInTabletop(tabletopId, this.userId);
}
const variables = CreatureVariables.findOne({ _creatureId: creatureId }) || {};
let logContent = []
let parsedResult = undefined;
try {
@@ -243,11 +241,11 @@ const logRoll = new ValidatedMethod({
date: new Date(),
};
let id = insertCreatureLogWork({ log, creature, method: this });
let id = insertCreatureLogWork({ log, creature, tabletopId, method: this });
return id;
},
});
export default CreatureLogs;
export { CreatureLogSchema, insertCreatureLog, logRoll, insertTabletopLog, PER_CREATURE_LOG_LIMIT };
export { CreatureLogSchema, insertCreatureLog, logRoll, PER_CREATURE_LOG_LIMIT };

View File

@@ -9,8 +9,7 @@ export default function computeAction(computation, node) {
computeResources(computation, node);
if (!prop.resources) return;
prop.resources.itemsConsumed.forEach(itemConsumed => {
if (!itemConsumed.itemId) return;
if (itemConsumed.available < itemConsumed.quantity?.value) {
if (!itemConsumed.itemId || itemConsumed.available < itemConsumed.quantity?.value) {
prop.insufficientResources = true;
}
});

View File

@@ -1,98 +0,0 @@
<template lang="html">
<div
style="height: 100%; overflow: hidden;"
class="character-log layout column justify-end"
>
<v-slide-y-reverse-transition
group
hide-on-leave
class="card-raised-background flex layout column reverse align-end pa-3"
style="overflow: auto;"
>
<log-entry
v-for="log in logs"
:key="log._id"
:model="log"
:show-name="showName"
/>
</v-slide-y-reverse-transition>
<v-card>
<v-text-field
v-model="input"
class="mx-2 mb-2"
persistent-hint
style="flex-grow: 0"
append-outer-icon="mdi-send"
:hint="inputHint"
:error-messages="inputError"
:disabled="!editPermission"
@click:append-outer="submit"
@keyup.enter="submit"
/>
</v-card>
</div>
</template>
<script lang="js">
import LogEntry from '/imports/client/ui/log/LogEntry.vue';
import { parse, prettifyParseError } from '/imports/parser/parser.js';
import resolve, { toString } from '/imports/parser/resolve.js';
export default {
components: {
LogEntry,
},
props: {
logs: {
type: Array,
required: true,
},
editPermission: Boolean,
showName: Boolean,
},
data(){return {
inputHint: undefined,
inputError: undefined,
input: undefined,
}},
watch: {
input(value){
this.input = value;
this.inputHint = this.inputError = undefined;
if (!this.input) return;
let result;
try {
result = parse(value);
} catch (e){
if (e.constructor.name === 'EndOfInputError'){
this.inputError = '...';
} else {
let error = prettifyParseError(e);
this.inputError = error;
}
return;
}
try {
let {result: compiled} = resolve('compile', result, this.creature.variables);
this.inputHint = toString(compiled);
return;
} catch (e){
console.warn(e);
this.inputError = 'Compilation error';
return;
}
},
},
methods: {
submit(){
if (this.inputError || !this.input) return;
this.$emit('submit', this.input);
this.input = '';
},
},
}
</script>
<style lang="css" scoped>
</style>