1
0
Fork 0

chore(locker): commit pending stock handling refinements

This commit is contained in:
Jason Fraley 2026-10-25 21:23:40 -04:00
parent 70b484ad31
commit c5bd74f297
9 changed files with 41 additions and 22 deletions

View file

@ -1206,11 +1206,17 @@ export async function attachItemFromGrid(
if (!weapon || typeof weapon === "number" || weapon.assetType !== "weapon") {
return { success: false, error: "Attachments can only be installed on weapons." };
}
if (items[weaponIdx].quantity < 1) {
return { success: false, error: "That weapon is out of stock." };
}
const attachment = items[attIdx].asset as Asset;
if (!attachment || typeof attachment === "number") {
return { success: false, error: "Invalid item." };
}
if (items[attIdx].quantity < 1) {
return { success: false, error: "That attachment is out of stock." };
}
const category = ATTACHMENT_CATEGORIES.find((c) => c.assetType === attachment.assetType);
if (!category) {

View file

@ -473,7 +473,7 @@ export const GameStructures: CollectionConfig = {
name: "quantity",
type: "number",
required: true,
min: 1,
min: 0,
defaultValue: 1,
},
{

View file

@ -77,7 +77,7 @@ export const LockerStorages: CollectionConfig = {
name: "quantity",
type: "number",
required: true,
min: 1,
min: 0,
defaultValue: 1,
},
{

View file

@ -7,6 +7,7 @@ import { processLockerEvent } from "@/lib/arma-bridge/lockers";
import { processGarageEvent } from "@/lib/arma-bridge/garages";
import { isOperationLedgerEnabled } from "@/lib/operations/rollout";
import { processOperationEvent } from "@/lib/operations/process";
import { toRawSyncEvent } from "@/lib/operations/reconcile";
export const ArmaSyncEvents: CollectionConfig = {
slug: "arma-sync-events",
@ -16,55 +17,60 @@ export const ArmaSyncEvents: CollectionConfig = {
afterChange: [
async ({ doc, req, operation }) => {
if (operation !== "create") return;
// Payload hands afterChange a doc whose relationship fields are
// populated at defaultDepth (an object, not the numeric FK). Every
// downstream processor expects `server` to be a number, so normalize
// once here; without this they all bail as "malformed".
const raw = toRawSyncEvent(doc as unknown as Record<string, unknown>);
// Ledger first: every raw event is consumed into the operation ledger
// before any downstream projection runs. Evidence is always stored;
// only derived effects are gated by the kill switch.
if (isOperationLedgerEnabled()) {
await processOperationEvent(req.payload, doc, req);
await processOperationEvent(req.payload, raw, req);
}
if (doc.type === "player.kill") {
processPlayerKill(req.payload, doc).catch((err) => {
req.payload.logger.error(`[KillTracker] Failed to process kill event ${doc.eventId}: ${err}`);
if (raw.type === "player.kill") {
processPlayerKill(req.payload, raw).catch((err) => {
req.payload.logger.error(`[KillTracker] Failed to process kill event ${raw.eventId}: ${err}`);
});
}
if (doc.type.startsWith("box.")) {
if (raw.type.startsWith("box.")) {
// Awaited (not fire-and-forget) so the crate writes join the raw-event
// transaction; processBoxEvent never throws, so ingestion cannot be
// rolled back by crate sync.
try {
await processBoxEvent(req.payload, doc, req);
await processBoxEvent(req.payload, raw, req);
} catch (err) {
req.payload.logger.error(`[CrateSync] Failed to process box event ${doc.eventId}: ${err}`);
req.payload.logger.error(`[CrateSync] Failed to process box event ${raw.eventId}: ${err}`);
}
}
if (doc.type === "money.delta") {
if (raw.type === "money.delta") {
// Awaited so that by the time the game's flush returns, the bank
// balance already reflects it (the game pulls balances right after
// flushing). processMoneyEvent never throws.
await processMoneyEvent(req.payload, doc);
await processMoneyEvent(req.payload, raw);
}
if (doc.type.startsWith("reinforcement.")) {
if (raw.type.startsWith("reinforcement.")) {
// Awaited (same posture as money.delta): the pool balance must be
// current before the game's next reinforcement pull, and
// processReinforcementEvent never throws.
await processReinforcementEvent(req.payload, doc, req);
await processReinforcementEvent(req.payload, raw, req);
}
if (doc.type.startsWith("locker.")) {
if (raw.type.startsWith("locker.")) {
// Awaited (same posture as box.*): locker writes join the raw-event
// transaction; processLockerEvent never throws.
try {
await processLockerEvent(req.payload, doc, req);
await processLockerEvent(req.payload, raw, req);
} catch (err) {
req.payload.logger.error(`[LockerSync] Failed to process locker event ${doc.eventId}: ${err}`);
req.payload.logger.error(`[LockerSync] Failed to process locker event ${raw.eventId}: ${err}`);
}
}
if (doc.type.startsWith("garage.")) {
if (raw.type.startsWith("garage.")) {
// Awaited (same posture as locker.*): garage writes join the
// raw-event transaction; processGarageEvent never throws.
try {
await processGarageEvent(req.payload, doc, req);
await processGarageEvent(req.payload, raw, req);
} catch (err) {
req.payload.logger.error(`[GarageSync] Failed to process garage event ${doc.eventId}: ${err}`);
req.payload.logger.error(`[GarageSync] Failed to process garage event ${raw.eventId}: ${err}`);
}
}
},

View file

@ -595,7 +595,7 @@ export function LockerGrid({
}),
)}
{items.map((item) => (
{items.filter((item) => item.quantity >= 1).map((item) => (
<DraggableLockerItem
key={item.id}
item={item}

View file

@ -280,7 +280,7 @@ export function LockerView({
>
<ItemContent className="gap-0 p-1.5">
<div className="flex flex-col">
{items.map((entry, index) => (
{items.filter((entry) => entry.quantity >= 1).map((entry, index) => (
<div key={entry.id}>
<button
type="button"

View file

@ -64,6 +64,7 @@ export function CreateListingDialog({
for (const entry of locker.items) {
const asset = entry.asset as Asset;
if (!asset || typeof asset === "number") continue;
if ((entry.quantity ?? 0) < 1) continue;
const attachments = entry.equipment?.attachments ?? [];
const skinId = resolveAssetId(entry.equipment?.skin);
if (attachments.length > 0 || skinId != null) continue;

View file

@ -29,6 +29,9 @@ export type LockerGridItem = {
/** Normalize raw locker `items` into populated grid items. */
export function toLockerGridItems(items: LockerStorage["items"]): LockerGridItem[] {
// Depleted rows (quantity 0) are kept: they still reserve their grid cell, so
// a restock cannot land on top of a live item, and their equipment resolves.
// Views that show stock on hand filter them out at the render boundary.
return (items ?? [])
.filter((e) => e.asset && typeof e.asset === "object" && "id" in e.asset)
.map((e) => {

View file

@ -142,7 +142,10 @@ export function buildSearchEntries(
for (const item of items) {
if (!item.asset) continue;
const displayName = item.equipment?.customName?.trim() || item.asset.name;
upsert(item.asset, item.quantity, { kind: "locker", text: "In locker" }, displayName);
// Quantity 0 is an explicit depletion from locker sync, not stock on hand.
if (item.quantity >= 1) {
upsert(item.asset, item.quantity, { kind: "locker", text: "In locker" }, displayName);
}
for (const attachment of item.equipment?.attachments ?? []) {
const asset = resolveAssetRef(attachment.asset, items);