Support account-wide item transfer targets and fix delete confirm exit

This commit is contained in:
Jage9
2026-02-28 20:24:37 -05:00
parent 9fe9c6da4d
commit daab7bb759
9 changed files with 308 additions and 57 deletions

View File

@@ -15,7 +15,7 @@ type MessageHandlerDeps = {
addItemTypeIndex: number;
player: { id: string | null; nickname: string; x: number; y: number };
running: boolean;
peers: Map<string, { id: string; nickname: string; x: number; y: number }>;
peers: Map<string, { id: string; userId?: string | null; nickname: string; x: number; y: number }>;
items: Map<string, WorldItem>;
mode: string;
selectedItemId: string | null;
@@ -77,6 +77,7 @@ type MessageHandlerDeps = {
handleAdminRolesList: (message: Extract<IncomingMessage, { type: 'admin_roles_list' }>) => void;
handleAdminUsersList: (message: Extract<IncomingMessage, { type: 'admin_users_list' }>) => void;
handleAdminActionResult: (message: Extract<IncomingMessage, { type: 'admin_action_result' }>) => void;
handleItemTransferTargets: (message: Extract<IncomingMessage, { type: 'item_transfer_targets' }>) => void;
isPeerNegotiationReady: () => boolean;
enqueuePendingSignal: (message: Extract<IncomingMessage, { type: 'signal' }>) => void;
};
@@ -106,6 +107,9 @@ export function createOnMessageHandler(deps: MessageHandlerDeps): (message: Inco
case 'admin_action_result':
deps.handleAdminActionResult(message);
break;
case 'item_transfer_targets':
deps.handleItemTransferTargets(message);
break;
case 'welcome':
if (message.worldConfig?.gridSize && Number.isInteger(message.worldConfig.gridSize) && message.worldConfig.gridSize > 0) {

View File

@@ -221,6 +221,18 @@ export const itemActionResultSchema = z.object({
itemId: z.string().optional(),
});
export const itemTransferTargetsSchema = z.object({
type: z.literal('item_transfer_targets'),
itemId: z.string(),
targets: z.array(
z.object({
userId: z.string(),
username: z.string(),
online: z.boolean(),
}),
),
});
export const itemUseSoundSchema = z.object({
type: z.literal('item_use_sound'),
itemId: z.string(),
@@ -337,6 +349,7 @@ export const incomingMessageSchema = z.discriminatedUnion('type', [
itemUpsertSchema,
itemRemoveSchema,
itemActionResultSchema,
itemTransferTargetsSchema,
itemUseSoundSchema,
itemClockAnnounceSchema,
itemPianoNoteSchema,
@@ -373,7 +386,8 @@ export type OutgoingMessage =
| { type: 'item_pickup'; itemId: string }
| { type: 'item_drop'; itemId: string; x: number; y: number }
| { type: 'item_delete'; itemId: string }
| { type: 'item_transfer'; itemId: string; targetId: string }
| { type: 'item_transfer_targets'; itemId: string }
| { type: 'item_transfer'; itemId: string; targetId?: string; targetUserId?: string }
| { type: 'item_use'; itemId: string }
| { type: 'item_secondary_use'; itemId: string }
| { type: 'item_piano_note'; itemId: string; keyId: string; midi: number; on: boolean }
@@ -387,6 +401,7 @@ export type OutgoingMessage =
export type RemoteUser = {
id: string;
userId?: string | null;
nickname: string;
x: number;
y: number;