From 61d1c4b379baf330890f05b24265bdd1b66c3930 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 28 Jul 2022 12:44:25 -0400 Subject: [PATCH] Update wired furni selector --- src/api/room/widgets/AvatarInfoUtilities.ts | 4 --- src/events/index.ts | 1 - src/events/wired/WiredEvent.ts | 6 ----- src/events/wired/WiredSelectObjectEvent.ts | 27 ------------------- src/events/wired/index.ts | 2 -- .../rooms/widgets/useAvatarInfoWidget.ts | 6 ++++- src/hooks/wired/useWired.ts | 21 +++++++-------- 7 files changed, 14 insertions(+), 53 deletions(-) delete mode 100644 src/events/wired/WiredEvent.ts delete mode 100644 src/events/wired/WiredSelectObjectEvent.ts delete mode 100644 src/events/wired/index.ts diff --git a/src/api/room/widgets/AvatarInfoUtilities.ts b/src/api/room/widgets/AvatarInfoUtilities.ts index 134e604e..57501993 100644 --- a/src/api/room/widgets/AvatarInfoUtilities.ts +++ b/src/api/room/widgets/AvatarInfoUtilities.ts @@ -1,6 +1,4 @@ import { IFurnitureData, ObjectDataFactory, PetFigureData, PetType, RoomControllerLevel, RoomModerationSettings, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomPetData, RoomTradingLevelEnum, RoomUserData, RoomWidgetEnumItemExtradataParameter, Vector3d } from '@nitrots/nitro-renderer'; -import { WiredSelectObjectEvent } from '../../../events'; -import { DispatchUiEvent } from '../../events'; import { GetNitroInstance, GetRoomEngine, GetRoomSession, GetSessionDataManager, IsOwnerOfFurniture } from '../../nitro'; import { LocalizeText } from '../../utils'; import { AvatarInfoFurni } from './AvatarInfoFurni'; @@ -133,8 +131,6 @@ export class AvatarInfoUtilities furniInfo.availableForBuildersClub = furnitureData.availableForBuildersClub; furniInfo.tileSizeX = furnitureData.tileSizeX; furniInfo.tileSizeY = furnitureData.tileSizeY; - - DispatchUiEvent(new WiredSelectObjectEvent(furniInfo.id, furniInfo.category)); } } diff --git a/src/events/index.ts b/src/events/index.ts index 4cc4c4f2..4c5e757d 100644 --- a/src/events/index.ts +++ b/src/events/index.ts @@ -4,4 +4,3 @@ export * from './help'; export * from './inventory'; export * from './room-widgets'; export * from './room-widgets/thumbnail'; -export * from './wired'; diff --git a/src/events/wired/WiredEvent.ts b/src/events/wired/WiredEvent.ts deleted file mode 100644 index 6020680b..00000000 --- a/src/events/wired/WiredEvent.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class WiredEvent extends NitroEvent -{ - public static SAVE_WIRED: string = 'WE_SAVE_WIRED'; -} diff --git a/src/events/wired/WiredSelectObjectEvent.ts b/src/events/wired/WiredSelectObjectEvent.ts deleted file mode 100644 index e82fc9d1..00000000 --- a/src/events/wired/WiredSelectObjectEvent.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { WiredEvent } from './WiredEvent'; - -export class WiredSelectObjectEvent extends WiredEvent -{ - public static SELECT_OBJECT: string = 'WE_SELECT_OBJECT'; - - private _objectId: number; - private _category: number; - - constructor(objectId = -1, category = -1) - { - super(WiredSelectObjectEvent.SELECT_OBJECT); - - this._objectId = objectId; - this._category = category; - } - - public get objectId(): number - { - return this._objectId; - } - - public get category(): number - { - return this._category; - } -} diff --git a/src/events/wired/index.ts b/src/events/wired/index.ts deleted file mode 100644 index 63ab5775..00000000 --- a/src/events/wired/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './WiredEvent'; -export * from './WiredSelectObjectEvent'; diff --git a/src/hooks/rooms/widgets/useAvatarInfoWidget.ts b/src/hooks/rooms/widgets/useAvatarInfoWidget.ts index a8545404..0b8ebd1d 100644 --- a/src/hooks/rooms/widgets/useAvatarInfoWidget.ts +++ b/src/hooks/rooms/widgets/useAvatarInfoWidget.ts @@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'; import { AvatarInfoFurni, AvatarInfoName, AvatarInfoPet, AvatarInfoRentableBot, AvatarInfoUser, AvatarInfoUtilities, CanManipulateFurniture, FurniCategory, GetRoomEngine, GetSessionDataManager, IAvatarInfo, IsOwnerOfFurniture, RoomWidgetUpdateRoomObjectEvent, UseProductItem } from '../../../api'; import { useRoomEngineEvent, useRoomSessionManagerEvent, useUiEvent } from '../../events'; import { useFriends } from '../../friends'; +import { useWired } from '../../wired'; import { useObjectDeselectedEvent, useObjectRollOutEvent, useObjectRollOverEvent, useObjectSelectedEvent } from '../engine'; import { useRoom } from '../useRoom'; @@ -16,6 +17,7 @@ const useAvatarInfoWidgetState = () => const [ pendingPetId, setPendingPetId ] = useState(-1); const [ isDecorating, setIsDecorating ] = useState(false); const { friends = [] } = useFriends(); + const { selectObjectForWired = null } = useWired(); const { roomSession = null } = useRoom(); const removeNameBubble = (index: number) => @@ -68,7 +70,9 @@ const useAvatarInfoWidgetState = () => { case RoomObjectCategory.FLOOR: case RoomObjectCategory.WALL: - info = AvatarInfoUtilities.getFurniInfo(objectId, category) + info = AvatarInfoUtilities.getFurniInfo(objectId, category); + + if(info) selectObjectForWired(objectId, category); break; case RoomObjectCategory.UNIT: { const userData = roomSession.userDataManager.getUserDataByIndex(objectId); diff --git a/src/hooks/wired/useWired.ts b/src/hooks/wired/useWired.ts index 4c28bbc9..43f91f11 100644 --- a/src/hooks/wired/useWired.ts +++ b/src/hooks/wired/useWired.ts @@ -2,8 +2,7 @@ import { ConditionDefinition, Triggerable, TriggerDefinition, UpdateActionMessag import { useEffect, useState } from 'react'; import { useBetween } from 'use-between'; import { IsOwnerOfFloorFurniture, LocalizeText, SendMessageComposer, WiredSelectionVisualizer } from '../../api'; -import { WiredSelectObjectEvent } from '../../events'; -import { useMessageEvent, useUiEvent } from '../events'; +import { useMessageEvent } from '../events'; import { useNotification } from '../notification'; const useWiredState = () => @@ -50,37 +49,35 @@ const useWiredState = () => } } - useUiEvent(WiredSelectObjectEvent.SELECT_OBJECT, event => + const selectObjectForWired = (objectId: number, category: number) => { if(!trigger) return; - - const furniId = event.objectId; - if(furniId <= 0) return; + if(objectId <= 0) return; setFurniIds(prevValue => { const newFurniIds = [ ...prevValue ]; - const index = prevValue.indexOf(furniId); + const index = prevValue.indexOf(objectId); if(index >= 0) { newFurniIds.splice(index, 1); - WiredSelectionVisualizer.hide(furniId); + WiredSelectionVisualizer.hide(objectId); } else if(newFurniIds.length < trigger.maximumItemSelectionCount) { - newFurniIds.push(furniId); + newFurniIds.push(objectId); - WiredSelectionVisualizer.show(furniId); + WiredSelectionVisualizer.show(objectId); } return newFurniIds; }); - }, !!trigger); + } useMessageEvent(WiredSaveSuccessEvent, event => { @@ -128,7 +125,7 @@ const useWiredState = () => } }, [ trigger ]); - return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, saveWired }; + return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, saveWired, selectObjectForWired }; } export const useWired = () => useBetween(useWiredState);