Fix busted stuff data update for catalog

This commit is contained in:
Bill 2021-09-01 00:47:04 -04:00
parent cf01a2cfc1
commit fe7ee1988e
7 changed files with 131 additions and 84 deletions

View File

@ -0,0 +1,27 @@
import { CatalogPageMessageOfferData, IObjectData, NitroEvent } from '@nitrots/nitro-renderer';
export class SetRoomPreviewerStuffDataEvent extends NitroEvent
{
public static UPDATE_STUFF_DATA: string = 'SRPSA_UPDATE_STUFF_DATA';
private _offer: CatalogPageMessageOfferData;
private _stuffData: IObjectData;
constructor(offer: CatalogPageMessageOfferData, stuffData: IObjectData)
{
super(SetRoomPreviewerStuffDataEvent.UPDATE_STUFF_DATA);
this._offer = offer;
this._stuffData = stuffData;
}
public get offer(): CatalogPageMessageOfferData
{
return this._offer;
}
public get stuffData(): IObjectData
{
return this._stuffData;
}
}

View File

@ -3,3 +3,4 @@ export * from './CatalogNameResultEvent';
export * from './CatalogPurchasedEvent'; export * from './CatalogPurchasedEvent';
export * from './CatalogPurchaseFailureEvent'; export * from './CatalogPurchaseFailureEvent';
export * from './CatalogPurchaseSoldOutEvent'; export * from './CatalogPurchaseSoldOutEvent';
export * from './SetRoomPreviewerStuffDataEvent';

View File

