Update wired furni selector

This commit is contained in:
Bill 2022-07-28 12:44:25 -04:00
parent 42cdd0ae4f
commit 61d1c4b379
7 changed files with 14 additions and 53 deletions

View File

@ -1,6 +1,4 @@
import { IFurnitureData, ObjectDataFactory, PetFigureData, PetType, RoomControllerLevel, RoomModerationSettings, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomPetData, RoomTradingLevelEnum, RoomUserData, RoomWidgetEnumItemExtradataParameter, Vector3d } from '@nitrots/nitro-renderer'; 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 { GetNitroInstance, GetRoomEngine, GetRoomSession, GetSessionDataManager, IsOwnerOfFurniture } from '../../nitro';
import { LocalizeText } from '../../utils'; import { LocalizeText } from '../../utils';
import { AvatarInfoFurni } from './AvatarInfoFurni'; import { AvatarInfoFurni } from './AvatarInfoFurni';
@ -133,8 +131,6 @@ export class AvatarInfoUtilities
furniInfo.availableForBuildersClub = furnitureData.availableForBuildersClub; furniInfo.availableForBuildersClub = furnitureData.availableForBuildersClub;
furniInfo.tileSizeX = furnitureData.tileSizeX; furniInfo.tileSizeX = furnitureData.tileSizeX;
furniInfo.tileSizeY = furnitureData.tileSizeY; furniInfo.tileSizeY = furnitureData.tileSizeY;
DispatchUiEvent(new WiredSelectObjectEvent(furniInfo.id, furniInfo.category));
} }
} }

View File

@ -4,4 +4,3 @@ export * from './help';
export * from './inventory'; export * from './inventory';
export * from './room-widgets'; export * from './room-widgets';
export * from './room-widgets/thumbnail'; export * from './room-widgets/thumbnail';
export * from './wired';

View File

@ -1,6 +0,0 @@
import { NitroEvent } from '@nitrots/nitro-renderer';
export class WiredEvent extends NitroEvent
{
public static SAVE_WIRED: string = 'WE_SAVE_WIRED';
}

View File

@ -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;
}
}

View File

@ -1,2 +0,0 @@
export * from './WiredEvent';
export * from './WiredSelectObjectEvent';

View File

@ -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 { AvatarInfoFurni, AvatarInfoName, AvatarInfoPet, AvatarInfoRentableBot, AvatarInfoUser, AvatarInfoUtilities, CanManipulateFurniture, FurniCategory, GetRoomEngine, GetSessionDataManager, IAvatarInfo, IsOwnerOfFurniture, RoomWidgetUpdateRoomObjectEvent, UseProductItem } from '../../../api';
import { useRoomEngineEvent, useRoomSessionManagerEvent, useUiEvent } from '../../events'; import { useRoomEngineEvent, useRoomSessionManagerEvent, useUiEvent } from '../../events';
import { useFriends } from '../../friends'; import { useFriends } from '../../friends';
import { useWired } from '../../wired';
import { useObjectDeselectedEvent, useObjectRollOutEvent, useObjectRollOverEvent, useObjectSelectedEvent } from '../engine'; import { useObjectDeselectedEvent, useObjectRollOutEvent, useObjectRollOverEvent, useObjectSelectedEvent } from '../engine';
import { useRoom } from '../useRoom'; import { useRoom } from '../useRoom';
@ -16,6 +17,7 @@ const useAvatarInfoWidgetState = () =>
const [ pendingPetId, setPendingPetId ] = useState<number>(-1); const [ pendingPetId, setPendingPetId ] = useState<number>(-1);
const [ isDecorating, setIsDecorating ] = useState(false); const [ isDecorating, setIsDecorating ] = useState(false);
const { friends = [] } = useFriends(); const { friends = [] } = useFriends();
const { selectObjectForWired = null } = useWired();
const { roomSession = null } = useRoom(); const { roomSession = null } = useRoom();
const removeNameBubble = (index: number) => const removeNameBubble = (index: number) =>
@ -68,7 +70,9 @@ const useAvatarInfoWidgetState = () =>
{ {
case RoomObjectCategory.FLOOR: case RoomObjectCategory.FLOOR:
case RoomObjectCategory.WALL: case RoomObjectCategory.WALL:
info = AvatarInfoUtilities.getFurniInfo(objectId, category) info = AvatarInfoUtilities.getFurniInfo(objectId, category);
if(info) selectObjectForWired(objectId, category);
break; break;
case RoomObjectCategory.UNIT: { case RoomObjectCategory.UNIT: {
const userData = roomSession.userDataManager.getUserDataByIndex(objectId); const userData = roomSession.userDataManager.getUserDataByIndex(objectId);

View File

@ -2,8 +2,7 @@ import { ConditionDefinition, Triggerable, TriggerDefinition, UpdateActionMessag
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useBetween } from 'use-between'; import { useBetween } from 'use-between';
import { IsOwnerOfFloorFurniture, LocalizeText, SendMessageComposer, WiredSelectionVisualizer } from '../../api'; import { IsOwnerOfFloorFurniture, LocalizeText, SendMessageComposer, WiredSelectionVisualizer } from '../../api';
import { WiredSelectObjectEvent } from '../../events'; import { useMessageEvent } from '../events';
import { useMessageEvent, useUiEvent } from '../events';
import { useNotification } from '../notification'; import { useNotification } from '../notification';
const useWiredState = () => const useWiredState = () =>
@ -50,37 +49,35 @@ const useWiredState = () =>
} }
} }
useUiEvent<WiredSelectObjectEvent>(WiredSelectObjectEvent.SELECT_OBJECT, event => const selectObjectForWired = (objectId: number, category: number) =>
{ {
if(!trigger) return; if(!trigger) return;
const furniId = event.objectId; if(objectId <= 0) return;
if(furniId <= 0) return;
setFurniIds(prevValue => setFurniIds(prevValue =>
{ {
const newFurniIds = [ ...prevValue ]; const newFurniIds = [ ...prevValue ];
const index = prevValue.indexOf(furniId); const index = prevValue.indexOf(objectId);
if(index >= 0) if(index >= 0)
{ {
newFurniIds.splice(index, 1); newFurniIds.splice(index, 1);
WiredSelectionVisualizer.hide(furniId); WiredSelectionVisualizer.hide(objectId);
} }
else if(newFurniIds.length < trigger.maximumItemSelectionCount) else if(newFurniIds.length < trigger.maximumItemSelectionCount)
{ {
newFurniIds.push(furniId); newFurniIds.push(objectId);
WiredSelectionVisualizer.show(furniId); WiredSelectionVisualizer.show(objectId);
} }
return newFurniIds; return newFurniIds;
}); });
}, !!trigger); }
useMessageEvent<WiredSaveSuccessEvent>(WiredSaveSuccessEvent, event => useMessageEvent<WiredSaveSuccessEvent>(WiredSaveSuccessEvent, event =>
{ {
@ -128,7 +125,7 @@ const useWiredState = () =>
} }
}, [ trigger ]); }, [ 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); export const useWired = () => useBetween(useWiredState);