Migrate props to typed schemas

This commit is contained in:
ThaumRystra
2025-01-12 19:29:26 +02:00
parent 0f32afd25a
commit 0125367085
33 changed files with 350 additions and 243 deletions

View File

@@ -14,6 +14,7 @@
"EJSON",
"healthbar",
"healthbars",
"Hitpoints",
"jank",
"meteortesting",
"multigraph",

View File

@@ -2,7 +2,7 @@ import SimpleSchema from 'simpl-schema';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
/*
* Attributes are numbered stats of a character
@@ -33,7 +33,7 @@ const AttributeSchema = createPropertySchema({
'resource', // Rages, sorcery points
'spellSlot', // Level 1, 2, 3... spell slots
'utility', // Aren't displayed, Jump height, Carry capacity
],
] as const,
defaultValue: 'stat',
index: 1,
},

View File

@@ -1,8 +1,9 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
let BranchSchema = createPropertySchema({
const BranchSchema = createPropertySchema({
branchType: {
type: String,
allowedValues: [
@@ -24,7 +25,7 @@ let BranchSchema = createPropertySchema({
// Otherwise presents its own text with yes/no
'choice',
//'option',
],
] as const,
defaultValue: 'if',
},
text: {
@@ -33,7 +34,7 @@ let BranchSchema = createPropertySchema({
max: STORAGE_LIMITS.name,
},
condition: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
parseLevel: 'compile',
},
@@ -44,9 +45,9 @@ let BranchSchema = createPropertySchema({
},
});
let ComputedOnlyBranchSchema = createPropertySchema({
const ComputedOnlyBranchSchema = createPropertySchema({
condition: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
parseLevel: 'compile',
},
@@ -56,4 +57,8 @@ const ComputedBranchSchema = new SimpleSchema({})
.extend(BranchSchema)
.extend(ComputedOnlyBranchSchema);
export type Branch = InferType<typeof BranchSchema>;
export type ComputedOnlyBranch = InferType<typeof ComputedOnlyBranchSchema>;
export type ComputedBranch = Expand<InferType<typeof BranchSchema> & InferType<typeof ComputedOnlyBranchSchema>>;
export { BranchSchema, ComputedBranchSchema, ComputedOnlyBranchSchema }

View File

@@ -1,8 +1,9 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
let BuffRemoverSchema = createPropertySchema({
const BuffRemoverSchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -75,10 +76,14 @@ let BuffRemoverSchema = createPropertySchema({
},
});
let ComputedOnlyBuffRemoverSchema = createPropertySchema({});
const ComputedOnlyBuffRemoverSchema = createPropertySchema({});
const ComputedBuffRemoverSchema = new SimpleSchema()
const ComputedBuffRemoverSchema = new SimpleSchema({})
.extend(BuffRemoverSchema)
.extend(ComputedOnlyBuffRemoverSchema);
export type BuffRemover = InferType<typeof BuffRemoverSchema>;
export type ComputedOnlyBuffRemover = InferType<typeof ComputedOnlyBuffRemoverSchema>;
export type ComputedBuffRemover = Expand<InferType<typeof BuffRemoverSchema> & InferType<typeof ComputedOnlyBuffRemoverSchema>>;
export { BuffRemoverSchema, ComputedOnlyBuffRemoverSchema, ComputedBuffRemoverSchema };

View File

@@ -2,6 +2,7 @@ import SimpleSchema from 'simpl-schema';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
const ClassLevelSchema = createPropertySchema({
name: {
@@ -10,7 +11,7 @@ const ClassLevelSchema = createPropertySchema({
max: STORAGE_LIMITS.name,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
// The name of this class level's variable
@@ -30,13 +31,17 @@ const ClassLevelSchema = createPropertySchema({
const ComputedOnlyClassLevelSchema = createPropertySchema({
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
});
const ComputedClassLevelSchema = new SimpleSchema()
const ComputedClassLevelSchema = new SimpleSchema({})
.extend(ComputedOnlyClassLevelSchema)
.extend(ClassLevelSchema);
export type ClassLevel = InferType<typeof ClassLevelSchema>;
export type ComputedOnlyClassLevel = InferType<typeof ComputedOnlyClassLevelSchema>;
export type ComputedClassLevel = Expand<InferType<typeof ClassLevelSchema> & InferType<typeof ComputedOnlyClassLevelSchema>>;
export { ClassLevelSchema, ComputedOnlyClassLevelSchema, ComputedClassLevelSchema };

View File

@@ -1,17 +1,18 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
// Classes are like slots, except they only take class levels and enforce that
// lower levels are taken before higher levels
let ClassSchema = createPropertySchema({
const ClassSchema = createPropertySchema({
name: {
type: String,
optional: true,
max: STORAGE_LIMITS.name,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
// Only `classLevel`s with the same variable name can fill the class
@@ -59,7 +60,7 @@ let ClassSchema = createPropertySchema({
max: STORAGE_LIMITS.tagLength,
},
slotCondition: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
});
@@ -67,11 +68,11 @@ let ClassSchema = createPropertySchema({
const ComputedOnlyClassSchema = createPropertySchema({
// Computed fields
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
slotCondition: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
@@ -91,8 +92,12 @@ const ComputedOnlyClassSchema = createPropertySchema({
},
});
const ComputedClassSchema = new SimpleSchema()
const ComputedClassSchema = new SimpleSchema({})
.extend(ClassSchema)
.extend(ComputedOnlyClassSchema);
export type Class = InferType<typeof ClassSchema>;
export type ComputedOnlyClass = InferType<typeof ComputedOnlyClassSchema>;
export type ComputedClass = Expand<InferType<typeof ClassSchema> & InferType<typeof ComputedOnlyClassSchema>>;
export { ClassSchema, ComputedOnlyClassSchema, ComputedClassSchema };

View File

@@ -1,4 +1,3 @@
import SimpleSchema from 'simpl-schema';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema';
import {
@@ -6,14 +5,17 @@ import {
prettifyParseError,
} from '/imports/parser/parser';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import resolve from '/imports/parser/resolve';
import Context from '../../parser/types/Context';
import Context from '/imports/parser/types/Context';
import traverse from '/imports/parser/traverse';
import type ResolveLevel from '/imports/parser/types/ResolveLevel';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
/*
* Constants are primitive values that can be used elsewhere in computations
*/
let ConstantSchema = new SimpleSchema({
const ConstantSchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -37,16 +39,16 @@ let ConstantSchema = new SimpleSchema({
errors: {
type: Array,
maxCount: STORAGE_LIMITS.errorCount,
autoValue() {
let calc = this.field('calculation');
async autoValue() {
const calc = this.field('calculation');
if (!calc.isSet && this.isModifier) {
this.unset()
return;
}
let string = calc.value;
const string = calc.value;
if (!string) return [];
// Evaluate the calculation with no scope
let { result, context } = parseString(string);
const { result, context } = await parseString(string);
// Any existing errors will result in an early failure
if (context && context.errors.length) return context.errors;
// Ban variables in constants if necessary
@@ -63,8 +65,8 @@ let ConstantSchema = new SimpleSchema({
},
});
function parseString(string, fn = 'compile') {
let context = new Context();
async function parseString(string, fn: ResolveLevel = 'compile') {
const context = new Context();
if (!string) {
return { result: string, context };
}
@@ -74,15 +76,19 @@ function parseString(string, fn = 'compile') {
try {
node = parse(string);
} catch (e) {
let message = prettifyParseError(e);
const message = prettifyParseError(e as Error);
context.error(message);
return { context };
}
if (!node) return { context };
let { result } = resolve(fn, node, {/*empty scope*/ }, context);
const { result } = await resolve(fn, node, {/*empty scope*/ }, context);
return { result, context }
}
const ComputedOnlyConstantSchema = new SimpleSchema({});
const ComputedOnlyConstantSchema = createPropertySchema({});
export type Constant = InferType<typeof ConstantSchema>;
export type ComputedOnlyConstant = InferType<typeof ComputedOnlyConstantSchema>;
export type ComputedConstant = Expand<InferType<typeof ConstantSchema> & InferType<typeof ComputedOnlyConstantSchema>>;
export { ConstantSchema, ComputedOnlyConstantSchema };

View File

@@ -1,8 +1,9 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
let ContainerSchema = createPropertySchema({
const ContainerSchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -29,14 +30,14 @@ let ContainerSchema = createPropertySchema({
optional: true,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
});
const ComputedOnlyContainerSchema = createPropertySchema({
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
// Weight of all the contents.
@@ -64,8 +65,12 @@ const ComputedOnlyContainerSchema = createPropertySchema({
},
});
const ComputedContainerSchema = new SimpleSchema()
const ComputedContainerSchema = new SimpleSchema({})
.extend(ComputedOnlyContainerSchema)
.extend(ContainerSchema);
export type Container = InferType<typeof ContainerSchema>;
export type ComputedOnlyContainer = InferType<typeof ComputedOnlyContainerSchema>;
export type ComputedContainer = Expand<InferType<typeof ContainerSchema> & InferType<typeof ComputedOnlyContainerSchema>>;
export { ContainerSchema, ComputedOnlyContainerSchema, ComputedContainerSchema };

View File

@@ -1,6 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
// Creature templates represent creatures that don't yet exist
// Used to store creatures in the library, or as templates for another creature to summon
@@ -11,7 +12,7 @@ const CreatureTemplateSchema = createPropertySchema({
optional: true,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
picture: {
@@ -28,7 +29,7 @@ const CreatureTemplateSchema = createPropertySchema({
const ComputedOnlyCreatureTemplateSchema = createPropertySchema({
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
});
@@ -37,4 +38,8 @@ const ComputedCreatureTemplateSchema = new SimpleSchema({})
.extend(CreatureTemplateSchema)
.extend(ComputedOnlyCreatureTemplateSchema);
export type CreatureTemplate = InferType<typeof CreatureTemplateSchema>;
export type ComputedOnlyCreatureTemplate = InferType<typeof ComputedOnlyCreatureTemplateSchema>;
export type ComputedCreatureTemplate = Expand<InferType<typeof CreatureTemplateSchema> & InferType<typeof ComputedOnlyCreatureTemplateSchema>>;
export { CreatureTemplateSchema, ComputedCreatureTemplateSchema, ComputedOnlyCreatureTemplateSchema };

View File

@@ -1,12 +1,13 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
/*
* DamageMultipliers are multipliers that affect how much damage is taken from
* a given damage type
*/
let DamageMultiplierSchema = new SimpleSchema({
const DamageMultiplierSchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -51,6 +52,10 @@ let DamageMultiplierSchema = new SimpleSchema({
},
});
const ComputedOnlyDamageMultiplierSchema = new SimpleSchema({});
const ComputedOnlyDamageMultiplierSchema = createPropertySchema({});
export type DamageMultiplier = InferType<typeof DamageMultiplierSchema>;
export type ComputedOnlyDamageMultiplier = InferType<typeof ComputedOnlyDamageMultiplierSchema>;
export type ComputedDamageMultiplier = Expand<InferType<typeof DamageMultiplierSchema> & InferType<typeof ComputedOnlyDamageMultiplierSchema>>;
export { DamageMultiplierSchema, ComputedOnlyDamageMultiplierSchema };

View File

@@ -2,12 +2,13 @@ import SimpleSchema from 'simpl-schema';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
const DamageSchema = createPropertySchema({
// The roll that determines how much to damage the attribute
// This can be simplified, but only computed when applied
amount: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
defaultValue: '1d8 + strength.modifier',
parseLevel: 'compile',
@@ -19,7 +20,7 @@ const DamageSchema = createPropertySchema({
allowedValues: [
'self',
'target',
],
] as const,
},
damageType: {
type: String,
@@ -39,7 +40,7 @@ const DamageSchema = createPropertySchema({
},
// The computed DC
'save.dc': {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
// The variable name of save to roll
@@ -50,7 +51,7 @@ const DamageSchema = createPropertySchema({
},
// The damage to deal on a successful save
'save.damageFunction': {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
parseLevel: 'compile',
},
@@ -58,7 +59,7 @@ const DamageSchema = createPropertySchema({
const ComputedOnlyDamageSchema = createPropertySchema({
amount: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
parseLevel: 'compile',
},
@@ -67,12 +68,12 @@ const ComputedOnlyDamageSchema = createPropertySchema({
optional: true,
},
'save.dc': {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
parseLevel: 'compile',
optional: true,
},
'save.damageFunction': {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
parseLevel: 'compile',
optional: true,
},
@@ -82,4 +83,8 @@ const ComputedDamageSchema = new SimpleSchema({})
.extend(DamageSchema)
.extend(ComputedOnlyDamageSchema);
export type Damage = InferType<typeof DamageSchema>;
export type ComputedOnlyDamage = InferType<typeof ComputedOnlyDamageSchema>;
export type ComputedDamage = Expand<InferType<typeof DamageSchema> & InferType<typeof ComputedOnlyDamageSchema>>;
export { DamageSchema, ComputedDamageSchema, ComputedOnlyDamageSchema };

View File

@@ -2,12 +2,13 @@ import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import TagTargetingSchema from '/imports/api/properties/subSchemas/TagTargetingSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
/*
* Effects are reason-value attached to skills and abilities
* that modify their final value or presentation in some way
*/
let EffectSchema = createPropertySchema({
const EffectSchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -28,17 +29,17 @@ let EffectSchema = createPropertySchema({
'passiveAdd',
'fail',
'conditional',
],
] as const,
},
amount: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
// Conditional benefits store just uncomputed text
text: {
type: String,
optional: true,
max: STORAGE_LIMITS.effectCondition,
max: STORAGE_LIMITS.effectText,
},
// Which stats the effect is applied to
// Each entry is a variableName targeted by this effect
@@ -55,13 +56,17 @@ let EffectSchema = createPropertySchema({
const ComputedOnlyEffectSchema = createPropertySchema({
amount: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
});
const ComputedEffectSchema = new SimpleSchema()
const ComputedEffectSchema = new SimpleSchema({})
.extend(ComputedOnlyEffectSchema)
.extend(EffectSchema);
export type Effect = InferType<typeof EffectSchema>;
export type ComputedOnlyEffect = InferType<typeof ComputedOnlyEffectSchema>;
export type ComputedEffect = Expand<InferType<typeof EffectSchema> & InferType<typeof ComputedOnlyEffectSchema>>;
export { EffectSchema, ComputedEffectSchema, ComputedOnlyEffectSchema };

View File

@@ -1,36 +0,0 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
let FeatureSchema = createPropertySchema({
name: {
type: String,
max: STORAGE_LIMITS.name,
optional: true,
},
summary: {
type: 'inlineCalculationFieldToCompute',
optional: true,
},
description: {
type: 'inlineCalculationFieldToCompute',
optional: true,
},
});
let ComputedOnlyFeatureSchema = createPropertySchema({
summary: {
type: 'computedOnlyInlineCalculationField',
optional: true,
},
description: {
type: 'computedOnlyInlineCalculationField',
optional: true,
},
});
const ComputedFeatureSchema = new SimpleSchema()
.extend(FeatureSchema)
.extend(ComputedOnlyFeatureSchema);
export { FeatureSchema, ComputedFeatureSchema, ComputedOnlyFeatureSchema }

View File

@@ -0,0 +1,41 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
const FeatureSchema = createPropertySchema({
name: {
type: String,
max: STORAGE_LIMITS.name,
optional: true,
},
summary: {
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
description: {
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
});
const ComputedOnlyFeatureSchema = createPropertySchema({
summary: {
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
description: {
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
});
const ComputedFeatureSchema = new SimpleSchema({})
.extend(FeatureSchema)
.extend(ComputedOnlyFeatureSchema);
export type Feature = InferType<typeof FeatureSchema>;
export type ComputedOnlyFeature = InferType<typeof ComputedOnlyFeatureSchema>;
export type ComputedFeature = Expand<InferType<typeof FeatureSchema> & InferType<typeof ComputedOnlyFeatureSchema>>;
export { FeatureSchema, ComputedFeatureSchema, ComputedOnlyFeatureSchema }

View File

@@ -1,17 +1,18 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
// Folders organize a character sheet into a tree, particularly to group things
// like 'race' and 'background'
let FolderSchema = createPropertySchema({
const FolderSchema = createPropertySchema({
name: {
type: String,
max: STORAGE_LIMITS.name,
optional: true,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
groupStats: {
@@ -27,26 +28,30 @@ let FolderSchema = createPropertySchema({
optional: true,
allowedValues: [
'stats', 'features', 'actions', 'spells', 'inventory', 'journal', 'build'
],
] as const,
},
location: {
type: String,
optional: true,
allowedValues: [
'start', 'events', 'stats', 'skills', 'proficiencies', 'end'
],
] as const,
},
});
const ComputedOnlyFolderSchema = createPropertySchema({
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
});
const ComputedFolderSchema = new SimpleSchema()
const ComputedFolderSchema = new SimpleSchema({})
.extend(FolderSchema)
.extend(ComputedOnlyFolderSchema);
export type Folder = InferType<typeof FolderSchema>;
export type ComputedOnlyFolder = InferType<typeof ComputedOnlyFolderSchema>;
export type ComputedFolder = Expand<InferType<typeof FolderSchema> & InferType<typeof ComputedOnlyFolderSchema>>;
export { FolderSchema, ComputedFolderSchema, ComputedOnlyFolderSchema };

View File

@@ -1,14 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { CreatureProperty } from '/imports/api/creature/creatureProperties/CreatureProperties';
export interface Item extends CreatureProperty {
type: 'item'
name?: string
plural?: string
quantity: number
}
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
const ItemSchema = createPropertySchema({
name: {
@@ -23,7 +16,7 @@ const ItemSchema = createPropertySchema({
max: STORAGE_LIMITS.name,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
// Number currently held
@@ -102,7 +95,7 @@ const ItemSchema = createPropertySchema({
const ComputedOnlyItemSchema = createPropertySchema({
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
});
@@ -111,4 +104,8 @@ const ComputedItemSchema = new SimpleSchema({})
.extend(ItemSchema)
.extend(ComputedOnlyItemSchema);
export type Item = InferType<typeof ItemSchema>;
export type ComputedOnlyItem = InferType<typeof ComputedOnlyItemSchema>;
export type ComputedItem = Expand<InferType<typeof ItemSchema> & InferType<typeof ComputedOnlyItemSchema>>;
export { ItemSchema, ComputedItemSchema, ComputedOnlyItemSchema };

View File

@@ -1,19 +1,20 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
let NoteSchema = createPropertySchema({
const NoteSchema = createPropertySchema({
name: {
type: String,
optional: true,
max: STORAGE_LIMITS.name,
},
summary: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
// Prevent the property from showing up in the log
@@ -23,19 +24,23 @@ let NoteSchema = createPropertySchema({
},
});
let ComputedOnlyNoteSchema = createPropertySchema({
const ComputedOnlyNoteSchema = createPropertySchema({
summary: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
});
const ComputedNoteSchema = new SimpleSchema()
const ComputedNoteSchema = new SimpleSchema({})
.extend(NoteSchema)
.extend(ComputedOnlyNoteSchema);
export type Note = InferType<typeof NoteSchema>;
export type ComputedOnlyNote = InferType<typeof ComputedOnlyNoteSchema>;
export type ComputedNote = Expand<InferType<typeof NoteSchema> & InferType<typeof ComputedOnlyNoteSchema>>;
export { NoteSchema, ComputedNoteSchema, ComputedOnlyNoteSchema, };

View File

@@ -3,12 +3,13 @@ import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
/*
* PointBuys are reason-value attached to skills and abilities
* that modify their final value or presentation in some way
*/
let PointBuySchema = createPropertySchema({
const PointBuySchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -50,19 +51,19 @@ let PointBuySchema = createPropertySchema({
optional: true,
},
min: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
max: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
total: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
cost: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
parseLevel: 'compile',
},
@@ -70,15 +71,15 @@ let PointBuySchema = createPropertySchema({
const ComputedOnlyPointBuySchema = createPropertySchema({
min: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
max: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
cost: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
parseLevel: 'compile',
},
@@ -104,7 +105,7 @@ const ComputedOnlyPointBuySchema = createPropertySchema({
type: ErrorSchema,
},
total: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
spent: {
@@ -127,8 +128,12 @@ const ComputedOnlyPointBuySchema = createPropertySchema({
},
});
const ComputedPointBuySchema = new SimpleSchema()
const ComputedPointBuySchema = new SimpleSchema({})
.extend(ComputedOnlyPointBuySchema)
.extend(PointBuySchema);
export type PointBuy = InferType<typeof PointBuySchema>;
export type ComputedOnlyPointBuy = InferType<typeof ComputedOnlyPointBuySchema>;
export type ComputedPointBuy = Expand<InferType<typeof PointBuySchema> & InferType<typeof ComputedOnlyPointBuySchema>>;
export { PointBuySchema, ComputedPointBuySchema, ComputedOnlyPointBuySchema };

View File

@@ -1,8 +1,9 @@
import SimpleSchema from 'simpl-schema';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import TagTargetingSchema from '/imports/api/properties/subSchemas/TagTargetingSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
let ProficiencySchema = new SimpleSchema({
const ProficiencySchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -27,6 +28,10 @@ let ProficiencySchema = new SimpleSchema({
},
}).extend(TagTargetingSchema);
const ComputedOnlyProficiencySchema = new SimpleSchema({});
const ComputedOnlyProficiencySchema = createPropertySchema({});
export type Proficiency = InferType<typeof ProficiencySchema>;
export type ComputedOnlyProficiency = InferType<typeof ComputedOnlyProficiencySchema>;
export type ComputedProficiency = Expand<InferType<typeof ProficiencySchema> & InferType<typeof ComputedOnlyProficiencySchema>>;
export { ProficiencySchema, ComputedOnlyProficiencySchema };

View File

@@ -1,12 +0,0 @@
import { TreeDoc } from '/imports/api/parenting/ChildSchema';
export default interface Property extends TreeDoc {
_id: string
_migrationError?: string
tags: string[]
icon?: {
name: string
shape: string
},
slotQuantityFilled?: number
}

View File

@@ -1,14 +1,14 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
let ReferenceSchema = new SimpleSchema({
const ReferenceSchema = createPropertySchema({
ref: {
type: Object,
defaultValue: {},
},
'ref.id': {
type: String,
regEx: SimpleSchema.RegEx.Id,
optional: true,
},
'ref.collection': {
@@ -62,6 +62,10 @@ let ReferenceSchema = new SimpleSchema({
},
});
const ComputedOnlyReferenceSchema = new SimpleSchema({});
const ComputedOnlyReferenceSchema = createPropertySchema({});
export type Reference = InferType<typeof ReferenceSchema>;
export type ComputedOnlyReference = InferType<typeof ComputedOnlyReferenceSchema>;
export type ComputedReference = Expand<InferType<typeof ReferenceSchema> & InferType<typeof ComputedOnlyReferenceSchema>>;
export { ReferenceSchema, ComputedOnlyReferenceSchema };

View File

@@ -2,6 +2,7 @@ import SimpleSchema from 'simpl-schema';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
/**
* Rolls are children to actions or other rolls, they are triggered with 0 or
@@ -21,7 +22,7 @@ import createPropertySchema from '/imports/api/properties/subSchemas/createPrope
* If the roll fails to meet or exceed the target number, the adjustments and
* child rolls are applied
*/
let RollSchema = createPropertySchema({
const RollSchema = createPropertySchema({
name: {
type: String,
defaultValue: 'New Roll',
@@ -37,7 +38,7 @@ let RollSchema = createPropertySchema({
},
// The roll, can be simplified, but only computed in context
roll: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
parseLevel: 'compile',
optional: true,
},
@@ -48,9 +49,9 @@ let RollSchema = createPropertySchema({
},
});
let ComputedOnlyRollSchema = createPropertySchema({
const ComputedOnlyRollSchema = createPropertySchema({
roll: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
parseLevel: 'compile',
optional: true,
},
@@ -60,4 +61,8 @@ const ComputedRollSchema = new SimpleSchema({})
.extend(RollSchema)
.extend(ComputedOnlyRollSchema);
export type Roll = InferType<typeof RollSchema>;
export type ComputedOnlyRoll = InferType<typeof ComputedOnlyRollSchema>;
export type ComputedRoll = Expand<InferType<typeof RollSchema> & InferType<typeof ComputedOnlyRollSchema>>;
export { RollSchema, ComputedRollSchema, ComputedOnlyRollSchema };

View File

@@ -1,10 +1,11 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
// These are the rolls made when saves are called for
// For the saving throw bonus or proficiency, see ./Skills.js
let SavingThrowSchema = createPropertySchema({
const SavingThrowSchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -12,7 +13,7 @@ let SavingThrowSchema = createPropertySchema({
},
// The computed DC
dc: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
// Who this saving throw applies to
@@ -22,7 +23,7 @@ let SavingThrowSchema = createPropertySchema({
allowedValues: [
'self',
'target',
],
] as const,
},
// The variable name of save to roll
stat: {
@@ -39,7 +40,7 @@ let SavingThrowSchema = createPropertySchema({
const ComputedOnlySavingThrowSchema = createPropertySchema({
dc: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
parseLevel: 'compile',
optional: true,
},
@@ -49,4 +50,8 @@ const ComputedSavingThrowSchema = new SimpleSchema({})
.extend(SavingThrowSchema)
.extend(ComputedOnlySavingThrowSchema);
export type SavingThrow = InferType<typeof SavingThrowSchema>;
export type ComputedOnlySavingThrow = InferType<typeof ComputedOnlySavingThrowSchema>;
export type ComputedSavingThrow = Expand<InferType<typeof SavingThrowSchema> & InferType<typeof ComputedOnlySavingThrowSchema>>;
export { SavingThrowSchema, ComputedOnlySavingThrowSchema, ComputedSavingThrowSchema };

View File

@@ -3,12 +3,13 @@ import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import TagTargetingSchema from '/imports/api/properties/subSchemas/TagTargetingSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
/*
* Skills are anything that results in a modifier to be added to a D20
* Skills have an ability score modifier that they use as their basis
*/
let SkillSchema = createPropertySchema({
const SkillSchema = createPropertySchema({
name: {
type: String,
optional: true,
@@ -41,29 +42,29 @@ let SkillSchema = createPropertySchema({
'armor',
'language',
'utility', //not displayed anywhere
],
] as const,
defaultValue: 'skill',
},
// The base proficiency of this skill
baseProficiency: {
type: Number,
optional: true,
allowedValues: [0.49, 0.5, 1, 2],
allowedValues: [0.49, 0.5, 1, 2] as const,
},
// The starting value, before effects
baseValue: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
// Description of what the skill is used for
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
// Skills can apply their value to other calculations as a proficiency using tag targeting
}).extend(TagTargetingSchema);
let ComputedOnlySkillSchema = createPropertySchema({
const ComputedOnlySkillSchema = createPropertySchema({
// Computed value of skill to be added to skill rolls
value: {
type: Number,
@@ -73,11 +74,11 @@ let ComputedOnlySkillSchema = createPropertySchema({
},
// The result of baseValueCalculation
baseValue: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
// Computed value added by the ability
@@ -90,7 +91,7 @@ let ComputedOnlySkillSchema = createPropertySchema({
advantage: {
type: SimpleSchema.Integer,
optional: true,
allowedValues: [-1, 0, 1],
allowedValues: [-1, 0, 1] as const,
removeBeforeCompute: true,
},
// Computed bonus to passive checks
@@ -102,7 +103,7 @@ let ComputedOnlySkillSchema = createPropertySchema({
// Computed proficiency multiplier
proficiency: {
type: Number,
allowedValues: [0, 0.49, 0.5, 1, 2],
allowedValues: [0, 0.49, 0.5, 1, 2] as const,
defaultValue: 0,
removeBeforeCompute: true,
},
@@ -174,4 +175,8 @@ const ComputedSkillSchema = new SimpleSchema({})
.extend(ComputedOnlySkillSchema)
.extend(SkillSchema);
export type Skill = InferType<typeof SkillSchema>;
export type ComputedOnlySkill = InferType<typeof ComputedOnlySkillSchema>;
export type ComputedSkill = Expand<InferType<typeof SkillSchema> & InferType<typeof ComputedOnlySkillSchema>>;
export { SkillSchema, ComputedSkillSchema, ComputedOnlySkillSchema };

View File

@@ -1,15 +1,16 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
let SlotSchema = createPropertySchema({
const SlotSchema = createPropertySchema({
name: {
type: String,
optional: true,
max: STORAGE_LIMITS.name,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
slotType: {
@@ -43,7 +44,7 @@ let SlotSchema = createPropertySchema({
},
'extraTags.$.operation': {
type: String,
allowedValues: ['OR', 'NOT'],
allowedValues: ['OR', 'NOT'] as const,
defaultValue: 'OR',
},
'extraTags.$.tags': {
@@ -56,7 +57,7 @@ let SlotSchema = createPropertySchema({
max: STORAGE_LIMITS.tagLength,
},
quantityExpected: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
defaultValue: '1',
},
@@ -65,7 +66,7 @@ let SlotSchema = createPropertySchema({
optional: true,
},
slotCondition: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
hideWhenFull: {
@@ -78,9 +79,9 @@ let SlotSchema = createPropertySchema({
allowedValues: [
// Can't choose the same slot filler twice in this slot
'uniqueInSlot',
// Can't choose the same slot filler twice accross the whole creature
// Can't choose the same slot filler twice across the whole creature
'uniqueInCreature'
],
] as const,
optional: true,
defaultValue: 'uniqueInSlot',
},
@@ -89,15 +90,15 @@ let SlotSchema = createPropertySchema({
const ComputedOnlySlotSchema = createPropertySchema({
// Computed fields
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
quantityExpected: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
slotCondition: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
@@ -114,8 +115,12 @@ const ComputedOnlySlotSchema = createPropertySchema({
},
});
const ComputedSlotSchema = new SimpleSchema()
const ComputedSlotSchema = new SimpleSchema({})
.extend(ComputedOnlySlotSchema)
.extend(SlotSchema);
export type Slot = InferType<typeof SlotSchema>;
export type ComputedOnlySlot = InferType<typeof ComputedOnlySlotSchema>;
export type ComputedSlot = Expand<InferType<typeof SlotSchema> & InferType<typeof ComputedOnlySlotSchema>>;
export { SlotSchema, ComputedSlotSchema, ComputedOnlySlotSchema };

View File

@@ -1,20 +1,21 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
let SpellListSchema = createPropertySchema({
const SpellListSchema = createPropertySchema({
name: {
type: String,
optional: true,
max: STORAGE_LIMITS.name,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
// Calculation of how many spells in this list can be prepared
maxPrepared: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
// The variable name of the ability this spell relies on
@@ -25,23 +26,23 @@ let SpellListSchema = createPropertySchema({
},
// Calculation of The attack roll bonus used by spell attacks in this list
attackRollBonus: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
// Calculation of the save dc used by spells in this list
dc: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
});
const ComputedOnlySpellListSchema = createPropertySchema({
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
maxPrepared: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
// Computed value determined by the ability
@@ -51,17 +52,21 @@ const ComputedOnlySpellListSchema = createPropertySchema({
removeBeforeCompute: true,
},
attackRollBonus: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
dc: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
});
const ComputedSpellListSchema = new SimpleSchema()
const ComputedSpellListSchema = new SimpleSchema({})
.extend(SpellListSchema)
.extend(ComputedOnlySpellListSchema);
export type SpellList = InferType<typeof SpellListSchema>;
export type ComputedOnlySpellList = InferType<typeof ComputedOnlySpellListSchema>;
export type ComputedSpellList = Expand<InferType<typeof SpellListSchema> & InferType<typeof ComputedOnlySpellListSchema>>;
export { SpellListSchema, ComputedOnlySpellListSchema, ComputedSpellListSchema };

View File

@@ -1,45 +1,13 @@
import { ActionBase, ActionSchema, ComputedOnlyActionSchema } from '/imports/api/properties/Actions';
import { ActionSchema, ComputedOnlyActionSchema } from '/imports/api/properties/Actions';
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { CreatureProperty } from '/imports/api/creature/creatureProperties/CreatureProperties';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import { TypedSimpleSchema } from '../utility/TypedSimpleSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
export interface Spell extends ActionBase {
name?: string
type: 'spell'
alwaysPrepared?: boolean
prepared?: boolean
castWithoutSpellSlots?: boolean
hasAttackRoll?: boolean
castingTime?: string
range?: string
duration?: string
verbal?: boolean
somatic?: boolean
concentration?: boolean
material?: string
ritual?: boolean
level?: number
school?: string
}
export function isSpell(prop: CreatureProperty): prop is Spell {
return prop.type === 'spell';
}
const magicSchools = [
'abjuration',
'conjuration',
'divination',
'enchantment',
'evocation',
'illusion',
'necromancy',
'transmutation',
];
const SpellSchema = new SimpleSchema({})
const SpellSchema = createPropertySchema({})
.extend(ActionSchema)
.extend({
.extend(new TypedSimpleSchema({
name: {
type: String,
optional: true,
@@ -111,15 +79,28 @@ const SpellSchema = new SimpleSchema({})
school: {
type: String,
defaultValue: 'abjuration',
allowedValues: magicSchools,
allowedValues: [
'abjuration',
'conjuration',
'divination',
'enchantment',
'evocation',
'illusion',
'necromancy',
'transmutation',
] as const,
},
});
}));
const ComputedOnlySpellSchema = new SimpleSchema({})
const ComputedOnlySpellSchema = createPropertySchema({})
.extend(ComputedOnlyActionSchema);
const ComputedSpellSchema = new SimpleSchema({})
.extend(SpellSchema)
.extend(ComputedOnlySpellSchema);
export type Spell = InferType<typeof SpellSchema>;
export type ComputedOnlySpell = InferType<typeof ComputedOnlySpellSchema>;
export type ComputedSpell = Expand<InferType<typeof SpellSchema> & InferType<typeof ComputedOnlySpellSchema>>;
export { SpellSchema, ComputedOnlySpellSchema, ComputedSpellSchema };

View File

@@ -2,6 +2,7 @@ import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import TagTargetingSchema from '/imports/api/properties/subSchemas/TagTargetingSchema';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
const ToggleSchema = createPropertySchema({
name: {
@@ -29,7 +30,7 @@ const ToggleSchema = createPropertySchema({
// if neither disabled or enabled, the condition will be run to determine
// if the children of the toggle should be active
condition: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
},
// Prevent the property from showing up in the log
@@ -41,11 +42,15 @@ const ToggleSchema = createPropertySchema({
const ComputedOnlyToggleSchema = createPropertySchema({
condition: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
},
});
export type Toggle = InferType<typeof ToggleSchema>;
export type ComputedOnlyToggle = InferType<typeof ComputedOnlyToggleSchema>;
export type ComputedToggle = Expand<InferType<typeof ToggleSchema> & InferType<typeof ComputedOnlyToggleSchema>>;
const ComputedToggleSchema = new SimpleSchema({})
.extend(ComputedOnlyToggleSchema)
.extend(ToggleSchema);

View File

@@ -1,6 +1,7 @@
import SimpleSchema from 'simpl-schema';
import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import type { Expand, InferType } from '/imports/api/utility/TypedSimpleSchema';
const eventOptions = {
doActionProperty: 'Do action',
@@ -9,7 +10,7 @@ const eventOptions = {
// flipToggle: 'Toggle changed',
// itemEquipped: 'Item equipped'
// itemUnequipped: 'Item unequipped'
damageProperty: 'Attribute damaged or healed',
damageProperty: 'Trigger damaged or healed',
anyRest: 'Short or long rest',
longRest: 'Long rest',
shortRest: 'Short rest',
@@ -24,7 +25,7 @@ const timingOptions = {
const actionPropertyTypeOptions = {
action: 'Action',
ammo: 'Ammo used',
adjustment: 'Attribute damage',
adjustment: 'Trigger damage',
branch: 'Branch',
buff: 'Buff',
buffRemover: 'Buff Removed',
@@ -41,34 +42,58 @@ const actionPropertyTypeOptions = {
* the sheet. Either during another action or as its own action after a sheet
* event. The same trigger can't fire twice in the same action step.
*/
let TriggerSchema = createPropertySchema({
const TriggerSchema = createPropertySchema({
name: {
type: String,
optional: true,
max: STORAGE_LIMITS.name,
},
description: {
type: 'inlineCalculationFieldToCompute',
type: 'inlineCalculationFieldToCompute' as const,
optional: true,
},
event: {
type: String,
allowedValues: Object.keys(eventOptions),
allowedValues: [
'doActionProperty',
'check',
'damageProperty',
'anyRest',
'longRest',
'shortRest',
] as const,
defaultValue: 'doActionProperty',
},
// Action type
actionPropertyType: {
type: String,
allowedValues: Object.keys(actionPropertyTypeOptions),
allowedValues: [
'action',
'ammo',
'adjustment',
'branch',
'buff',
'buffRemover',
'damage',
'note',
'roll',
'savingThrow',
'spell',
'toggle',
] as const,
optional: true,
},
timing: {
type: String,
allowedValues: Object.keys(timingOptions),
allowedValues: [
'before',
'after',
'afterChildren',
] as const,
defaultValue: 'after',
},
condition: {
type: 'fieldToCompute',
type: 'fieldToCompute' as const,
optional: true,
parseLevel: 'compile',
},
@@ -99,7 +124,7 @@ let TriggerSchema = createPropertySchema({
},
'extraTags.$.operation': {
type: String,
allowedValues: ['OR', 'NOT'],
allowedValues: ['OR', 'NOT'] as const,
defaultValue: 'OR',
},
'extraTags.$.tags': {
@@ -120,15 +145,15 @@ let TriggerSchema = createPropertySchema({
const ComputedOnlyTriggerSchema = createPropertySchema({
summary: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
description: {
type: 'computedOnlyInlineCalculationField',
type: 'computedOnlyInlineCalculationField' as const,
optional: true,
},
condition: {
type: 'computedOnlyField',
type: 'computedOnlyField' as const,
optional: true,
parseLevel: 'compile',
},
@@ -138,6 +163,10 @@ const ComputedTriggerSchema = new SimpleSchema({})
.extend(TriggerSchema)
.extend(ComputedOnlyTriggerSchema);
export type Trigger = InferType<typeof TriggerSchema>;
export type ComputedOnlyTrigger = InferType<typeof ComputedOnlyTriggerSchema>;
export type ComputedTrigger = Expand<InferType<typeof TriggerSchema> & InferType<typeof ComputedOnlyTriggerSchema>>;
export {
TriggerSchema, ComputedOnlyTriggerSchema, ComputedTriggerSchema,
eventOptions, timingOptions, actionPropertyTypeOptions

View File

@@ -21,13 +21,13 @@ import { PointBuySchema } from '/imports/api/properties/PointBuys';
import { ProficiencySchema } from '/imports/api/properties/Proficiencies';
import { ReferenceSchema } from '/imports/api/properties/References';
import { RollSchema } from '/imports/api/properties/Rolls';
import { SavingThrowSchema } from '/imports/api/properties/SavingThrows';
import { SkillSchema } from '/imports/api/properties/Skills';
import { SavingThrowSchema } from './SavingThrows';
import { SkillSchema } from './Skills';
import { SlotSchema } from '/imports/api/properties/Slots';
import { SpellListSchema } from '/imports/api/properties/SpellLists';
import { SpellListSchema } from './SpellLists';
import { SpellSchema } from '/imports/api/properties/Spells';
import { ToggleSchema } from '/imports/api/properties/Toggles';
import { TriggerSchema } from '/imports/api/properties/Triggers';
import { TriggerSchema } from './Triggers';
const propertySchemasIndex = {
action: ActionSchema,

View File

@@ -1,7 +1,7 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { TypedSimpleSchema } from 'imports/api/utility/TypedSimpleSchema';
const ErrorSchema = new SimpleSchema({
const ErrorSchema = new TypedSimpleSchema({
message: {
type: String,
max: STORAGE_LIMITS.errorMessage,

View File

@@ -1,7 +1,8 @@
import SimpleSchema from 'simpl-schema';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { TypedSimpleSchema } from 'imports/api/utility/TypedSimpleSchema';
const TagTargetingSchema = new SimpleSchema({
const TagTargetingSchema = new TypedSimpleSchema({
// True when targeting by tags instead of stats
targetByTags: {
type: Boolean,
@@ -40,7 +41,7 @@ const TagTargetingSchema = new SimpleSchema({
},
'extraTags.$.operation': {
type: String,
allowedValues: ['OR', 'NOT'],
allowedValues: ['OR', 'NOT'] as const,
defaultValue: 'OR',
},
'extraTags.$.tags': {