@ -1,9 +1,9 @@
import { IEventDispatcher, NitroEvent } from '@nitrots/nitro-renderer'; import { IEventDispatcher, NitroEvent } from '@nitrots/nitro-renderer';
import { useEffect } from 'react'; import { useEffect } from 'react';
export function CreateEventDispatcherHook(type: string, eventDispatcher: IEventDispatcher, handler: (event: NitroEvent) => void): void export const CreateEventDispatcherHook = (type: string, eventDispatcher: IEventDispatcher, handler: (event: NitroEvent) => void) =>
{ {
useEffect(() => return useEffect(() =>
{ {
eventDispatcher.addEventListener(type, handler); eventDispatcher.addEventListener(type, handler);
@ -14,7 +14,7 @@ export function CreateEventDispatcherHook(type: string, eventDispatcher: IEventD
}, [ type, eventDispatcher, handler ]); }, [ type, eventDispatcher, handler ]);
} }
export function DispatchEventHook(eventDispatcher: IEventDispatcher, event: NitroEvent): void export const DispatchEventHook = (eventDispatcher: IEventDispatcher, event: NitroEvent) =>
{ {
eventDispatcher.dispatchEvent(event); eventDispatcher.dispatchEvent(event);
} }

View File

@ -3,9 +3,9 @@ import { CreateEventDispatcherHook, DispatchEventHook } from '../event-dispatche
const uiEventDispatcher: IEventDispatcher = new EventDispatcher(); const uiEventDispatcher: IEventDispatcher = new EventDispatcher();
export function useUiEvent(type: string, handler: (event: NitroEvent) => void): void export const useUiEvent = (type: string, handler: (event: NitroEvent) => void) =>
{ {
CreateEventDispatcherHook(type, uiEventDispatcher, handler); return CreateEventDispatcherHook(type, uiEventDispatcher, handler);
} }
export function dispatchUiEvent(event: NitroEvent): void export function dispatchUiEvent(event: NitroEvent): void

View File

@ -1,6 +1,8 @@
import { Vector3d } from '@nitrots/nitro-renderer'; import { CatalogPageMessageOfferData, IObjectData, Vector3d } from '@nitrots/nitro-renderer';
import { FC, useEffect } from 'react'; import { FC, useCallback, useEffect, useState } from 'react';
import { GetAvatarRenderManager, GetFurnitureDataForProductOffer, GetSessionDataManager } from '../../../../api'; import { GetAvatarRenderManager, GetFurnitureDataForProductOffer, GetSessionDataManager } from '../../../../api';
import { SetRoomPreviewerStuffDataEvent } from '../../../../events';
import { useUiEvent } from '../../../../hooks';
import { FurniCategory } from '../../common/FurniCategory'; import { FurniCategory } from '../../common/FurniCategory';
import { ProductTypeEnum } from '../../common/ProductTypeEnum'; import { ProductTypeEnum } from '../../common/ProductTypeEnum';
import { useCatalogContext } from '../../context/CatalogContext'; import { useCatalogContext } from '../../context/CatalogContext';
@ -11,21 +13,15 @@ import { CatalogLayoutSearchResultView } from './search-result/CatalogLayoutSear
export const CatalogPageView: FC<CatalogPageViewProps> = props => export const CatalogPageView: FC<CatalogPageViewProps> = props =>
{ {
const { roomPreviewer = null } = props; const { roomPreviewer = null } = props;
const [ lastOffer, setLastOffer ] = useState<CatalogPageMessageOfferData>(null);
const { catalogState = null } = useCatalogContext(); const { catalogState = null } = useCatalogContext();
const { pageParser = null, activeOffer = null, searchResult = null } = catalogState; const { pageParser = null, activeOffer = null, searchResult = null } = catalogState;
useEffect(() => const updatePreviewerForOffer = useCallback((offer: CatalogPageMessageOfferData, stuffData: IObjectData = null) =>
{ {
if(!roomPreviewer) return; if(!offer || !roomPreviewer) return;
roomPreviewer && roomPreviewer.reset(false);
if(activeOffer && activeOffer.products.length)
{
const product = activeOffer.products[0];
if(!product) return;
const product = offer.products[0];
const furniData = GetFurnitureDataForProductOffer(product); const furniData = GetFurnitureDataForProductOffer(product);
if(!furniData && (product.productType !== ProductTypeEnum.ROBOT)) return; if(!furniData && (product.productType !== ProductTypeEnum.ROBOT)) return;
@ -61,12 +57,11 @@ export const CatalogPageView: FC<CatalogPageViewProps> = props =>
} }
else else
{ {
roomPreviewer.addFurnitureIntoRoom(product.furniClassId, new Vector3d(90)); roomPreviewer.addFurnitureIntoRoom(product.furniClassId, new Vector3d(90), stuffData);
} }
return; return;
} }
case ProductTypeEnum.WALL: case ProductTypeEnum.WALL: {
switch(furniData.className) switch(furniData.className)
{ {
case 'floor': case 'floor':
@ -94,7 +89,23 @@ export const CatalogPageView: FC<CatalogPageViewProps> = props =>
return; return;
} }
} }
}, [ roomPreviewer, activeOffer ]); }, [ roomPreviewer ]);
const onSetRoomPreviewerStuffDataEvent = useCallback((event: SetRoomPreviewerStuffDataEvent) =>
{
if(roomPreviewer) roomPreviewer.reset(false);
updatePreviewerForOffer(event.offer, event.stuffData);
}, [ roomPreviewer, updatePreviewerForOffer ]);
useUiEvent(SetRoomPreviewerStuffDataEvent.UPDATE_STUFF_DATA, onSetRoomPreviewerStuffDataEvent);
useEffect(() =>
{
if(!activeOffer) return;
updatePreviewerForOffer(activeOffer);
}, [ activeOffer, updatePreviewerForOffer ]);
if(searchResult && searchResult.furniture) if(searchResult && searchResult.furniture)
{ {

View File

@ -1,7 +1,7 @@
import { StringDataType } from '@nitrots/nitro-renderer'; import { StringDataType } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useMemo, useState } from 'react'; import { FC, useCallback, useEffect, useMemo, useState } from 'react';
import { LocalizeText } from '../../../../../../api'; import { LocalizeText } from '../../../../../../api';
import { InventoryBadgesUpdatedEvent } from '../../../../../../events'; import { InventoryBadgesUpdatedEvent, SetRoomPreviewerStuffDataEvent } from '../../../../../../events';
import { InventoryBadgesRequestEvent } from '../../../../../../events/inventory/InventoryBadgesRequestEvent'; import { InventoryBadgesRequestEvent } from '../../../../../../events/inventory/InventoryBadgesRequestEvent';
import { dispatchUiEvent, useUiEvent } from '../../../../../../hooks'; import { dispatchUiEvent, useUiEvent } from '../../../../../../hooks';
import { NitroCardGridItemView } from '../../../../../../layout/card/grid/item/NitroCardGridItemView'; import { NitroCardGridItemView } from '../../../../../../layout/card/grid/item/NitroCardGridItemView';
@ -53,11 +53,19 @@ export const CatalogLayoutBadgeDisplayView: FC<CatalogLayoutBadgeDisplayViewProp
{ {
if(!currentBadge || !activeOffer) return; if(!currentBadge || !activeOffer) return;
const stuffData = new StringDataType(); const productData = [];
productData.push('0');
productData.push(currentBadge);
productData.push('');
productData.push('');
productData.push('');
stuffData.setValue([ null, currentBadge ]); const stringDataType = new StringDataType();
stringDataType.setValue(productData);
roomPreviewer.updateObjectStuffData(stuffData); console.log(stringDataType);
dispatchUiEvent(new SetRoomPreviewerStuffDataEvent(activeOffer, stringDataType));
}, [ currentBadge, activeOffer, roomPreviewer ]); }, [ currentBadge, activeOffer, roomPreviewer ]);
return ( return (

View File

@ -1,6 +1,8 @@
import { CatalogGroupsComposer, StringDataType } from '@nitrots/nitro-renderer'; import { CatalogGroupsComposer, StringDataType } from '@nitrots/nitro-renderer';
import { FC, useEffect, useState } from 'react'; import { FC, useEffect, useState } from 'react';
import { LocalizeText } from '../../../../../../api'; import { LocalizeText } from '../../../../../../api';
import { SetRoomPreviewerStuffDataEvent } from '../../../../../../events';
import { dispatchUiEvent } from '../../../../../../hooks';
import { SendMessageHook } from '../../../../../../hooks/messages'; import { SendMessageHook } from '../../../../../../hooks/messages';
import { BadgeImageView } from '../../../../../shared/badge-image/BadgeImageView'; import { BadgeImageView } from '../../../../../shared/badge-image/BadgeImageView';
import { GetOfferName } from '../../../../common/CatalogUtilities'; import { GetOfferName } from '../../../../common/CatalogUtilities';
@ -13,14 +15,10 @@ import { CatalogLayoutGuildCustomFurniViewProps } from './CatalogLayoutGuildCust
export const CatalogLayouGuildCustomFurniView: FC<CatalogLayoutGuildCustomFurniViewProps> = props => export const CatalogLayouGuildCustomFurniView: FC<CatalogLayoutGuildCustomFurniViewProps> = props =>
{ {
const { roomPreviewer = null, pageParser = null } = props; const { roomPreviewer = null, pageParser = null } = props;
const [ selectedGroupIndex, setSelectedGroupIndex ] = useState<number>(0);
const { catalogState = null } = useCatalogContext(); const { catalogState = null } = useCatalogContext();
const { activeOffer = null, groups = null } = catalogState; const { activeOffer = null, groups = null } = catalogState;
const product = ((activeOffer && activeOffer.products[0]) || null);
const [ selectedGroupIndex, setSelectedGroupIndex ] = useState<number>(0);
useEffect(() => useEffect(() =>
{ {
SendMessageHook(new CatalogGroupsComposer()); SendMessageHook(new CatalogGroupsComposer());
@ -28,7 +26,7 @@ export const CatalogLayouGuildCustomFurniView: FC<CatalogLayoutGuildCustomFurniV
useEffect(() => useEffect(() =>
{ {
if(!groups[selectedGroupIndex]) return; if(!activeOffer || !groups[selectedGroupIndex]) return;
const productData = []; const productData = [];
productData.push('0'); productData.push('0');
@ -40,11 +38,13 @@ export const CatalogLayouGuildCustomFurniView: FC<CatalogLayoutGuildCustomFurniV
const stringDataType = new StringDataType(); const stringDataType = new StringDataType();
stringDataType.setValue(productData); stringDataType.setValue(productData);
roomPreviewer.updateObjectStuffData(stringDataType); dispatchUiEvent(new SetRoomPreviewerStuffDataEvent(activeOffer, stringDataType));
}, [ selectedGroupIndex, activeOffer ]); }, [ groups, selectedGroupIndex, activeOffer ]);
if(!groups) return null; if(!groups) return null;
const product = ((activeOffer && activeOffer.products[0]) || null);
return ( return (
<div className="row h-100 nitro-catalog-layout-guild-custom-furni"> <div className="row h-100 nitro-catalog-layout-guild-custom-furni">
<div className="d-flex flex-column col-7 h-100"> <div className="d-flex flex-column col-7 h-100">