Merge branch 'feature-tabletop' into develop
This commit is contained in:
@@ -62,6 +62,34 @@ let CreatureSettingsSchema = new SimpleSchema({
|
||||
},
|
||||
});
|
||||
|
||||
let IconGroupSchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
max: STORAGE_LIMITS.name,
|
||||
optional: true,
|
||||
},
|
||||
iconIds: {
|
||||
type: Array,
|
||||
max: 4,
|
||||
defaultValue: [],
|
||||
},
|
||||
'iconIds.$': {
|
||||
type: String,
|
||||
max: STORAGE_LIMITS.variableName,
|
||||
},
|
||||
});
|
||||
|
||||
let CreatureTabletopSettingsSchema = new SimpleSchema({
|
||||
iconGroups: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
max: 10,
|
||||
},
|
||||
'iconGroups.$': {
|
||||
type: IconGroupSchema,
|
||||
},
|
||||
});
|
||||
|
||||
let CreatureSchema = new SimpleSchema({
|
||||
// Strings
|
||||
name: {
|
||||
@@ -177,6 +205,10 @@ let CreatureSchema = new SimpleSchema({
|
||||
type: SimpleSchema.Integer,
|
||||
optional: true,
|
||||
},
|
||||
tabletopSettings: {
|
||||
type: CreatureTabletopSettingsSchema,
|
||||
optional: true,
|
||||
},
|
||||
|
||||
// Settings
|
||||
settings: {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { assertEditPermission } from '/imports/api/creature/creatures/creaturePe
|
||||
import { parse, prettifyParseError } from '/imports/parser/parser';
|
||||
import resolve, { toString } from '/imports/parser/resolve';
|
||||
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
|
||||
import { assertUserInTabletop } from '/imports/api/tabletop/methods/shared/tabletopPermissions.js';
|
||||
|
||||
const PER_CREATURE_LOG_LIMIT = 100;
|
||||
|
||||
@@ -42,6 +43,12 @@ let CreatureLogSchema = new SimpleSchema({
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
index: 1,
|
||||
},
|
||||
tabletopId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
index: 1,
|
||||
optional: true,
|
||||
},
|
||||
creatureName: {
|
||||
type: String,
|
||||
optional: true,
|
||||
@@ -119,6 +126,7 @@ const insertCreatureLog = new ValidatedMethod({
|
||||
'settings.discordWebhook': 1,
|
||||
name: 1,
|
||||
avatarPicture: 1,
|
||||
tabletop: 1,
|
||||
}
|
||||
});
|
||||
assertEditPermission(creature, this.userId);
|
||||
@@ -128,7 +136,7 @@ const insertCreatureLog = new ValidatedMethod({
|
||||
},
|
||||
});
|
||||
|
||||
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 }] };
|
||||
@@ -142,13 +150,20 @@ export function insertCreatureLogWork({ log, creature, method }) {
|
||||
}
|
||||
});
|
||||
log.date = new Date();
|
||||
|
||||
if (tabletopId) log.tabletopId = tabletopId;
|
||||
if (creature && creature.tabletop) log.tabletopId = creature.tabletop;
|
||||
// Insert it
|
||||
let id = CreatureLogs.insert(log);
|
||||
if (Meteor.isServer) {
|
||||
method?.unblock();
|
||||
removeOldLogs(creature._id);
|
||||
logWebhook({ log, creature });
|
||||
if (creature) {
|
||||
removeOldLogs(creature._id);
|
||||
logWebhook({ log, creature });
|
||||
}
|
||||
if (log.tabletopId) {
|
||||
// Todo remove old tabletop logs
|
||||
// Log webhook if it's different to creature webhook
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
@@ -170,24 +185,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 {
|
||||
@@ -228,7 +258,7 @@ const logRoll = new ValidatedMethod({
|
||||
date: new Date(),
|
||||
};
|
||||
|
||||
let id = insertCreatureLogWork({ log, creature, method: this });
|
||||
let id = insertCreatureLogWork({ log, creature, tabletopId, method: this });
|
||||
|
||||
return id;
|
||||
},
|
||||
|
||||
@@ -16,8 +16,7 @@ export default function computeAction(computation, node) {
|
||||
}
|
||||
});
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -12,15 +12,17 @@ export const loadedCreatures: Map<string, LoadedCreature> = new Map(); // creatu
|
||||
export function loadCreature(creatureId: string, subscription: Tracker.Computation) {
|
||||
if (!creatureId) throw 'creatureId is required';
|
||||
let creature = loadedCreatures.get(creatureId);
|
||||
if (!creature || !creature.subs.has(subscription)) {
|
||||
subscription.onStop(() => {
|
||||
unloadCreature(creatureId, subscription);
|
||||
});
|
||||
}
|
||||
if (creature) {
|
||||
creature.subs.add(subscription);
|
||||
} else {
|
||||
creature = new LoadedCreature(subscription, creatureId);
|
||||
loadedCreatures.set(creatureId, creature);
|
||||
}
|
||||
subscription.onStop(() => {
|
||||
unloadCreature(creatureId, subscription);
|
||||
});
|
||||
}
|
||||
|
||||
function unloadCreature(creatureId, subscription) {
|
||||
@@ -188,14 +190,15 @@ export function getPropertyChildren(creatureId, property) {
|
||||
// This propertyId will always appear in the parent of the children
|
||||
if (loadedCreatures.has(creatureId)) {
|
||||
const creature = loadedCreatures.get(creatureId);
|
||||
const props = [];
|
||||
if (!creature) return [];
|
||||
const props: CreatureProperty[] = [];
|
||||
for (const prop of creature.properties.values()) {
|
||||
if (prop.parent?.id === property._id) {
|
||||
if (prop.parentId === property._id) {
|
||||
props.push(prop);
|
||||
}
|
||||
}
|
||||
const cloneProps = EJSON.clone(props);
|
||||
return cloneProps.sort((a, b) => a.order - b.order);
|
||||
return cloneProps.sort((a, b) => a.left - b.left);
|
||||
} else {
|
||||
return CreatureProperties.find({
|
||||
'parent.id': property._id,
|
||||
|
||||
49
app/imports/api/tabletop/TabletopMaps.js
Normal file
49
app/imports/api/tabletop/TabletopMaps.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
||||
|
||||
let TabletopMaps = new Mongo.Collection('tabletopmaps');
|
||||
|
||||
let TabletopMapschema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
texture: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
position: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
},
|
||||
'position.x': {
|
||||
type: Number,
|
||||
},
|
||||
'position.y': {
|
||||
type: Number,
|
||||
},
|
||||
width: {
|
||||
type: Number,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
},
|
||||
rotation: {
|
||||
type: Number,
|
||||
max: 360,
|
||||
min: 0,
|
||||
},
|
||||
// If this map was copied from a library map, this ID will be set
|
||||
libraryMapId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
const schema = new SimpleSchema({});
|
||||
schema.extend(ChildSchema);
|
||||
schema.extend(TabletopMapschema);
|
||||
TabletopMaps.attachSchema(schema);
|
||||
|
||||
export default TabletopMaps;
|
||||
43
app/imports/api/tabletop/TabletopObjects.js
Normal file
43
app/imports/api/tabletop/TabletopObjects.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
||||
|
||||
let TabletopObjects = new Mongo.Collection('tabletopObjects');
|
||||
|
||||
let TabletopObjectSchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
texture: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
position: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
},
|
||||
'position.x': {
|
||||
type: Number,
|
||||
},
|
||||
'position.y': {
|
||||
type: Number,
|
||||
},
|
||||
width: {
|
||||
type: Number,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
},
|
||||
rotation: {
|
||||
type: Number,
|
||||
max: 360,
|
||||
min: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const schema = new SimpleSchema({});
|
||||
schema.extend(ChildSchema);
|
||||
schema.extend(TabletopObjectSchema);
|
||||
TabletopObjects.attachSchema(schema);
|
||||
|
||||
export default TabletopObjects;
|
||||
1253
app/imports/api/tabletop/three/OrbitControls.js
Normal file
1253
app/imports/api/tabletop/three/OrbitControls.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user