Replace the maps:create/update/delete catch-all for map features: roads, zones, and nodes each take a per-collection author permission, structure placement takes maps:place (still co-gated with the logistics qualification), and GeoJSON import requires all three author permissions. The map view page keys edit UI per feature type; admin role seed grants the new values. Tests updated for the permission split.
86 lines
2.1 KiB
TypeScript
86 lines
2.1 KiB
TypeScript
import { CollectionConfig } from "payload";
|
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
|
import { validatePosition } from "@/lib/map/points";
|
|
import { NODE_ICON_OPTIONS } from "@/lib/map/nodeIcons";
|
|
|
|
/**
|
|
* Map resource nodes (deposits, forests, wells, ...). Display + placement
|
|
* validation only: blueprints with resourcesInRange require a matching node
|
|
* within range. Nodes do not produce anything.
|
|
*/
|
|
export const ResourceNodes: CollectionConfig = {
|
|
slug: "resource-nodes",
|
|
admin: {
|
|
group: "World",
|
|
useAsTitle: "name",
|
|
},
|
|
access: {
|
|
read: ({ req }) => !!req.user,
|
|
create: requirePermission("resource-nodes:author"),
|
|
update: requirePermission("resource-nodes:author"),
|
|
delete: requirePermission("resource-nodes:author"),
|
|
},
|
|
fields: [
|
|
{
|
|
name: "name",
|
|
type: "text",
|
|
required: true,
|
|
admin: {
|
|
description: 'Node label (e.g. "North copper deposit").',
|
|
},
|
|
},
|
|
{
|
|
name: "description",
|
|
type: "textarea",
|
|
admin: {
|
|
description: "Shown in the node's tooltip and popup on the map.",
|
|
},
|
|
},
|
|
{
|
|
name: "map",
|
|
type: "relationship",
|
|
relationTo: "maps",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "resources",
|
|
type: "relationship",
|
|
relationTo: "resources",
|
|
hasMany: true,
|
|
admin: {
|
|
description:
|
|
"Every resource this node yields (e.g. copper AND oil). Leave empty for a plain marker node.",
|
|
},
|
|
},
|
|
{
|
|
name: "icon",
|
|
type: "select",
|
|
options: NODE_ICON_OPTIONS.map((option) => ({
|
|
label: option.label,
|
|
value: option.value,
|
|
})),
|
|
defaultValue: "marker",
|
|
admin: {
|
|
description: "Marker icon shown on the map.",
|
|
},
|
|
},
|
|
{
|
|
name: "position",
|
|
type: "json",
|
|
required: true,
|
|
validate: validatePosition,
|
|
admin: {
|
|
description: "[x, y] tuple in meters on the map grid.",
|
|
},
|
|
},
|
|
{
|
|
name: "richness",
|
|
type: "number",
|
|
defaultValue: 100,
|
|
min: 0,
|
|
admin: {
|
|
description: "Display-only abundance rating for the map UI.",
|
|
},
|
|
},
|
|
],
|
|
};
|