From adea2dc996063d7474d7a1919fe9ee3ac4dc8e18 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Fri, 19 Dec 2025 01:28:40 -0500 Subject: [PATCH] feat: add ranges to production amounts and frequencies, add dynamic value description to build time --- src/app/(payload)/admin/importMap.js | 2 + src/collections/logistics/Structures.ts | 53 +++++++++++++++++-- .../static/TickDurationDescription.tsx | 29 ++++++++++ src/payload-types.ts | 34 +++++++++--- 4 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 src/components/static/TickDurationDescription.tsx diff --git a/src/app/(payload)/admin/importMap.js b/src/app/(payload)/admin/importMap.js index 0a3a717..86e7727 100644 --- a/src/app/(payload)/admin/importMap.js +++ b/src/app/(payload)/admin/importMap.js @@ -22,6 +22,7 @@ import { UnderlineFeatureClient as UnderlineFeatureClient_e70f5e05f09f93e00b997e import { BoldFeatureClient as BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { ItalicFeatureClient as ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { default as default_2d468cc5cf0b647ffca3201592c20825 } from '@/components/static/WarningMessage' +import { default as default_0edde40a6ccd30c893b1227360f69360 } from '@/components/static/TickDurationDescription' import { default as default_508743824696caae2894ebf34c2e68bb } from '@/components/graphics/AppIcon' import { default as default_e752fee78378294ff03f91dba0a75a04 } from '@/components/graphics/AppLogo' import { default as default_05548cb43495e62d80b80ec4d9f0f7e9 } from '@/components/static/BeforeDashboardText' @@ -51,6 +52,7 @@ export const importMap = { "@payloadcms/richtext-lexical/client#BoldFeatureClient": BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@payloadcms/richtext-lexical/client#ItalicFeatureClient": ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@/components/static/WarningMessage#default": default_2d468cc5cf0b647ffca3201592c20825, + "@/components/static/TickDurationDescription#default": default_0edde40a6ccd30c893b1227360f69360, "@/components/graphics/AppIcon#default": default_508743824696caae2894ebf34c2e68bb, "@/components/graphics/AppLogo#default": default_e752fee78378294ff03f91dba0a75a04, "@/components/static/BeforeDashboardText#default": default_05548cb43495e62d80b80ec4d9f0f7e9 diff --git a/src/collections/logistics/Structures.ts b/src/collections/logistics/Structures.ts index f8e6283..c4d3c80 100644 --- a/src/collections/logistics/Structures.ts +++ b/src/collections/logistics/Structures.ts @@ -93,8 +93,16 @@ export const Structures: CollectionConfig = { type: "number", required: true, label: "Build Time (in game ticks)", + min: 1, admin: { - description: "The number of ticks it takes to complete construction of this structure.", + components: { + Description: { + path: "@/components/static/TickDurationDescription", + clientProps: { + task: "complete construction of this structure", + }, + }, + }, }, }, { @@ -286,15 +294,54 @@ export const Structures: CollectionConfig = { { name: "resource", type: "relationship", + required: true, relationTo: "resources", }, { - name: "amount", + name: "minAmount", type: "number", + required: true, + admin: { + description: + "The minimum amount of this resource produced each production cycle.", + }, }, { - name: "frequency", + name: "maxAmount", + type: "number", + admin: { + description: + "The maximum amount of this resource produced each production cycle. If this field is left empty, will produce a static amount equal to the minimum value.", + }, + }, + { + name: "minFrequency", type: "text", + required: true, + defaultValue: 1, + admin: { + description: + "The minimum number of ticks it takes to produce this resource (e.g., '5' would produce this resource, at minimum, every 5 ticks).", + }, + }, + { + name: "maxFrequency", + type: "text", + admin: { + description: + "The maximum number of ticks it takes to produce this resource (e.g., '5' would produce this resource, at maximum, every 5 ticks, ignoring production chance).", + }, + }, + { + name: "produceChance", + type: "number", + defaultValue: 100, + min: 1, + max: 100, + admin: { + description: + "The chance (1-100) that this resource will be produced each production cycle.", + }, }, ], }, diff --git a/src/components/static/TickDurationDescription.tsx b/src/components/static/TickDurationDescription.tsx new file mode 100644 index 0000000..17def07 --- /dev/null +++ b/src/components/static/TickDurationDescription.tsx @@ -0,0 +1,29 @@ +"use client"; + +import { useFormFields } from "@payloadcms/ui"; + +const calculateTicks = (value: number) => { + const totalMinutes = value * 10; + const days = Math.floor(value / 144); + const hours = Math.floor(totalMinutes / 60) % 24; + const minutes = totalMinutes % 60; + return `${days >= 1 ? `${days}d ` : ""}${hours}h ${minutes}m`; +}; + +export const TickDurationDescription = ({ task }: { task: string }) => { + const ticks = useFormFields(([fields, dispatch]) => fields.constructionTime); + + return ticks && typeof ticks?.value === "number" ? ( +

+ The number of ticks (10 minutes *{" "} + {ticks.value} ={" "} + {calculateTicks(ticks.value)}) it takes to {task}. +

+ ) : ( +

+ The number of ticks it takes to {task}. +

+ ); +}; + +export default TickDurationDescription; diff --git a/src/payload-types.ts b/src/payload-types.ts index fda2147..2be9a56 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -959,9 +959,6 @@ export interface Structure { amount?: number | null; id?: string | null; }[]; - /** - * The number of ticks it takes to complete construction of this structure. - */ constructionTime: number; /** * What research must be done before this can be built. @@ -1039,9 +1036,27 @@ export interface Structure { | null; autoGeneratedResources?: | { - resource?: (number | null) | Resource; - amount?: number | null; - frequency?: string | null; + resource: number | Resource; + /** + * The minimum amount of this resource produced each production cycle. + */ + minAmount: number; + /** + * The maximum amount of this resource produced each production cycle. If this field is left empty, will produce a static amount equal to the minimum value. + */ + maxAmount?: number | null; + /** + * The minimum number of ticks it takes to produce this resource (e.g., '5' would produce this resource, at minimum, every 5 ticks). + */ + minFrequency: string; + /** + * The maximum number of ticks it takes to produce this resource (e.g., '5' would produce this resource, at maximum, every 5 ticks, ignoring production chance). + */ + maxFrequency?: string | null; + /** + * The chance (1-100) that this resource will be produced each production cycle. + */ + produceChance?: number | null; id?: string | null; }[] | null; @@ -1945,8 +1960,11 @@ export interface StructuresSelect { | T | { resource?: T; - amount?: T; - frequency?: T; + minAmount?: T; + maxAmount?: T; + minFrequency?: T; + maxFrequency?: T; + produceChance?: T; id?: T; }; maxCapacityMass?: T;