From 77cb36be4481869a7afcb0870fcb92e0603d7f47 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 3 Apr 2022 14:50:31 -0400 Subject: [PATCH] Updates --- .../GetAchievementCategoryTotalUnseen.ts | 2 +- src/api/common/index.ts | 1 - src/api/index.ts | 2 +- .../handlers/RoomWidgetInfostandHandler.ts | 6 +- .../{common => utils}/ProductImageUtility.ts | 4 +- src/api/utils/index.ts | 1 + .../achievements/AchievementsView.tsx | 239 +++--------------- .../views/AchievementCategoryView.tsx | 30 ++- .../views/AchievementDetailsView.tsx | 5 +- .../AchievementListItemView.tsx | 12 +- .../achievement-list/AchievementListView.tsx | 8 +- .../AchievementsCategoryListItemView.tsx | 18 +- .../AchievementsCategoryListView.tsx | 10 +- .../checkout/CameraWidgetCheckoutView.tsx | 7 +- src/components/hc-center/HcCenterView.tsx | 39 +-- src/components/hotel-view/HotelView.tsx | 44 +--- .../views/badge/InventoryBadgeView.tsx | 2 +- .../NavigatorSearchResultItemInfoView.tsx | 8 +- src/components/purse/PurseView.tsx | 4 +- src/components/toolbar/ToolbarView.tsx | 51 +--- .../AchievementsUIUnseenCountEvent.ts | 20 -- src/events/achievements/index.ts | 1 - src/events/friends/FriendEnteredRoomEvent.ts | 48 ---- src/events/friends/index.ts | 1 - src/events/hc-center/HcCenterEvent.ts | 6 - src/events/hc-center/index.ts | 1 - src/events/index.ts | 4 - src/events/inventory/InventoryEvent.ts | 8 - .../inventory/InventoryTradeRequestEvent.ts | 27 -- .../inventory/InventoryTradeStartEvent.ts | 28 -- src/events/inventory/index.ts | 3 - src/hooks/achievements/index.ts | 1 + src/hooks/achievements/useAchievements.ts | 169 +++++++++++++ src/hooks/index.ts | 2 + src/hooks/inventory/useInventoryTrade.ts | 18 +- .../inventory/useInventoryUnseenTracker.ts | 12 +- src/hooks/session/index.ts | 1 + src/hooks/session/useSessionInfo.ts | 33 +++ 38 files changed, 341 insertions(+), 535 deletions(-) delete mode 100644 src/api/common/index.ts rename src/api/{common => utils}/ProductImageUtility.ts (94%) delete mode 100644 src/events/achievements/AchievementsUIUnseenCountEvent.ts delete mode 100644 src/events/achievements/index.ts delete mode 100644 src/events/friends/FriendEnteredRoomEvent.ts delete mode 100644 src/events/friends/index.ts delete mode 100644 src/events/hc-center/HcCenterEvent.ts delete mode 100644 src/events/hc-center/index.ts delete mode 100644 src/events/inventory/InventoryEvent.ts delete mode 100644 src/events/inventory/InventoryTradeRequestEvent.ts delete mode 100644 src/events/inventory/InventoryTradeStartEvent.ts delete mode 100644 src/events/inventory/index.ts create mode 100644 src/hooks/achievements/index.ts create mode 100644 src/hooks/achievements/useAchievements.ts create mode 100644 src/hooks/session/index.ts create mode 100644 src/hooks/session/useSessionInfo.ts diff --git a/src/api/achievements/GetAchievementCategoryTotalUnseen.ts b/src/api/achievements/GetAchievementCategoryTotalUnseen.ts index 940b7023..a2771275 100644 --- a/src/api/achievements/GetAchievementCategoryTotalUnseen.ts +++ b/src/api/achievements/GetAchievementCategoryTotalUnseen.ts @@ -6,7 +6,7 @@ export const GetAchievementCategoryTotalUnseen = (category: IAchievementCategory let unseen = 0; - for(const achievement of category.achievements) unseen += achievement.unseen; + for(const achievement of category.achievements) ((achievement.unseen > 0) && unseen++); return unseen; } diff --git a/src/api/common/index.ts b/src/api/common/index.ts deleted file mode 100644 index 8fa51bfb..00000000 --- a/src/api/common/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './ProductImageUtility'; diff --git a/src/api/index.ts b/src/api/index.ts index 612baf3d..92da5d94 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,13 +1,13 @@ export * from './achievements'; export * from './campaign'; export * from './catalog'; -export * from './common'; export * from './core'; export * from './friends'; export * from './GetRendererVersion'; export * from './GetUIVersion'; export * from './groups'; export * from './inventory'; +export * from './inventory/unseen'; export * from './navigator'; export * from './nitro'; export * from './nitro/avatar'; diff --git a/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts b/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts index 5ebf0902..1b620f2b 100644 --- a/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts +++ b/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts @@ -1,8 +1,8 @@ -import { IFurnitureData, NitroEvent, ObjectDataFactory, PetFigureData, PetRespectComposer, PetSupplementComposer, PetType, RoomControllerLevel, RoomModerationSettings, RoomObjectCategory, RoomObjectOperationType, RoomObjectType, RoomObjectVariable, RoomSessionFavoriteGroupUpdateEvent, RoomSessionPetInfoUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent, RoomTradingLevelEnum, RoomUnitDropHandItemComposer, RoomUnitGiveHandItemComposer, RoomUnitGiveHandItemPetComposer, RoomUserData, RoomWidgetEnum, RoomWidgetEnumItemExtradataParameter, Vector3d } from '@nitrots/nitro-renderer'; +import { IFurnitureData, NitroEvent, ObjectDataFactory, PetFigureData, PetRespectComposer, PetSupplementComposer, PetType, RoomControllerLevel, RoomModerationSettings, RoomObjectCategory, RoomObjectOperationType, RoomObjectType, RoomObjectVariable, RoomSessionFavoriteGroupUpdateEvent, RoomSessionPetInfoUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent, RoomTradingLevelEnum, RoomUnitDropHandItemComposer, RoomUnitGiveHandItemComposer, RoomUnitGiveHandItemPetComposer, RoomUserData, RoomWidgetEnum, RoomWidgetEnumItemExtradataParameter, TradingOpenComposer, Vector3d } from '@nitrots/nitro-renderer'; import { SendMessageComposer } from '../../..'; import { GetNitroInstance, GetRoomEngine, GetSessionDataManager, IsOwnerOfFurniture } from '../../../..'; import { PetSupplementEnum } from '../../../../../components/room/widgets/avatar-info/common/PetSupplementEnum'; -import { HelpReportUserEvent, InventoryTradeRequestEvent, WiredSelectObjectEvent } from '../../../../../events'; +import { HelpReportUserEvent, WiredSelectObjectEvent } from '../../../../../events'; import { DispatchUiEvent } from '../../../../../hooks'; import { LocalizeText } from '../../../../utils/LocalizeText'; import { RoomWidgetObjectNameEvent, RoomWidgetUpdateChatInputContentEvent, RoomWidgetUpdateEvent, RoomWidgetUpdateInfostandFurniEvent, RoomWidgetUpdateInfostandPetEvent, RoomWidgetUpdateInfostandRentableBotEvent, RoomWidgetUpdateInfostandUserEvent } from '../events'; @@ -119,7 +119,7 @@ export class RoomWidgetInfostandHandler extends RoomWidgetHandler this.container.roomSession.sendTakeRightsMessage((message as RoomWidgetUserActionMessage).userId); break; case RoomWidgetUserActionMessage.START_TRADING: - DispatchUiEvent(new InventoryTradeRequestEvent(userData.roomIndex, userData.name)); + SendMessageComposer(new TradingOpenComposer(userData.roomIndex)); break; // case RoomWidgetUserActionMessage.RWUAM_OPEN_HOME_PAGE: // this._container.sessionDataManager._Str_21275((message as RoomWidgetUserActionMessage).userId, _local_3.name); diff --git a/src/api/common/ProductImageUtility.ts b/src/api/utils/ProductImageUtility.ts similarity index 94% rename from src/api/common/ProductImageUtility.ts rename to src/api/utils/ProductImageUtility.ts index 460c8594..59c8c4f4 100644 --- a/src/api/common/ProductImageUtility.ts +++ b/src/api/utils/ProductImageUtility.ts @@ -1,6 +1,6 @@ import { CatalogPageMessageProductData } from '@nitrots/nitro-renderer'; -import { GetRoomEngine } from '..'; -import { FurniCategory } from '../../components/catalog/common/FurniCategory'; +import { FurniCategory } from '../inventory'; +import { GetRoomEngine } from '../nitro'; export class ProductImageUtility { diff --git a/src/api/utils/index.ts b/src/api/utils/index.ts index 398758cb..0b5596ee 100644 --- a/src/api/utils/index.ts +++ b/src/api/utils/index.ts @@ -6,6 +6,7 @@ export * from './LocalizeFormattedNumber'; export * from './LocalizeShortNumber'; export * from './LocalizeText'; export * from './PlaySound'; +export * from './ProductImageUtility'; export * from './Randomizer'; export * from './RoomChatFormatter'; export * from './SoundNames'; diff --git a/src/components/achievements/AchievementsView.tsx b/src/components/achievements/AchievementsView.tsx index 5809c88c..4b2c38d6 100644 --- a/src/components/achievements/AchievementsView.tsx +++ b/src/components/achievements/AchievementsView.tsx @@ -1,236 +1,69 @@ -import { AchievementData, AchievementEvent, AchievementsEvent, AchievementsScoreEvent, ILinkEventTracker, RequestAchievementsMessageComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useMemo, useState } from 'react'; -import { AchievementCategory, AddEventLinkTracker, CloneObject, GetAchievementCategoryImageUrl, GetAchievementIsIgnored, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; +import { ILinkEventTracker } from '@nitrots/nitro-renderer'; +import { FC, useEffect, useMemo, useState } from 'react'; +import { AddEventLinkTracker, GetAchievementCategoryImageUrl, LocalizeText, RemoveLinkEventTracker } from '../../api'; import { Base, Column, LayoutImage, LayoutProgressBar, NitroCardContentView, NitroCardHeaderView, NitroCardSubHeaderView, NitroCardView, Text } from '../../common'; -import { AchievementsUIUnseenCountEvent } from '../../events'; -import { DispatchUiEvent, UseMessageEventHook } from '../../hooks'; +import { useAchievements } from '../../hooks'; import { AchievementCategoryView } from './views/AchievementCategoryView'; import { AchievementsCategoryListView } from './views/category-list/AchievementsCategoryListView'; export const AchievementsView: FC<{}> = props => { const [ isVisible, setIsVisible ] = useState(false); - const [ isInitalized, setIsInitalized ] = useState(false); - const [ achievementCategories, setAchievementCategories ] = useState([]); - const [ selectedCategoryCode, setSelectedCategoryCode ] = useState(null); - const [ achievementScore, setAchievementScore ] = useState(0); + const { achievementCategories = [], selectedCategoryCode = null, setSelectedCategoryCode = null, selectedAchievementId = -1, setSelectedAchievementId = null, achievementScore = 0, getProgress = 0, getMaxProgress = 0, setAchievementSeen = null } = useAchievements(); - const onAchievementEvent = useCallback((event: AchievementEvent) => + const selectedCategory = useMemo(() => { - const parser = event.getParser(); - const achievement = parser.achievement; - const categoryName = achievement.category; + if(selectedCategoryCode === null) return null; - setAchievementCategories(prevValue => - { - const newValue = [ ...prevValue ]; - const categoryIndex = newValue.findIndex(existing => (existing.code === categoryName)); - - if(categoryIndex === -1) - { - const category = new AchievementCategory(categoryName); - - category.achievements.push(achievement); - - newValue.push(category); - } - else - { - const category = CloneObject(newValue[categoryIndex]); - const newAchievements = [ ...category.achievements ]; - const achievementIndex = newAchievements.findIndex(existing => (existing.achievementId === achievement.achievementId)); - let previousAchievement: AchievementData = null; - - if(achievementIndex === -1) - { - newAchievements.push(achievement); - } - else - { - previousAchievement = newAchievements[achievementIndex]; - - newAchievements[achievementIndex] = achievement; - } - - if(!GetAchievementIsIgnored(achievement)) - { - achievement.unseen++; - - if(previousAchievement) achievement.unseen += previousAchievement.unseen; - } - - category.achievements = newAchievements; - - newValue[categoryIndex] = category; - } - - return newValue; - }); - }, []); - - UseMessageEventHook(AchievementEvent, onAchievementEvent); - - const onAchievementsEvent = useCallback((event: AchievementsEvent) => - { - const parser = event.getParser(); - - const categories: AchievementCategory[] = []; - - for(const achievement of parser.achievements) - { - const categoryName = achievement.category; - - let existing = categories.find(category => (category.code === categoryName)); - - if(!existing) - { - existing = new AchievementCategory(categoryName); - - categories.push(existing); - } - - existing.achievements.push(achievement); - } - - setAchievementCategories(categories); - setIsInitalized(true); - }, []); - - UseMessageEventHook(AchievementsEvent, onAchievementsEvent); - - const onAchievementsScoreEvent = useCallback((event: AchievementsScoreEvent) => - { - const parser = event.getParser(); - - setAchievementScore(parser.score); - }, []); - - UseMessageEventHook(AchievementsScoreEvent, onAchievementsScoreEvent); - - const getTotalUnseen = useMemo(() => - { - let unseen = 0; - - for(const category of achievementCategories) - { - for(const achievement of category.achievements) unseen += achievement.unseen; - } - - return unseen; - }, [ achievementCategories ]); - - const getProgress = useMemo(() => - { - let progress = 0; - - for(const category of achievementCategories) progress += category.getProgress(); - - return progress; - }, [ achievementCategories ]); - - const getMaxProgress = useMemo(() => - { - let progress = 0; - - for(const category of achievementCategories) progress += category.getMaxProgress(); - - return progress; - }, [ achievementCategories ]); - - const scaledProgressPercent = useMemo(() => - { - return ~~((((getProgress - 0) * (100 - 0)) / (getMaxProgress - 0)) + 0); - }, [ getProgress, getMaxProgress ]); - - const getSelectedCategory = useMemo(() => - { - if(!achievementCategories || !achievementCategories.length) return null; - - return achievementCategories.find(existing => (existing.code === selectedCategoryCode)); + return achievementCategories.find(category => (category.code === selectedCategoryCode)); }, [ achievementCategories, selectedCategoryCode ]); - const setAchievementSeen = useCallback((code: string, achievementId: number) => - { - setAchievementCategories(prevValue => - { - const newValue = [ ...prevValue ]; - - for(const category of newValue) - { - if(category.code !== code) continue; - - for(const achievement of category.achievements) - { - if(achievement.achievementId !== achievementId) continue; - - achievement.unseen = 0; - } - } - - return newValue; - }); - }, []); - - const linkReceived = useCallback((url: string) => - { - const parts = url.split('/'); - - if(parts.length < 2) return; - - switch(parts[1]) - { - case 'show': - setIsVisible(true); - return; - case 'hide': - setIsVisible(false); - return; - case 'toggle': - setIsVisible(prevValue => !prevValue); - return; - } - }, []); - useEffect(() => { const linkTracker: ILinkEventTracker = { - linkReceived, + linkReceived: (url: string) => + { + const parts = url.split('/'); + + if(parts.length < 2) return; + + switch(parts[1]) + { + case 'show': + setIsVisible(true); + return; + case 'hide': + setIsVisible(false); + return; + case 'toggle': + setIsVisible(prevValue => !prevValue); + return; + } + }, eventUrlPrefix: 'achievements/' }; AddEventLinkTracker(linkTracker); return () => RemoveLinkEventTracker(linkTracker); - }, [ linkReceived ]); + }, []); - useEffect(() => - { - if(!isVisible || isInitalized) return; - - SendMessageComposer(new RequestAchievementsMessageComposer()); - }, [ isVisible, isInitalized ]); - - useEffect(() => - { - DispatchUiEvent(new AchievementsUIUnseenCountEvent(getTotalUnseen)); - }, [ getTotalUnseen ]); - - if(!isVisible || !isInitalized) return null; + if(!isVisible) return null; return ( setIsVisible(false) } /> - { getSelectedCategory && + { selectedCategory && setSelectedCategoryCode(null) } className="nitro-achievements-back-arrow" /> - { LocalizeText(`quests.${ getSelectedCategory.code }.name`) } - { LocalizeText('achievements.details.categoryprogress', [ 'progress', 'limit' ], [ getSelectedCategory.getProgress().toString(), getSelectedCategory.getMaxProgress().toString() ]) } + { LocalizeText(`quests.${ selectedCategory.code }.name`) } + { LocalizeText('achievements.details.categoryprogress', [ 'progress', 'limit' ], [ selectedCategory.getProgress().toString(), selectedCategory.getMaxProgress().toString() ]) } - + } - { !getSelectedCategory && + { !selectedCategory && <> @@ -238,8 +71,8 @@ export const AchievementsView: FC<{}> = props => } - { getSelectedCategory && - } + { selectedCategory && + } ); diff --git a/src/components/achievements/views/AchievementCategoryView.tsx b/src/components/achievements/views/AchievementCategoryView.tsx index e8a20579..d5834c7c 100644 --- a/src/components/achievements/views/AchievementCategoryView.tsx +++ b/src/components/achievements/views/AchievementCategoryView.tsx @@ -1,4 +1,4 @@ -import { FC, useEffect, useMemo, useState } from 'react'; +import { Dispatch, FC, SetStateAction, useEffect, useMemo } from 'react'; import { AchievementCategory } from '../../../api'; import { Column } from '../../../common'; import { AchievementListView } from './achievement-list/AchievementListView'; @@ -7,40 +7,44 @@ import { AchievementDetailsView } from './AchievementDetailsView'; interface AchievementCategoryViewProps { category: AchievementCategory; + selectedAchievementId: number; + setSelectedAchievementId: Dispatch>; setAchievementSeen: (code: string, achievementId: number) => void; } export const AchievementCategoryView: FC = props => { - const { category = null, setAchievementSeen = null } = props; - const [ selectedAchievementId, setSelectedAchievementId ] = useState(0); + const { category = null, selectedAchievementId = -1, setSelectedAchievementId = null, setAchievementSeen = null } = props; - const getSelectedAchievement = useMemo(() => + const selectedAchievement = useMemo(() => { - if(!category || !category.achievements.length) return null; + if(selectedAchievementId === -1) return null; - return category.achievements.find(existing => (existing.achievementId === selectedAchievementId)); + return category.achievements.find(achievement => (achievement.achievementId === selectedAchievementId)); }, [ category, selectedAchievementId ]); useEffect(() => { - setSelectedAchievementId((!category || !category.achievements.length) ? 0 : category.achievements[0].achievementId); - }, [ category ]); + if(!selectedAchievement) + { + if(category.achievements.length) setSelectedAchievementId(category.achievements[0].achievementId); + } + }, [ selectedAchievement, category, setSelectedAchievementId ]); useEffect(() => { - if(!getSelectedAchievement || !getSelectedAchievement.unseen) return; + if(!selectedAchievement) return; - setAchievementSeen(category.code, getSelectedAchievement.achievementId); - }, [ category, getSelectedAchievement, setAchievementSeen ]); + setAchievementSeen(category.code, selectedAchievement.achievementId); + }, [ selectedAchievement, category, setAchievementSeen ]); if(!category) return null; return ( - { getSelectedAchievement && - } + { !!selectedAchievement && + } ); } diff --git a/src/components/achievements/views/AchievementDetailsView.tsx b/src/components/achievements/views/AchievementDetailsView.tsx index 64532f52..0c0065a9 100644 --- a/src/components/achievements/views/AchievementDetailsView.tsx +++ b/src/components/achievements/views/AchievementDetailsView.tsx @@ -11,12 +11,12 @@ interface AchievementDetailsViewProps export const AchievementDetailsView: FC = props => { - const { achievement = null } = props; + const { achievement = null, children = null, ...rest } = props; if(!achievement) return null; return ( - + @@ -48,6 +48,7 @@ export const AchievementDetailsView: FC = props => } } + { children } ) } diff --git a/src/components/achievements/views/achievement-list/AchievementListItemView.tsx b/src/components/achievements/views/achievement-list/AchievementListItemView.tsx index 0041783b..1c1d0687 100644 --- a/src/components/achievements/views/achievement-list/AchievementListItemView.tsx +++ b/src/components/achievements/views/achievement-list/AchievementListItemView.tsx @@ -1,21 +1,23 @@ import { AchievementData } from '@nitrots/nitro-renderer'; -import { FC } from 'react'; -import { LayoutGridItem, LayoutGridItemProps } from '../../../../common'; +import { Dispatch, FC, SetStateAction } from 'react'; +import { LayoutGridItem } from '../../../../common'; import { AchievementBadgeView } from '../AchievementBadgeView'; -interface AchievementListItemViewProps extends LayoutGridItemProps +interface AchievementListItemViewProps { achievement: AchievementData; + selectedAchievementId: number; + setSelectedAchievementId: Dispatch>; } export const AchievementListItemView: FC = props => { - const { achievement = null, children = null, ...rest } = props; + const { achievement = null, selectedAchievementId = -1, setSelectedAchievementId = null, children = null, ...rest } = props; if(!achievement) return null; return ( - + 0) } onClick={ event => setSelectedAchievementId(achievement.achievementId) } { ...rest }> { children } diff --git a/src/components/achievements/views/achievement-list/AchievementListView.tsx b/src/components/achievements/views/achievement-list/AchievementListView.tsx index bad0ffe9..25cbb942 100644 --- a/src/components/achievements/views/achievement-list/AchievementListView.tsx +++ b/src/components/achievements/views/achievement-list/AchievementListView.tsx @@ -3,7 +3,7 @@ import { Dispatch, FC, SetStateAction } from 'react'; import { AutoGrid } from '../../../../common'; import { AchievementListItemView } from './AchievementListItemView'; -export interface AchievementListViewProps +interface AchievementListViewProps { achievements: AchievementData[]; selectedAchievementId: number; @@ -12,11 +12,11 @@ export interface AchievementListViewProps export const AchievementListView: FC = props => { - const { achievements = null, selectedAchievementId = 0, setSelectedAchievementId = null, children = null } = props; + const { achievements = null, selectedAchievementId = -1, setSelectedAchievementId = null, children = null, ...rest } = props; return ( - - { achievements && (achievements.length > 0) && achievements.map((achievement, index) => 0) } onClick={ event => setSelectedAchievementId(achievement.achievementId) } />) } + + { achievements && (achievements.length > 0) && achievements.map((achievement, index) => ) } { children } ); diff --git a/src/components/achievements/views/category-list/AchievementsCategoryListItemView.tsx b/src/components/achievements/views/category-list/AchievementsCategoryListItemView.tsx index 92661d9c..7b301486 100644 --- a/src/components/achievements/views/category-list/AchievementsCategoryListItemView.tsx +++ b/src/components/achievements/views/category-list/AchievementsCategoryListItemView.tsx @@ -1,15 +1,19 @@ -import { FC } from 'react'; +import { Dispatch, FC, SetStateAction } from 'react'; import { GetAchievementCategoryImageUrl, GetAchievementCategoryMaxProgress, GetAchievementCategoryProgress, GetAchievementCategoryTotalUnseen, IAchievementCategory, LocalizeText } from '../../../../api'; -import { LayoutBackgroundImage, LayoutGridItem, LayoutGridItemProps, Text } from '../../../../common'; +import { LayoutBackgroundImage, LayoutGridItem, Text } from '../../../../common'; -export interface AchievementCategoryListItemViewProps extends LayoutGridItemProps +interface AchievementCategoryListItemViewProps { category: IAchievementCategory; + selectedCategoryCode: string; + setSelectedCategoryCode: Dispatch>; } export const AchievementsCategoryListItemView: FC = props => { - const { category = null, children = null, ...rest } = props; + const { category = null, selectedCategoryCode = null, setSelectedCategoryCode = null, children = null, ...rest } = props; + + if(!category) return null; const progress = GetAchievementCategoryProgress(category); const maxProgress = GetAchievementCategoryMaxProgress(category); @@ -17,9 +21,9 @@ export const AchievementsCategoryListItemView: FC - { LocalizeText(`quests.${ category.code }.name`) } - + setSelectedCategoryCode(category.code) } { ...rest }> + { LocalizeText(`quests.${ category.code }.name`) } + { progress } / { maxProgress } { children } diff --git a/src/components/achievements/views/category-list/AchievementsCategoryListView.tsx b/src/components/achievements/views/category-list/AchievementsCategoryListView.tsx index f77dabbf..c0f51fa4 100644 --- a/src/components/achievements/views/category-list/AchievementsCategoryListView.tsx +++ b/src/components/achievements/views/category-list/AchievementsCategoryListView.tsx @@ -1,9 +1,9 @@ import { Dispatch, FC, SetStateAction } from 'react'; import { IAchievementCategory } from '../../../../api'; -import { AutoGrid, AutoGridProps } from '../../../../common'; +import { AutoGrid } from '../../../../common'; import { AchievementsCategoryListItemView } from './AchievementsCategoryListItemView'; -export interface AchievementsCategoryListViewProps extends AutoGridProps +interface AchievementsCategoryListViewProps { categories: IAchievementCategory[]; selectedCategoryCode: string; @@ -12,11 +12,11 @@ export interface AchievementsCategoryListViewProps extends AutoGridProps export const AchievementsCategoryListView: FC = props => { - const { categories = null, selectedCategoryCode = null, setSelectedCategoryCode = null, columnCount = 3, columnMinWidth = 90, columnMinHeight = 100, children = null, ...rest } = props; + const { categories = null, selectedCategoryCode = null, setSelectedCategoryCode = null, children = null, ...rest } = props; return ( - - { categories && (categories.length > 0) && categories.map((category, index) => setSelectedCategoryCode(category.code) } /> ) } + + { categories && (categories.length > 0) && categories.map((category, index) => ) } { children } ); diff --git a/src/components/camera/views/checkout/CameraWidgetCheckoutView.tsx b/src/components/camera/views/checkout/CameraWidgetCheckoutView.tsx index a399d1ac..2c8680f3 100644 --- a/src/components/camera/views/checkout/CameraWidgetCheckoutView.tsx +++ b/src/components/camera/views/checkout/CameraWidgetCheckoutView.tsx @@ -1,9 +1,8 @@ import { CameraPublishStatusMessageEvent, CameraPurchaseOKMessageEvent, CameraStorageUrlMessageEvent, PublishPhotoMessageComposer, PurchasePhotoMessageComposer } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useMemo, useState } from 'react'; -import { GetConfiguration, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api'; +import { CreateLinkEvent, GetConfiguration, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api'; import { Button, Column, Flex, LayoutCurrencyIcon, LayoutImage, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; -import { InventoryEvent } from '../../../../events'; -import { DispatchUiEvent, UseMessageEventHook } from '../../../../hooks'; +import { UseMessageEventHook } from '../../../../hooks'; export interface CameraWidgetCheckoutViewProps { @@ -122,7 +121,7 @@ export const CameraWidgetCheckoutView: FC = props { (picturesBought > 0) && { LocalizeText('camera.purchase.count.info') } { picturesBought } - DispatchUiEvent(new InventoryEvent(InventoryEvent.SHOW_INVENTORY)) }>{ LocalizeText('camera.open.inventory') } + CreateLinkEvent('inventory/open') }>{ LocalizeText('camera.open.inventory') } } diff --git a/src/components/hc-center/HcCenterView.tsx b/src/components/hc-center/HcCenterView.tsx index 4a5fd5cc..94f70260 100644 --- a/src/components/hc-center/HcCenterView.tsx +++ b/src/components/hc-center/HcCenterView.tsx @@ -1,10 +1,9 @@ -import { BadgesEvent, ClubGiftInfoEvent, FigureUpdateEvent, FriendlyTime, GetClubGiftInfo, ILinkEventTracker, RequestBadgesComposer, ScrGetKickbackInfoMessageComposer, ScrKickbackData, ScrSendKickbackInfoMessageEvent, UserInfoEvent, UserSubscriptionEvent } from '@nitrots/nitro-renderer'; +import { BadgesEvent, ClubGiftInfoEvent, FriendlyTime, GetClubGiftInfo, ILinkEventTracker, RequestBadgesComposer, ScrGetKickbackInfoMessageComposer, ScrKickbackData, ScrSendKickbackInfoMessageEvent, UserSubscriptionEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; import { OverlayTrigger, Popover } from 'react-bootstrap'; import { AddEventLinkTracker, CreateLinkEvent, GetConfiguration, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; import { Base, Button, Column, Flex, LayoutAvatarImageView, LayoutBadgeImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../common'; -import { HcCenterEvent } from '../../events'; -import { UseMessageEventHook, UseUiEvent } from '../../hooks'; +import { UseMessageEventHook, useSessionInfo } from '../../hooks'; import { BadgeResolver } from './common/BadgeResolver'; import { ClubStatus } from './common/ClubStatus'; @@ -12,7 +11,6 @@ import { ClubStatus } from './common/ClubStatus'; export const HcCenterView: FC<{}> = props => { const [ isVisible, setIsVisible ] = useState(false); - const [ userFigure, setUserFigure ] = useState(null); const [ kickbackData, setKickbackData ] = useState(null); const [ clubDays, setClubDays ] = useState(0); const [ pastClubDays, setPastClubDays ] = useState(0); @@ -21,6 +19,7 @@ export const HcCenterView: FC<{}> = props => const [ clubStatus, setClubStatus ] = useState(ClubStatus.NONE); const [ unclaimedGifts, setUnclaimedGifts ] = useState(0); const [ badgeCode, setBadgeCode ] = useState(BadgeResolver.default_badge); + const { userFigure = null } = useSessionInfo(); const getClubText = () => { @@ -64,36 +63,6 @@ export const HcCenterView: FC<{}> = props => return LocalizeText('hccenter.special.sum', [ 'credits' ], [ (kickbackData.creditRewardForStreakBonus + kickbackData.creditRewardForMonthlySpent).toString() ]); } - const onUserInfoEvent = useCallback((event: UserInfoEvent) => - { - const parser = event.getParser(); - - setUserFigure(parser.userInfo.figure); - }, []); - - UseMessageEventHook(UserInfoEvent, onUserInfoEvent); - - const onUserFigureEvent = useCallback((event: FigureUpdateEvent) => - { - const parser = event.getParser(); - - setUserFigure(parser.figure); - }, []); - - UseMessageEventHook(FigureUpdateEvent, onUserFigureEvent); - - const onHcCenterEvent = useCallback((event: HcCenterEvent) => - { - switch(event.type) - { - case HcCenterEvent.TOGGLE_HC_CENTER: - setIsVisible(!isVisible); - break; - } - }, [ isVisible ]); - - UseUiEvent(HcCenterEvent.TOGGLE_HC_CENTER, onHcCenterEvent); - const onClubGiftInfoEvent = useCallback((event: ClubGiftInfoEvent) => { const parser = event.getParser(); @@ -265,7 +234,7 @@ export const HcCenterView: FC<{}> = props =>
{LocalizeText('hccenter.special.amount.title')}
{getHcPaydayAmount()}
- +
{LocalizeText('hccenter.breakdown.infolink')}
diff --git a/src/components/hotel-view/HotelView.tsx b/src/components/hotel-view/HotelView.tsx index 13df886f..51d3eeab 100644 --- a/src/components/hotel-view/HotelView.tsx +++ b/src/components/hotel-view/HotelView.tsx @@ -1,36 +1,16 @@ -import { FigureUpdateEvent, RoomSessionEvent, UserInfoDataParser, UserInfoEvent } from '@nitrots/nitro-renderer'; +import { RoomSessionEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useState } from 'react'; import { GetConfiguration, GetConfigurationManager } from '../../api'; import { LayoutAvatarImageView } from '../../common'; -import { UseMessageEventHook, UseRoomSessionManagerEvent } from '../../hooks'; +import { UseRoomSessionManagerEvent, useSessionInfo } from '../../hooks'; import { WidgetSlotView } from './views/widgets/WidgetSlotView'; + +const widgetSlotCount = 7; + export const HotelView: FC<{}> = props => { const [ isVisible, setIsVisible ] = useState(true); - const widgetSlotCount = 7; - const [ userFigure, setUserFigure ] = useState(null); - const [ userInfo, setUserInfo ] = useState(null); - - - const onUserInfoEvent = useCallback((event: UserInfoEvent) => - { - const parser = event.getParser(); - - setUserInfo(parser.userInfo); - setUserFigure(parser.userInfo.figure); - }, []); - - UseMessageEventHook(UserInfoEvent, onUserInfoEvent); - - const onUserFigureEvent = useCallback((event: FigureUpdateEvent) => - { - const parser = event.getParser(); - - setUserFigure(parser.figure); - }, []); - - UseMessageEventHook(FigureUpdateEvent, onUserFigureEvent); - + const { userFigure = null } = useSessionInfo(); const onRoomSessionEvent = useCallback((event: RoomSessionEvent) => { @@ -51,12 +31,12 @@ export const HotelView: FC<{}> = props => if(!isVisible) return null; const backgroundColor = GetConfiguration('hotelview')['images']['background.colour']; - const background = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['background']); - const sun = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['sun']); - const drape = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['drape']); - const left = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['left']); - const rightRepeat = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['right.repeat']); - const right = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['right']); + const background = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['background']); + const sun = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['sun']); + const drape = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['drape']); + const left = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['left']); + const rightRepeat = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['right.repeat']); + const right = GetConfigurationManager().interpolate(GetConfiguration('hotelview')['images']['right']); return (
diff --git a/src/components/inventory/views/badge/InventoryBadgeView.tsx b/src/components/inventory/views/badge/InventoryBadgeView.tsx index 336899b6..eb4e2fbe 100644 --- a/src/components/inventory/views/badge/InventoryBadgeView.tsx +++ b/src/components/inventory/views/badge/InventoryBadgeView.tsx @@ -8,7 +8,7 @@ export const InventoryBadgeView: FC<{}> = props => { const [ isVisible, setIsVisible ] = useState(false); const { badgeCodes = [], activeBadgeCodes = [], selectedBadgeCode = null, isWearingBadge = null, canWearBadges = null, toggleBadge = null, getBadgeId = null, activate = null, deactivate = null } = useInventoryBadges(); - const { getCount = null, resetCategory = null, isUnseen = null, removeUnseen = null } = useInventoryUnseenTracker(); + const { isUnseen = null, removeUnseen = null } = useInventoryUnseenTracker(); useEffect(() => { diff --git a/src/components/navigator/views/search/NavigatorSearchResultItemInfoView.tsx b/src/components/navigator/views/search/NavigatorSearchResultItemInfoView.tsx index cbca0af4..6b1959c9 100644 --- a/src/components/navigator/views/search/NavigatorSearchResultItemInfoView.tsx +++ b/src/components/navigator/views/search/NavigatorSearchResultItemInfoView.tsx @@ -70,9 +70,9 @@ export const NavigatorSearchResultItemInfoView: FC {roomData.habboGroupId > 0 && ( - )} + )} {roomData.doorMode !== RoomDataParser.OPEN_STATE && ( - )} + )} @@ -80,7 +80,7 @@ export const NavigatorSearchResultItemInfoView: FC - {LocalizeText("navigator.roomownercaption")} + {LocalizeText('navigator.roomownercaption')} {roomData.description} - + {roomData.userCount} diff --git a/src/components/purse/PurseView.tsx b/src/components/purse/PurseView.tsx index eef8db1e..fa8c14dd 100644 --- a/src/components/purse/PurseView.tsx +++ b/src/components/purse/PurseView.tsx @@ -2,7 +2,7 @@ import { ActivityPointNotificationMessageEvent, FriendlyTime, HabboClubLevelEnum import { FC, useCallback, useEffect, useMemo, useState } from 'react'; import { CreateLinkEvent, GetConfiguration, LocalizeText, PlaySound, SendMessageComposer, SoundNames } from '../../api'; import { Column, Flex, Grid, LayoutCurrencyIcon, Text } from '../../common'; -import { HcCenterEvent, UserSettingsUIEvent } from '../../events'; +import { UserSettingsUIEvent } from '../../events'; import { DispatchUiEvent, UseMessageEventHook } from '../../hooks'; import { IPurse } from './common/IPurse'; import { Purse } from './common/Purse'; @@ -179,7 +179,7 @@ export const PurseView: FC<{}> = props => { getCurrencyElements(0, 2) } { !hcDisabled && - DispatchUiEvent(new HcCenterEvent(HcCenterEvent.TOGGLE_HC_CENTER)) }> + CreateLinkEvent('habboUI/open/hccenter') }> { getClubText } } diff --git a/src/components/toolbar/ToolbarView.tsx b/src/components/toolbar/ToolbarView.tsx index 213f6196..cc78c737 100644 --- a/src/components/toolbar/ToolbarView.tsx +++ b/src/components/toolbar/ToolbarView.tsx @@ -1,44 +1,24 @@ -import { Dispose, DropBounce, EaseOut, FigureUpdateEvent, JumpBy, Motions, NitroToolbarAnimateIconEvent, PerkAllowancesMessageEvent, PerkEnum, Queue, UserInfoDataParser, UserInfoEvent, Wait } from '@nitrots/nitro-renderer'; +import { Dispose, DropBounce, EaseOut, JumpBy, Motions, NitroToolbarAnimateIconEvent, PerkAllowancesMessageEvent, PerkEnum, Queue, Wait } from '@nitrots/nitro-renderer'; import { FC, useCallback, useState } from 'react'; import { CreateLinkEvent, GetSessionDataManager, MessengerIconState, OpenMessengerChat, VisitDesktop } from '../../api'; import { Base, Flex, LayoutAvatarImageView, LayoutItemCountView, TransitionAnimation, TransitionAnimationTypes } from '../../common'; -import { AchievementsUIUnseenCountEvent, ModToolsEvent } from '../../events'; -import { DispatchUiEvent, useFriends, useInventoryUnseenTracker, UseMessageEventHook, useMessenger, UseRoomEngineEvent, UseUiEvent } from '../../hooks'; +import { ModToolsEvent } from '../../events'; +import { DispatchUiEvent, useAchievements, useFriends, useInventoryUnseenTracker, UseMessageEventHook, useMessenger, UseRoomEngineEvent, useSessionInfo } from '../../hooks'; import { ToolbarMeView } from './ToolbarMeView'; export const ToolbarView: FC<{ isInRoom: boolean }> = props => { const { isInRoom } = props; - const [ userInfo, setUserInfo ] = useState(null); - const [ userFigure, setUserFigure ] = useState(null); const [ isMeExpanded, setMeExpanded ] = useState(false); const [ useGuideTool, setUseGuideTool ] = useState(false); - const [ unseenAchievementCount, setUnseenAchievementCount ] = useState(0); - const { getFullCount = null } = useInventoryUnseenTracker(); + const { userFigure = null } = useSessionInfo(); + const { getFullCount = 0 } = useInventoryUnseenTracker(); + const { getTotalUnseen = 0 } = useAchievements(); const { requests = [] } = useFriends(); const { iconState = MessengerIconState.HIDDEN } = useMessenger(); const isMod = GetSessionDataManager().isModerator; - const onUserInfoEvent = useCallback((event: UserInfoEvent) => - { - const parser = event.getParser(); - - setUserInfo(parser.userInfo); - setUserFigure(parser.userInfo.figure); - }, []); - - UseMessageEventHook(UserInfoEvent, onUserInfoEvent); - - const onUserFigureEvent = useCallback((event: FigureUpdateEvent) => - { - const parser = event.getParser(); - - setUserFigure(parser.figure); - }, []); - - UseMessageEventHook(FigureUpdateEvent, onUserFigureEvent); - const onPerkAllowancesMessageEvent = useCallback((event: PerkAllowancesMessageEvent) => { const parser = event.getParser(); @@ -48,13 +28,6 @@ export const ToolbarView: FC<{ isInRoom: boolean }> = props => UseMessageEventHook(PerkAllowancesMessageEvent, onPerkAllowancesMessageEvent); - const onAchievementsUIUnseenCountEvent = useCallback((event: AchievementsUIUnseenCountEvent) => - { - setUnseenAchievementCount(event.count); - }, []); - - UseUiEvent(AchievementsUIUnseenCountEvent.UNSEEN_COUNT, onAchievementsUIUnseenCountEvent); - const animationIconToToolbar = useCallback((iconName: string, image: HTMLImageElement, x: number, y: number) => { const target = (document.body.getElementsByClassName(iconName)[0] as HTMLElement); @@ -96,20 +69,18 @@ export const ToolbarView: FC<{ isInRoom: boolean }> = props => UseRoomEngineEvent(NitroToolbarAnimateIconEvent.ANIMATE_ICON, onNitroToolbarAnimateIconEvent); - const unseenInventoryCount = getFullCount(); - return ( <> - + setMeExpanded(!isMeExpanded) }> - { (unseenAchievementCount > 0) && - } + { (getTotalUnseen > 0) && + } { isInRoom && VisitDesktop() } /> } @@ -118,8 +89,8 @@ export const ToolbarView: FC<{ isInRoom: boolean }> = props => CreateLinkEvent('navigator/toggle') } /> CreateLinkEvent('catalog/toggle') } /> CreateLinkEvent('inventory/toggle') }> - { (unseenInventoryCount > 0) && - } + { (getFullCount > 0) && + } { isInRoom && CreateLinkEvent('camera/toggle') } /> } diff --git a/src/events/achievements/AchievementsUIUnseenCountEvent.ts b/src/events/achievements/AchievementsUIUnseenCountEvent.ts deleted file mode 100644 index 330e991c..00000000 --- a/src/events/achievements/AchievementsUIUnseenCountEvent.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class AchievementsUIUnseenCountEvent extends NitroEvent -{ - public static UNSEEN_COUNT: string = 'AUUCE_UNSEEN_COUNT'; - - private _count: number; - - constructor(count: number) - { - super(AchievementsUIUnseenCountEvent.UNSEEN_COUNT); - - this._count = count; - } - - public get count(): number - { - return this._count; - } -} diff --git a/src/events/achievements/index.ts b/src/events/achievements/index.ts deleted file mode 100644 index 9bebf51d..00000000 --- a/src/events/achievements/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './AchievementsUIUnseenCountEvent'; diff --git a/src/events/friends/FriendEnteredRoomEvent.ts b/src/events/friends/FriendEnteredRoomEvent.ts deleted file mode 100644 index 698e5407..00000000 --- a/src/events/friends/FriendEnteredRoomEvent.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class FriendEnteredRoomEvent extends NitroEvent -{ - public static ENTERED: string = 'FERE_ENTERED'; - - private _roomIndex: number; - private _category: number; - private _id: number; - private _name: string; - private _userType: number; - - constructor(roomIndex: number, category: number, id: number, name: string, userType: number) - { - super(FriendEnteredRoomEvent.ENTERED); - - this._roomIndex = roomIndex; - this._category = category; - this._id = id; - this._name = name; - this._userType = userType; - } - - public get roomIndex(): number - { - return this._roomIndex; - } - - public get category(): number - { - return this._category; - } - - public get id(): number - { - return this._id; - } - - public get name(): string - { - return this._name; - } - - public get userType(): number - { - return this._userType; - } -} diff --git a/src/events/friends/index.ts b/src/events/friends/index.ts deleted file mode 100644 index fe4cbb5b..00000000 --- a/src/events/friends/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './FriendEnteredRoomEvent'; diff --git a/src/events/hc-center/HcCenterEvent.ts b/src/events/hc-center/HcCenterEvent.ts deleted file mode 100644 index 1beec349..00000000 --- a/src/events/hc-center/HcCenterEvent.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class HcCenterEvent extends NitroEvent -{ - public static TOGGLE_HC_CENTER: string = 'HCC_TOGGLE'; -} diff --git a/src/events/hc-center/index.ts b/src/events/hc-center/index.ts deleted file mode 100644 index 8bea7bdc..00000000 --- a/src/events/hc-center/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './HcCenterEvent'; diff --git a/src/events/index.ts b/src/events/index.ts index bb569cd6..fd1f1572 100644 --- a/src/events/index.ts +++ b/src/events/index.ts @@ -1,11 +1,7 @@ -export * from './achievements'; export * from './catalog'; export * from './floorplan-editor'; -export * from './friends'; export * from './guide-tool'; -export * from './hc-center'; export * from './help'; -export * from './inventory'; export * from './mod-tools'; export * from './notification-center'; export * from './room-widgets'; diff --git a/src/events/inventory/InventoryEvent.ts b/src/events/inventory/InventoryEvent.ts deleted file mode 100644 index 94d242dd..00000000 --- a/src/events/inventory/InventoryEvent.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class InventoryEvent extends NitroEvent -{ - public static SHOW_INVENTORY: string = 'IE_SHOW_INVENTORY'; - public static HIDE_INVENTORY: string = 'IE_HIDE_INVENTORY'; - public static TOGGLE_INVENTORY: string = 'IE_TOGGLE_INVENTORY'; -} diff --git a/src/events/inventory/InventoryTradeRequestEvent.ts b/src/events/inventory/InventoryTradeRequestEvent.ts deleted file mode 100644 index 8cc0ee9f..00000000 --- a/src/events/inventory/InventoryTradeRequestEvent.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { InventoryEvent } from './InventoryEvent'; - -export class InventoryTradeRequestEvent extends InventoryEvent -{ - public static REQUEST_TRADE: string = 'ITSE_REQUEST_TRADE'; - - private _objectId: number; - private _username: string; - - constructor(objectId: number, username: string) - { - super(InventoryTradeRequestEvent.REQUEST_TRADE); - - this._objectId = objectId; - this._username = username; - } - - public get objectId(): number - { - return this._objectId; - } - - public get username(): string - { - return this._username; - } -} diff --git a/src/events/inventory/InventoryTradeStartEvent.ts b/src/events/inventory/InventoryTradeStartEvent.ts deleted file mode 100644 index afe5a386..00000000 --- a/src/events/inventory/InventoryTradeStartEvent.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { TradeUserData } from '../../api'; -import { InventoryEvent } from './InventoryEvent'; - -export class InventoryTradeStartEvent extends InventoryEvent -{ - public static START_TRADE: string = 'ITSE_START_TRADE'; - - private _ownUserTradeData: TradeUserData; - private _otherUserTradeData: TradeUserData; - - constructor(ownUserTradeData: TradeUserData, otherUserTradeData: TradeUserData) - { - super(InventoryTradeStartEvent.START_TRADE); - - this._ownUserTradeData = ownUserTradeData; - this._otherUserTradeData = otherUserTradeData; - } - - public get ownUserTradeData(): TradeUserData - { - return this._ownUserTradeData; - } - - public get otherUserTradeData(): TradeUserData - { - return this._otherUserTradeData; - } -} diff --git a/src/events/inventory/index.ts b/src/events/inventory/index.ts deleted file mode 100644 index e795837f..00000000 --- a/src/events/inventory/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './InventoryEvent'; -export * from './InventoryTradeRequestEvent'; -export * from './InventoryTradeStartEvent'; diff --git a/src/hooks/achievements/index.ts b/src/hooks/achievements/index.ts new file mode 100644 index 00000000..1a2a81e1 --- /dev/null +++ b/src/hooks/achievements/index.ts @@ -0,0 +1 @@ +export * from './useAchievements'; diff --git a/src/hooks/achievements/useAchievements.ts b/src/hooks/achievements/useAchievements.ts new file mode 100644 index 00000000..7b06bd4c --- /dev/null +++ b/src/hooks/achievements/useAchievements.ts @@ -0,0 +1,169 @@ +import { AchievementData, AchievementEvent, AchievementsEvent, AchievementsScoreEvent, RequestAchievementsMessageComposer } from '@nitrots/nitro-renderer'; +import { useCallback, useEffect, useMemo, useState } from 'react'; +import { AchievementCategory, CloneObject, GetAchievementCategoryTotalUnseen, GetAchievementIsIgnored, SendMessageComposer } from '../../api'; +import { UseMessageEventHook } from '../messages'; + +const useAchievementsState = () => +{ + const [ needsUpdate, setNeedsUpdate ] = useState(true); + const [ achievementCategories, setAchievementCategories ] = useState([]); + const [ selectedCategoryCode, setSelectedCategoryCode ] = useState(null); + const [ selectedAchievementId, setSelectedAchievementId ] = useState(-1); + const [ achievementScore, setAchievementScore ] = useState(0); + + const getTotalUnseen = useMemo(() => + { + let unseen = 0; + + achievementCategories.forEach(category => unseen += GetAchievementCategoryTotalUnseen(category)); + + return unseen; + }, [ achievementCategories ]); + + const getProgress = useMemo(() => + { + let progress = 0; + + achievementCategories.forEach(category => (progress += category.getProgress())); + + return progress; + }, [ achievementCategories ]); + + const getMaxProgress = useMemo(() => + { + let progress = 0; + + achievementCategories.forEach(category => (progress += category.getMaxProgress())); + + return progress; + }, [ achievementCategories ]); + + const scaledProgressPercent = useMemo(() => + { + return ~~((((getProgress - 0) * (100 - 0)) / (getMaxProgress - 0)) + 0); + }, [ getProgress, getMaxProgress ]); + + const setAchievementSeen = useCallback((categoryCode: string, achievementId: number) => + { + setAchievementCategories(prevValue => + { + const newValue = [ ...prevValue ]; + + for(const category of newValue) + { + if(category.code !== categoryCode) continue; + + for(const achievement of category.achievements) + { + if(achievement.achievementId !== achievementId) continue; + + achievement.unseen = 0; + } + } + + return newValue; + }); + }, []); + + const onAchievementEvent = useCallback((event: AchievementEvent) => + { + const parser = event.getParser(); + const achievement = parser.achievement; + + setAchievementCategories(prevValue => + { + const newValue = [ ...prevValue ]; + const categoryIndex = newValue.findIndex(existing => (existing.code === achievement.category)); + + if(categoryIndex === -1) + { + const category = new AchievementCategory(achievement.category); + + category.achievements.push(achievement); + + newValue.push(category); + } + else + { + const category = CloneObject(newValue[categoryIndex]); + const newAchievements = [ ...category.achievements ]; + const achievementIndex = newAchievements.findIndex(existing => (existing.achievementId === achievement.achievementId)); + let previousAchievement: AchievementData = null; + + if(achievementIndex === -1) + { + newAchievements.push(achievement); + } + else + { + previousAchievement = newAchievements[achievementIndex]; + + newAchievements[achievementIndex] = achievement; + } + + if(!GetAchievementIsIgnored(achievement)) + { + achievement.unseen++; + + if(previousAchievement) achievement.unseen += previousAchievement.unseen; + } + + category.achievements = newAchievements; + + newValue[categoryIndex] = category; + } + + return newValue; + }); + }, []); + + UseMessageEventHook(AchievementEvent, onAchievementEvent); + + const onAchievementsEvent = useCallback((event: AchievementsEvent) => + { + const parser = event.getParser(); + const categories: AchievementCategory[] = []; + + for(const achievement of parser.achievements) + { + const categoryName = achievement.category; + + let existing = categories.find(category => (category.code === categoryName)); + + if(!existing) + { + existing = new AchievementCategory(categoryName); + + categories.push(existing); + } + + existing.achievements.push(achievement); + } + + setAchievementCategories(categories); + }, []); + + UseMessageEventHook(AchievementsEvent, onAchievementsEvent); + + const onAchievementsScoreEvent = useCallback((event: AchievementsScoreEvent) => + { + const parser = event.getParser(); + + setAchievementScore(parser.score); + }, []); + + UseMessageEventHook(AchievementsScoreEvent, onAchievementsScoreEvent); + + useEffect(() => + { + if(!needsUpdate) return; + + SendMessageComposer(new RequestAchievementsMessageComposer()); + + setNeedsUpdate(false); + }, [ needsUpdate ]); + + return { achievementCategories, selectedCategoryCode, setSelectedCategoryCode, selectedAchievementId, setSelectedAchievementId, achievementScore, getTotalUnseen, getProgress, getMaxProgress, scaledProgressPercent, setAchievementSeen }; +} + +export const useAchievements = useAchievementsState; diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 80612b06..f072b824 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1,3 +1,4 @@ +export * from './achievements'; export * from './events'; export * from './events/core'; export * from './events/nitro'; @@ -6,5 +7,6 @@ export * from './friends'; export * from './inventory'; export * from './messages'; export * from './navigator'; +export * from './session'; export * from './UseMountEffect'; export * from './useSharedVisibility'; diff --git a/src/hooks/inventory/useInventoryTrade.ts b/src/hooks/inventory/useInventoryTrade.ts index 0d208b52..72166600 100644 --- a/src/hooks/inventory/useInventoryTrade.ts +++ b/src/hooks/inventory/useInventoryTrade.ts @@ -1,11 +1,9 @@ -import { AdvancedMap, TradingAcceptComposer, TradingAcceptEvent, TradingCancelComposer, TradingCloseComposer, TradingCloseEvent, TradingCloseParser, TradingCompletedEvent, TradingConfirmationComposer, TradingConfirmationEvent, TradingListItemEvent, TradingListItemRemoveComposer, TradingNotOpenEvent, TradingOpenComposer, TradingOpenEvent, TradingOpenFailedEvent, TradingOtherNotAllowedEvent, TradingUnacceptComposer, TradingYouAreNotAllowedEvent } from '@nitrots/nitro-renderer'; +import { AdvancedMap, TradingAcceptComposer, TradingAcceptEvent, TradingCancelComposer, TradingCloseComposer, TradingCloseEvent, TradingCloseParser, TradingCompletedEvent, TradingConfirmationComposer, TradingConfirmationEvent, TradingListItemEvent, TradingListItemRemoveComposer, TradingNotOpenEvent, TradingOpenEvent, TradingOpenFailedEvent, TradingOtherNotAllowedEvent, TradingUnacceptComposer, TradingYouAreNotAllowedEvent } from '@nitrots/nitro-renderer'; import { useCallback, useEffect, useState } from 'react'; import { useBetween } from 'use-between'; import { useInventoryFurni } from '.'; import { UseMessageEventHook } from '..'; import { CloneObject, GetRoomSession, GetSessionDataManager, GroupItem, LocalizeText, NotificationUtilities, parseTradeItems, SendMessageComposer, TradeState, TradeUserData, TradingNotificationMessage, TradingNotificationType } from '../../api'; -import { InventoryTradeRequestEvent } from '../../events'; -import { UseUiEvent } from '../events'; const useInventoryTradeState = () => { @@ -66,20 +64,6 @@ const useInventoryTradeState = () => } } - const onInventoryTradeRequestEvent = useCallback((event: InventoryTradeRequestEvent) => - { - switch(event.type) - { - case InventoryTradeRequestEvent.REQUEST_TRADE: { - const tradeEvent = (event as InventoryTradeRequestEvent); - - SendMessageComposer(new TradingOpenComposer(tradeEvent.objectId)); - } - } - }, []); - - UseUiEvent(InventoryTradeRequestEvent.REQUEST_TRADE, onInventoryTradeRequestEvent); - const onTradingAcceptEvent = useCallback((event: TradingAcceptEvent) => { const parser = event.getParser(); diff --git a/src/hooks/inventory/useInventoryUnseenTracker.ts b/src/hooks/inventory/useInventoryUnseenTracker.ts index 939a21a5..fe21007e 100644 --- a/src/hooks/inventory/useInventoryUnseenTracker.ts +++ b/src/hooks/inventory/useInventoryUnseenTracker.ts @@ -1,5 +1,5 @@ import { UnseenItemsEvent, UnseenResetCategoryComposer, UnseenResetItemsComposer } from '@nitrots/nitro-renderer'; -import { useCallback, useState } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import { useBetween } from 'use-between'; import { UseMessageEventHook } from '..'; import { SendMessageComposer } from '../../api'; @@ -10,17 +10,17 @@ const sendResetItemsMessage = (category: number, itemIds: number[]) => SendMessa const useInventoryUnseenTrackerState = () => { const [ unseenItems, setUnseenItems ] = useState>(new Map()); - const getIds = (category: number) => unseenItems.get(category); - const getCount = (category: number) => (unseenItems.get(category)?.length || 0); - const getFullCount = () => + const getCount = useCallback((category: number) => (unseenItems.get(category)?.length || 0), [ unseenItems ]); + + const getFullCount = useMemo(() => { let count = 0; for(const key of unseenItems.keys()) count += getCount(key); return count; - } + }, [ unseenItems, getCount ]); const resetCategory = useCallback((category: number) => { @@ -128,7 +128,7 @@ const useInventoryUnseenTrackerState = () => UseMessageEventHook(UnseenItemsEvent, onUnseenItemsEvent); - return { getIds, getCount, getFullCount, resetCategory, resetItems, isUnseen, removeUnseen }; + return { getCount, getFullCount, resetCategory, resetItems, isUnseen, removeUnseen }; } export const useInventoryUnseenTracker = () => useBetween(useInventoryUnseenTrackerState); diff --git a/src/hooks/session/index.ts b/src/hooks/session/index.ts new file mode 100644 index 00000000..e61c7f33 --- /dev/null +++ b/src/hooks/session/index.ts @@ -0,0 +1 @@ +export * from './useSessionInfo'; diff --git a/src/hooks/session/useSessionInfo.ts b/src/hooks/session/useSessionInfo.ts new file mode 100644 index 00000000..39c102f6 --- /dev/null +++ b/src/hooks/session/useSessionInfo.ts @@ -0,0 +1,33 @@ +import { FigureUpdateEvent, UserInfoDataParser, UserInfoEvent } from '@nitrots/nitro-renderer'; +import { useCallback, useState } from 'react'; +import { useBetween } from 'use-between'; +import { UseMessageEventHook } from '../messages'; + +const useSessionInfoState = () => +{ + const [ userInfo, setUserInfo ] = useState(null); + const [ userFigure, setUserFigure ] = useState(null); + + const onUserInfoEvent = useCallback((event: UserInfoEvent) => + { + const parser = event.getParser(); + + setUserInfo(parser.userInfo); + setUserFigure(parser.userInfo.figure); + }, []); + + UseMessageEventHook(UserInfoEvent, onUserInfoEvent); + + const onUserFigureEvent = useCallback((event: FigureUpdateEvent) => + { + const parser = event.getParser(); + + setUserFigure(parser.figure); + }, []); + + UseMessageEventHook(FigureUpdateEvent, onUserFigureEvent); + + return { userInfo, userFigure }; +} + +export const useSessionInfo = () => useBetween(useSessionInfoState);