From 37225d32611663cce0b6bf9ff042234e954939d6 Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 14 Apr 2021 17:47:02 -0400 Subject: [PATCH] Update events --- src/hooks/events/event-dispatcher.base.tsx | 10 +- .../session/room-session-manager-event.tsx | 7 ++ src/hooks/messages/message-event.tsx | 16 ++++ src/views/main/MainView.tsx | 93 ++++++++++++++++++- 4 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 src/hooks/events/nitro/session/room-session-manager-event.tsx create mode 100644 src/hooks/messages/message-event.tsx diff --git a/src/hooks/events/event-dispatcher.base.tsx b/src/hooks/events/event-dispatcher.base.tsx index 3a93ef37..d18c25c4 100644 --- a/src/hooks/events/event-dispatcher.base.tsx +++ b/src/hooks/events/event-dispatcher.base.tsx @@ -12,15 +12,17 @@ export function CreateEventDispatcherHook(type: string, eventDispatcher: IEventD useEffect(() => { - const eventListener = (event: NitroEvent) => handlerRef.current(event); + console.log('register', type); - eventDispatcher.addEventListener(type, eventListener); + eventDispatcher.addEventListener(type, handlerRef.current); return () => { - eventDispatcher.removeEventListener(type, eventListener); + console.log('unregister', type); + + eventDispatcher.removeEventListener(type, handlerRef.current); } - }, [ type, eventDispatcher ]); + }, [ type, eventDispatcher, handler ]); } export function DispatchEventHook(eventDispatcher: IEventDispatcher, event: NitroEvent): void diff --git a/src/hooks/events/nitro/session/room-session-manager-event.tsx b/src/hooks/events/nitro/session/room-session-manager-event.tsx new file mode 100644 index 00000000..518e90df --- /dev/null +++ b/src/hooks/events/nitro/session/room-session-manager-event.tsx @@ -0,0 +1,7 @@ +import { Nitro, NitroEvent } from 'nitro-renderer'; +import { CreateEventDispatcherHook } from '../../event-dispatcher.base'; + +export function useRoomSessionManagerEvent(type: string, handler: (event: NitroEvent) => void): void +{ + CreateEventDispatcherHook(type, Nitro.instance.roomSessionManager.events, handler); +} diff --git a/src/hooks/messages/message-event.tsx b/src/hooks/messages/message-event.tsx new file mode 100644 index 00000000..9f1d4110 --- /dev/null +++ b/src/hooks/messages/message-event.tsx @@ -0,0 +1,16 @@ +import { IMessageEvent } from 'nitro-renderer'; +import { Nitro } from 'nitro-renderer/src/nitro/Nitro'; +import { useEffect } from 'react'; + +export function CreateMessageHook(event: IMessageEvent) +{ + useEffect(() => + { + Nitro.instance.communication.registerMessageEvent(event); + + return () => + { + Nitro.instance.communication.removeMessageEvent(event); + } + }); +} diff --git a/src/views/main/MainView.tsx b/src/views/main/MainView.tsx index 4f961ad5..f5798479 100644 --- a/src/views/main/MainView.tsx +++ b/src/views/main/MainView.tsx @@ -1,11 +1,102 @@ -import { Nitro } from 'nitro-renderer/src/nitro/Nitro'; +import { Nitro, RoomBackgroundColorEvent, RoomEngineDimmerStateEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomEngineTriggerWidgetEvent, RoomObjectHSLColorEnabledEvent, RoomObjectWidgetRequestEvent, RoomSessionChatEvent, RoomSessionDanceEvent, RoomSessionDimmerPresetsEvent, RoomSessionDoorbellEvent, RoomSessionErrorMessageEvent, RoomSessionEvent, RoomSessionFriendRequestEvent, RoomSessionPresentEvent, RoomSessionUserBadgesEvent, RoomZoomEvent } from 'nitro-renderer'; import { useEffect } from 'react'; +import { useRoomEngineEvent } from '../../hooks/events/nitro/room/room-engine-event'; +import { useRoomSessionManagerEvent } from '../../hooks/events/nitro/session/room-session-manager-event'; import { HotelView } from '../hotel-view/HotelView'; import { ToolbarView } from '../toolbar/ToolbarView'; import { MainViewProps } from './MainView.types'; export function MainView(props: MainViewProps): JSX.Element { + const onInterstitialEvent = (event: RoomEngineEvent) => + { + console.log(event); + }; + + const onRoomEngineEvent = (event: RoomEngineEvent) => + { + console.log(event); + }; + + const onRoomEngineObjectEvent = (event: RoomEngineObjectEvent) => + { + console.log(event); + }; + + const onRoomSessionEvent = (event: RoomSessionEvent) => + { + console.log(event); + } + + const onRoomSessionErrorMessageEvent = (event: RoomSessionErrorMessageEvent) => + { + console.log(event); + } + + useRoomEngineEvent(RoomEngineEvent.ENGINE_INITIALIZED, onInterstitialEvent); + useRoomEngineEvent(RoomEngineEvent.OBJECTS_INITIALIZED, onInterstitialEvent); + useRoomEngineEvent(RoomEngineEvent.NORMAL_MODE, onInterstitialEvent); + useRoomEngineEvent(RoomEngineEvent.GAME_MODE, onInterstitialEvent); + + useRoomEngineEvent(RoomEngineEvent.INITIALIZED, onRoomEngineEvent); + useRoomEngineEvent(RoomEngineEvent.DISPOSED, onRoomEngineEvent); + useRoomEngineEvent(RoomZoomEvent.ROOM_ZOOM, onRoomEngineEvent); + useRoomEngineEvent(RoomObjectHSLColorEnabledEvent.ROOM_BACKGROUND_COLOR, onRoomEngineEvent); + useRoomEngineEvent(RoomBackgroundColorEvent.ROOM_COLOR, onRoomEngineEvent); + useRoomEngineEvent(RoomEngineDimmerStateEvent.ROOM_COLOR, onRoomEngineEvent); + + useRoomEngineEvent(RoomEngineObjectEvent.SELECTED, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineObjectEvent.DESELECTED, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineObjectEvent.ADDED, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineObjectEvent.REMOVED, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineObjectEvent.PLACED, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineObjectEvent.REQUEST_MOVE, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineObjectEvent.REQUEST_ROTATE, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineObjectEvent.MOUSE_ENTER, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineObjectEvent.MOUSE_LEAVE, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.OPEN_WIDGET, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.CLOSE_WIDGET, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_INTERNAL_LINK, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_ROOM_LINK, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_TROPHY, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_CREDITFURNI, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomObjectWidgetRequestEvent.OPEN_FURNI_CONTEXT_MENU, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_STICKIE, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_DIMMER, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_BACKGROUND_COLOR, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_FRIEND_FURNITURE_ENGRAVING, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_MANNEQUIN, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_PRESENT, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_HIGH_SCORE_DISPLAY, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_HIDE_HIGH_SCORE_DISPLAY, onRoomEngineObjectEvent); + + useRoomSessionManagerEvent(RoomSessionEvent.CREATED, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionEvent.STARTED, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionEvent.ROOM_DATA, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionEvent.ENDED, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionChatEvent.CHAT_EVENT, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionChatEvent.FLOOD_EVENT, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionDanceEvent.RSDE_DANCE, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionUserBadgesEvent.RSUBE_BADGES, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionDoorbellEvent.DOORBELL, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionDoorbellEvent.RSDE_REJECTED, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionDoorbellEvent.RSDE_ACCEPTED, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionDimmerPresetsEvent.RSDPE_PRESETS, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionFriendRequestEvent.RSFRE_FRIEND_REQUEST, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionPresentEvent.RSPE_PRESENT_OPENED, onRoomSessionEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_KICKED, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_PETS_FORBIDDEN_IN_HOTEL, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_PETS_FORBIDDEN_IN_FLAT, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_MAX_PETS, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_MAX_NUMBER_OF_OWN_PETS, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_NO_FREE_TILES_FOR_PET, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_SELECTED_TILE_NOT_FREE_FOR_PET, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_BOTS_FORBIDDEN_IN_HOTEL, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_BOTS_FORBIDDEN_IN_FLAT, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_BOT_LIMIT_REACHED, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_SELECTED_TILE_NOT_FREE_FOR_BOT, onRoomSessionErrorMessageEvent); + useRoomSessionManagerEvent(RoomSessionErrorMessageEvent.RSEME_BOT_NAME_NOT_ACCEPTED, onRoomSessionErrorMessageEvent); + useEffect(() => { Nitro.instance.communication.connection.onReady();