From d4999bb2bcf3ad2efba5850c178f6666fd0884a2 Mon Sep 17 00:00:00 2001 From: Emma Date: Sat, 17 Jun 2023 11:34:44 -0600 Subject: [PATCH] reserved fields --- project-warstone/query syntax | 3 + .../components/SchemaBuilder/field-editor.tsx | 84 +++++++++++-------- .../components/SchemaBuilder/type-editor.tsx | 11 ++- .../src/constants/ReservedFields.ts | 25 ++++++ 4 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 project-warstone/src/constants/ReservedFields.ts diff --git a/project-warstone/query syntax b/project-warstone/query syntax index de5c07e..2ca7f02 100644 --- a/project-warstone/query syntax +++ b/project-warstone/query syntax @@ -1,6 +1,9 @@ Start query: ? - by default, queries search the publication Query current object: ^ + - refers specifically to the object based off of this specific type +Query relative object: $ + - refers to the last relative object in the heirarchy Access child: . - this also maps over all items in a list and returns a list of the relevant children - if the parent is a list, it will return a list of just the specified child diff --git a/project-warstone/src/components/SchemaBuilder/field-editor.tsx b/project-warstone/src/components/SchemaBuilder/field-editor.tsx index 27e35f4..b57387c 100644 --- a/project-warstone/src/components/SchemaBuilder/field-editor.tsx +++ b/project-warstone/src/components/SchemaBuilder/field-editor.tsx @@ -1,9 +1,10 @@ -import { FC, useCallback, useEffect } from 'react' +import { FC, useCallback, useEffect, useState } from 'react' import { FieldType, FieldTypes, fieldTypeOptions, fieldTypesWithValues } from '../../types/schema' import { useObjectStateWrapper } from '../../hooks/useObjectState'; import { ValueField } from './value-field'; import { HelpPopper } from '../Poppables/help'; import { Icon } from '../Icon'; +import { RESERVED_FIELDS } from '../../constants/ReservedFields'; interface IProps { update: (arg: FieldType) => void; @@ -13,50 +14,67 @@ interface IProps { } export const FieldEditor: FC = ({ update, field, fieldName, deleteField }) => { - const { bindProperty, bindPropertyCheck } = useObjectStateWrapper(field, (e) => update(typeof e === 'function' ? e(field) : e)) + const { bindProperty, bindPropertyCheck } = useObjectStateWrapper(field, (e) => update(typeof e === 'function' ? e(field) : e)); const shouldShowValueField = useCallback(() => fieldTypesWithValues.includes(field.type) || field.isConstant, [field.isConstant, field.type]); + const [reserved, setReserved] = useState(RESERVED_FIELDS[fieldName]); + + useEffect(() => { + setReserved(RESERVED_FIELDS[fieldName]); + }, [fieldName]) + useEffect(() => { console.log(field.value); }, [field]) return (
  • -

    {fieldName}

    -
    - - {shouldShowValueField() && ( - - )} - - +
    +

    {fieldName}

    + {reserved && ( -

    Constant values can't be overwritten in publications. When a dice field is set to a constant value, it instead rolls a dice of that value whenever this field is displayed (unless exported). This could be useful for a randomly generated scenario or for cards being drawn as the dice value will automatically be determined by the dice roll.

    +

    This is a reserved field name, these exist for internal purposes, but are still useful when creating a type, and as such have specific settings that you cannot override. If you need control over the field properties, please use a different field name

    - - - - -

    Minimum and Limit apply to the number of entries allowed for this field, not the maximum and minimum value. Set the minimum to 0 to make a field optional. Set the limit to 0 to allow for unlimited entries.

    -
    - + )}
    + {!reserved && ( +
    + + + {shouldShowValueField() && ( + + )} + + + +

    Constant values can't be overwritten in publications. When a dice field is set to a constant value, it instead rolls a dice of that value whenever this field is displayed (unless exported). This could be useful for a randomly generated scenario or for cards being drawn as the dice value will automatically be determined by the dice roll.

    +
    +
    + + + +

    Minimum and Limit apply to the number of entries allowed for this field, not the maximum and minimum value. Set the minimum to 0 to make a field optional. Set the limit to 0 to allow for unlimited entries.

    +
    + + +
    + )}
  • ) } diff --git a/project-warstone/src/components/SchemaBuilder/type-editor.tsx b/project-warstone/src/components/SchemaBuilder/type-editor.tsx index e917a9a..ec04ba8 100644 --- a/project-warstone/src/components/SchemaBuilder/type-editor.tsx +++ b/project-warstone/src/components/SchemaBuilder/type-editor.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect } from 'react' +import { FormEvent, useCallback, useEffect } from 'react' import { FCC } from '../../types' import { FieldType, FieldTypes, TypeType } from '../../types/schema' import { useObjectState } from '../../hooks/useObjectState'; @@ -23,7 +23,8 @@ export const TypeEditor: FCC = ({ saveType, name, type: passedType }) => resetType(); } - const addField = useCallback(() => { + const addField = useCallback((e: FormEvent) => { + e.preventDefault(); updateType({ [propertyName]: { type: FieldTypes.number, @@ -55,8 +56,10 @@ export const TypeEditor: FCC = ({ saveType, name, type: passedType }) => return (

    {passedType ? 'Editing' : 'Creating'} type "{name}"

    - - +
    + + +
      {Object.entries(type).reverse().filter(([k]) => !constantProperties.includes(k)).map(([key, value]) => ( diff --git a/project-warstone/src/constants/ReservedFields.ts b/project-warstone/src/constants/ReservedFields.ts new file mode 100644 index 0000000..a86567f --- /dev/null +++ b/project-warstone/src/constants/ReservedFields.ts @@ -0,0 +1,25 @@ +import { FieldType, FieldTypes } from '../types/schema'; + +export const RESERVED_FIELDS: Record = { + maximum: { + isConstant: false, + limit: 1, + minimum: 1, + type: FieldTypes.number, + value: '' + }, + minimum: { + isConstant: false, + limit: 1, + minimum: 1, + type: FieldTypes.number, + value: '' + }, + relative: { + isConstant: true, + limit: 1, + minimum: 1, + type: FieldTypes.text, + value: '$' + }, +} \ No newline at end of file