From b35ca4b23ea30aefeca1ef9af1290acb2f3f71eb Mon Sep 17 00:00:00 2001 From: dank074 Date: Wed, 16 Mar 2022 21:17:12 -0500 Subject: [PATCH 1/2] add internal link widget handler --- .../handlers/FurnitureInternalLinkHandler.ts | 54 +++++++++++++++++++ src/components/room/RoomView.tsx | 2 + 2 files changed, 56 insertions(+) create mode 100644 src/api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler.ts diff --git a/src/api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler.ts b/src/api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler.ts new file mode 100644 index 00000000..740844b1 --- /dev/null +++ b/src/api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler.ts @@ -0,0 +1,54 @@ +import { NitroEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable, RoomWidgetEnum } from '@nitrots/nitro-renderer'; +import { CreateLinkEvent } from '../../../CreateLinkEvent'; +import { GetRoomEngine } from '../../GetRoomEngine'; +import { RoomWidgetUpdateEvent } from '../events'; +import { RoomWidgetMessage } from '../messages'; +import { RoomWidgetHandler } from './RoomWidgetHandler'; + +export class FurnitureInternalLinkHandler extends RoomWidgetHandler +{ + private static readonly INTERNALLINK = 'internalLink'; + + public processEvent(event: NitroEvent): void + { + if(!event) return; + + switch(event.type) + { + case RoomEngineTriggerWidgetEvent.REQUEST_INTERNAL_LINK: + const linkEvent = event as RoomEngineTriggerWidgetEvent; + const roomEngine = GetRoomEngine(); + if(!linkEvent || !roomEngine) return; + + const object = roomEngine.getRoomObject(linkEvent.roomId, linkEvent.objectId, linkEvent.category); + if(object) + { + let data = object.model.getValue(RoomObjectVariable.FURNITURE_DATA); + let link = data[FurnitureInternalLinkHandler.INTERNALLINK]; + console.log(link); + if(!link || !link.length) link = object.model.getValue(RoomObjectVariable.FURNITURE_INTERNAL_LINK); + if(link && link.length) CreateLinkEvent(link); + } + } + } + + public processWidgetMessage(message: RoomWidgetMessage): RoomWidgetUpdateEvent + { + return null; + } + + public get type(): string + { + return RoomWidgetEnum.INTERNAL_LINK; + } + + public get eventTypes(): string[] + { + return [RoomEngineTriggerWidgetEvent.REQUEST_INTERNAL_LINK]; + } + + public get messageTypes(): string[] + { + return []; + } +} diff --git a/src/components/room/RoomView.tsx b/src/components/room/RoomView.tsx index 8c067e17..bedad92b 100644 --- a/src/components/room/RoomView.tsx +++ b/src/components/room/RoomView.tsx @@ -1,6 +1,7 @@ import { EventDispatcher, IRoomSession, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer'; import { FC, useEffect, useRef, useState } from 'react'; import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FriendRequestHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCreditWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureDimmerWidgetHandler, FurnitureExternalImageWidgetHandler, FurnitureMannequinWidgetHandler, FurniturePresentWidgetHandler, FurnitureYoutubeDisplayWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, PollWidgetHandler, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler, WordQuizWidgetHandler } from '../../api'; +import { FurnitureInternalLinkHandler } from '../../api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler'; import { Base } from '../../common'; import { RoomColorView } from './RoomColorView'; import { RoomContextProvider } from './RoomContext'; @@ -52,6 +53,7 @@ export const RoomView: FC = props => widgetHandlerManager.registerHandler(new FurnitureDimmerWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureYoutubeDisplayWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureMannequinWidgetHandler()); + widgetHandlerManager.registerHandler(new FurnitureInternalLinkHandler()); setWidgetHandler(widgetHandlerManager); From 5d2384f8a8db7b55d889618ad83e1cb716746d45 Mon Sep 17 00:00:00 2001 From: dank074 Date: Wed, 16 Mar 2022 21:44:43 -0500 Subject: [PATCH 2/2] added FurnitureRoomLinkHandler --- .../handlers/FurnitureInternalLinkHandler.ts | 1 - .../handlers/FurnitureRoomLinkHandler.ts | 59 +++++++++++++++++++ src/api/nitro/room/widgets/handlers/index.ts | 2 + src/components/room/RoomView.tsx | 4 +- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/api/nitro/room/widgets/handlers/FurnitureRoomLinkHandler.ts diff --git a/src/api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler.ts b/src/api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler.ts index 740844b1..493f7052 100644 --- a/src/api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler.ts +++ b/src/api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler.ts @@ -25,7 +25,6 @@ export class FurnitureInternalLinkHandler extends RoomWidgetHandler { let data = object.model.getValue(RoomObjectVariable.FURNITURE_DATA); let link = data[FurnitureInternalLinkHandler.INTERNALLINK]; - console.log(link); if(!link || !link.length) link = object.model.getValue(RoomObjectVariable.FURNITURE_INTERNAL_LINK); if(link && link.length) CreateLinkEvent(link); } diff --git a/src/api/nitro/room/widgets/handlers/FurnitureRoomLinkHandler.ts b/src/api/nitro/room/widgets/handlers/FurnitureRoomLinkHandler.ts new file mode 100644 index 00000000..9396ba27 --- /dev/null +++ b/src/api/nitro/room/widgets/handlers/FurnitureRoomLinkHandler.ts @@ -0,0 +1,59 @@ +import { IMessageEvent, NitroEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable, RoomWidgetEnum } from '@nitrots/nitro-renderer'; +import { CreateLinkEvent } from '../../../CreateLinkEvent'; +import { GetRoomEngine } from '../../GetRoomEngine'; +import { RoomWidgetUpdateEvent } from '../events'; +import { RoomWidgetMessage } from '../messages'; +import { RoomWidgetHandler } from './RoomWidgetHandler'; + +export class FurnitureRoomLinkHandler extends RoomWidgetHandler +{ + private static readonly INTERNALLINK = 'internalLink'; + + private onRoomInfo(event: IMessageEvent): void + { + //todo + } + + public processEvent(event: NitroEvent): void + { + if(!event) return; + + switch(event.type) + { + case RoomEngineTriggerWidgetEvent.REQUEST_ROOM_LINK: + const roomLinkEvent = (event as RoomEngineTriggerWidgetEvent); + const roomEngine = GetRoomEngine(); + + if(!roomLinkEvent || !roomEngine) return; + + const object = roomEngine.getRoomObject(roomLinkEvent.roomId, roomLinkEvent.objectId, roomLinkEvent.category); + if(object) + { + const data = object.model.getValue(RoomObjectVariable.FURNITURE_DATA); + let roomId = data[FurnitureRoomLinkHandler.INTERNALLINK]; + if(!roomId || !roomId.length) roomId = object.model.getValue(RoomObjectVariable.FURNITURE_INTERNAL_LINK); + if(roomId && roomId.length) CreateLinkEvent('navigator/goto/' + roomId); + } + } + } + + public processWidgetMessage(message: RoomWidgetMessage): RoomWidgetUpdateEvent + { + return null; + } + + public get type(): string + { + return RoomWidgetEnum.ROOM_LINK; + } + + public get eventTypes(): string[] + { + return [RoomEngineTriggerWidgetEvent.REQUEST_ROOM_LINK]; + } + + public get messageTypes(): string[] + { + return []; + } +} diff --git a/src/api/nitro/room/widgets/handlers/index.ts b/src/api/nitro/room/widgets/handlers/index.ts index 1af4c0e0..40fadc00 100644 --- a/src/api/nitro/room/widgets/handlers/index.ts +++ b/src/api/nitro/room/widgets/handlers/index.ts @@ -6,8 +6,10 @@ export * from './FurnitureCreditWidgetHandler'; export * from './FurnitureCustomStackHeightWidgetHandler'; export * from './FurnitureDimmerWidgetHandler'; export * from './FurnitureExternalImageWidgetHandler'; +export * from './FurnitureInternalLinkHandler'; export * from './FurnitureMannequinWidgetHandler'; export * from './FurniturePresentWidgetHandler'; +export * from './FurnitureRoomLinkHandler'; export * from './FurnitureTrophyWidgetHandler'; export * from './FurnitureYoutubeDisplayWidgetHandler'; export * from './IRoomWidgetHandler'; diff --git a/src/components/room/RoomView.tsx b/src/components/room/RoomView.tsx index bedad92b..ce2743f3 100644 --- a/src/components/room/RoomView.tsx +++ b/src/components/room/RoomView.tsx @@ -1,7 +1,6 @@ import { EventDispatcher, IRoomSession, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer'; import { FC, useEffect, useRef, useState } from 'react'; -import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FriendRequestHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCreditWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureDimmerWidgetHandler, FurnitureExternalImageWidgetHandler, FurnitureMannequinWidgetHandler, FurniturePresentWidgetHandler, FurnitureYoutubeDisplayWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, PollWidgetHandler, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler, WordQuizWidgetHandler } from '../../api'; -import { FurnitureInternalLinkHandler } from '../../api/nitro/room/widgets/handlers/FurnitureInternalLinkHandler'; +import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FriendRequestHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCreditWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureDimmerWidgetHandler, FurnitureExternalImageWidgetHandler, FurnitureInternalLinkHandler, FurnitureMannequinWidgetHandler, FurniturePresentWidgetHandler, FurnitureRoomLinkHandler, FurnitureYoutubeDisplayWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, PollWidgetHandler, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler, WordQuizWidgetHandler } from '../../api'; import { Base } from '../../common'; import { RoomColorView } from './RoomColorView'; import { RoomContextProvider } from './RoomContext'; @@ -54,6 +53,7 @@ export const RoomView: FC = props => widgetHandlerManager.registerHandler(new FurnitureYoutubeDisplayWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureMannequinWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureInternalLinkHandler()); + widgetHandlerManager.registerHandler(new FurnitureRoomLinkHandler()); setWidgetHandler(widgetHandlerManager);