Add the tech-categories collection that gives technologies a home off the
flat uncategorized pool, plus the schema support the admin editor needs.
- New `tech-categories` collection (unique name, timeline `position`,
optional hex `color`) with a `Technologies.category` FK (ON DELETE set
null) so deleting a category just unfiles its technologies.
- Add `Technologies.treePosition {x,y}` so the canvas can pin a node's
manual position; clearing it uses `{x:null,y:null}`.
- Register the two hand-written migrations (tech-categories + treePosition)
and regenerate payload-types, the drizzle schema, and the admin importMap.
- Register the `tech-categories:*` permission group and grant Intelligence
division members admin-panel access, mirroring technologies.
232 lines
6.7 KiB
TypeScript
232 lines
6.7 KiB
TypeScript
import { CollectionConfig } from "payload";
|
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
|
import {
|
|
approvalStatusFieldAccess,
|
|
requireApprovalPermission,
|
|
requireIntelligencePermission,
|
|
} from "@/utils/access-control/divisionAccess";
|
|
|
|
const approvalStatusFieldAccessConfig = approvalStatusFieldAccess("technologies");
|
|
|
|
export const Technologies: CollectionConfig = {
|
|
slug: "technologies",
|
|
admin: {
|
|
group: "Intelligence",
|
|
useAsTitle: "name",
|
|
},
|
|
access: {
|
|
create: requireIntelligencePermission("technologies:create"),
|
|
update: requireIntelligencePermission("technologies:update"),
|
|
delete: requireIntelligencePermission("technologies:delete"),
|
|
read: requirePermission("technologies:read"),
|
|
},
|
|
fields: [
|
|
{
|
|
name: "name",
|
|
type: "text",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "category",
|
|
type: "relationship",
|
|
relationTo: "tech-categories",
|
|
admin: {
|
|
description:
|
|
"Tech Tree column this technology belongs to. Uncategorized technologies are auto-placed on the Tech Tree by prerequisite depth.",
|
|
},
|
|
},
|
|
{
|
|
name: "treePosition",
|
|
type: "group",
|
|
label: "Tech Tree Position",
|
|
admin: {
|
|
description:
|
|
"Manual position on the Tech Tree canvas (set by dragging a node). Leave empty to use the automatic layout.",
|
|
},
|
|
fields: [
|
|
{
|
|
name: "x",
|
|
type: "number",
|
|
},
|
|
{
|
|
name: "y",
|
|
type: "number",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "approvalStatus",
|
|
type: "select",
|
|
label: "Approval Status",
|
|
access: approvalStatusFieldAccessConfig,
|
|
options: [
|
|
{ label: "In Progress", value: "in_progress" },
|
|
{ label: "Ready for Review", value: "ready_for_review" },
|
|
{ label: "Approved", value: "approved" },
|
|
{ label: "Rejected", value: "rejected" },
|
|
{ label: "Revision Requested", value: "revision_requested" },
|
|
],
|
|
defaultValue: "in_progress",
|
|
required: true,
|
|
admin: {
|
|
description:
|
|
"Mark whether this technology is ready for developer approval and implementation into the live environment.",
|
|
},
|
|
},
|
|
{
|
|
name: "type",
|
|
type: "select",
|
|
options: [
|
|
{
|
|
label: "Asset",
|
|
value: "asset",
|
|
},
|
|
{
|
|
label: "Upgrade",
|
|
value: "upgrade",
|
|
},
|
|
],
|
|
admin: {
|
|
description:
|
|
'An "Asset" technology will unlock a new item, vehicle, gear piece, structure, etc. An "Upgrade" technology will unlock an improvement to an Asset, like faster build speed, more storage capacity, etc.',
|
|
},
|
|
required: true,
|
|
defaultValue: "upgrade",
|
|
},
|
|
{
|
|
name: "summary",
|
|
type: "textarea",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "description",
|
|
type: "richText",
|
|
},
|
|
{
|
|
name: "requirements",
|
|
type: "group",
|
|
fields: [
|
|
{
|
|
name: "prerequisiteTechnologies",
|
|
type: "array",
|
|
fields: [
|
|
{
|
|
type: "row",
|
|
fields: [
|
|
{
|
|
name: "requiresAnd",
|
|
type: "group",
|
|
label: "Requires (AND)",
|
|
admin: {
|
|
description:
|
|
"ALL of these technologies MUST be unlocked before this one can be.",
|
|
},
|
|
fields: [
|
|
{
|
|
name: "technology",
|
|
type: "relationship",
|
|
relationTo: "technologies",
|
|
hasMany: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "requiresOr",
|
|
type: "group",
|
|
label: "Requires (OR)",
|
|
admin: {
|
|
description:
|
|
"One or more of these technologies MUST be unlocked before this one can be.",
|
|
},
|
|
fields: [
|
|
{
|
|
name: "technology",
|
|
type: "relationship",
|
|
relationTo: "technologies",
|
|
hasMany: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "researchCosts",
|
|
type: "group",
|
|
fields: [
|
|
{
|
|
name: "resources",
|
|
type: "array",
|
|
admin: {
|
|
description:
|
|
"These resources are consumed when this technology is researched. If a resource is not listed, you can add a new one, but creating new resources requires the Logistics qualification. Without it, the save will fail.",
|
|
},
|
|
fields: [
|
|
{
|
|
name: "resource",
|
|
type: "relationship",
|
|
relationTo: "resources",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "amount",
|
|
type: "number",
|
|
defaultValue: 1,
|
|
required: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
type: "row",
|
|
fields: [
|
|
{
|
|
name: "minimumResearchDuration",
|
|
type: "number",
|
|
admin: {
|
|
components: {
|
|
Description: {
|
|
path: "@/components/static/TickDurationDescription",
|
|
clientProps: {
|
|
task: "research this technology",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
min: 1,
|
|
max: 10000,
|
|
required: true,
|
|
defaultValue: 0,
|
|
},
|
|
{
|
|
name: "maximumResearchDuration",
|
|
type: "number",
|
|
admin: {
|
|
components: {
|
|
Description: {
|
|
path: "@/components/static/TickDurationDescription",
|
|
clientProps: {
|
|
task: "research this technology",
|
|
field: "maximumResearchDuration",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
min: 1,
|
|
max: 10000,
|
|
/*validate: (value: number, { data, siblingData }: { data: any; siblingData: any }) => {
|
|
const minDuration = siblingData?.minimumResearchDuration;
|
|
if (value !== undefined && minDuration !== undefined && value < minDuration) {
|
|
return `Maximum research duration must be at least ${minDuration} (the minimum research duration)`;
|
|
}
|
|
return true;
|
|
},*/
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|