Improved typing of Creature Properties
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Random } from 'meteor/random';
|
||||
import { InferType, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
|
||||
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
|
||||
|
||||
const AdjustmentSchema = new TypedSimpleSchema({
|
||||
const AdjustmentSchema = TypedSimpleSchema.from({
|
||||
_id: {
|
||||
type: String,
|
||||
max: 17,
|
||||
@@ -32,6 +32,4 @@ const AdjustmentSchema = new TypedSimpleSchema({
|
||||
},
|
||||
});
|
||||
|
||||
export type Adjustment = InferType<typeof AdjustmentSchema>;
|
||||
|
||||
export default AdjustmentSchema;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
|
||||
|
||||
const ColorSchema = new TypedSimpleSchema({
|
||||
const ColorSchema = TypedSimpleSchema.from({
|
||||
color: {
|
||||
type: String,
|
||||
// match hex colors of the form #A23 or #A23f56
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
|
||||
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
|
||||
|
||||
const ErrorSchema = new TypedSimpleSchema({
|
||||
const ErrorSchema = TypedSimpleSchema.from({
|
||||
message: {
|
||||
type: String,
|
||||
max: STORAGE_LIMITS.errorMessage,
|
||||
|
||||
@@ -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 RollDetailsSchema = new SimpleSchema({
|
||||
const RollDetailsSchema = TypedSimpleSchema.from({
|
||||
number: {
|
||||
type: Number,
|
||||
},
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ResultsSchema from '/imports/api/properties/subSchemas/ResultsSchema';
|
||||
|
||||
let RollResultsSchema = new SimpleSchema({
|
||||
_id: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
autoValue() {
|
||||
if (!this.isSet) return Random.id();
|
||||
}
|
||||
},
|
||||
// Expression of whether or not to apply the roll
|
||||
// Evaluates to an expression which gets compared to the roll
|
||||
// or a number which the roll must equal
|
||||
comparison: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
results: {
|
||||
type: ResultsSchema,
|
||||
defaultValue: {},
|
||||
},
|
||||
});
|
||||
|
||||
export default RollResultsSchema;
|
||||
@@ -2,7 +2,7 @@ import SimpleSchema from 'simpl-schema';
|
||||
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
|
||||
import { TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
|
||||
|
||||
const TagTargetingSchema = new TypedSimpleSchema({
|
||||
const TagTargetingSchema = TypedSimpleSchema.from({
|
||||
// True when targeting by tags instead of stats
|
||||
targetByTags: {
|
||||
type: Boolean,
|
||||
|
||||
@@ -6,12 +6,12 @@ import {
|
||||
fieldToCompute,
|
||||
computedOnlyField,
|
||||
} from '/imports/api/properties/subSchemas/computedField';
|
||||
import { Definition, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
|
||||
import { Definition, InferSchema, TypedSimpleSchema } from '/imports/api/utility/TypedSimpleSchema';
|
||||
|
||||
// Search through the schema for keys whose type is 'fieldToCompute' etc.
|
||||
// replace the type with Object and attach extend the schema with
|
||||
// the required fields to make the computation work
|
||||
export default function createPropertySchema<T extends Definition>(definition: T): TypedSimpleSchema<T> {
|
||||
export default function createPropertySchema<D extends Definition>(definition: D): TypedSimpleSchema<InferSchema<D>> {
|
||||
const computationFields = {
|
||||
inlineCalculationFieldToCompute: [],
|
||||
computedOnlyInlineCalculationField: [],
|
||||
@@ -41,7 +41,7 @@ export default function createPropertySchema<T extends Definition>(definition: T
|
||||
}
|
||||
|
||||
// Create a schema with the edited definition
|
||||
const schema = new TypedSimpleSchema(definition);
|
||||
const schema = TypedSimpleSchema.from(definition);
|
||||
|
||||
// Extend the schema with all the computation fields
|
||||
computationFields.inlineCalculationFieldToCompute.forEach(key => {
|
||||
|
||||
Reference in New Issue
Block a user