From 6ffeb3d34092dbbd86143f0bb8f8fdadd9152c40 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 22 Aug 2021 00:59:55 -0400 Subject: [PATCH] Update things --- .../handlers/RoomWidgetInfostandHandler.ts | 18 +-- .../views/furni/InfoStandWidgetFurniView.tsx | 112 ++++++++++++++---- 2 files changed, 92 insertions(+), 38 deletions(-) diff --git a/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts b/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts index 50f663f4..8693cb23 100644 --- a/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts +++ b/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts @@ -1,4 +1,4 @@ -import { IFurnitureData, NitroEvent, ObjectDataFactory, PetFigureData, PetRespectComposer, PetSupplementComposer, PetType, RoomAdsUpdateComposer, RoomControllerLevel, RoomModerationSettings, RoomObjectCategory, RoomObjectOperationType, RoomObjectType, RoomObjectVariable, RoomSessionPetInfoUpdateEvent, RoomSessionUserBadgesEvent, RoomTradingLevelEnum, RoomUnitDropHandItemComposer, RoomUnitGiveHandItemComposer, RoomUnitGiveHandItemPetComposer, RoomUserData, RoomWidgetEnum, RoomWidgetEnumItemExtradataParameter, SecurityLevel, Vector3d } from '@nitrots/nitro-renderer'; +import { IFurnitureData, NitroEvent, ObjectDataFactory, PetFigureData, PetRespectComposer, PetSupplementComposer, PetType, RoomControllerLevel, RoomModerationSettings, RoomObjectCategory, RoomObjectOperationType, RoomObjectType, RoomObjectVariable, RoomSessionPetInfoUpdateEvent, RoomSessionUserBadgesEvent, RoomTradingLevelEnum, RoomUnitDropHandItemComposer, RoomUnitGiveHandItemComposer, RoomUnitGiveHandItemPetComposer, RoomUserData, RoomWidgetEnum, RoomWidgetEnumItemExtradataParameter, Vector3d } from '@nitrots/nitro-renderer'; import { GetNitroInstance, GetRoomEngine, GetSessionDataManager, IsOwnerOfFurniture } from '../../../..'; import { InventoryTradeRequestEvent, WiredSelectObjectEvent } from '../../../../../events'; import { FriendListSendFriendRequestEvent } from '../../../../../events/friend-list/FriendListSendFriendRequestEvent'; @@ -210,21 +210,13 @@ export class RoomWidgetInfostandHandler extends RoomWidgetHandler { for(const part of dataParts) { - const partPieces = part.split('=', 2); - - if(partPieces && partPieces.length === 2) - { - const piece1 = partPieces[0]; - const piece2 = partPieces[1]; - - mapData.set(piece1, piece2); - } + const [ key, value ] = part.split('=', 2); + + mapData.set(key, value); } } - GetRoomEngine().processRoomObjectWallOperation(objectId, category, RoomObjectOperationType.OBJECT_SAVE_STUFF_DATA, mapData); - - if(GetSessionDataManager().hasSecurity(SecurityLevel.MODERATOR)) SendMessageHook(new RoomAdsUpdateComposer(objectId, mapData)); + GetRoomEngine().modifyRoomObjectDataWithMap(objectId, category, RoomObjectOperationType.OBJECT_SAVE_STUFF_DATA, mapData); return; } diff --git a/src/views/room/widgets/infostand/views/furni/InfoStandWidgetFurniView.tsx b/src/views/room/widgets/infostand/views/furni/InfoStandWidgetFurniView.tsx index 803b44d0..6e8a3ace 100644 --- a/src/views/room/widgets/infostand/views/furni/InfoStandWidgetFurniView.tsx +++ b/src/views/room/widgets/infostand/views/furni/InfoStandWidgetFurniView.tsx @@ -1,6 +1,7 @@ -import { CrackableDataType, RoomControllerLevel, RoomWidgetEnumItemExtradataParameter, RoomWidgetFurniInfoUsagePolicyEnum, StringDataType } from '@nitrots/nitro-renderer'; +import { CrackableDataType, RoomControllerLevel, RoomObjectCategory, RoomObjectVariable, RoomWidgetEnumItemExtradataParameter, RoomWidgetFurniInfoUsagePolicyEnum, SetObjectDataMessageComposer, StringDataType } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { CreateLinkEvent, LocalizeText, RoomWidgetFurniActionMessage } from '../../../../../../api'; +import { CreateLinkEvent, GetRoomEngine, LocalizeText, RoomWidgetFurniActionMessage } from '../../../../../../api'; +import { SendMessageHook } from '../../../../../../hooks'; import { BadgeImageView } from '../../../../../shared/badge-image/BadgeImageView'; import { LimitedEditionCompactPlateView } from '../../../../../shared/limited-edition/compact-plate/LimitedEditionCompactPlateView'; import { RarityLevelView } from '../../../../../shared/rarity-level/RarityLevelView'; @@ -15,14 +16,16 @@ const PICKUP_MODE_FULL: number = 2; export const InfoStandWidgetFurniView: FC = props => { const { furniData = null, close = null } = props; - const { eventDispatcher = null, widgetHandler = null } = useRoomContext(); + const { roomSession = null, eventDispatcher = null, widgetHandler = null } = useRoomContext(); const [ pickupMode, setPickupMode ] = useState(0); const [ canMove, setCanMove ] = useState(false); const [ canRotate, setCanRotate ] = useState(false); const [ canUse, setCanUse ] = useState(false); - const [ furniSettingsKeys, setFurniSettingsKeys ] = useState([]); - const [ furniSettingsValues, setFurniSettingsValues ] = useState([]); + const [ furniKeys, setFurniKeys ] = useState([]); + const [ furniValues, setFurniValues ] = useState([]); + const [ customKeys, setCustomKeys ] = useState([]); + const [ customValues, setCustomValues ] = useState([]); const [ isCrackable, setIsCrackable ] = useState(false); const [ crackableHits, setCrackableHits ] = useState(0); const [ crackableTarget, setCrackableTarget ] = useState(0); @@ -34,8 +37,10 @@ export const InfoStandWidgetFurniView: FC = props let canMove = false; let canRotate = false; let canUse = false; - let furniSettings: string[] = []; - let furniValues: string[] = []; + let furniKeyss: string[] = []; + let furniValuess: string[] = []; + let customKeyss: string[] = []; + let customValuess: string[] = []; let isCrackable = false; let crackableHits = 0; let crackableTarget = 0; @@ -79,14 +84,31 @@ export const InfoStandWidgetFurniView: FC = props if(value && (value.length === 2)) { - furniSettings.push(value[0]); - furniValues.push(value[1]); + furniKeyss.push(value[0]); + furniValuess.push(value[1]); } } } } } + const roomObject = GetRoomEngine().getRoomObject(roomSession.roomId, furniData.id, (furniData.isWallItem) ? RoomObjectCategory.WALL : RoomObjectCategory.FLOOR); + + if(roomObject) + { + const customVariables = roomObject.model.getValue(RoomObjectVariable.FURNITURE_CUSTOM_VARIABLES); + const furnitureData = roomObject.model.getValue<{ [index: string]: string }>(RoomObjectVariable.FURNITURE_DATA); + + if(customVariables && customVariables.length) + { + for(const customVariable of customVariables) + { + customKeyss.push(customVariable); + customValuess.push((furnitureData[customVariable]) || ''); + } + } + } + if(furniData.isOwner || furniData.isAnyRoomController) pickupMode = PICKUP_MODE_FULL; else if(furniData.isRoomOwner || (furniData.roomControllerLevel >= RoomControllerLevel.GUILD_ADMIN)) pickupMode = PICKUP_MODE_EJECT; @@ -97,13 +119,15 @@ export const InfoStandWidgetFurniView: FC = props setCanMove(canMove); setCanRotate(canRotate); setCanUse(canUse); - setFurniSettingsKeys(furniSettings); - setFurniSettingsValues(furniValues); + setFurniKeys(furniKeyss); + setFurniValues(furniValuess); + setCustomKeys(customKeyss); + setCustomValues(customValuess); setIsCrackable(isCrackable); setCrackableHits(crackableHits); setCrackableTarget(crackableTarget); setGodMode(godMode); - }, [ furniData ]); + }, [ roomSession, furniData ]); const openFurniGroupInfo = useCallback(() => { @@ -112,25 +136,34 @@ export const InfoStandWidgetFurniView: FC = props const onFurniSettingChange = useCallback((index: number, value: string) => { - const clone = Array.from(furniSettingsValues); + const clone = Array.from(furniValues); clone[index] = value; - setFurniSettingsValues(clone); - }, [ furniSettingsValues ]); + setFurniValues(clone); + }, [ furniValues ]); + + const onCustomVariableChange = useCallback((index: number, value: string) => + { + const clone = Array.from(customValues); + + clone[index] = value; + + setCustomValues(clone); + }, [ customValues ]); const getFurniSettingsAsString = useCallback(() => { - if(furniSettingsKeys.length === 0 || furniSettingsValues.length === 0) return ''; + if(furniKeys.length === 0 || furniValues.length === 0) return ''; let data = ''; let i = 0; - while(i < furniSettingsKeys.length) + while(i < furniKeys.length) { - const key = furniSettingsKeys[i]; - const value = furniSettingsValues[i]; + const key = furniKeys[i]; + const value = furniValues[i]; data = (data + (key + '=' + value + '\t')); @@ -138,7 +171,7 @@ export const InfoStandWidgetFurniView: FC = props } return data; - }, [ furniSettingsKeys, furniSettingsValues ]); + }, [ furniKeys, furniValues ]); const processButtonAction = useCallback((action: string) => { @@ -169,12 +202,25 @@ export const InfoStandWidgetFurniView: FC = props messageType = RoomWidgetFurniActionMessage.SAVE_STUFF_DATA; objectData = getFurniSettingsAsString(); break; + case 'save_custom_variables': + const map = new Map(); + + for(let i = 0; i < customKeys.length; i++) + { + const key = customKeys[i]; + const value = customValues[i]; + + if((key && key.length) && (value && value.length)) map.set(key, value); + } + + SendMessageHook(new SetObjectDataMessageComposer(furniData.id, map)); + break; } if(!messageType) return; widgetHandler.processWidgetMessage(new RoomWidgetFurniActionMessage(messageType, furniData.id, furniData.category, furniData.purchaseOfferId, objectData)); - }, [ furniData, pickupMode, widgetHandler, getFurniSettingsAsString ]); + }, [ widgetHandler, furniData, pickupMode, customKeys, customValues, getFurniSettingsAsString ]); if(!furniData) return null; @@ -217,19 +263,31 @@ export const InfoStandWidgetFurniView: FC = props <>
ID: { furniData.id }
- { (furniSettingsKeys.length > 0) && + { (furniKeys.length > 0) && <>
- { furniSettingsKeys.map((key, index) => + { furniKeys.map((key, index) => { return (
{ key }
- onFurniSettingChange(index, event.target.value) }/> + onFurniSettingChange(index, event.target.value) }/>
); }) } } } + { (customKeys.length > 0) && + <> +
+ { customKeys.map((key, index) => + { + return ( +
+
{ key }
+ onCustomVariableChange(index, event.target.value) }/> +
); + }) } + }
{ canMove && @@ -248,10 +306,14 @@ export const InfoStandWidgetFurniView: FC = props } - { ((furniSettingsKeys.length > 0 && furniSettingsValues.length > 0) && (furniSettingsKeys.length === furniSettingsValues.length)) && + { ((furniKeys.length > 0 && furniValues.length > 0) && (furniKeys.length === furniValues.length)) && } + { ((customKeys.length > 0 && customValues.length > 0) && (customKeys.length === customValues.length)) && + }
);