1
0
Fork 0
polaris-task-force/src/collections/logistics/Vehicles.ts
Z8MB1E 40b074a693 feat(vehicles): add per-vehicle disallowed-cargo blacklist enforced at shipment
Vehicles gain a virtual-block disallowedCargo array (asset/vehicle/resource item + optional amount cap, 0 forbids outright). createShipment consults findDisallowedCargo() before deducting any origin stock and rejects matching cargo lines cleanly. Includes Payload migration + 7 integration tests.
2026-10-26 22:17:21 -04:00

506 lines
14 KiB
TypeScript

import { CollectionConfig } from "payload";
import {
approvalStatusFieldAccess,
requireApprovalPermission,
requireLogisticsPermission,
resetApprovalStatusOnEdit,
} from "@/utils/access-control/divisionAccess";
const approvalStatusFieldAccessConfig = approvalStatusFieldAccess("vehicles");
export const Vehicles: CollectionConfig = {
slug: "vehicles",
admin: {
useAsTitle: "name",
group: "Logistics",
},
access: {
create: requireLogisticsPermission("vehicles:create"),
update: requireLogisticsPermission("vehicles:update"),
delete: requireLogisticsPermission("vehicles:delete"),
},
hooks: {
beforeChange: [resetApprovalStatusOnEdit()],
},
fields: [
{
// D11b: searchable imported-library picker (name, classname, thumbnail)
// that copies an imported entry into this form on click.
name: "libraryPicker",
type: "ui",
admin: {
components: {
Field: "@/components/admin/VehicleLibraryPicker",
},
},
},
{
label: "Identity",
type: "group",
fields: [
{
name: "name",
type: "text",
required: true,
},
{
name: "classname",
type: "text",
admin: {
description:
"If not provided, this vehicle will ONLY be available as a virtual asset (i.e., cannot be used in Arma.)",
},
},
{
name: "mod",
type: "text",
defaultValue: "Arma 3",
admin: {
description:
"Mod package this template belongs to (imported from the game catalog; backfilled from the classname prefix for older rows). Dedupe keeps one template per name + mod.",
},
},
{
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 vehicle is ready for developer approval and implementation into the live environment.",
},
},
{
name: "description",
type: "richText",
admin: {
description:
"A detailed description of the vehicle, including details like tactical usage, mechanical details, and/or world lore regarding this vehicle.",
},
},
{
name: "image",
type: "upload",
relationTo: "media",
},
{
name: "category",
type: "select",
hasMany: true,
options: [
{
label: "Civilian",
value: "civilian",
},
{
label: "Utility",
value: "utility",
},
{
label: "Transport",
value: "transport",
},
{
label: "Drone",
value: "drone",
},
{
label: "Weaponized",
value: "weaponized",
},
{
label: "Static",
value: "static",
},
{
label: "Military",
value: "military",
},
],
},
{
name: "fuel",
type: "group",
admin: {
description:
"Fuel configuration for this vehicle. Defines what fuel type it uses, how much it can hold, and how fast it consumes fuel.",
},
fields: [
{
name: "fuelType",
type: "relationship",
relationTo: "resources",
required: true,
admin: {
description:
"The type of fuel this vehicle consumes (e.g., gasoline, diesel, jet fuel).",
},
},
{
name: "fuelCapacity",
type: "number",
required: true,
admin: {
description: "Maximum fuel units this vehicle's tank can hold.",
},
},
{
name: "fuelConsumptionRate",
type: "number",
required: true,
defaultValue: 1,
admin: {
description: "Fuel consumed per unit of distance traveled.",
},
},
],
},
],
},
{
label: "Construction",
type: "group",
fields: [
{
name: "materials",
type: "array",
fields: [
{
name: "resource",
type: "relationship",
required: true,
relationTo: "resources",
},
{
name: "amount",
type: "number",
},
],
},
{
name: "constructionTime",
type: "number",
admin: {
description: "The number of ticks it takes to complete construction of this vehicle.",
},
},
{
name: "requiredTech",
type: "relationship",
relationTo: "technologies",
hasMany: true,
label: "Required Technologies",
admin: {
description: "What research must be done before this can be built.",
},
},
{
name: "requiredStructure",
type: "join",
collection: "structures",
on: "canProduce",
},
],
},
{
label: "Scrapping & Maintenance",
type: "group",
fields: [
{
name: "scrapReturns",
type: "array",
label: "Materials Returned when Scrapped",
fields: [
{
name: "resource",
type: "relationship",
required: true,
relationTo: "resources",
},
{
name: "amount",
type: "number",
defaultValue: 1,
},
{
name: "chance",
type: "number",
min: 0,
max: 100,
defaultValue: 100,
admin: {
description:
"An optional percent (%) chance to recover this specific resource (between 0 and 100).",
},
},
],
},
{
name: "upkeepCosts",
type: "array",
admin: {
description: "Recurring costs to keep this vehicle operational.",
},
fields: [
{
name: "resource",
type: "relationship",
required: true,
relationTo: "resources",
},
{
name: "amount",
type: "number",
defaultValue: 1,
admin: {
description: "How much of this resource is consumed per tick.",
},
},
],
},
],
},
{
label: "Logistics & Grid Storage",
type: "group",
fields: [
{
name: "transportMode",
type: "select",
required: true,
defaultValue: "ground",
options: [
{ label: "Ground", value: "ground" },
{ label: "Air", value: "air" },
{ label: "Sea", value: "sea" },
],
admin: {
description:
"Ground vehicles route over the road network and refuse shipments with no connected route. Air and sea vehicles travel straight-line.",
},
},
{
label: "Storage Grid Dimensions",
type: "group",
fields: [
{
name: "width",
type: "number",
},
{
name: "height",
type: "number",
},
],
},
{
label: "Garage Footprint",
type: "group",
admin: {
description:
"Cells this vehicle's type occupies in a structure's Garage vehicle bay (width = columns, height = rows). Unset defaults to 1x1. Independent of the display-only storage grid dimensions above.",
},
fields: [
{
name: "garageWidth",
type: "number",
label: "Garage Width (cells)",
min: 1,
},
{
name: "garageHeight",
type: "number",
label: "Garage Height (cells)",
min: 1,
},
],
},
{
label: "Cargo Capacity",
type: "group",
fields: [
{
name: "maxMass",
label: "Max Weight (kg.)",
type: "number",
},
{
name: "aceCargoSlots",
type: "number",
label: "ACE Cargo Slots",
admin: {
description: "The number of ACE cargo slots this vehicle has by default.",
},
},
{
name: "allowedVirtualCargo",
type: "array",
admin: {
description:
"The cargo this vehicle is permitted to carry if used virtually (e.g., during deliveries, moving troops, etc.)",
},
fields: [
{
name: "item",
type: "relationship",
relationTo: ["assets", "vehicles", "resources"],
required: true,
},
{
name: "amount",
type: "number",
defaultValue: 1,
},
],
},
{
name: "disallowedCargo",
label: "Disallowed Virtual Cargo",
type: "array",
admin: {
description:
"Items this vehicle may NOT carry when used virtually (e.g., during deliveries, moving troops). A shipment using this vehicle is rejected before its cargo is deducted if any cargo line matches.",
},
fields: [
{
name: "item",
type: "relationship",
relationTo: ["assets", "vehicles", "resources"],
required: true,
},
{
name: "amount",
type: "number",
defaultValue: 0,
admin: {
description:
"Optional cap. Leave at 0 to forbid the item entirely; set a positive number to allow up to that amount only.",
},
},
],
},
],
},
],
},
{
label: "Combat & Performance",
type: "group",
fields: [
{
label: "Durability",
type: "group",
admin: {
description:
"These attributes only apply to the virtual vehicle and are not required nor expected to match the in-game version's actual attributes.",
},
fields: [
{
name: "maxHealth",
type: "number",
},
{
name: "armorRating",
type: "select",
options: [
{
label: "None",
value: "none",
},
{
label: "Light",
value: "light",
},
{
label: "Medium",
value: "medium",
},
{
label: "Heavy",
value: "heavy",
},
{
label: "Composite",
value: "composite",
},
],
},
],
},
{
label: "Speed & Agility",
type: "group",
fields: [
{
name: "maxSpeedOnRoad",
type: "number",
},
{
name: "maxSpeedOffRoad",
type: "number",
},
{
name: "maxAirspeed",
type: "number",
},
{
name: "maxKnots",
type: "number",
},
],
},
{
name: "pylons",
label: "Pylons & Mounted Weapons",
type: "array",
fields: [
{
name: "pylonName",
type: "text",
required: true,
},
{
name: "pylonType",
type: "select",
required: true,
defaultValue: "mountedWeapon",
options: [
{
label: "Mounted Weapon",
value: "mountedWeapon",
},
{
label: "Pylon",
value: "pylon",
},
],
},
{
name: "amount",
type: "number",
defaultValue: 1,
},
{
name: "ammoType",
type: "relationship",
relationTo: "assets",
},
],
},
],
},
],
};