Update things

This commit is contained in:
Bill 2021-08-22 00:59:55 -04:00
parent d046e40409
commit 6ffeb3d340
2 changed files with 92 additions and 38 deletions

View File

@ -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 { GetNitroInstance, GetRoomEngine, GetSessionDataManager, IsOwnerOfFurniture } from '../../../..';
import { InventoryTradeRequestEvent, WiredSelectObjectEvent } from '../../../../../events'; import { InventoryTradeRequestEvent, WiredSelectObjectEvent } from '../../../../../events';
import { FriendListSendFriendRequestEvent } from '../../../../../events/friend-list/FriendListSendFriendRequestEvent'; import { FriendListSendFriendRequestEvent } from '../../../../../events/friend-list/FriendListSendFriendRequestEvent';
@ -210,21 +210,13 @@ export class RoomWidgetInfostandHandler extends RoomWidgetHandler
{ {
for(const part of dataParts) for(const part of dataParts)
{ {
const partPieces = part.split('=', 2); const [ key, value ] = part.split('=', 2);
if(partPieces && partPieces.length === 2) mapData.set(key, value);
{
const piece1 = partPieces[0];
const piece2 = partPieces[1];
mapData.set(piece1, piece2);
}
} }
} }
GetRoomEngine().processRoomObjectWallOperation(objectId, category, RoomObjectOperationType.OBJECT_SAVE_STUFF_DATA, mapData); GetRoomEngine().modifyRoomObjectDataWithMap(objectId, category, RoomObjectOperationType.OBJECT_SAVE_STUFF_DATA, mapData);
if(GetSessionDataManager().hasSecurity(SecurityLevel.MODERATOR)) SendMessageHook(new RoomAdsUpdateComposer(objectId, mapData));
return; return;
} }

View File

