From 6ac361443b4926f5e0f3a5a5916af92697a2a72e Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 11 Apr 2022 03:18:07 -0400 Subject: [PATCH] Fix floor editor --- .../handlers/RoomWidgetChatInputHandler.ts | 11 +-- .../FloorplanEditorContext.tsx | 5 +- .../floorplan-editor/FloorplanEditorView.tsx | 87 ++++++++++--------- .../views/FloorplanCanvasView.tsx | 14 +-- .../navigator/views/NavigatorRoomInfoView.tsx | 4 +- .../floorplan-editor/FloorplanEditorEvent.ts | 8 -- src/events/floorplan-editor/index.ts | 1 - src/events/index.ts | 1 - 8 files changed, 56 insertions(+), 75 deletions(-) delete mode 100644 src/events/floorplan-editor/FloorplanEditorEvent.ts delete mode 100644 src/events/floorplan-editor/index.ts diff --git a/src/api/nitro/room/widgets/handlers/RoomWidgetChatInputHandler.ts b/src/api/nitro/room/widgets/handlers/RoomWidgetChatInputHandler.ts index a02fc4a0..997eb4b4 100644 --- a/src/api/nitro/room/widgets/handlers/RoomWidgetChatInputHandler.ts +++ b/src/api/nitro/room/widgets/handlers/RoomWidgetChatInputHandler.ts @@ -1,8 +1,7 @@ import { AvatarExpressionEnum, HabboClubLevelEnum, NitroEvent, RoomControllerLevel, RoomRotatingEffect, RoomSessionChatEvent, RoomSettingsComposer, RoomShakingEffect, RoomWidgetEnum, RoomZoomEvent, TextureUtils } from '@nitrots/nitro-renderer'; import { GetClubMemberLevel, GetConfiguration, GetNitroInstance, SendMessageComposer } from '../../..'; import { GetRoomEngine, GetSessionDataManager, LocalizeText, NotificationUtilities } from '../../../..'; -import { FloorplanEditorEvent } from '../../../../../events/floorplan-editor/FloorplanEditorEvent'; -import { DispatchUiEvent } from '../../../../../hooks'; +import { CreateLinkEvent } from '../../../CreateLinkEvent'; import { RoomWidgetFloodControlEvent, RoomWidgetUpdateEvent } from '../events'; import { RoomWidgetChatMessage, RoomWidgetChatSelectAvatarMessage, RoomWidgetChatTypingMessage, RoomWidgetMessage, RoomWidgetRequestWidgetMessage } from '../messages'; import { RoomWidgetHandler } from './RoomWidgetHandler'; @@ -158,12 +157,8 @@ export class RoomWidgetChatInputHandler extends RoomWidgetHandler return null; case ':floor': case ':bcfloor': - if(this.container.roomSession.controllerLevel >= RoomControllerLevel.ROOM_OWNER) - { - //this.container.processWidgetMessage(new RoomWidgetRequestWidgetMessage(RoomWidgetRequestWidgetMessage.FLOOR_EDITOR)); - DispatchUiEvent(new FloorplanEditorEvent(FloorplanEditorEvent.SHOW_FLOORPLAN_EDITOR)); - } - + if(this.container.roomSession.controllerLevel >= RoomControllerLevel.ROOM_OWNER) CreateLinkEvent('floor-editor/show'); + return null; case ':togglefps': { if(GetNitroInstance().ticker.maxFPS > 0) GetNitroInstance().ticker.maxFPS = 0; diff --git a/src/components/floorplan-editor/FloorplanEditorContext.tsx b/src/components/floorplan-editor/FloorplanEditorContext.tsx index bd0c1ddf..6c582ed8 100644 --- a/src/components/floorplan-editor/FloorplanEditorContext.tsx +++ b/src/components/floorplan-editor/FloorplanEditorContext.tsx @@ -17,9 +17,6 @@ const FloorplanEditorContext = createContext({ setVisualizationSettings: null }); -export const FloorplanEditorContextProvider: FC> = props => -{ - return { props.children } -} +export const FloorplanEditorContextProvider: FC> = props => ; export const useFloorplanEditorContext = () => useContext(FloorplanEditorContext); diff --git a/src/components/floorplan-editor/FloorplanEditorView.tsx b/src/components/floorplan-editor/FloorplanEditorView.tsx index 34f82aa5..76ad8b53 100644 --- a/src/components/floorplan-editor/FloorplanEditorView.tsx +++ b/src/components/floorplan-editor/FloorplanEditorView.tsx @@ -1,9 +1,8 @@ -import { FloorHeightMapEvent, NitroPoint, RoomEngineEvent, RoomVisualizationSettingsEvent, UpdateFloorPropertiesMessageComposer } from '@nitrots/nitro-renderer'; +import { FloorHeightMapEvent, ILinkEventTracker, NitroPoint, RoomEngineEvent, RoomVisualizationSettingsEvent, UpdateFloorPropertiesMessageComposer } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { LocalizeText, SendMessageComposer } from '../../api'; +import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; import { Button, ButtonGroup, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common'; -import { FloorplanEditorEvent } from '../../events'; -import { UseMessageEventHook, UseRoomEngineEvent, UseUiEvent } from '../../hooks'; +import { UseMessageEventHook, UseRoomEngineEvent } from '../../hooks'; import { FloorplanEditor } from './common/FloorplanEditor'; import { IFloorplanSettings } from './common/IFloorplanSettings'; import { IVisualizationSettings } from './common/IVisualizationSettings'; @@ -33,25 +32,27 @@ export const FloorplanEditorView: FC<{}> = props => thicknessFloor: 1 }); - const onFloorplanEditorEvent = useCallback((event: FloorplanEditorEvent) => + const saveFloorChanges = () => { - switch(event.type) - { - case FloorplanEditorEvent.HIDE_FLOORPLAN_EDITOR: - setIsVisible(false); - break; - case FloorplanEditorEvent.SHOW_FLOORPLAN_EDITOR: - setIsVisible(true); - break; - case FloorplanEditorEvent.TOGGLE_FLOORPLAN_EDITOR: - setIsVisible(prevValue => !prevValue); - break; - } - }, []); + SendMessageComposer(new UpdateFloorPropertiesMessageComposer( + FloorplanEditor.instance.getCurrentTilemapString(), + FloorplanEditor.instance.doorLocation.x, + FloorplanEditor.instance.doorLocation.y, + visualizationSettings.entryPointDir, + convertNumbersForSaving(visualizationSettings.thicknessWall), + convertNumbersForSaving(visualizationSettings.thicknessFloor), + (visualizationSettings.wallHeight - 1) + )); + } - UseUiEvent(FloorplanEditorEvent.HIDE_FLOORPLAN_EDITOR, onFloorplanEditorEvent); - UseUiEvent(FloorplanEditorEvent.SHOW_FLOORPLAN_EDITOR, onFloorplanEditorEvent); - UseUiEvent(FloorplanEditorEvent.TOGGLE_FLOORPLAN_EDITOR, onFloorplanEditorEvent); + const revertChanges = () => + { + setVisualizationSettings({ wallHeight: originalFloorplanSettings.wallHeight, thicknessWall: originalFloorplanSettings.thicknessWall, thicknessFloor: originalFloorplanSettings.thicknessFloor, entryPointDir: originalFloorplanSettings.entryPointDir }); + + FloorplanEditor.instance.doorLocation = new NitroPoint(originalFloorplanSettings.entryPoint[0], originalFloorplanSettings.entryPoint[1]); + FloorplanEditor.instance.setTilemap(originalFloorplanSettings.tilemap, originalFloorplanSettings.reservedTiles); + FloorplanEditor.instance.renderTiles(); + } const onRoomEngineEvent = useCallback((event: RoomEngineEvent) => { @@ -113,27 +114,35 @@ export const FloorplanEditorView: FC<{}> = props => UseMessageEventHook(RoomVisualizationSettingsEvent, onRoomVisualizationSettingsEvent); - const saveFloorChanges = () => + useEffect(() => { - SendMessageComposer(new UpdateFloorPropertiesMessageComposer( - FloorplanEditor.instance.getCurrentTilemapString(), - FloorplanEditor.instance.doorLocation.x, - FloorplanEditor.instance.doorLocation.y, - visualizationSettings.entryPointDir, - convertNumbersForSaving(visualizationSettings.thicknessWall), - convertNumbersForSaving(visualizationSettings.thicknessFloor), - (visualizationSettings.wallHeight - 1) - )); - } + const linkTracker: ILinkEventTracker = { + linkReceived: (url: string) => + { + const parts = url.split('/'); - const revertChanges = () => - { - setVisualizationSettings({ wallHeight: originalFloorplanSettings.wallHeight, thicknessWall: originalFloorplanSettings.thicknessWall, thicknessFloor: originalFloorplanSettings.thicknessFloor, entryPointDir: originalFloorplanSettings.entryPointDir }); + if(parts.length < 2) return; - FloorplanEditor.instance.doorLocation = new NitroPoint(originalFloorplanSettings.entryPoint[0], originalFloorplanSettings.entryPoint[1]); - FloorplanEditor.instance.setTilemap(originalFloorplanSettings.tilemap, originalFloorplanSettings.reservedTiles); - FloorplanEditor.instance.renderTiles(); - } + switch(parts[1]) + { + case 'show': + setIsVisible(true); + return; + case 'hide': + setIsVisible(false); + return; + case 'toggle': + setIsVisible(prevValue => !prevValue); + return; + } + }, + eventUrlPrefix: 'floor-editor/' + }; + + AddEventLinkTracker(linkTracker); + + return () => RemoveLinkEventTracker(linkTracker); + }, []); useEffect(() => { diff --git a/src/components/floorplan-editor/views/FloorplanCanvasView.tsx b/src/components/floorplan-editor/views/FloorplanCanvasView.tsx index da93fc68..9ff612ab 100644 --- a/src/components/floorplan-editor/views/FloorplanCanvasView.tsx +++ b/src/components/floorplan-editor/views/FloorplanCanvasView.tsx @@ -5,15 +5,9 @@ import { SendMessageComposer } from '../../../api'; import { Base, Button, Column, ColumnProps, Flex, Grid } from '../../../common'; import { UseMessageEventHook } from '../../../hooks'; import { FloorplanEditor } from '../common/FloorplanEditor'; -import { IFloorplanSettings } from '../common/IFloorplanSettings'; import { useFloorplanEditorContext } from '../FloorplanEditorContext'; -interface FloorplanCanvasViewProps extends ColumnProps -{ - -} - -export const FloorplanCanvasView: FC = props => +export const FloorplanCanvasView: FC = props => { const { gap = 1, children = null, ...rest } = props; const [ occupiedTilesReceived , setOccupiedTilesReceived ] = useState(false); @@ -25,20 +19,16 @@ export const FloorplanCanvasView: FC = props => { const parser = event.getParser(); - let newFloorPlanSettings: IFloorplanSettings = null; - setOriginalFloorplanSettings(prevValue => { const newValue = { ...prevValue }; newValue.reservedTiles = parser.blockedTilesMap; - newFloorPlanSettings = newValue; + FloorplanEditor.instance.setTilemap(newValue.tilemap, newValue.reservedTiles); return newValue; }); - - FloorplanEditor.instance.setTilemap(newFloorPlanSettings.tilemap, parser.blockedTilesMap); setOccupiedTilesReceived(true); diff --git a/src/components/navigator/views/NavigatorRoomInfoView.tsx b/src/components/navigator/views/NavigatorRoomInfoView.tsx index b1222ee3..46feca66 100644 --- a/src/components/navigator/views/NavigatorRoomInfoView.tsx +++ b/src/components/navigator/views/NavigatorRoomInfoView.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import { FC, useEffect, useState } from 'react'; import { CreateLinkEvent, GetGroupInformation, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../api'; import { Button, Column, Flex, LayoutBadgeImageView, LayoutRoomThumbnailView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text, UserProfileIconView } from '../../../common'; -import { FloorplanEditorEvent, RoomWidgetThumbnailEvent } from '../../../events'; +import { RoomWidgetThumbnailEvent } from '../../../events'; import { DispatchUiEvent } from '../../../hooks'; import { useNavigatorContext } from '../NavigatorContext'; @@ -72,7 +72,7 @@ export const NavigatorRoomInfoView: FC = props => SendMessageComposer(new RoomMuteComposer()); return; case 'open_floorplan_editor': - DispatchUiEvent(new FloorplanEditorEvent(FloorplanEditorEvent.TOGGLE_FLOORPLAN_EDITOR)); + CreateLinkEvent('floor-editor/toggle'); return; case 'close': onCloseClick(); diff --git a/src/events/floorplan-editor/FloorplanEditorEvent.ts b/src/events/floorplan-editor/FloorplanEditorEvent.ts deleted file mode 100644 index 62f7f3bf..00000000 --- a/src/events/floorplan-editor/FloorplanEditorEvent.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class FloorplanEditorEvent extends NitroEvent -{ - public static SHOW_FLOORPLAN_EDITOR: string = 'FPEE_SHOW_FLOORPLAN_EDITOR'; - public static HIDE_FLOORPLAN_EDITOR: string = 'FPEE_HIDE_FLOORPLAN_EDITOR'; - public static TOGGLE_FLOORPLAN_EDITOR: string = 'FPEE_TOGGLE_FLOORPLAN_EDITOR'; -} diff --git a/src/events/floorplan-editor/index.ts b/src/events/floorplan-editor/index.ts deleted file mode 100644 index f429f780..00000000 --- a/src/events/floorplan-editor/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './FloorplanEditorEvent'; diff --git a/src/events/index.ts b/src/events/index.ts index 4cf8a7f8..288b2364 100644 --- a/src/events/index.ts +++ b/src/events/index.ts @@ -1,5 +1,4 @@ export * from './catalog'; -export * from './floorplan-editor'; export * from './guide-tool'; export * from './help'; export * from './mod-tools';