@ -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 { 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 { BadgeImageView } from '../../../../../shared/badge-image/BadgeImageView';
import { LimitedEditionCompactPlateView } from '../../../../../shared/limited-edition/compact-plate/LimitedEditionCompactPlateView'; import { LimitedEditionCompactPlateView } from '../../../../../shared/limited-edition/compact-plate/LimitedEditionCompactPlateView';
import { RarityLevelView } from '../../../../../shared/rarity-level/RarityLevelView'; import { RarityLevelView } from '../../../../../shared/rarity-level/RarityLevelView';
@ -15,14 +16,16 @@ const PICKUP_MODE_FULL: number = 2;
export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props => export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props =>
{ {
const { furniData = null, close = null } = 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 [ pickupMode, setPickupMode ] = useState(0);
const [ canMove, setCanMove ] = useState(false); const [ canMove, setCanMove ] = useState(false);
const [ canRotate, setCanRotate ] = useState(false); const [ canRotate, setCanRotate ] = useState(false);
const [ canUse, setCanUse ] = useState(false); const [ canUse, setCanUse ] = useState(false);
const [ furniSettingsKeys, setFurniSettingsKeys ] = useState<string[]>([]); const [ furniKeys, setFurniKeys ] = useState<string[]>([]);
const [ furniSettingsValues, setFurniSettingsValues ] = useState<string[]>([]); const [ furniValues, setFurniValues ] = useState<string[]>([]);
const [ customKeys, setCustomKeys ] = useState<string[]>([]);
const [ customValues, setCustomValues ] = useState<string[]>([]);
const [ isCrackable, setIsCrackable ] = useState(false); const [ isCrackable, setIsCrackable ] = useState(false);
const [ crackableHits, setCrackableHits ] = useState(0); const [ crackableHits, setCrackableHits ] = useState(0);
const [ crackableTarget, setCrackableTarget ] = useState(0); const [ crackableTarget, setCrackableTarget ] = useState(0);
@ -34,8 +37,10 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
let canMove = false; let canMove = false;
let canRotate = false; let canRotate = false;
let canUse = false; let canUse = false;
let furniSettings: string[] = []; let furniKeyss: string[] = [];
let furniValues: string[] = []; let furniValuess: string[] = [];
let customKeyss: string[] = [];
let customValuess: string[] = [];
let isCrackable = false; let isCrackable = false;
let crackableHits = 0; let crackableHits = 0;
let crackableTarget = 0; let crackableTarget = 0;
@ -79,14 +84,31 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
if(value && (value.length === 2)) if(value && (value.length === 2))
{ {
furniSettings.push(value[0]); furniKeyss.push(value[0]);
furniValues.push(value[1]); 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<string[]>(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; if(furniData.isOwner || furniData.isAnyRoomController) pickupMode = PICKUP_MODE_FULL;
else if(furniData.isRoomOwner || (furniData.roomControllerLevel >= RoomControllerLevel.GUILD_ADMIN)) pickupMode = PICKUP_MODE_EJECT; else if(furniData.isRoomOwner || (furniData.roomControllerLevel >= RoomControllerLevel.GUILD_ADMIN)) pickupMode = PICKUP_MODE_EJECT;
@ -97,13 +119,15 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
setCanMove(canMove); setCanMove(canMove);
setCanRotate(canRotate); setCanRotate(canRotate);
setCanUse(canUse); setCanUse(canUse);
setFurniSettingsKeys(furniSettings); setFurniKeys(furniKeyss);
setFurniSettingsValues(furniValues); setFurniValues(furniValuess);
setCustomKeys(customKeyss);
setCustomValues(customValuess);
setIsCrackable(isCrackable); setIsCrackable(isCrackable);
setCrackableHits(crackableHits); setCrackableHits(crackableHits);
setCrackableTarget(crackableTarget); setCrackableTarget(crackableTarget);
setGodMode(godMode); setGodMode(godMode);
}, [ furniData ]); }, [ roomSession, furniData ]);
const openFurniGroupInfo = useCallback(() => const openFurniGroupInfo = useCallback(() =>
{ {
@ -112,25 +136,34 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
const onFurniSettingChange = useCallback((index: number, value: string) => const onFurniSettingChange = useCallback((index: number, value: string) =>
{ {
const clone = Array.from(furniSettingsValues); const clone = Array.from(furniValues);
clone[index] = value; clone[index] = value;
setFurniSettingsValues(clone); setFurniValues(clone);
}, [ furniSettingsValues ]); }, [ furniValues ]);
const onCustomVariableChange = useCallback((index: number, value: string) =>
{
const clone = Array.from(customValues);
clone[index] = value;
setCustomValues(clone);
}, [ customValues ]);
const getFurniSettingsAsString = useCallback(() => const getFurniSettingsAsString = useCallback(() =>
{ {
if(furniSettingsKeys.length === 0 || furniSettingsValues.length === 0) return ''; if(furniKeys.length === 0 || furniValues.length === 0) return '';
let data = ''; let data = '';
let i = 0; let i = 0;
while(i < furniSettingsKeys.length) while(i < furniKeys.length)
{ {
const key = furniSettingsKeys[i]; const key = furniKeys[i];
const value = furniSettingsValues[i]; const value = furniValues[i];
data = (data + (key + '=' + value + '\t')); data = (data + (key + '=' + value + '\t'));
@ -138,7 +171,7 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
} }
return data; return data;
}, [ furniSettingsKeys, furniSettingsValues ]); }, [ furniKeys, furniValues ]);
const processButtonAction = useCallback((action: string) => const processButtonAction = useCallback((action: string) =>
{ {
@ -169,12 +202,25 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
messageType = RoomWidgetFurniActionMessage.SAVE_STUFF_DATA; messageType = RoomWidgetFurniActionMessage.SAVE_STUFF_DATA;
objectData = getFurniSettingsAsString(); objectData = getFurniSettingsAsString();
break; 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; if(!messageType) return;
widgetHandler.processWidgetMessage(new RoomWidgetFurniActionMessage(messageType, furniData.id, furniData.category, furniData.purchaseOfferId, objectData)); 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; if(!furniData) return null;
@ -217,19 +263,31 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
<> <>
<hr className="m-0 my-1" /> <hr className="m-0 my-1" />
<div className="small text-wrap">ID: { furniData.id }</div> <div className="small text-wrap">ID: { furniData.id }</div>
{ (furniSettingsKeys.length > 0) && { (furniKeys.length > 0) &&
<> <>
<hr className="m-0 my-1"/> <hr className="m-0 my-1"/>
{ furniSettingsKeys.map((key, index) => { furniKeys.map((key, index) =>
{ {
return ( return (
<div key={ index } className="mb-1"> <div key={ index } className="mb-1">
<div className="small text-wrap">{ key }</div> <div className="small text-wrap">{ key }</div>
<input type="text" className="form-control form-control-sm" value={ furniSettingsValues[index] } onChange={ event => onFurniSettingChange(index, event.target.value) }/> <input type="text" className="form-control form-control-sm" value={ furniValues[index] } onChange={ event => onFurniSettingChange(index, event.target.value) }/>
</div>); </div>);
}) } }) }
</> } </> }
</> } </> }
{ (customKeys.length > 0) &&
<>
<hr className="m-0 my-1"/>
{ customKeys.map((key, index) =>
{
return (
<div key={ index } className="mb-1">
<div className="small text-wrap">{ key }</div>
<input type="text" className="form-control form-control-sm" value={ customValues[index] } onChange={ event => onCustomVariableChange(index, event.target.value) }/>
</div>);
}) }
</> }
</InfoStandBaseView> </InfoStandBaseView>
<div className="button-container mt-2"> <div className="button-container mt-2">
{ canMove && { canMove &&
@ -248,10 +306,14 @@ export const InfoStandWidgetFurniView: FC<InfoStandWidgetFurniViewProps> = props
<button type="button" className="btn btn-sm btn-dark ms-1" onClick={ event => processButtonAction('pickup') }> <button type="button" className="btn btn-sm btn-dark ms-1" onClick={ event => processButtonAction('pickup') }>
{ LocalizeText((pickupMode === PICKUP_MODE_EJECT) ? 'infostand.button.eject' : 'infostand.button.pickup') } { LocalizeText((pickupMode === PICKUP_MODE_EJECT) ? 'infostand.button.eject' : 'infostand.button.pickup') }
</button> } </button> }
{ ((furniSettingsKeys.length > 0 && furniSettingsValues.length > 0) && (furniSettingsKeys.length === furniSettingsValues.length)) && { ((furniKeys.length > 0 && furniValues.length > 0) && (furniKeys.length === furniValues.length)) &&
<button className="btn btn-sm btn-dark ms-1" onClick={ () => processButtonAction('save_branding_configuration') }> <button className="btn btn-sm btn-dark ms-1" onClick={ () => processButtonAction('save_branding_configuration') }>
{ LocalizeText('save') } { LocalizeText('save') }
</button> } </button> }
{ ((customKeys.length > 0 && customValues.length > 0) && (customKeys.length === customValues.length)) &&
<button className="btn btn-sm btn-dark ms-1" onClick={ () => processButtonAction('save_custom_variables') }>
Set values
</button> }
</div> </div>
</> </>
); );