diff --git a/src/components/avatar-editor/common/AvatarEditorAction.ts b/src/api/avatar/AvatarEditorAction.ts similarity index 100% rename from src/components/avatar-editor/common/AvatarEditorAction.ts rename to src/api/avatar/AvatarEditorAction.ts diff --git a/src/components/avatar-editor/common/AvatarEditorGridColorItem.ts b/src/api/avatar/AvatarEditorGridColorItem.ts similarity index 100% rename from src/components/avatar-editor/common/AvatarEditorGridColorItem.ts rename to src/api/avatar/AvatarEditorGridColorItem.ts diff --git a/src/components/avatar-editor/common/AvatarEditorGridPartItem.ts b/src/api/avatar/AvatarEditorGridPartItem.ts similarity index 99% rename from src/components/avatar-editor/common/AvatarEditorGridPartItem.ts rename to src/api/avatar/AvatarEditorGridPartItem.ts index a277b5ad..a3b16616 100644 --- a/src/components/avatar-editor/common/AvatarEditorGridPartItem.ts +++ b/src/api/avatar/AvatarEditorGridPartItem.ts @@ -1,5 +1,5 @@ import { AvatarFigurePartType, IAvatarImageListener, IAvatarRenderManager, IFigurePart, IFigurePartSet, IGraphicAsset, IPartColor, NitroAlphaFilter, NitroContainer, NitroSprite, TextureUtils } from '@nitrots/nitro-renderer'; -import { GetAvatarRenderManager } from '../../../api'; +import { GetAvatarRenderManager } from '../nitro'; import { FigureData } from './FigureData'; export class AvatarEditorGridPartItem implements IAvatarImageListener diff --git a/src/components/avatar-editor/common/AvatarEditorUtilities.ts b/src/api/avatar/AvatarEditorUtilities.ts similarity index 99% rename from src/components/avatar-editor/common/AvatarEditorUtilities.ts rename to src/api/avatar/AvatarEditorUtilities.ts index 5a7b9f52..3626ab8e 100644 --- a/src/components/avatar-editor/common/AvatarEditorUtilities.ts +++ b/src/api/avatar/AvatarEditorUtilities.ts @@ -1,5 +1,5 @@ import { IPartColor } from '@nitrots/nitro-renderer'; -import { GetAvatarPalette, GetAvatarRenderManager, GetAvatarSetType, GetClubMemberLevel, GetConfiguration } from '../../../api'; +import { GetAvatarPalette, GetAvatarRenderManager, GetAvatarSetType, GetClubMemberLevel, GetConfiguration } from '../nitro'; import { AvatarEditorGridColorItem } from './AvatarEditorGridColorItem'; import { AvatarEditorGridPartItem } from './AvatarEditorGridPartItem'; import { CategoryBaseModel } from './CategoryBaseModel'; diff --git a/src/components/avatar-editor/common/BodyModel.ts b/src/api/avatar/BodyModel.ts similarity index 97% rename from src/components/avatar-editor/common/BodyModel.ts rename to src/api/avatar/BodyModel.ts index d7170dbd..7cdb34ce 100644 --- a/src/components/avatar-editor/common/BodyModel.ts +++ b/src/api/avatar/BodyModel.ts @@ -1,5 +1,5 @@ import { AvatarEditorFigureCategory, AvatarScaleType, AvatarSetType } from '@nitrots/nitro-renderer'; -import { GetAvatarRenderManager } from '../../../api'; +import { GetAvatarRenderManager } from '../nitro'; import { AvatarEditorUtilities } from './AvatarEditorUtilities'; import { CategoryBaseModel } from './CategoryBaseModel'; import { FigureData } from './FigureData'; diff --git a/src/components/avatar-editor/common/CategoryBaseModel.ts b/src/api/avatar/CategoryBaseModel.ts similarity index 100% rename from src/components/avatar-editor/common/CategoryBaseModel.ts rename to src/api/avatar/CategoryBaseModel.ts diff --git a/src/components/avatar-editor/common/CategoryData.ts b/src/api/avatar/CategoryData.ts similarity index 100% rename from src/components/avatar-editor/common/CategoryData.ts rename to src/api/avatar/CategoryData.ts diff --git a/src/components/avatar-editor/common/FigureData.ts b/src/api/avatar/FigureData.ts similarity index 100% rename from src/components/avatar-editor/common/FigureData.ts rename to src/api/avatar/FigureData.ts diff --git a/src/components/avatar-editor/common/FigureGenerator.ts b/src/api/avatar/FigureGenerator.ts similarity index 96% rename from src/components/avatar-editor/common/FigureGenerator.ts rename to src/api/avatar/FigureGenerator.ts index 30ac1385..b83a6616 100644 --- a/src/components/avatar-editor/common/FigureGenerator.ts +++ b/src/api/avatar/FigureGenerator.ts @@ -1,6 +1,6 @@ import { AvatarFigureContainer, IFigurePartSet, IPalette, IPartColor, SetType } from '@nitrots/nitro-renderer'; -import { GetAvatarRenderManager } from '../../../api'; -import { Randomizer } from '../../../api/utils'; +import { GetAvatarRenderManager } from '../nitro'; +import { Randomizer } from '../utils'; import { FigureData } from './FigureData'; function getTotalColors(partSet: IFigurePartSet): number diff --git a/src/components/avatar-editor/common/HeadModel.ts b/src/api/avatar/HeadModel.ts similarity index 100% rename from src/components/avatar-editor/common/HeadModel.ts rename to src/api/avatar/HeadModel.ts diff --git a/src/components/avatar-editor/common/IAvatarEditorCategoryModel.ts b/src/api/avatar/IAvatarEditorCategoryModel.ts similarity index 100% rename from src/components/avatar-editor/common/IAvatarEditorCategoryModel.ts rename to src/api/avatar/IAvatarEditorCategoryModel.ts diff --git a/src/components/avatar-editor/common/LegModel.ts b/src/api/avatar/LegModel.ts similarity index 100% rename from src/components/avatar-editor/common/LegModel.ts rename to src/api/avatar/LegModel.ts diff --git a/src/components/avatar-editor/common/TorsoModel.ts b/src/api/avatar/TorsoModel.ts similarity index 100% rename from src/components/avatar-editor/common/TorsoModel.ts rename to src/api/avatar/TorsoModel.ts diff --git a/src/api/avatar/index.ts b/src/api/avatar/index.ts new file mode 100644 index 00000000..37b30721 --- /dev/null +++ b/src/api/avatar/index.ts @@ -0,0 +1,13 @@ +export * from './AvatarEditorAction'; +export * from './AvatarEditorGridColorItem'; +export * from './AvatarEditorGridPartItem'; +export * from './AvatarEditorUtilities'; +export * from './BodyModel'; +export * from './CategoryBaseModel'; +export * from './CategoryData'; +export * from './FigureData'; +export * from './FigureGenerator'; +export * from './HeadModel'; +export * from './IAvatarEditorCategoryModel'; +export * from './LegModel'; +export * from './TorsoModel'; diff --git a/src/components/camera/common/CameraEditorTabs.ts b/src/api/camera/CameraEditorTabs.ts similarity index 100% rename from src/components/camera/common/CameraEditorTabs.ts rename to src/api/camera/CameraEditorTabs.ts diff --git a/src/components/camera/common/CameraPicture.ts b/src/api/camera/CameraPicture.ts similarity index 100% rename from src/components/camera/common/CameraPicture.ts rename to src/api/camera/CameraPicture.ts diff --git a/src/components/camera/common/CameraPictureThumbnail.ts b/src/api/camera/CameraPictureThumbnail.ts similarity index 100% rename from src/components/camera/common/CameraPictureThumbnail.ts rename to src/api/camera/CameraPictureThumbnail.ts diff --git a/src/api/camera/index.ts b/src/api/camera/index.ts new file mode 100644 index 00000000..93c6ccb9 --- /dev/null +++ b/src/api/camera/index.ts @@ -0,0 +1,3 @@ +export * from './CameraEditorTabs'; +export * from './CameraPicture'; +export * from './CameraPictureThumbnail'; diff --git a/src/components/chat-history/common/ChatEntryType.ts b/src/api/chat-history/ChatEntryType.ts similarity index 100% rename from src/components/chat-history/common/ChatEntryType.ts rename to src/api/chat-history/ChatEntryType.ts diff --git a/src/components/chat-history/common/Utilities.ts b/src/api/chat-history/ChatHistoryCurrentDate.ts similarity index 78% rename from src/components/chat-history/common/Utilities.ts rename to src/api/chat-history/ChatHistoryCurrentDate.ts index 12d6d3eb..6947bca4 100644 --- a/src/components/chat-history/common/Utilities.ts +++ b/src/api/chat-history/ChatHistoryCurrentDate.ts @@ -1,5 +1,6 @@ -export const currentDate = () => +export const ChatHistoryCurrentDate = () => { const currentTime = new Date(); + return `${ currentTime.getHours().toString().padStart(2, '0') }:${ currentTime.getMinutes().toString().padStart(2, '0') }`; } diff --git a/src/components/chat-history/common/IChatEntry.ts b/src/api/chat-history/IChatEntry.ts similarity index 100% rename from src/components/chat-history/common/IChatEntry.ts rename to src/api/chat-history/IChatEntry.ts diff --git a/src/api/chat-history/IRoomHistoryEntry.ts b/src/api/chat-history/IRoomHistoryEntry.ts new file mode 100644 index 00000000..4986154a --- /dev/null +++ b/src/api/chat-history/IRoomHistoryEntry.ts @@ -0,0 +1,5 @@ +export interface IRoomHistoryEntry +{ + id: number; + name: string; +} diff --git a/src/api/chat-history/index.ts b/src/api/chat-history/index.ts new file mode 100644 index 00000000..a1447992 --- /dev/null +++ b/src/api/chat-history/index.ts @@ -0,0 +1,4 @@ +export * from './ChatEntryType'; +export * from './ChatHistoryCurrentDate'; +export * from './IChatEntry'; +export * from './IRoomHistoryEntry'; diff --git a/src/api/friends/GroupType.ts b/src/api/friends/MessengerGroupType.ts similarity index 74% rename from src/api/friends/GroupType.ts rename to src/api/friends/MessengerGroupType.ts index 0cbc1a43..d46a1b63 100644 --- a/src/api/friends/GroupType.ts +++ b/src/api/friends/MessengerGroupType.ts @@ -1,4 +1,4 @@ -export class GroupType +export class MessengerGroupType { public static readonly GROUP_CHAT = 0; public static readonly PRIVATE_CHAT = 1; diff --git a/src/api/friends/MessengerThread.ts b/src/api/friends/MessengerThread.ts index e0b0ca85..88128065 100644 --- a/src/api/friends/MessengerThread.ts +++ b/src/api/friends/MessengerThread.ts @@ -1,7 +1,7 @@ import { LocalizeText } from '../utils'; import { GetGroupChatData } from './GetGroupChatData'; -import { GroupType } from './GroupType'; import { MessengerFriend } from './MessengerFriend'; +import { MessengerGroupType } from './MessengerGroupType'; import { MessengerThreadChat } from './MessengerThreadChat'; import { MessengerThreadChatGroup } from './MessengerThreadChatGroup'; @@ -41,7 +41,7 @@ export class MessengerThread if(!group) return; - if(isGroupChat) group.type = GroupType.GROUP_CHAT; + if(isGroupChat) group.type = MessengerGroupType.GROUP_CHAT; const chat = new MessengerThreadChat(senderId, message, secondsSinceSent, extraData, type); diff --git a/src/api/friends/MessengerThreadChatGroup.ts b/src/api/friends/MessengerThreadChatGroup.ts index b1eb9a60..1668aedc 100644 --- a/src/api/friends/MessengerThreadChatGroup.ts +++ b/src/api/friends/MessengerThreadChatGroup.ts @@ -1,4 +1,4 @@ -import { GroupType } from './GroupType'; +import { MessengerGroupType } from './MessengerGroupType'; import { MessengerThreadChat } from './MessengerThreadChat'; export class MessengerThreadChatGroup @@ -7,7 +7,7 @@ export class MessengerThreadChatGroup private _chats: MessengerThreadChat[]; private _type: number; - constructor(userId: number, type = GroupType.PRIVATE_CHAT) + constructor(userId: number, type = MessengerGroupType.PRIVATE_CHAT) { this._userId = userId; this._chats = []; diff --git a/src/api/friends/index.ts b/src/api/friends/index.ts index da3d2c64..ce1ed60a 100644 --- a/src/api/friends/index.ts +++ b/src/api/friends/index.ts @@ -1,7 +1,7 @@ export * from './GetGroupChatData'; -export * from './GroupType'; export * from './IGroupChatData'; export * from './MessengerFriend'; +export * from './MessengerGroupType'; export * from './MessengerIconState'; export * from './MessengerRequest'; export * from './MessengerSettings'; diff --git a/src/components/groups/common/GroupBadgePart.ts b/src/api/groups/GroupBadgePart.ts similarity index 100% rename from src/components/groups/common/GroupBadgePart.ts rename to src/api/groups/GroupBadgePart.ts diff --git a/src/components/groups/common/GroupMembershipType.ts b/src/api/groups/GroupMembershipType.ts similarity index 100% rename from src/components/groups/common/GroupMembershipType.ts rename to src/api/groups/GroupMembershipType.ts diff --git a/src/components/groups/common/GroupType.ts b/src/api/groups/GroupType.ts similarity index 100% rename from src/components/groups/common/GroupType.ts rename to src/api/groups/GroupType.ts diff --git a/src/components/groups/common/IGroupCustomize.ts b/src/api/groups/IGroupCustomize.ts similarity index 100% rename from src/components/groups/common/IGroupCustomize.ts rename to src/api/groups/IGroupCustomize.ts diff --git a/src/components/groups/common/IGroupData.ts b/src/api/groups/IGroupData.ts similarity index 100% rename from src/components/groups/common/IGroupData.ts rename to src/api/groups/IGroupData.ts diff --git a/src/api/groups/index.ts b/src/api/groups/index.ts index 2f528cab..4842948b 100644 --- a/src/api/groups/index.ts +++ b/src/api/groups/index.ts @@ -1,5 +1,10 @@ export * from './GetGroupInformation'; export * from './GetGroupManager'; export * from './GetGroupMembers'; +export * from './GroupBadgePart'; +export * from './GroupMembershipType'; +export * from './GroupType'; +export * from './IGroupCustomize'; +export * from './IGroupData'; export * from './ToggleFavoriteGroup'; export * from './TryJoinGroup'; diff --git a/src/components/guide-tool/common/GuideSessionState.ts b/src/api/guide-tool/GuideSessionState.ts similarity index 100% rename from src/components/guide-tool/common/GuideSessionState.ts rename to src/api/guide-tool/GuideSessionState.ts diff --git a/src/components/guide-tool/common/GuideToolMessage.ts b/src/api/guide-tool/GuideToolMessage.ts similarity index 100% rename from src/components/guide-tool/common/GuideToolMessage.ts rename to src/api/guide-tool/GuideToolMessage.ts diff --git a/src/components/guide-tool/common/GuideToolMessageGroup.ts b/src/api/guide-tool/GuideToolMessageGroup.ts similarity index 100% rename from src/components/guide-tool/common/GuideToolMessageGroup.ts rename to src/api/guide-tool/GuideToolMessageGroup.ts diff --git a/src/api/guide-tool/index.ts b/src/api/guide-tool/index.ts new file mode 100644 index 00000000..1400adc9 --- /dev/null +++ b/src/api/guide-tool/index.ts @@ -0,0 +1,3 @@ +export * from './GuideSessionState'; +export * from './GuideToolMessage'; +export * from './GuideToolMessageGroup'; diff --git a/src/components/help/common/CallForHelpResult.ts b/src/api/help/CallForHelpResult.ts similarity index 100% rename from src/components/help/common/CallForHelpResult.ts rename to src/api/help/CallForHelpResult.ts diff --git a/src/components/help/common/GetCloseReasonKey.ts b/src/api/help/GetCloseReasonKey.ts similarity index 100% rename from src/components/help/common/GetCloseReasonKey.ts rename to src/api/help/GetCloseReasonKey.ts diff --git a/src/components/help/common/IHelpReportState.ts b/src/api/help/IHelpReportState.ts similarity index 76% rename from src/components/help/common/IHelpReportState.ts rename to src/api/help/IHelpReportState.ts index 26aba823..38c73095 100644 --- a/src/components/help/common/IHelpReportState.ts +++ b/src/api/help/IHelpReportState.ts @@ -1,4 +1,4 @@ -import { IChatEntry } from '../../chat-history/common/IChatEntry'; +import { IChatEntry } from '../chat-history'; export interface IHelpReportState { diff --git a/src/components/help/common/IReportedUser.ts b/src/api/help/IReportedUser.ts similarity index 100% rename from src/components/help/common/IReportedUser.ts rename to src/api/help/IReportedUser.ts diff --git a/src/api/help/index.ts b/src/api/help/index.ts new file mode 100644 index 00000000..b46aad9e --- /dev/null +++ b/src/api/help/index.ts @@ -0,0 +1,4 @@ +export * from './CallForHelpResult'; +export * from './GetCloseReasonKey'; +export * from './IHelpReportState'; +export * from './IReportedUser'; diff --git a/src/api/index.ts b/src/api/index.ts index eaaf0bf0..58e6f4ca 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,12 +1,17 @@ export * from './achievements'; +export * from './avatar'; +export * from './camera'; export * from './campaign'; export * from './catalog'; +export * from './chat-history'; export * from './events'; export * from './friends'; export * from './GetRendererVersion'; export * from './GetUIVersion'; export * from './groups'; +export * from './guide-tool'; export * from './hc-center'; +export * from './help'; export * from './inventory'; export * from './navigator'; export * from './nitro'; diff --git a/src/api/wired/WiredActionLayoutCode.ts b/src/api/wired/WiredActionLayoutCode.ts index f15a527f..5282dc59 100644 --- a/src/api/wired/WiredActionLayoutCode.ts +++ b/src/api/wired/WiredActionLayoutCode.ts @@ -1,4 +1,4 @@ -export class WiredActionLayout +export class WiredActionLayoutCode { public static TOGGLE_FURNI_STATE: number = 0; public static RESET: number = 1; diff --git a/src/common/layout/LayoutMiniCameraView.tsx b/src/common/layout/LayoutMiniCameraView.tsx index 0a8fb07b..934e1cc8 100644 --- a/src/common/layout/LayoutMiniCameraView.tsx +++ b/src/common/layout/LayoutMiniCameraView.tsx @@ -1,7 +1,6 @@ import { NitroRectangle, NitroRenderTexture } from '@nitrots/nitro-renderer'; import { FC, useCallback, useRef } from 'react'; -import { GetRoomEngine, LocalizeText, SoundNames } from '../../api'; -import { PlaySound } from '../../api/utils/PlaySound'; +import { GetRoomEngine, LocalizeText, PlaySound, SoundNames } from '../../api'; import { DraggableWindow } from '../draggable-window'; interface LayoutMiniCameraViewProps diff --git a/src/components/avatar-editor/AvatarEditorView.tsx b/src/components/avatar-editor/AvatarEditorView.tsx index 4378b8af..e757eab5 100644 --- a/src/components/avatar-editor/AvatarEditorView.tsx +++ b/src/components/avatar-editor/AvatarEditorView.tsx @@ -1,25 +1,12 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { AvatarEditorFigureCategory, FigureSetIdsMessageEvent, GetWardrobeMessageComposer, IAvatarFigureContainer, ILinkEventTracker, UserFigureComposer, UserWardrobePageEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useMemo, useState } from 'react'; -import { AddEventLinkTracker, GetAvatarRenderManager, GetClubMemberLevel, GetConfiguration, GetSessionDataManager, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; -import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; -import { Button } from '../../common/Button'; -import { ButtonGroup } from '../../common/ButtonGroup'; -import { Column } from '../../common/Column'; -import { Grid } from '../../common/Grid'; +import { AddEventLinkTracker, AvatarEditorAction, AvatarEditorUtilities, BodyModel, FigureData, generateRandomFigure, GetAvatarRenderManager, GetClubMemberLevel, GetConfiguration, GetSessionDataManager, HeadModel, IAvatarEditorCategoryModel, LegModel, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TorsoModel } from '../../api'; +import { Button, ButtonGroup, Column, Grid, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; import { useMessageEvent } from '../../hooks'; -import { AvatarEditorAction } from './common/AvatarEditorAction'; -import { AvatarEditorUtilities } from './common/AvatarEditorUtilities'; -import { BodyModel } from './common/BodyModel'; -import { FigureData } from './common/FigureData'; -import { generateRandomFigure } from './common/FigureGenerator'; -import { HeadModel } from './common/HeadModel'; -import { IAvatarEditorCategoryModel } from './common/IAvatarEditorCategoryModel'; -import { LegModel } from './common/LegModel'; -import { TorsoModel } from './common/TorsoModel'; -import { AvatarEditorFigurePreviewView } from './views/figure-preview/AvatarEditorFigurePreviewView'; -import { AvatarEditorModelView } from './views/model/AvatarEditorModelView'; -import { AvatarEditorWardrobeView } from './views/wardrobe/AvatarEditorWardrobeView'; +import { AvatarEditorFigurePreviewView } from './views/AvatarEditorFigurePreviewView'; +import { AvatarEditorModelView } from './views/AvatarEditorModelView'; +import { AvatarEditorWardrobeView } from './views/AvatarEditorWardrobeView'; const DEFAULT_MALE_FIGURE: string = 'hr-100.hd-180-7.ch-215-66.lg-270-79.sh-305-62.ha-1002-70.wa-2007'; const DEFAULT_FEMALE_FIGURE: string = 'hr-515-33.hd-600-1.ch-635-70.lg-716-66-62.sh-735-68'; @@ -42,17 +29,15 @@ export const AvatarEditorView: FC<{}> = props => const maxWardrobeSlots = useMemo(() => GetConfiguration('avatar.wardrobe.max.slots', 10), []); - const onFigureSetIdsMessageEvent = useCallback((event: FigureSetIdsMessageEvent) => + useMessageEvent(FigureSetIdsMessageEvent, event => { const parser = event.getParser(); setFigureSetIds(parser.figureSetIds); setBoundFurnitureNames(parser.boundsFurnitureNames); - }, []); + }); - useMessageEvent(FigureSetIdsMessageEvent, onFigureSetIdsMessageEvent); - - const onUserWardrobePageEvent = useCallback((event: UserWardrobePageEvent) => + useMessageEvent(UserWardrobePageEvent, event => { const parser = event.getParser(); const savedFigures: [ IAvatarFigureContainer, string ][] = []; @@ -73,10 +58,8 @@ export const AvatarEditorView: FC<{}> = props => savedFigures[(index - 1)] = [ container, gender ]; } - setSavedFigures(savedFigures) - }, [ maxWardrobeSlots ]); - - useMessageEvent(UserWardrobePageEvent, onUserWardrobePageEvent); + setSavedFigures(savedFigures); + }); const selectCategory = useCallback((name: string) => { diff --git a/src/components/avatar-editor/views/figure-preview/AvatarEditorFigurePreviewView.tsx b/src/components/avatar-editor/views/AvatarEditorFigurePreviewView.tsx similarity index 91% rename from src/components/avatar-editor/views/figure-preview/AvatarEditorFigurePreviewView.tsx rename to src/components/avatar-editor/views/AvatarEditorFigurePreviewView.tsx index abe2866f..0c6afbf8 100644 --- a/src/components/avatar-editor/views/figure-preview/AvatarEditorFigurePreviewView.tsx +++ b/src/components/avatar-editor/views/AvatarEditorFigurePreviewView.tsx @@ -1,8 +1,8 @@ import { AvatarDirectionAngle } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { Base, Column, LayoutAvatarImageView } from '../../../../common'; -import { FigureData } from '../../common/FigureData'; -import { AvatarEditorIcon } from '../AvatarEditorIcon'; +import { FigureData } from '../../../api'; +import { Base, Column, LayoutAvatarImageView } from '../../../common'; +import { AvatarEditorIcon } from './AvatarEditorIcon'; export interface AvatarEditorFigurePreviewViewProps { diff --git a/src/components/avatar-editor/views/AvatarEditorIcon.tsx b/src/components/avatar-editor/views/AvatarEditorIcon.tsx index b74ef3c9..a05baa1d 100644 --- a/src/components/avatar-editor/views/AvatarEditorIcon.tsx +++ b/src/components/avatar-editor/views/AvatarEditorIcon.tsx @@ -1,5 +1,5 @@ import { FC, useMemo } from 'react'; -import { Base, BaseProps } from '../../../common/Base'; +import { Base, BaseProps } from '../../../common'; type AvatarIconType = 'male' | 'female' | 'clear' | 'sellable' | string; diff --git a/src/components/avatar-editor/views/model/AvatarEditorModelView.tsx b/src/components/avatar-editor/views/AvatarEditorModelView.tsx similarity index 84% rename from src/components/avatar-editor/views/model/AvatarEditorModelView.tsx rename to src/components/avatar-editor/views/AvatarEditorModelView.tsx index ea9cbda7..6eb8fe3e 100644 --- a/src/components/avatar-editor/views/model/AvatarEditorModelView.tsx +++ b/src/components/avatar-editor/views/AvatarEditorModelView.tsx @@ -1,13 +1,9 @@ import { Dispatch, FC, SetStateAction, useCallback, useEffect, useState } from 'react'; -import { Column } from '../../../../common/Column'; -import { Flex } from '../../../../common/Flex'; -import { Grid } from '../../../../common/Grid'; -import { CategoryData } from '../../common/CategoryData'; -import { FigureData } from '../../common/FigureData'; -import { IAvatarEditorCategoryModel } from '../../common/IAvatarEditorCategoryModel'; -import { AvatarEditorIcon } from '../AvatarEditorIcon'; -import { AvatarEditorFigureSetView } from '../figure-set/AvatarEditorFigureSetView'; -import { AvatarEditorPaletteSetView } from '../palette-set/AvatarEditorPaletteSetView'; +import { CategoryData, FigureData, IAvatarEditorCategoryModel } from '../../../api'; +import { Column, Flex, Grid } from '../../../common'; +import { AvatarEditorIcon } from './AvatarEditorIcon'; +import { AvatarEditorFigureSetView } from './figure-set/AvatarEditorFigureSetView'; +import { AvatarEditorPaletteSetView } from './palette-set/AvatarEditorPaletteSetView'; export interface AvatarEditorModelViewProps { model: IAvatarEditorCategoryModel; diff --git a/src/components/avatar-editor/views/wardrobe/AvatarEditorWardrobeView.tsx b/src/components/avatar-editor/views/AvatarEditorWardrobeView.tsx similarity index 93% rename from src/components/avatar-editor/views/wardrobe/AvatarEditorWardrobeView.tsx rename to src/components/avatar-editor/views/AvatarEditorWardrobeView.tsx index 6efea5ed..9811ab88 100644 --- a/src/components/avatar-editor/views/wardrobe/AvatarEditorWardrobeView.tsx +++ b/src/components/avatar-editor/views/AvatarEditorWardrobeView.tsx @@ -1,8 +1,7 @@ import { IAvatarFigureContainer, SaveWardrobeOutfitMessageComposer } from '@nitrots/nitro-renderer'; import { Dispatch, FC, SetStateAction, useCallback, useMemo } from 'react'; -import { GetAvatarRenderManager, GetClubMemberLevel, GetConfiguration, LocalizeText, SendMessageComposer } from '../../../../api'; -import { AutoGrid, Base, Button, Flex, LayoutAvatarImageView, LayoutCurrencyIcon, LayoutGridItem } from '../../../../common'; -import { FigureData } from '../../common/FigureData'; +import { FigureData, GetAvatarRenderManager, GetClubMemberLevel, GetConfiguration, LocalizeText, SendMessageComposer } from '../../../api'; +import { AutoGrid, Base, Button, Flex, LayoutAvatarImageView, LayoutCurrencyIcon, LayoutGridItem } from '../../../common'; export interface AvatarEditorWardrobeViewProps { diff --git a/src/components/avatar-editor/views/figure-set/AvatarEditorFigureSetItemView.tsx b/src/components/avatar-editor/views/figure-set/AvatarEditorFigureSetItemView.tsx index 9bc42217..8df5b95d 100644 --- a/src/components/avatar-editor/views/figure-set/AvatarEditorFigureSetItemView.tsx +++ b/src/components/avatar-editor/views/figure-set/AvatarEditorFigureSetItemView.tsx @@ -1,7 +1,6 @@ import { FC, useCallback, useEffect, useState } from 'react'; -import { GetConfiguration } from '../../../../api'; +import { AvatarEditorGridPartItem, GetConfiguration } from '../../../../api'; import { LayoutCurrencyIcon, LayoutGridItem, LayoutGridItemProps } from '../../../../common'; -import { AvatarEditorGridPartItem } from '../../common/AvatarEditorGridPartItem'; import { AvatarEditorIcon } from '../AvatarEditorIcon'; export interface AvatarEditorFigureSetItemViewProps extends LayoutGridItemProps diff --git a/src/components/avatar-editor/views/figure-set/AvatarEditorFigureSetView.tsx b/src/components/avatar-editor/views/figure-set/AvatarEditorFigureSetView.tsx index e99502f1..8a813a03 100644 --- a/src/components/avatar-editor/views/figure-set/AvatarEditorFigureSetView.tsx +++ b/src/components/avatar-editor/views/figure-set/AvatarEditorFigureSetView.tsx @@ -1,8 +1,6 @@ import { Dispatch, FC, SetStateAction, useCallback } from 'react'; -import { AutoGrid } from '../../../../common/AutoGrid'; -import { AvatarEditorGridPartItem } from '../../common/AvatarEditorGridPartItem'; -import { CategoryData } from '../../common/CategoryData'; -import { IAvatarEditorCategoryModel } from '../../common/IAvatarEditorCategoryModel'; +import { AvatarEditorGridPartItem, CategoryData, IAvatarEditorCategoryModel } from '../../../../api'; +import { AutoGrid } from '../../../../common'; import { AvatarEditorFigureSetItemView } from './AvatarEditorFigureSetItemView'; export interface AvatarEditorFigureSetViewProps diff --git a/src/components/avatar-editor/views/palette-set/AvatarEditorPaletteSetItemView.tsx b/src/components/avatar-editor/views/palette-set/AvatarEditorPaletteSetItemView.tsx index 2933c244..8138e951 100644 --- a/src/components/avatar-editor/views/palette-set/AvatarEditorPaletteSetItemView.tsx +++ b/src/components/avatar-editor/views/palette-set/AvatarEditorPaletteSetItemView.tsx @@ -1,7 +1,6 @@ import { FC, useCallback, useEffect, useState } from 'react'; -import { GetConfiguration } from '../../../../api'; +import { AvatarEditorGridColorItem, GetConfiguration } from '../../../../api'; import { LayoutCurrencyIcon, LayoutGridItem, LayoutGridItemProps } from '../../../../common'; -import { AvatarEditorGridColorItem } from '../../common/AvatarEditorGridColorItem'; export interface AvatarEditorPaletteSetItemProps extends LayoutGridItemProps { diff --git a/src/components/avatar-editor/views/palette-set/AvatarEditorPaletteSetView.tsx b/src/components/avatar-editor/views/palette-set/AvatarEditorPaletteSetView.tsx index 6b715127..4ed984be 100644 --- a/src/components/avatar-editor/views/palette-set/AvatarEditorPaletteSetView.tsx +++ b/src/components/avatar-editor/views/palette-set/AvatarEditorPaletteSetView.tsx @@ -1,8 +1,6 @@ import { FC, useCallback } from 'react'; -import { AutoGrid } from '../../../../common/AutoGrid'; -import { AvatarEditorGridColorItem } from '../../common/AvatarEditorGridColorItem'; -import { CategoryData } from '../../common/CategoryData'; -import { IAvatarEditorCategoryModel } from '../../common/IAvatarEditorCategoryModel'; +import { AvatarEditorGridColorItem, CategoryData, IAvatarEditorCategoryModel } from '../../../../api'; +import { AutoGrid } from '../../../../common'; import { AvatarEditorPaletteSetItem } from './AvatarEditorPaletteSetItemView'; export interface AvatarEditorPaletteSetViewProps diff --git a/src/components/camera/CameraWidgetContext.tsx b/src/components/camera/CameraWidgetContext.tsx deleted file mode 100644 index 5f574029..00000000 --- a/src/components/camera/CameraWidgetContext.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react'; -import { CameraPicture } from './common/CameraPicture'; - -export interface ICameraWidgetContext -{ - cameraRoll: CameraPicture[], - setCameraRoll: Dispatch>; - selectedPictureIndex: number, - setSelectedPictureIndex: Dispatch>; -} - -const CameraWidgetContext = createContext({ - cameraRoll: null, - setCameraRoll: null, - selectedPictureIndex: null, - setSelectedPictureIndex: null -}); - -export const CameraWidgetContextProvider: FC> = props => -{ - return { props.children } -} - -export const useCameraWidgetContext = () => useContext(CameraWidgetContext); diff --git a/src/components/camera/CameraWidgetView.tsx b/src/components/camera/CameraWidgetView.tsx index 095d7a08..db168554 100644 --- a/src/components/camera/CameraWidgetView.tsx +++ b/src/components/camera/CameraWidgetView.tsx @@ -1,11 +1,9 @@ -import { ILinkEventTracker, InitCameraMessageEvent, IRoomCameraWidgetEffect, RequestCameraConfigurationComposer, RoomCameraWidgetManagerEvent, RoomSessionEvent } from '@nitrots/nitro-renderer'; +import { ILinkEventTracker, RoomSessionEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { AddEventLinkTracker, GetRoomCameraWidgetManager, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; -import { useCameraEvent, useMessageEvent, useRoomSessionManagerEvent } from '../../hooks'; -import { CameraWidgetContextProvider } from './CameraWidgetContext'; -import { CameraPicture } from './common/CameraPicture'; -import { CameraWidgetCaptureView } from './views/capture/CameraWidgetCaptureView'; -import { CameraWidgetCheckoutView } from './views/checkout/CameraWidgetCheckoutView'; +import { AddEventLinkTracker, RemoveLinkEventTracker } from '../../api'; +import { useCamera, useRoomSessionManagerEvent } from '../../hooks'; +import { CameraWidgetCaptureView } from './views/CameraWidgetCaptureView'; +import { CameraWidgetCheckoutView } from './views/CameraWidgetCheckoutView'; import { CameraWidgetEditorView } from './views/editor/CameraWidgetEditorView'; const MODE_NONE: number = 0; @@ -16,49 +14,10 @@ const MODE_CHECKOUT: number = 3; export const CameraWidgetView: FC<{}> = props => { const [ mode, setMode ] = useState(MODE_NONE); - const [ availableEffects, setAvailableEffects ] = useState([]); - const [ cameraRoll, setCameraRoll ] = useState([]); - const [ selectedPictureIndex, setSelectedPictureIndex ] = useState(-1); - const [ myLevel, setMyLevel ] = useState(10); const [ base64Url, setSavedPictureUrl ] = useState(null); - const [ price, setPrice ] = useState<{ credits: number, duckets: number, publishDucketPrice: number }>(null); + const { availableEffects = [], selectedPictureIndex = -1, cameraRoll = [], setCameraRoll = null, myLevel = 0, price = { credits: 0, duckets: 0, publishDucketPrice: 0 }} = useCamera(); - const onRoomCameraWidgetManagerEvent = useCallback((event: RoomCameraWidgetManagerEvent) => - { - setAvailableEffects(Array.from(GetRoomCameraWidgetManager().effects.values())) - }, []); - - useCameraEvent(RoomCameraWidgetManagerEvent.INITIALIZED, onRoomCameraWidgetManagerEvent); - - const onCameraConfigurationEvent = useCallback((event: InitCameraMessageEvent) => - { - const parser = event.getParser(); - - setPrice({ credits: parser.creditPrice, duckets: parser.ducketPrice, publishDucketPrice: parser.publishDucketPrice }); - }, []); - - useMessageEvent(InitCameraMessageEvent, onCameraConfigurationEvent); - - const onRoomSessionEvent = useCallback((event: RoomSessionEvent) => - { - setMode(MODE_NONE); - }, []); - - useRoomSessionManagerEvent(RoomSessionEvent.ENDED, onRoomSessionEvent); - - useEffect(() => - { - if(!GetRoomCameraWidgetManager().isLoaded) - { - GetRoomCameraWidgetManager().init(); - - SendMessageComposer(new RequestCameraConfigurationComposer()); - - return; - } - }, []); - - const processAction = useCallback((type: string) => + const processAction = (type: string) => { switch(type) { @@ -82,7 +41,7 @@ export const CameraWidgetView: FC<{}> = props => setMode(MODE_CAPTURE); return; } - }, [ selectedPictureIndex ]); + } const checkoutPictureUrl = useCallback((pictureUrl: string) => { @@ -90,49 +49,49 @@ export const CameraWidgetView: FC<{}> = props => setMode(MODE_CHECKOUT); }, []); - const linkReceived = useCallback((url: string) => - { - const parts = url.split('/'); - - if(parts.length < 2) return; - - switch(parts[1]) - { - case 'show': - setMode(MODE_CAPTURE); - return; - case 'hide': - setMode(MODE_NONE); - return; - case 'toggle': - setMode(prevValue => - { - if(!prevValue) return MODE_CAPTURE; - else return MODE_NONE; - }); - return; - } - }, []); + useRoomSessionManagerEvent(RoomSessionEvent.ENDED, event => setMode(MODE_NONE)); useEffect(() => { const linkTracker: ILinkEventTracker = { - linkReceived, + linkReceived: (url: string) => + { + const parts = url.split('/'); + + if(parts.length < 2) return; + + switch(parts[1]) + { + case 'show': + setMode(MODE_CAPTURE); + return; + case 'hide': + setMode(MODE_NONE); + return; + case 'toggle': + setMode(prevValue => + { + if(!prevValue) return MODE_CAPTURE; + else return MODE_NONE; + }); + return; + } + }, eventUrlPrefix: 'camera/' }; AddEventLinkTracker(linkTracker); return () => RemoveLinkEventTracker(linkTracker); - }, [ linkReceived ]); + }, []); if(mode === MODE_NONE) return null; return ( - + <> { (mode === MODE_CAPTURE) && processAction('close') } onEdit={ () => processAction('edit') } onDelete={ () => processAction('delete') } /> } { (mode === MODE_EDITOR) && processAction('close') } onCancel={ () => processAction('editor_cancel') } onCheckout={ checkoutPictureUrl } availableEffects={ availableEffects } /> } { (mode === MODE_CHECKOUT) && processAction('close') } onCancelClick={ () => processAction('editor_cancel') } price={ price }> } - + ); } diff --git a/src/components/camera/views/capture/CameraWidgetCaptureView.tsx b/src/components/camera/views/CameraWidgetCaptureView.tsx similarity index 90% rename from src/components/camera/views/capture/CameraWidgetCaptureView.tsx rename to src/components/camera/views/CameraWidgetCaptureView.tsx index 07a3ded1..51df7484 100644 --- a/src/components/camera/views/capture/CameraWidgetCaptureView.tsx +++ b/src/components/camera/views/CameraWidgetCaptureView.tsx @@ -1,10 +1,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { NitroRectangle, TextureUtils } from '@nitrots/nitro-renderer'; import { FC, useCallback, useRef } from 'react'; -import { GetRoomEngine, GetRoomSession, LocalizeText, NotificationUtilities, PlaySound, SoundNames } from '../../../../api'; -import { Column, DraggableWindow, Flex } from '../../../../common'; -import { useCameraWidgetContext } from '../../CameraWidgetContext'; -import { CameraPicture } from '../../common/CameraPicture'; +import { CameraPicture, GetRoomEngine, GetRoomSession, LocalizeText, NotificationUtilities, PlaySound, SoundNames } from '../../../api'; +import { Column, DraggableWindow, Flex } from '../../../common'; +import { useCamera } from '../../../hooks'; export interface CameraWidgetCaptureViewProps { @@ -18,7 +17,7 @@ const CAMERA_ROLL_LIMIT: number = 5; export const CameraWidgetCaptureView: FC = props => { const { onClose = null, onEdit = null, onDelete = null } = props; - const { cameraRoll = null, setCameraRoll = null, selectedPictureIndex = -1, setSelectedPictureIndex = null } = useCameraWidgetContext(); + const { cameraRoll = null, setCameraRoll = null, selectedPictureIndex = -1, setSelectedPictureIndex = null } = useCamera(); const elementRef = useRef(); const selectedPicture = ((selectedPictureIndex > -1) ? cameraRoll[selectedPictureIndex] : null); diff --git a/src/components/camera/views/checkout/CameraWidgetCheckoutView.tsx b/src/components/camera/views/CameraWidgetCheckoutView.tsx similarity index 98% rename from src/components/camera/views/checkout/CameraWidgetCheckoutView.tsx rename to src/components/camera/views/CameraWidgetCheckoutView.tsx index 61be5cb8..cba04320 100644 --- a/src/components/camera/views/checkout/CameraWidgetCheckoutView.tsx +++ b/src/components/camera/views/CameraWidgetCheckoutView.tsx @@ -1,8 +1,8 @@ import { CameraPublishStatusMessageEvent, CameraPurchaseOKMessageEvent, CameraStorageUrlMessageEvent, PublishPhotoMessageComposer, PurchasePhotoMessageComposer } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useMemo, useState } from 'react'; -import { CreateLinkEvent, GetConfiguration, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api'; -import { Button, Column, Flex, LayoutCurrencyIcon, LayoutImage, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; -import { useMessageEvent } from '../../../../hooks'; +import { CreateLinkEvent, GetConfiguration, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../api'; +import { Button, Column, Flex, LayoutCurrencyIcon, LayoutImage, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../common'; +import { useMessageEvent } from '../../../hooks'; export interface CameraWidgetCheckoutViewProps { diff --git a/src/components/camera/views/editor/CameraWidgetEditorView.tsx b/src/components/camera/views/editor/CameraWidgetEditorView.tsx index 18f1da98..0c059b82 100644 --- a/src/components/camera/views/editor/CameraWidgetEditorView.tsx +++ b/src/components/camera/views/editor/CameraWidgetEditorView.tsx @@ -2,11 +2,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { IRoomCameraWidgetEffect, IRoomCameraWidgetSelectedEffect, RoomCameraWidgetSelectedEffect } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useMemo, useState } from 'react'; import ReactSlider from 'react-slider'; -import { GetRoomCameraWidgetManager, LocalizeText } from '../../../../api'; +import { CameraEditorTabs, CameraPicture, CameraPictureThumbnail, GetRoomCameraWidgetManager, LocalizeText } from '../../../../api'; import { Button, ButtonGroup, Column, Flex, Grid, LayoutImage, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView, Text } from '../../../../common'; -import { CameraEditorTabs } from '../../common/CameraEditorTabs'; -import { CameraPicture } from '../../common/CameraPicture'; -import { CameraPictureThumbnail } from '../../common/CameraPictureThumbnail'; import { CameraWidgetEffectListView } from './effect-list/CameraWidgetEffectListView'; export interface CameraWidgetEditorViewProps diff --git a/src/components/camera/views/editor/effect-list/CameraWidgetEffectListItemView.tsx b/src/components/camera/views/editor/effect-list/CameraWidgetEffectListItemView.tsx index 7451ab75..79971457 100644 --- a/src/components/camera/views/editor/effect-list/CameraWidgetEffectListItemView.tsx +++ b/src/components/camera/views/editor/effect-list/CameraWidgetEffectListItemView.tsx @@ -2,9 +2,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { IRoomCameraWidgetEffect } from '@nitrots/nitro-renderer'; import { FC } from 'react'; import { LocalizeText } from '../../../../../api'; -import { Button } from '../../../../../common/Button'; -import { LayoutGridItem } from '../../../../../common/layout/LayoutGridItem'; -import { Text } from '../../../../../common/Text'; +import { Button, LayoutGridItem, Text } from '../../../../../common'; export interface CameraWidgetEffectListItemViewProps { diff --git a/src/components/camera/views/editor/effect-list/CameraWidgetEffectListView.tsx b/src/components/camera/views/editor/effect-list/CameraWidgetEffectListView.tsx index faf8cea6..3f67cea7 100644 --- a/src/components/camera/views/editor/effect-list/CameraWidgetEffectListView.tsx +++ b/src/components/camera/views/editor/effect-list/CameraWidgetEffectListView.tsx @@ -1,7 +1,7 @@ import { IRoomCameraWidgetEffect, IRoomCameraWidgetSelectedEffect } from '@nitrots/nitro-renderer'; import { FC } from 'react'; +import { CameraPictureThumbnail } from '../../../../../api'; import { Grid } from '../../../../../common'; -import { CameraPictureThumbnail } from '../../../common/CameraPictureThumbnail'; import { CameraWidgetEffectListItemView } from './CameraWidgetEffectListItemView'; export interface CameraWidgetEffectListViewProps diff --git a/src/components/campaign/CalendarItemView.tsx b/src/components/campaign/CalendarItemView.tsx index 7a745c18..816fa75b 100644 --- a/src/components/campaign/CalendarItemView.tsx +++ b/src/components/campaign/CalendarItemView.tsx @@ -1,6 +1,5 @@ import { FC } from 'react'; -import { CalendarItemState, GetConfiguration, GetRoomEngine, GetSessionDataManager } from '../../api'; -import { ICalendarItem } from '../../api/campaign/ICalendarItem'; +import { CalendarItemState, GetConfiguration, GetRoomEngine, GetSessionDataManager, ICalendarItem } from '../../api'; import { Base, Column, Flex, LayoutImage } from '../../common'; interface CalendarItemViewProps diff --git a/src/components/chat-history/ChatHistoryContext.tsx b/src/components/chat-history/ChatHistoryContext.tsx deleted file mode 100644 index 086fcfe5..00000000 --- a/src/components/chat-history/ChatHistoryContext.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { createContext, FC, ProviderProps, useContext } from 'react'; -import { IChatHistoryState } from './common/IChatHistoryState'; -import { IRoomHistoryState } from './common/IRoomHistoryState'; - -export interface IChatHistoryContext -{ - chatHistoryState: IChatHistoryState; - roomHistoryState: IRoomHistoryState; -} - -const ChatHistoryContext = createContext({ - chatHistoryState: null, - roomHistoryState: null -}); - -export const ChatHistoryContextProvider: FC> = props => -{ - return { props.children } -} - -export const useChatHistoryContext = () => useContext(ChatHistoryContext); diff --git a/src/components/chat-history/ChatHistoryMessageHandler.tsx b/src/components/chat-history/ChatHistoryMessageHandler.tsx deleted file mode 100644 index 9cabf6f5..00000000 --- a/src/components/chat-history/ChatHistoryMessageHandler.tsx +++ /dev/null @@ -1,112 +0,0 @@ -import { GetGuestRoomResultEvent, RoomSessionChatEvent, RoomSessionEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useState } from 'react'; -import { GetRoomSession } from '../../api'; -import { useMessageEvent, useRoomSessionManagerEvent } from '../../hooks'; -import { useChatHistoryContext } from './ChatHistoryContext'; -import { ChatEntryType } from './common/ChatEntryType'; -import { IChatEntry } from './common/IChatEntry'; -import { IRoomHistoryEntry } from './common/IRoomHistoryEntry'; -import { currentDate } from './common/Utilities'; - -const CHAT_HISTORY_MAX = 1000; -const ROOM_HISTORY_MAX = 10; - -export const ChatHistoryMessageHandler: FC<{}> = props => -{ - const { chatHistoryState = null, roomHistoryState = null } = useChatHistoryContext(); - - const [ needsRoomInsert, setNeedsRoomInsert ] = useState(false); - - const addChatEntry = useCallback((entry: IChatEntry) => - { - entry.id = chatHistoryState.chats.length; - - chatHistoryState.chats.push(entry); - - //check for overflow - if(chatHistoryState.chats.length > CHAT_HISTORY_MAX) - { - chatHistoryState.chats.shift(); - } - chatHistoryState.notify(); - - //dispatchUiEvent(new ChatHistoryEvent(ChatHistoryEvent.CHAT_HISTORY_CHANGED)); - - }, [ chatHistoryState ]); - - const addRoomHistoryEntry = useCallback((entry: IRoomHistoryEntry) => - { - roomHistoryState.roomHistory.push(entry); - - // check for overflow - if(roomHistoryState.roomHistory.length > ROOM_HISTORY_MAX) - { - roomHistoryState.roomHistory.shift(); - } - - roomHistoryState.notify(); - }, [ roomHistoryState ]); - - const onChatEvent = useCallback((event: RoomSessionChatEvent) => - { - const roomSession = GetRoomSession(); - - if(!roomSession) return; - - const userData = roomSession.userDataManager.getUserDataByIndex(event.objectId); - - if(!userData) return; - - const timeString = currentDate(); - - const entry: IChatEntry = { id: -1, entityId: userData.webID, name: userData.name, look: userData.figure, entityType: userData.type, message: event.message, timestamp: timeString, type: ChatEntryType.TYPE_CHAT, roomId: roomSession.roomId }; - - addChatEntry(entry); - }, [ addChatEntry ]); - - useRoomSessionManagerEvent(RoomSessionChatEvent.CHAT_EVENT, onChatEvent); - - const onRoomSessionEvent = useCallback((event: RoomSessionEvent) => - { - switch(event.type) - { - case RoomSessionEvent.STARTED: - setNeedsRoomInsert(true); - break; - case RoomSessionEvent.ENDED: - //dispatchUiEvent(new ChatHistoryEvent(ChatHistoryEvent.HIDE_CHAT_HISTORY)); - break; - } - }, []); - - useRoomSessionManagerEvent(RoomSessionEvent.ENDED, onRoomSessionEvent); - useRoomSessionManagerEvent(RoomSessionEvent.STARTED, onRoomSessionEvent); - - const onGetGuestRoomResultEvent = useCallback((event: GetGuestRoomResultEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - const session = GetRoomSession(); - - if(!session || (session.roomId !== parser.data.roomId)) return; - - if(needsRoomInsert) - { - const chatEntry: IChatEntry = { id: -1, entityId: parser.data.roomId, name: parser.data.roomName, timestamp: currentDate(), type: ChatEntryType.TYPE_ROOM_INFO, roomId: parser.data.roomId }; - - addChatEntry(chatEntry); - - const roomEntry: IRoomHistoryEntry = { id: parser.data.roomId, name: parser.data.roomName }; - - addRoomHistoryEntry(roomEntry); - - setNeedsRoomInsert(false); - } - }, [ addChatEntry, addRoomHistoryEntry, needsRoomInsert ]); - - useMessageEvent(GetGuestRoomResultEvent, onGetGuestRoomResultEvent); - - return null; -} diff --git a/src/components/chat-history/ChatHistoryView.tsx b/src/components/chat-history/ChatHistoryView.tsx index 03e63c0d..c9653bc8 100644 --- a/src/components/chat-history/ChatHistoryView.tsx +++ b/src/components/chat-history/ChatHistoryView.tsx @@ -1,29 +1,21 @@ import { ILinkEventTracker } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { FC, useEffect, useMemo, useRef, useState } from 'react'; import { AutoSizer, CellMeasurer, CellMeasurerCache, List, ListRowProps, ListRowRenderer, Size } from 'react-virtualized'; -import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker } from '../../api'; +import { AddEventLinkTracker, ChatEntryType, LocalizeText, RemoveLinkEventTracker } from '../../api'; import { Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../common'; -import { ChatHistoryContextProvider } from './ChatHistoryContext'; -import { ChatHistoryMessageHandler } from './ChatHistoryMessageHandler'; -import { ChatEntryType } from './common/ChatEntryType'; -import { ChatHistoryState } from './common/ChatHistoryState'; -import { SetChatHistory } from './common/GetChatHistory'; -import { RoomHistoryState } from './common/RoomHistoryState'; +import { useChatHistory } from '../../hooks'; export const ChatHistoryView: FC<{}> = props => { const [ isVisible, setIsVisible ] = useState(false); - const [ chatHistoryUpdateId, setChatHistoryUpdateId ] = useState(-1); - const [ roomHistoryUpdateId, setRoomHistoryUpdateId ] = useState(-1); - const [ chatHistoryState, setChatHistoryState ] = useState(new ChatHistoryState()); - const [ roomHistoryState, setRoomHistoryState ] = useState(new RoomHistoryState()); + const { chatHistory = [] } = useChatHistory(); const elementRef = useRef(null); const cache = useMemo(() => new CellMeasurerCache({ defaultHeight: 25, fixedWidth: true }), []); const RowRenderer: ListRowRenderer = (props: ListRowProps) => { - const item = chatHistoryState.chats[props.index]; + const item = chatHistory[props.index]; const isDark = (props.index % 2 === 0); @@ -48,56 +40,34 @@ export const ChatHistoryView: FC<{}> = props => const onResize = (info: Size) => cache.clearAll(); - 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: 'chat-history/' }; AddEventLinkTracker(linkTracker); return () => RemoveLinkEventTracker(linkTracker); - }, [ linkReceived ]); - - useEffect(() => - { - const chatState = new ChatHistoryState(); - const roomState = new RoomHistoryState(); - - SetChatHistory(chatState); - - chatState.notifier = () => setChatHistoryUpdateId(prevValue => (prevValue + 1)); - roomState.notifier = () => setRoomHistoryUpdateId(prevValue => (prevValue + 1)); - - setChatHistoryState(chatState); - setRoomHistoryState(roomState); - - return () => - { - chatState.notifier = null; - roomState.notifier = null; - }; }, []); useEffect(() => @@ -105,31 +75,29 @@ export const ChatHistoryView: FC<{}> = props => if(elementRef && elementRef.current && isVisible) elementRef.current.scrollToRow(-1); }, [ isVisible ]); + if(!isVisible) return null; + return ( - - - { isVisible && - - setIsVisible(false) }/> - - - { ({ height, width }) => - { - return ( - - ) - } } - - - } - + + setIsVisible(false) }/> + + + { ({ height, width }) => + { + return ( + + ) + } } + + + ); } diff --git a/src/components/chat-history/common/ChatHistoryState.ts b/src/components/chat-history/common/ChatHistoryState.ts deleted file mode 100644 index 53c96ef4..00000000 --- a/src/components/chat-history/common/ChatHistoryState.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { IChatEntry } from './IChatEntry'; -import { IChatHistoryState } from './IChatHistoryState'; - -export class ChatHistoryState implements IChatHistoryState -{ - private _chats: IChatEntry[]; - private _notifier: () => void; - - constructor() - { - this._chats = []; - } - - public notify(): void - { - if(this._notifier) this._notifier(); - } - - public get chats(): IChatEntry[] - { - return this._chats; - } - - public get notifier(): () => void - { - return this._notifier; - } - - public set notifier(notifier: () => void) - { - this._notifier = notifier; - } -} diff --git a/src/components/chat-history/common/GetChatHistory.ts b/src/components/chat-history/common/GetChatHistory.ts deleted file mode 100644 index dbf546b1..00000000 --- a/src/components/chat-history/common/GetChatHistory.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IChatHistoryState } from './IChatHistoryState'; - -let GLOBAL_CHATS: IChatHistoryState = null; - -export const SetChatHistory = (chatHistory: IChatHistoryState) => (GLOBAL_CHATS = chatHistory); - -export const GetChatHistory = () => GLOBAL_CHATS; diff --git a/src/components/chat-history/common/IChatHistoryState.ts b/src/components/chat-history/common/IChatHistoryState.ts deleted file mode 100644 index 4fecbae8..00000000 --- a/src/components/chat-history/common/IChatHistoryState.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IChatEntry } from './IChatEntry'; - -export interface IChatHistoryState -{ - chats: IChatEntry[]; - notifier: () => void - notify(): void; -} diff --git a/src/components/chat-history/common/IRoomHistoryEntry.ts b/src/components/chat-history/common/IRoomHistoryEntry.ts deleted file mode 100644 index 19e6f917..00000000 --- a/src/components/chat-history/common/IRoomHistoryEntry.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IRoomHistoryEntry { - id: number; - name: string; -} diff --git a/src/components/chat-history/common/IRoomHistoryState.ts b/src/components/chat-history/common/IRoomHistoryState.ts deleted file mode 100644 index 64192f88..00000000 --- a/src/components/chat-history/common/IRoomHistoryState.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IRoomHistoryEntry } from './IRoomHistoryEntry'; - -export interface IRoomHistoryState -{ - roomHistory: IRoomHistoryEntry[]; - notifier: () => void; - notify: () => void; -} diff --git a/src/components/chat-history/common/RoomHistoryState.ts b/src/components/chat-history/common/RoomHistoryState.ts deleted file mode 100644 index c59ac73e..00000000 --- a/src/components/chat-history/common/RoomHistoryState.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { IRoomHistoryEntry } from './IRoomHistoryEntry'; -import { IRoomHistoryState } from './IRoomHistoryState'; - -export class RoomHistoryState implements IRoomHistoryState -{ - private _roomHistory: IRoomHistoryEntry[]; - private _notifier: () => void; - - constructor() - { - this._roomHistory = []; - } - - public get roomHistory(): IRoomHistoryEntry[] - { - return this._roomHistory; - } - - public get notifier(): () => void - { - return this._notifier; - } - - public set notifier(notifier: () => void) - { - this._notifier = notifier; - } - - notify(): void - { - if(this._notifier) this._notifier(); - } -} diff --git a/src/components/friends/views/messenger/messenger-thread/FriendsMessengerThreadGroup.tsx b/src/components/friends/views/messenger/messenger-thread/FriendsMessengerThreadGroup.tsx index 9ff19499..ad3d755b 100644 --- a/src/components/friends/views/messenger/messenger-thread/FriendsMessengerThreadGroup.tsx +++ b/src/components/friends/views/messenger/messenger-thread/FriendsMessengerThreadGroup.tsx @@ -1,18 +1,18 @@ import { FC, useMemo } from 'react'; -import { GetGroupChatData, GetSessionDataManager, GroupType, LocalizeText, MessengerThread, MessengerThreadChat, MessengerThreadChatGroup } from '../../../../../api'; +import { GetGroupChatData, GetSessionDataManager, LocalizeText, MessengerGroupType, MessengerThread, MessengerThreadChat, MessengerThreadChatGroup } from '../../../../../api'; import { Base, Flex, LayoutAvatarImageView } from '../../../../../common'; export const FriendsMessengerThreadGroup: FC<{ thread: MessengerThread, group: MessengerThreadChatGroup }> = props => { const { thread = null, group = null } = props; - const groupChatData = useMemo(() => ((group.type === GroupType.GROUP_CHAT) && GetGroupChatData(group.chats[0].extraData)), [ group ]); + const groupChatData = useMemo(() => ((group.type === MessengerGroupType.GROUP_CHAT) && GetGroupChatData(group.chats[0].extraData)), [ group ]); const isOwnChat = useMemo(() => { if(!thread || !group) return false; - if((group.type === GroupType.PRIVATE_CHAT) && (group.userId === GetSessionDataManager().userId)) return true; + if((group.type === MessengerGroupType.PRIVATE_CHAT) && (group.userId === GetSessionDataManager().userId)) return true; if(groupChatData && group.chats.length && (groupChatData.userId === GetSessionDataManager().userId)) return true; @@ -51,7 +51,7 @@ export const FriendsMessengerThreadGroup: FC<{ thread: MessengerThread, group: M return ( - { ((group.type === GroupType.PRIVATE_CHAT) && !isOwnChat) && + { ((group.type === MessengerGroupType.PRIVATE_CHAT) && !isOwnChat) && } { (groupChatData && !isOwnChat) && } diff --git a/src/components/groups/GroupsContext.tsx b/src/components/groups/GroupsContext.tsx deleted file mode 100644 index 7a19e688..00000000 --- a/src/components/groups/GroupsContext.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react'; -import { IGroupCustomize } from './common/IGroupCustomize'; - -interface IGroupsContext -{ - groupCustomize: IGroupCustomize; - setGroupCustomize: Dispatch>; -} - -const GroupsContext = createContext({ - groupCustomize: null, - setGroupCustomize: null -}); - -export const GroupsContextProvider: FC> = props => -{ - return { props.children } -} - -export const useGroupsContext = () => useContext(GroupsContext); diff --git a/src/components/groups/GroupsView.tsx b/src/components/groups/GroupsView.tsx index ab856cae..e6017b4c 100644 --- a/src/components/groups/GroupsView.tsx +++ b/src/components/groups/GroupsView.tsx @@ -1,10 +1,7 @@ -import { GroupBadgePartsComposer, GroupBadgePartsEvent, GroupPurchasedEvent, GroupSettingsComposer, ILinkEventTracker } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { GroupPurchasedEvent, GroupSettingsComposer, ILinkEventTracker } from '@nitrots/nitro-renderer'; +import { FC, useEffect, useState } from 'react'; import { AddEventLinkTracker, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api'; import { useMessageEvent } from '../../hooks'; -import { CompareId } from './common/CompareId'; -import { IGroupCustomize } from './common/IGroupCustomize'; -import { GroupsContextProvider } from './GroupsContext'; import { GroupCreatorView } from './views/GroupCreatorView'; import { GroupInformationStandaloneView } from './views/GroupInformationStandaloneView'; import { GroupManagerView } from './views/GroupManagerView'; @@ -13,92 +10,53 @@ import { GroupMembersView } from './views/GroupMembersView'; export const GroupsView: FC<{}> = props => { const [ isCreatorVisible, setCreatorVisible ] = useState(false); - const [ groupCustomize, setGroupCustomize ] = useState(null); - const onGroupPurchasedEvent = useCallback((event: GroupPurchasedEvent) => + useMessageEvent(GroupPurchasedEvent, event => { const parser = event.getParser(); setCreatorVisible(false); TryVisitRoom(parser.roomId); - }, []); - - useMessageEvent(GroupPurchasedEvent, onGroupPurchasedEvent); - - const onGroupBadgePartsEvent = useCallback((event: GroupBadgePartsEvent) => - { - const parser = event.getParser(); - - const customize: IGroupCustomize = { - badgeBases: [], - badgeSymbols: [], - badgePartColors: [], - groupColorsA: [], - groupColorsB: [] - }; - - parser.bases.forEach((images, id) => customize.badgeBases.push({ id, images })); - parser.symbols.forEach((images, id) => customize.badgeSymbols.push({ id, images })); - parser.partColors.forEach((color, id) => customize.badgePartColors.push({ id, color })); - parser.colorsA.forEach((color, id) => customize.groupColorsA.push({ id, color })); - parser.colorsB.forEach((color, id) => customize.groupColorsB.push({ id, color })); - - customize.badgeBases.sort(CompareId); - customize.badgeSymbols.sort(CompareId); - customize.badgePartColors.sort(CompareId); - customize.groupColorsA.sort(CompareId); - customize.groupColorsB.sort(CompareId); - - setGroupCustomize(customize); - }, [ setGroupCustomize ]); - - useMessageEvent(GroupBadgePartsEvent, onGroupBadgePartsEvent); - - const linkReceived = useCallback((url: string) => - { - const parts = url.split('/'); - - if(parts.length < 2) return; - - switch(parts[1]) - { - case 'create': - setCreatorVisible(true); - return; - case 'manage': - if(!parts[2]) return; - - setCreatorVisible(false); - SendMessageComposer(new GroupSettingsComposer(Number(parts[2]))); - return; - } - }, []); + }); useEffect(() => { const linkTracker: ILinkEventTracker = { - linkReceived, + linkReceived: (url: string) => + { + const parts = url.split('/'); + + if(parts.length < 2) return; + + switch(parts[1]) + { + case 'create': + setCreatorVisible(true); + return; + case 'manage': + if(!parts[2]) return; + + setCreatorVisible(false); + SendMessageComposer(new GroupSettingsComposer(Number(parts[2]))); + return; + } + }, eventUrlPrefix: 'groups/' }; AddEventLinkTracker(linkTracker); return () => RemoveLinkEventTracker(linkTracker); - }, [ linkReceived ]); - - useEffect(() => - { - SendMessageComposer(new GroupBadgePartsComposer()); }, []); return ( - + <> { isCreatorVisible && setCreatorVisible(false) } /> } { !isCreatorVisible && } - + ); }; diff --git a/src/components/groups/common/CompareId.ts b/src/components/groups/common/CompareId.ts deleted file mode 100644 index c6fdda40..00000000 --- a/src/components/groups/common/CompareId.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const CompareId = (a, b) => -{ - if(a.id < b.id) return -1; - - if(a.id > b.id) return 1; - - return 0; -} diff --git a/src/components/groups/views/GroupBadgeCreatorView.tsx b/src/components/groups/views/GroupBadgeCreatorView.tsx index 8fe77c9f..45d5d7bc 100644 --- a/src/components/groups/views/GroupBadgeCreatorView.tsx +++ b/src/components/groups/views/GroupBadgeCreatorView.tsx @@ -1,8 +1,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Dispatch, FC, SetStateAction, useState } from 'react'; +import { GroupBadgePart } from '../../../api'; import { Base, Column, Flex, Grid, LayoutBadgeImageView } from '../../../common'; -import { GroupBadgePart } from '../common/GroupBadgePart'; -import { useGroupsContext } from '../GroupsContext'; +import { useGroup } from '../../../hooks'; interface GroupBadgeCreatorViewProps { @@ -16,7 +16,7 @@ export const GroupBadgeCreatorView: FC = props => { const { badgeParts = [], setBadgeParts = null } = props; const [ selectedIndex, setSelectedIndex ] = useState(-1); - const { groupCustomize = null } = useGroupsContext(); + const { groupCustomize = null } = useGroup(); const setPartProperty = (partIndex: number, property: string, value: number) => { diff --git a/src/components/groups/views/GroupCreatorView.tsx b/src/components/groups/views/GroupCreatorView.tsx index 24fc40c4..4b1401ff 100644 --- a/src/components/groups/views/GroupCreatorView.tsx +++ b/src/components/groups/views/GroupCreatorView.tsx @@ -1,9 +1,8 @@ import { GroupBuyComposer, GroupBuyDataComposer, GroupBuyDataEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { HasHabboClub, LocalizeText, SendMessageComposer } from '../../../api'; +import { HasHabboClub, IGroupData, LocalizeText, SendMessageComposer } from '../../../api'; import { Base, Button, Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../common'; import { useMessageEvent } from '../../../hooks'; -import { IGroupData } from '../common/IGroupData'; import { GroupTabBadgeView } from './tabs/GroupTabBadgeView'; import { GroupTabColorsView } from './tabs/GroupTabColorsView'; import { GroupTabCreatorConfirmationView } from './tabs/GroupTabCreatorConfirmationView'; diff --git a/src/components/groups/views/GroupInformationView.tsx b/src/components/groups/views/GroupInformationView.tsx index e330898a..6488e31e 100644 --- a/src/components/groups/views/GroupInformationView.tsx +++ b/src/components/groups/views/GroupInformationView.tsx @@ -1,9 +1,7 @@ import { GroupInformationParser, GroupRemoveMemberComposer } from '@nitrots/nitro-renderer'; import { FC, useCallback } from 'react'; -import { CatalogPageName, CreateLinkEvent, GetGroupManager, GetGroupMembers, GetSessionDataManager, LocalizeText, NotificationUtilities, SendMessageComposer, TryJoinGroup, TryVisitRoom } from '../../../api'; +import { CatalogPageName, CreateLinkEvent, GetGroupManager, GetGroupMembers, GetSessionDataManager, GroupMembershipType, GroupType, LocalizeText, NotificationUtilities, SendMessageComposer, TryJoinGroup, TryVisitRoom } from '../../../api'; import { Button, Column, Flex, Grid, GridProps, LayoutBadgeImageView, Text } from '../../../common'; -import { GroupMembershipType } from '../common/GroupMembershipType'; -import { GroupType } from '../common/GroupType'; const STATES: string[] = [ 'regular', 'exclusive', 'private' ]; diff --git a/src/components/groups/views/GroupManagerView.tsx b/src/components/groups/views/GroupManagerView.tsx index d1dc5cde..43c4882a 100644 --- a/src/components/groups/views/GroupManagerView.tsx +++ b/src/components/groups/views/GroupManagerView.tsx @@ -1,9 +1,8 @@ import { GroupBadgePart, GroupInformationEvent, GroupSettingsEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useState } from 'react'; -import { LocalizeText } from '../../../api'; +import { IGroupData, LocalizeText } from '../../../api'; import { Base, Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView, Text } from '../../../common'; import { useMessageEvent } from '../../../hooks'; -import { IGroupData } from '../common/IGroupData'; import { GroupTabBadgeView } from './tabs/GroupTabBadgeView'; import { GroupTabColorsView } from './tabs/GroupTabColorsView'; import { GroupTabIdentityView } from './tabs/GroupTabIdentityView'; diff --git a/src/components/groups/views/GroupRoomInformationView.tsx b/src/components/groups/views/GroupRoomInformationView.tsx index 7b5c03c7..2fea613f 100644 --- a/src/components/groups/views/GroupRoomInformationView.tsx +++ b/src/components/groups/views/GroupRoomInformationView.tsx @@ -1,11 +1,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { DesktopViewEvent, GetGuestRoomResultEvent, GroupInformationComposer, GroupInformationEvent, GroupInformationParser, GroupRemoveMemberComposer, HabboGroupDeactivatedMessageEvent, RoomEntryInfoMessageEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useState } from 'react'; -import { GetGroupInformation, GetGroupManager, GetSessionDataManager, LocalizeText, NotificationUtilities, SendMessageComposer, TryJoinGroup } from '../../../api'; +import { GetGroupInformation, GetGroupManager, GetSessionDataManager, GroupMembershipType, GroupType, LocalizeText, NotificationUtilities, SendMessageComposer, TryJoinGroup } from '../../../api'; import { Base, Button, Column, Flex, LayoutBadgeImageView, Text } from '../../../common'; import { useMessageEvent } from '../../../hooks'; -import { GroupMembershipType } from '../common/GroupMembershipType'; -import { GroupType } from '../common/GroupType'; export const GroupRoomInformationView: FC<{}> = props => { diff --git a/src/components/groups/views/tabs/GroupTabBadgeView.tsx b/src/components/groups/views/tabs/GroupTabBadgeView.tsx index b26869a6..73d65c08 100644 --- a/src/components/groups/views/tabs/GroupTabBadgeView.tsx +++ b/src/components/groups/views/tabs/GroupTabBadgeView.tsx @@ -1,10 +1,8 @@ import { GroupSaveBadgeComposer } from '@nitrots/nitro-renderer'; import { Dispatch, FC, SetStateAction, useCallback, useEffect, useState } from 'react'; -import { SendMessageComposer } from '../../../../api'; +import { GroupBadgePart, IGroupData, SendMessageComposer } from '../../../../api'; import { Column, Flex, Grid, LayoutBadgeImageView } from '../../../../common'; -import { GroupBadgePart } from '../../common/GroupBadgePart'; -import { IGroupData } from '../../common/IGroupData'; -import { useGroupsContext } from '../../GroupsContext'; +import { useGroup } from '../../../../hooks'; import { GroupBadgeCreatorView } from '../GroupBadgeCreatorView'; interface GroupTabBadgeViewProps @@ -19,7 +17,7 @@ export const GroupTabBadgeView: FC = props => { const { groupData = null, setGroupData = null, setCloseAction = null, skipDefault = null } = props; const [ badgeParts, setBadgeParts ] = useState(null); - const { groupCustomize = null } = useGroupsContext(); + const { groupCustomize = null } = useGroup(); const getModifiedBadgeCode = () => { diff --git a/src/components/groups/views/tabs/GroupTabColorsView.tsx b/src/components/groups/views/tabs/GroupTabColorsView.tsx index a593e1ee..41ad29d5 100644 --- a/src/components/groups/views/tabs/GroupTabColorsView.tsx +++ b/src/components/groups/views/tabs/GroupTabColorsView.tsx @@ -1,10 +1,9 @@ import { GroupSaveColorsComposer } from '@nitrots/nitro-renderer'; import classNames from 'classnames'; import { Dispatch, FC, SetStateAction, useCallback, useEffect, useState } from 'react'; -import { LocalizeText, SendMessageComposer } from '../../../../api'; +import { IGroupData, LocalizeText, SendMessageComposer } from '../../../../api'; import { AutoGrid, Base, Column, Flex, Grid, Text } from '../../../../common'; -import { IGroupData } from '../../common/IGroupData'; -import { useGroupsContext } from '../../GroupsContext'; +import { useGroup } from '../../../../hooks'; interface GroupTabColorsViewProps { @@ -17,7 +16,7 @@ export const GroupTabColorsView: FC = props => { const { groupData = null, setGroupData = null, setCloseAction = null } = props; const [ colors, setColors ] = useState(null); - const { groupCustomize = null } = useGroupsContext(); + const { groupCustomize = null } = useGroup(); const getGroupColor = (colorIndex: number) => { diff --git a/src/components/groups/views/tabs/GroupTabCreatorConfirmationView.tsx b/src/components/groups/views/tabs/GroupTabCreatorConfirmationView.tsx index dd43225a..30460385 100644 --- a/src/components/groups/views/tabs/GroupTabCreatorConfirmationView.tsx +++ b/src/components/groups/views/tabs/GroupTabCreatorConfirmationView.tsx @@ -1,8 +1,7 @@ import { Dispatch, FC, SetStateAction } from 'react'; -import { LocalizeText } from '../../../../api'; +import { IGroupData, LocalizeText } from '../../../../api'; import { Base, Column, Flex, Grid, LayoutBadgeImageView, Text } from '../../../../common'; -import { IGroupData } from '../../common/IGroupData'; -import { useGroupsContext } from '../../GroupsContext'; +import { useGroup } from '../../../../hooks'; interface GroupTabCreatorConfirmationViewProps { @@ -14,7 +13,7 @@ interface GroupTabCreatorConfirmationViewProps export const GroupTabCreatorConfirmationView: FC = props => { const { groupData = null, setGroupData = null, purchaseCost = 0 } = props; - const { groupCustomize = null } = useGroupsContext(); + const { groupCustomize = null } = useGroup(); const getCompleteBadgeCode = () => { diff --git a/src/components/groups/views/tabs/GroupTabIdentityView.tsx b/src/components/groups/views/tabs/GroupTabIdentityView.tsx index a21f55aa..6d911791 100644 --- a/src/components/groups/views/tabs/GroupTabIdentityView.tsx +++ b/src/components/groups/views/tabs/GroupTabIdentityView.tsx @@ -1,8 +1,7 @@ import { GroupDeleteComposer, GroupSaveInformationComposer } from '@nitrots/nitro-renderer'; import { Dispatch, FC, SetStateAction, useCallback, useEffect, useState } from 'react'; -import { CreateLinkEvent, LocalizeText, NotificationUtilities, SendMessageComposer } from '../../../../api'; +import { CreateLinkEvent, IGroupData, LocalizeText, NotificationUtilities, SendMessageComposer } from '../../../../api'; import { Base, Button, Column, Flex, Text } from '../../../../common'; -import { IGroupData } from '../../common/IGroupData'; interface GroupTabIdentityViewProps { diff --git a/src/components/groups/views/tabs/GroupTabSettingsView.tsx b/src/components/groups/views/tabs/GroupTabSettingsView.tsx index 8ef4adbc..64785e0f 100644 --- a/src/components/groups/views/tabs/GroupTabSettingsView.tsx +++ b/src/components/groups/views/tabs/GroupTabSettingsView.tsx @@ -1,9 +1,7 @@ import { GroupSavePreferencesComposer } from '@nitrots/nitro-renderer'; import { Dispatch, FC, SetStateAction, useCallback, useEffect, useState } from 'react'; -import { SendMessageComposer } from '../../../../api'; -import { LocalizeText } from '../../../../api/utils/LocalizeText'; +import { IGroupData, LocalizeText, SendMessageComposer } from '../../../../api'; import { Column, Flex, HorizontalRule, Text } from '../../../../common'; -import { IGroupData } from '../../common/IGroupData'; const STATES: string[] = [ 'regular', 'exclusive', 'private' ]; diff --git a/src/components/guide-tool/GuideToolView.tsx b/src/components/guide-tool/GuideToolView.tsx index 76958eec..2025f493 100644 --- a/src/components/guide-tool/GuideToolView.tsx +++ b/src/components/guide-tool/GuideToolView.tsx @@ -1,12 +1,9 @@ import { GuideOnDutyStatusMessageEvent, GuideSessionAttachedMessageEvent, GuideSessionDetachedMessageEvent, GuideSessionEndedMessageEvent, GuideSessionInvitedToGuideRoomMessageEvent, GuideSessionMessageMessageEvent, GuideSessionOnDutyUpdateMessageComposer, GuideSessionPartnerIsTypingMessageEvent, GuideSessionStartedMessageEvent, ILinkEventTracker, PerkAllowancesMessageEvent, PerkEnum } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { AddEventLinkTracker, DispatchUiEvent, GetConfiguration, GetSessionDataManager, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; +import { AddEventLinkTracker, DispatchUiEvent, GetConfiguration, GetSessionDataManager, GuideSessionState, GuideToolMessage, GuideToolMessageGroup, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common'; import { GuideToolEvent, NotificationAlertEvent } from '../../events'; import { useMessageEvent, useUiEvent } from '../../hooks'; -import { GuideSessionState } from './common/GuideSessionState'; -import { GuideToolMessage } from './common/GuideToolMessage'; -import { GuideToolMessageGroup } from './common/GuideToolMessageGroup'; import { GuideToolAcceptView } from './views/GuideToolAcceptView'; import { GuideToolMenuView } from './views/GuideToolMenuView'; import { GuideToolOngoingView } from './views/GuideToolOngoingView'; diff --git a/src/components/guide-tool/views/GuideToolOngoingView.tsx b/src/components/guide-tool/views/GuideToolOngoingView.tsx index bc9d6604..08ed8119 100644 --- a/src/components/guide-tool/views/GuideToolOngoingView.tsx +++ b/src/components/guide-tool/views/GuideToolOngoingView.tsx @@ -1,9 +1,8 @@ import { GuideSessionGetRequesterRoomMessageComposer, GuideSessionInviteRequesterMessageComposer, GuideSessionMessageMessageComposer, GuideSessionRequesterRoomMessageEvent, GuideSessionResolvedMessageComposer } from '@nitrots/nitro-renderer'; import { FC, KeyboardEvent, useCallback, useState } from 'react'; -import { GetSessionDataManager, LocalizeText, SendMessageComposer, TryVisitRoom } from '../../../api'; +import { GetSessionDataManager, GuideToolMessageGroup, LocalizeText, SendMessageComposer, TryVisitRoom } from '../../../api'; import { Base, Button, ButtonGroup, Column, Flex, LayoutAvatarImageView, Text } from '../../../common'; import { useMessageEvent } from '../../../hooks'; -import { GuideToolMessageGroup } from '../common/GuideToolMessageGroup'; interface GuideToolOngoingViewProps { diff --git a/src/components/help/HelpContext.tsx b/src/components/help/HelpContext.tsx index 2905830b..aee8e96c 100644 --- a/src/components/help/HelpContext.tsx +++ b/src/components/help/HelpContext.tsx @@ -1,5 +1,5 @@ import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react'; -import { IHelpReportState } from './common/IHelpReportState'; +import { IHelpReportState } from '../../api'; interface IHelpContext { diff --git a/src/components/help/HelpMessageHandler.tsx b/src/components/help/HelpMessageHandler.tsx index a46951b2..52ec1af7 100644 --- a/src/components/help/HelpMessageHandler.tsx +++ b/src/components/help/HelpMessageHandler.tsx @@ -1,9 +1,7 @@ import { CallForHelpResultMessageEvent, GetPendingCallsForHelpMessageComposer, IssueCloseNotificationMessageEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback } from 'react'; -import { LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer } from '../../api'; +import { CallForHelpResult, GetCloseReasonKey, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer } from '../../api'; import { useMessageEvent } from '../../hooks'; -import { CallForHelpResult } from './common/CallForHelpResult'; -import { GetCloseReasonKey } from './common/GetCloseReasonKey'; export const HelpMessageHandler: FC<{}> = props => { diff --git a/src/components/help/HelpView.tsx b/src/components/help/HelpView.tsx index fddf1e49..128f50cc 100644 --- a/src/components/help/HelpView.tsx +++ b/src/components/help/HelpView.tsx @@ -1,10 +1,9 @@ import { ILinkEventTracker } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker } from '../../api'; +import { AddEventLinkTracker, IHelpReportState, LocalizeText, RemoveLinkEventTracker } from '../../api'; import { Base, Column, Grid, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common'; -import { HelpReportUserEvent } from '../../events/help/HelpReportUserEvent'; +import { HelpReportUserEvent } from '../../events'; import { useUiEvent } from '../../hooks'; -import { IHelpReportState } from './common/IHelpReportState'; import { HelpContextProvider } from './HelpContext'; import { HelpMessageHandler } from './HelpMessageHandler'; import { DescribeReportView } from './views/DescribeReportView'; diff --git a/src/components/help/views/SelectReportedChatsView.tsx b/src/components/help/views/SelectReportedChatsView.tsx index 6a24704f..243b1c23 100644 --- a/src/components/help/views/SelectReportedChatsView.tsx +++ b/src/components/help/views/SelectReportedChatsView.tsx @@ -1,22 +1,21 @@ import { RoomObjectType } from '@nitrots/nitro-renderer'; import { FC, useMemo, useState } from 'react'; -import { LocalizeText } from '../../../api'; +import { ChatEntryType, IChatEntry, LocalizeText } from '../../../api'; import { AutoGrid, Button, Column, Flex, LayoutGridItem, Text } from '../../../common'; -import { ChatEntryType } from '../../chat-history/common/ChatEntryType'; -import { GetChatHistory } from '../../chat-history/common/GetChatHistory'; -import { IChatEntry } from '../../chat-history/common/IChatEntry'; +import { useChatHistory } from '../../../hooks'; import { useHelpContext } from '../HelpContext'; export const SelectReportedChatsView: FC<{}> = props => { const [ selectedChats, setSelectedChats ] = useState>(new Map()); + const { chatHistory = [] } = useChatHistory(); const { helpReportState = null, setHelpReportState = null } = useHelpContext(); const { reportedUserId = -1 } = helpReportState; const userChats = useMemo(() => { - return GetChatHistory().chats.filter(chat => (chat.type === ChatEntryType.TYPE_CHAT) && (chat.entityId === reportedUserId) && (chat.entityType === RoomObjectType.USER)); - }, [ reportedUserId ]); + return chatHistory.filter(chat => (chat.type === ChatEntryType.TYPE_CHAT) && (chat.entityId === reportedUserId) && (chat.entityType === RoomObjectType.USER)); + }, [ chatHistory, reportedUserId ]); const selectChat = (chatEntry: IChatEntry) => { diff --git a/src/components/help/views/SelectReportedUserView.tsx b/src/components/help/views/SelectReportedUserView.tsx index c2d267b7..9de8b653 100644 --- a/src/components/help/views/SelectReportedUserView.tsx +++ b/src/components/help/views/SelectReportedUserView.tsx @@ -1,22 +1,21 @@ import { RoomObjectType } from '@nitrots/nitro-renderer'; import { FC, useMemo, useState } from 'react'; -import { GetSessionDataManager, LocalizeText } from '../../../api'; +import { ChatEntryType, GetSessionDataManager, IReportedUser, LocalizeText } from '../../../api'; import { AutoGrid, Button, Column, Flex, LayoutGridItem, Text } from '../../../common'; -import { ChatEntryType } from '../../chat-history/common/ChatEntryType'; -import { GetChatHistory } from '../../chat-history/common/GetChatHistory'; -import { IReportedUser } from '../common/IReportedUser'; +import { useChatHistory } from '../../../hooks'; import { useHelpContext } from '../HelpContext'; export const SelectReportedUserView: FC<{}> = props => { const [ selectedUserId, setSelectedUserId ] = useState(-1); + const { chatHistory = [] } = useChatHistory(); const { helpReportState = null, setHelpReportState = null } = useHelpContext(); const availableUsers = useMemo(() => { const users: Map = new Map(); - GetChatHistory().chats.forEach(chat => + chatHistory.forEach(chat => { if((chat.type === ChatEntryType.TYPE_CHAT) && (chat.entityType === RoomObjectType.USER) && (chat.entityId !== GetSessionDataManager().userId)) { @@ -28,7 +27,7 @@ export const SelectReportedUserView: FC<{}> = props => }); return Array.from(users.values()); - }, []); + }, [ chatHistory ]); const submitUser = () => { diff --git a/src/components/inventory/InventoryView.tsx b/src/components/inventory/InventoryView.tsx index cec4aa73..0424a3cf 100644 --- a/src/components/inventory/InventoryView.tsx +++ b/src/components/inventory/InventoryView.tsx @@ -1,7 +1,6 @@ import { BadgePointLimitsEvent, ILinkEventTracker, IRoomSession, RoomEngineObjectEvent, RoomEngineObjectPlacedEvent, RoomPreviewer, RoomSessionEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { AddEventLinkTracker, GetLocalization, GetRoomEngine, LocalizeText, RemoveLinkEventTracker, UnseenItemCategory } from '../../api'; -import { isObjectMoverRequested, setObjectMoverRequested } from '../../api/inventory/InventoryUtilities'; +import { AddEventLinkTracker, GetLocalization, GetRoomEngine, isObjectMoverRequested, LocalizeText, RemoveLinkEventTracker, setObjectMoverRequested, UnseenItemCategory } from '../../api'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; import { useInventoryTrade, useInventoryUnseenTracker, useMessageEvent, useRoomEngineEvent, useRoomSessionManagerEvent } from '../../hooks'; import { InventoryBadgeView } from './views/badge/InventoryBadgeView'; diff --git a/src/components/room/widgets/choosers/ChooserWidgetView.tsx b/src/components/room/widgets/choosers/ChooserWidgetView.tsx index 7dd5bb61..b424760b 100644 --- a/src/components/room/widgets/choosers/ChooserWidgetView.tsx +++ b/src/components/room/widgets/choosers/ChooserWidgetView.tsx @@ -1,7 +1,6 @@ import { FC, useEffect, useMemo, useState } from 'react'; import { AutoSizer, List, ListRowProps, ListRowRenderer } from 'react-virtualized'; -import { GetSessionDataManager, RoomObjectItem } from '../../../../api'; -import { LocalizeText } from '../../../../api/utils'; +import { GetSessionDataManager, LocalizeText, RoomObjectItem } from '../../../../api'; import { Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; interface ChooserWidgetViewProps diff --git a/src/components/room/widgets/furniture/FurnitureStickieView.tsx b/src/components/room/widgets/furniture/FurnitureStickieView.tsx index 3917d28e..e171bb69 100644 --- a/src/components/room/widgets/furniture/FurnitureStickieView.tsx +++ b/src/components/room/widgets/furniture/FurnitureStickieView.tsx @@ -28,7 +28,7 @@ export const FurnitureStickieView: FC<{}> = props => if(objectId === -1) return null; return ( - +
diff --git a/src/components/room/widgets/furniture/context-menu/PurchasableClothingConfirmView.tsx b/src/components/room/widgets/furniture/context-menu/PurchasableClothingConfirmView.tsx index a8a6c24f..60bbb2f9 100644 --- a/src/components/room/widgets/furniture/context-menu/PurchasableClothingConfirmView.tsx +++ b/src/components/room/widgets/furniture/context-menu/PurchasableClothingConfirmView.tsx @@ -1,9 +1,8 @@ import { RedeemItemClothingComposer, RoomObjectCategory, UserFigureComposer } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; -import { FurniCategory, GetAvatarRenderManager, GetConnection, GetFurnitureDataForRoomObject, GetSessionDataManager, LocalizeText } from '../../../../../api'; +import { FigureData, FurniCategory, GetAvatarRenderManager, GetConnection, GetFurnitureDataForRoomObject, GetSessionDataManager, LocalizeText } from '../../../../../api'; import { Base, Button, Column, Flex, LayoutAvatarImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../../common'; import { useRoom } from '../../../../../hooks'; -import { FigureData } from '../../../../avatar-editor/common/FigureData'; interface PurchasableClothingConfirmViewProps { diff --git a/src/components/wired/WiredContext.tsx b/src/components/wired/WiredContext.tsx deleted file mode 100644 index f0e3bc45..00000000 --- a/src/components/wired/WiredContext.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { Triggerable } from '@nitrots/nitro-renderer'; -import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react'; - -export interface IWiredContext -{ - trigger: Triggerable; - setTrigger: Dispatch>; - intParams: number[], - setIntParams: Dispatch>; - stringParam: string; - setStringParam: Dispatch>; - furniIds: number[]; - setFurniIds: Dispatch>; - actionDelay: number; - setActionDelay: Dispatch>; - saveWired: () => void; -} - -const WiredContext = createContext({ - trigger: null, - setTrigger: null, - intParams: null, - setIntParams: null, - stringParam: null, - setStringParam: null, - furniIds: null, - setFurniIds: null, - actionDelay: null, - setActionDelay: null, - saveWired: null -}); - -export const WiredContextProvider: FC> = props => -{ - return { props.children } -} - -export const useWiredContext = () => useContext(WiredContext); diff --git a/src/components/wired/WiredMessageHandler.tsx b/src/components/wired/WiredMessageHandler.tsx deleted file mode 100644 index bcefb6dc..00000000 --- a/src/components/wired/WiredMessageHandler.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import { WiredFurniActionEvent, WiredFurniConditionEvent, WiredFurniTriggerEvent, WiredOpenEvent, WiredRewardResultMessageEvent, WiredSaveSuccessEvent, WiredValidationErrorEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback } from 'react'; -import { LocalizeText, NotificationAlertType, NotificationUtilities } from '../../api'; -import { useMessageEvent } from '../../hooks'; -import { useWiredContext } from './WiredContext'; - -export const WiredMessageHandler: FC<{}> = props => -{ - const { setTrigger = null } = useWiredContext(); - - const onWiredFurniActionEvent = useCallback((event: WiredFurniActionEvent) => - { - const parser = event.getParser(); - - setTrigger(parser.definition); - }, [ setTrigger ]); - - const onWiredFurniConditionEvent = useCallback((event: WiredFurniConditionEvent) => - { - const parser = event.getParser(); - - setTrigger(parser.definition); - }, [ setTrigger ]); - - const onWiredFurniTriggerEvent = useCallback((event: WiredFurniTriggerEvent) => - { - const parser = event.getParser(); - - setTrigger(parser.definition); - }, [ setTrigger ]); - - const onWiredOpenEvent = useCallback((event: WiredOpenEvent) => - { - const parser = event.getParser(); - - console.log(parser); - }, []); - - const onWiredRewardResultMessageEvent = useCallback((event: WiredRewardResultMessageEvent) => - { - const parser = event.getParser(); - - console.log(parser); - }, []); - - const onWiredSaveSuccessEvent = useCallback((event: WiredSaveSuccessEvent) => - { - setTrigger(null); - }, [ setTrigger ]); - - const onWiredValidationErrorEvent = useCallback((event: WiredValidationErrorEvent) => - { - const parser = event.getParser(); - - NotificationUtilities.simpleAlert(parser.info, NotificationAlertType.DEFAULT, null, null, LocalizeText('error.title')); - console.log(parser); - }, []); - - useMessageEvent(WiredFurniActionEvent, onWiredFurniActionEvent); - useMessageEvent(WiredFurniConditionEvent, onWiredFurniConditionEvent); - useMessageEvent(WiredFurniTriggerEvent, onWiredFurniTriggerEvent); - useMessageEvent(WiredOpenEvent, onWiredOpenEvent); - useMessageEvent(WiredRewardResultMessageEvent, onWiredRewardResultMessageEvent); - useMessageEvent(WiredSaveSuccessEvent, onWiredSaveSuccessEvent); - useMessageEvent(WiredValidationErrorEvent, onWiredValidationErrorEvent); - - return null; -}; diff --git a/src/components/wired/WiredView.tsx b/src/components/wired/WiredView.tsx index 971aec0a..cb3b4baf 100644 --- a/src/components/wired/WiredView.tsx +++ b/src/components/wired/WiredView.tsx @@ -1,58 +1,21 @@ -import { ConditionDefinition, Triggerable, TriggerDefinition, UpdateActionMessageComposer, UpdateConditionMessageComposer, UpdateTriggerMessageComposer, WiredActionDefinition } from '@nitrots/nitro-renderer'; -import { FC, useState } from 'react'; -import { IsOwnerOfFloorFurniture, LocalizeText, NotificationUtilities, SendMessageComposer } from '../../api'; -import { GetWiredLayout } from './common/GetWiredLayout'; -import { WiredContextProvider } from './WiredContext'; -import { WiredMessageHandler } from './WiredMessageHandler'; +import { ConditionDefinition, TriggerDefinition, WiredActionDefinition } from '@nitrots/nitro-renderer'; +import { FC } from 'react'; +import { useWired } from '../../hooks'; +import { WiredActionLayoutView } from './views/actions/WiredActionLayoutView'; +import { WiredConditionLayoutView } from './views/conditions/WiredConditionLayoutView'; +import { WiredTriggerLayoutView } from './views/triggers/WiredTriggerLayoutView'; export const WiredView: FC<{}> = props => { - const [ trigger, setTrigger ] = useState(null); - const [ intParams, setIntParams ] = useState([]); - const [ stringParam, setStringParam ] = useState(''); - const [ furniIds, setFurniIds ] = useState([]); - const [ actionDelay, setActionDelay ] = useState(0); + const { trigger = null } = useWired(); - const saveWired = () => - { - const save = (trigger: Triggerable) => - { - if(!trigger) return; + if(!trigger) return null; - if(trigger instanceof WiredActionDefinition) - { - SendMessageComposer(new UpdateActionMessageComposer(trigger.id, intParams, stringParam, furniIds, actionDelay, trigger.stuffTypeSelectionCode)); - } + if(trigger instanceof WiredActionDefinition) return WiredActionLayoutView(trigger.code); - else if(trigger instanceof TriggerDefinition) - { - SendMessageComposer(new UpdateTriggerMessageComposer(trigger.id, intParams, stringParam, furniIds, trigger.stuffTypeSelectionCode)); - } - - else if(trigger instanceof ConditionDefinition) - { - SendMessageComposer(new UpdateConditionMessageComposer(trigger.id, intParams, stringParam, furniIds, trigger.stuffTypeSelectionCode)); - } - } - - if(!IsOwnerOfFloorFurniture(trigger.id)) - { - NotificationUtilities.confirm(LocalizeText('wiredfurni.nonowner.change.confirm.body'), () => - { - save(trigger) - }, null, null, null, LocalizeText('wiredfurni.nonowner.change.confirm.title')); - } - else - { - save(trigger); - } - } - - return ( - - - { (trigger !== null) && - GetWiredLayout(trigger) } - - ); + if(trigger instanceof TriggerDefinition) return WiredTriggerLayoutView(trigger.code); + + if(trigger instanceof ConditionDefinition) return WiredConditionLayoutView(trigger.code); + + return null; }; diff --git a/src/components/wired/common/GetWiredActionLayout.tsx b/src/components/wired/common/GetWiredActionLayout.tsx deleted file mode 100644 index a5fc49e9..00000000 --- a/src/components/wired/common/GetWiredActionLayout.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import { WiredActionLayout } from '../../../api'; -import { WiredActionBotChangeFigureView } from '../views/actions/WiredActionBotChangeFigureView'; -import { WiredActionBotFollowAvatarView } from '../views/actions/WiredActionBotFollowAvatarView'; -import { WiredActionBotGiveHandItemView } from '../views/actions/WiredActionBotGiveHandItemView'; -import { WiredActionBotMoveView } from '../views/actions/WiredActionBotMoveView'; -import { WiredActionBotTalkToAvatarView } from '../views/actions/WiredActionBotTalkToAvatarView'; -import { WiredActionBotTalkView } from '../views/actions/WiredActionBotTalkView'; -import { WiredActionBotTeleportView } from '../views/actions/WiredActionBotTeleportView'; -import { WiredActionCallAnotherStackView } from '../views/actions/WiredActionCallAnotherStackView'; -import { WiredActionChaseView } from '../views/actions/WiredActionChaseView'; -import { WiredActionChatView } from '../views/actions/WiredActionChatView'; -import { WiredActionFleeView } from '../views/actions/WiredActionFleeView'; -import { WiredActionGiveRewardView } from '../views/actions/WiredActionGiveRewardView'; -import { WiredActionGiveScoreToPredefinedTeamView } from '../views/actions/WiredActionGiveScoreToPredefinedTeamView'; -import { WiredActionGiveScoreView } from '../views/actions/WiredActionGiveScoreView'; -import { WiredActionJoinTeamView } from '../views/actions/WiredActionJoinTeamView'; -import { WiredActionKickFromRoomView } from '../views/actions/WiredActionKickFromRoomView'; -import { WiredActionLeaveTeamView } from '../views/actions/WiredActionLeaveTeamView'; -import { WiredActionMoveAndRotateFurniView } from '../views/actions/WiredActionMoveAndRotateFurniView'; -import { WiredActionMoveFurniToView } from '../views/actions/WiredActionMoveFurniToView'; -import { WiredActionMoveFurniView } from '../views/actions/WiredActionMoveFurniView'; -import { WiredActionMuteUserView } from '../views/actions/WiredActionMuteUserView'; -import { WiredActionResetView } from '../views/actions/WiredActionResetView'; -import { WiredActionSetFurniStateToView } from '../views/actions/WiredActionSetFurniStateToView'; -import { WiredActionTeleportView } from '../views/actions/WiredActionTeleportView'; -import { WiredActionToggleFurniStateView } from '../views/actions/WiredActionToggleFurniStateView'; - -export const GetWiredActionLayout = (code: number) => -{ - switch(code) - { - case WiredActionLayout.BOT_CHANGE_FIGURE: - return ; - case WiredActionLayout.BOT_FOLLOW_AVATAR: - return ; - case WiredActionLayout.BOT_GIVE_HAND_ITEM: - return ; - case WiredActionLayout.BOT_MOVE: - return ; - case WiredActionLayout.BOT_TALK: - return ; - case WiredActionLayout.BOT_TALK_DIRECT_TO_AVTR: - return ; - case WiredActionLayout.BOT_TELEPORT: - return ; - case WiredActionLayout.CALL_ANOTHER_STACK: - return ; - case WiredActionLayout.CHASE: - return ; - case WiredActionLayout.CHAT: - return ; - case WiredActionLayout.FLEE: - return ; - case WiredActionLayout.GIVE_REWARD: - return ; - case WiredActionLayout.GIVE_SCORE: - return ; - case WiredActionLayout.GIVE_SCORE_TO_PREDEFINED_TEAM: - return ; - case WiredActionLayout.JOIN_TEAM: - return ; - case WiredActionLayout.KICK_FROM_ROOM: - return ; - case WiredActionLayout.LEAVE_TEAM: - return ; - case WiredActionLayout.MOVE_FURNI: - return ; - case WiredActionLayout.MOVE_AND_ROTATE_FURNI: - return ; - case WiredActionLayout.MOVE_FURNI_TO: - return ; - case WiredActionLayout.MUTE_USER: - return ; - case WiredActionLayout.RESET: - return ; - case WiredActionLayout.SET_FURNI_STATE: - return ; - case WiredActionLayout.TELEPORT: - return ; - case WiredActionLayout.TOGGLE_FURNI_STATE: - return ; - } - - return null; -} diff --git a/src/components/wired/common/GetWiredLayout.tsx b/src/components/wired/common/GetWiredLayout.tsx deleted file mode 100644 index 5b5a6bed..00000000 --- a/src/components/wired/common/GetWiredLayout.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { ConditionDefinition, Triggerable, TriggerDefinition, WiredActionDefinition } from '@nitrots/nitro-renderer'; -import { GetWiredActionLayout } from './GetWiredActionLayout'; -import { GetWiredConditionLayout } from './GetWiredConditionLayout'; -import { GetWiredTriggerLayout } from './GetWiredTriggerLayout'; - -export const GetWiredLayout = (trigger: Triggerable) => -{ - if(trigger instanceof WiredActionDefinition) return GetWiredActionLayout(trigger.code); - - if(trigger instanceof TriggerDefinition) return GetWiredTriggerLayout(trigger.code); - - if(trigger instanceof ConditionDefinition) return GetWiredConditionLayout(trigger.code); - - return null; -} diff --git a/src/components/wired/views/WiredBaseView.tsx b/src/components/wired/views/WiredBaseView.tsx index 7836ce39..05ec25bf 100644 --- a/src/components/wired/views/WiredBaseView.tsx +++ b/src/components/wired/views/WiredBaseView.tsx @@ -1,7 +1,7 @@ import { FC, PropsWithChildren, useEffect, useState } from 'react'; import { GetSessionDataManager, LocalizeText, WiredFurniType, WiredSelectionVisualizer } from '../../../api'; import { Button, Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../common'; -import { useWiredContext } from '../WiredContext'; +import { useWired } from '../../../hooks'; import { WiredFurniSelectorView } from './WiredFurniSelectorView'; export interface WiredBaseViewProps @@ -19,7 +19,7 @@ export const WiredBaseView: FC> = props => const [ wiredName, setWiredName ] = useState(null); const [ wiredDescription, setWiredDescription ] = useState(null); const [ needsSave, setNeedsSave ] = useState(false); - const { trigger = null, setTrigger = null, setIntParams = null, setStringParam = null, setFurniIds = null, saveWired = null } = useWiredContext(); + const { trigger = null, setTrigger = null, setIntParams = null, setStringParam = null, setFurniIds = null, saveWired = null } = useWired(); const close = () => setTrigger(null); diff --git a/src/components/wired/views/WiredFurniSelectorView.tsx b/src/components/wired/views/WiredFurniSelectorView.tsx index 90d560a0..9b38f972 100644 --- a/src/components/wired/views/WiredFurniSelectorView.tsx +++ b/src/components/wired/views/WiredFurniSelectorView.tsx @@ -1,45 +1,11 @@ -import { FC, useCallback } from 'react'; -import { LocalizeText, WiredSelectionVisualizer } from '../../../api'; +import { FC } from 'react'; +import { LocalizeText } from '../../../api'; import { Column, Text } from '../../../common'; -import { WiredSelectObjectEvent } from '../../../events'; -import { useUiEvent } from '../../../hooks'; -import { useWiredContext } from '../WiredContext'; +import { useWired } from '../../../hooks'; export const WiredFurniSelectorView: FC<{}> = props => { - const { trigger = null, furniIds = [], setFurniIds = null } = useWiredContext(); - - const onWiredSelectObjectEvent = useCallback((event: WiredSelectObjectEvent) => - { - const furniId = event.objectId; - - if(furniId <= 0) return; - - setFurniIds(prevValue => - { - const newFurniIds = [ ...prevValue ]; - - const index = prevValue.indexOf(furniId); - - if(index >= 0) - { - newFurniIds.splice(index, 1); - - WiredSelectionVisualizer.hide(furniId); - } - - else if(newFurniIds.length < trigger.maximumItemSelectionCount) - { - newFurniIds.push(furniId); - - WiredSelectionVisualizer.show(furniId); - } - - return newFurniIds; - }); - }, [ trigger, setFurniIds ]); - - useUiEvent(WiredSelectObjectEvent.SELECT_OBJECT, onWiredSelectObjectEvent); + const { trigger = null, furniIds = [] } = useWired(); return ( diff --git a/src/components/wired/views/actions/WiredActionBaseView.tsx b/src/components/wired/views/actions/WiredActionBaseView.tsx index 71e187a0..6c7a86eb 100644 --- a/src/components/wired/views/actions/WiredActionBaseView.tsx +++ b/src/components/wired/views/actions/WiredActionBaseView.tsx @@ -3,7 +3,7 @@ import { FC, PropsWithChildren, useEffect } from 'react'; import ReactSlider from 'react-slider'; import { GetWiredTimeLocale, LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredBaseView } from '../WiredBaseView'; export interface WiredActionBaseViewProps @@ -16,7 +16,7 @@ export interface WiredActionBaseViewProps export const WiredActionBaseView: FC> = props => { const { requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, hasSpecialInput = false, children = null } = props; - const { trigger = null, actionDelay = 0, setActionDelay = null } = useWiredContext(); + const { trigger = null, actionDelay = 0, setActionDelay = null } = useWired(); useEffect(() => { diff --git a/src/components/wired/views/actions/WiredActionBotChangeFigureView.tsx b/src/components/wired/views/actions/WiredActionBotChangeFigureView.tsx index 48ca80e9..4289f951 100644 --- a/src/components/wired/views/actions/WiredActionBotChangeFigureView.tsx +++ b/src/components/wired/views/actions/WiredActionBotChangeFigureView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { GetSessionDataManager, LocalizeText, WiredFurniType, WIRED_STRING_DELIMETER } from '../../../../api'; import { Button, Column, Flex, LayoutAvatarImageView, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; const DEFAULT_FIGURE: string = 'hd-180-1.ch-210-66.lg-270-82.sh-290-81'; @@ -10,7 +10,7 @@ export const WiredActionBotChangeFigureView: FC<{}> = props => { const [ botName, setBotName ] = useState(''); const [ figure, setFigure ] = useState(''); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam((botName + WIRED_STRING_DELIMETER + figure)); diff --git a/src/components/wired/views/actions/WiredActionBotFollowAvatarView.tsx b/src/components/wired/views/actions/WiredActionBotFollowAvatarView.tsx index 0a609506..2acb5cc1 100644 --- a/src/components/wired/views/actions/WiredActionBotFollowAvatarView.tsx +++ b/src/components/wired/views/actions/WiredActionBotFollowAvatarView.tsx @@ -1,14 +1,14 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionBotFollowAvatarView: FC<{}> = props => { const [ botName, setBotName ] = useState(''); const [ followMode, setFollowMode ] = useState(-1); - const { trigger = null, setStringParam = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setStringParam = null, setIntParams = null } = useWired(); const save = () => { diff --git a/src/components/wired/views/actions/WiredActionBotGiveHandItemView.tsx b/src/components/wired/views/actions/WiredActionBotGiveHandItemView.tsx index b3e7d6b2..c93d0de3 100644 --- a/src/components/wired/views/actions/WiredActionBotGiveHandItemView.tsx +++ b/src/components/wired/views/actions/WiredActionBotGiveHandItemView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; const ALLOWED_HAND_ITEM_IDS: number[] = [ 2, 5, 7, 8, 9, 10, 27 ]; @@ -10,7 +10,7 @@ export const WiredActionBotGiveHandItemView: FC<{}> = props => { const [ botName, setBotName ] = useState(''); const [ handItemId, setHandItemId ] = useState(-1); - const { trigger = null, setStringParam = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setStringParam = null, setIntParams = null } = useWired(); const save = () => { diff --git a/src/components/wired/views/actions/WiredActionBotMoveView.tsx b/src/components/wired/views/actions/WiredActionBotMoveView.tsx index 414047c2..d09a359a 100644 --- a/src/components/wired/views/actions/WiredActionBotMoveView.tsx +++ b/src/components/wired/views/actions/WiredActionBotMoveView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionBotMoveView: FC<{}> = props => { const [ botName, setBotName ] = useState(''); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam(botName); diff --git a/src/components/wired/views/actions/WiredActionBotTalkToAvatarView.tsx b/src/components/wired/views/actions/WiredActionBotTalkToAvatarView.tsx index 2aa05687..f2866e05 100644 --- a/src/components/wired/views/actions/WiredActionBotTalkToAvatarView.tsx +++ b/src/components/wired/views/actions/WiredActionBotTalkToAvatarView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType, WIRED_STRING_DELIMETER } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionBotTalkToAvatarView: FC<{}> = props => @@ -9,7 +9,7 @@ export const WiredActionBotTalkToAvatarView: FC<{}> = props => const [ botName, setBotName ] = useState(''); const [ message, setMessage ] = useState(''); const [ talkMode, setTalkMode ] = useState(-1); - const { trigger = null, setStringParam = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setStringParam = null, setIntParams = null } = useWired(); const save = () => { diff --git a/src/components/wired/views/actions/WiredActionBotTalkView.tsx b/src/components/wired/views/actions/WiredActionBotTalkView.tsx index df1070b3..b457c431 100644 --- a/src/components/wired/views/actions/WiredActionBotTalkView.tsx +++ b/src/components/wired/views/actions/WiredActionBotTalkView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType, WIRED_STRING_DELIMETER } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionBotTalkView: FC<{}> = props => @@ -9,7 +9,7 @@ export const WiredActionBotTalkView: FC<{}> = props => const [ botName, setBotName ] = useState(''); const [ message, setMessage ] = useState(''); const [ talkMode, setTalkMode ] = useState(-1); - const { trigger = null, setStringParam = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setStringParam = null, setIntParams = null } = useWired(); const save = () => { diff --git a/src/components/wired/views/actions/WiredActionBotTeleportView.tsx b/src/components/wired/views/actions/WiredActionBotTeleportView.tsx index a77c514f..5d767b1c 100644 --- a/src/components/wired/views/actions/WiredActionBotTeleportView.tsx +++ b/src/components/wired/views/actions/WiredActionBotTeleportView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionBotTeleportView: FC<{}> = props => { const [ botName, setBotName ] = useState(''); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam(botName); diff --git a/src/components/wired/views/actions/WiredActionChatView.tsx b/src/components/wired/views/actions/WiredActionChatView.tsx index cea1c02a..b570af7f 100644 --- a/src/components/wired/views/actions/WiredActionChatView.tsx +++ b/src/components/wired/views/actions/WiredActionChatView.tsx @@ -1,14 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; -import { Column } from '../../../../common/Column'; -import { Text } from '../../../../common/Text'; -import { useWiredContext } from '../../WiredContext'; +import { Column, Text } from '../../../../common'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionChatView: FC<{}> = props => { const [ message, setMessage ] = useState(''); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam(message); diff --git a/src/components/wired/views/actions/WiredActionGiveRewardView.tsx b/src/components/wired/views/actions/WiredActionGiveRewardView.tsx index 43a8f943..937a175d 100644 --- a/src/components/wired/views/actions/WiredActionGiveRewardView.tsx +++ b/src/components/wired/views/actions/WiredActionGiveRewardView.tsx @@ -2,11 +2,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FC, useCallback, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { LocalizeText, WiredFurniType } from '../../../../api'; -import { Button } from '../../../../common/Button'; -import { Column } from '../../../../common/Column'; -import { Flex } from '../../../../common/Flex'; -import { Text } from '../../../../common/Text'; -import { useWiredContext } from '../../WiredContext'; +import { Button, Column, Flex, Text } from '../../../../common'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionGiveRewardView: FC<{}> = props => @@ -17,7 +14,7 @@ export const WiredActionGiveRewardView: FC<{}> = props => const [ rewardsLimit, setRewardsLimit ] = useState(1); const [ limitationInterval, setLimitationInterval ] = useState(1); const [ rewards, setRewards ] = useState<{ isBadge: boolean, itemCode: string, probability: number }[]>([]); - const { trigger = null, setIntParams = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setIntParams = null, setStringParam = null } = useWired(); const addReward = useCallback(() => { diff --git a/src/components/wired/views/actions/WiredActionGiveScoreToPredefinedTeamView.tsx b/src/components/wired/views/actions/WiredActionGiveScoreToPredefinedTeamView.tsx index 0e74317d..43ab240a 100644 --- a/src/components/wired/views/actions/WiredActionGiveScoreToPredefinedTeamView.tsx +++ b/src/components/wired/views/actions/WiredActionGiveScoreToPredefinedTeamView.tsx @@ -2,7 +2,7 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionGiveScoreToPredefinedTeamView: FC<{}> = props => @@ -10,7 +10,7 @@ export const WiredActionGiveScoreToPredefinedTeamView: FC<{}> = props => const [ points, setPoints ] = useState(1); const [ time, setTime ] = useState(1); const [ selectedTeam, setSelectedTeam ] = useState(1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ points, time, selectedTeam ]); diff --git a/src/components/wired/views/actions/WiredActionGiveScoreView.tsx b/src/components/wired/views/actions/WiredActionGiveScoreView.tsx index 9110795f..28bfb0b2 100644 --- a/src/components/wired/views/actions/WiredActionGiveScoreView.tsx +++ b/src/components/wired/views/actions/WiredActionGiveScoreView.tsx @@ -2,14 +2,14 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionGiveScoreView: FC<{}> = props => { const [ points, setPoints ] = useState(1); const [ time, setTime ] = useState(1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ points, time ]); diff --git a/src/components/wired/views/actions/WiredActionJoinTeamView.tsx b/src/components/wired/views/actions/WiredActionJoinTeamView.tsx index 9684ec23..7580564e 100644 --- a/src/components/wired/views/actions/WiredActionJoinTeamView.tsx +++ b/src/components/wired/views/actions/WiredActionJoinTeamView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionJoinTeamView: FC<{}> = props => { const [ selectedTeam, setSelectedTeam ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ selectedTeam ]); diff --git a/src/components/wired/views/actions/WiredActionKickFromRoomView.tsx b/src/components/wired/views/actions/WiredActionKickFromRoomView.tsx index 81d03160..e16b6684 100644 --- a/src/components/wired/views/actions/WiredActionKickFromRoomView.tsx +++ b/src/components/wired/views/actions/WiredActionKickFromRoomView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionKickFromRoomView: FC<{}> = props => { const [ message, setMessage ] = useState(''); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam(message); diff --git a/src/components/wired/views/actions/WiredActionLayoutView.tsx b/src/components/wired/views/actions/WiredActionLayoutView.tsx new file mode 100644 index 00000000..f43666ab --- /dev/null +++ b/src/components/wired/views/actions/WiredActionLayoutView.tsx @@ -0,0 +1,85 @@ +import { WiredActionLayoutCode } from '../../../../api'; +import { WiredActionBotChangeFigureView } from './WiredActionBotChangeFigureView'; +import { WiredActionBotFollowAvatarView } from './WiredActionBotFollowAvatarView'; +import { WiredActionBotGiveHandItemView } from './WiredActionBotGiveHandItemView'; +import { WiredActionBotMoveView } from './WiredActionBotMoveView'; +import { WiredActionBotTalkToAvatarView } from './WiredActionBotTalkToAvatarView'; +import { WiredActionBotTalkView } from './WiredActionBotTalkView'; +import { WiredActionBotTeleportView } from './WiredActionBotTeleportView'; +import { WiredActionCallAnotherStackView } from './WiredActionCallAnotherStackView'; +import { WiredActionChaseView } from './WiredActionChaseView'; +import { WiredActionChatView } from './WiredActionChatView'; +import { WiredActionFleeView } from './WiredActionFleeView'; +import { WiredActionGiveRewardView } from './WiredActionGiveRewardView'; +import { WiredActionGiveScoreToPredefinedTeamView } from './WiredActionGiveScoreToPredefinedTeamView'; +import { WiredActionGiveScoreView } from './WiredActionGiveScoreView'; +import { WiredActionJoinTeamView } from './WiredActionJoinTeamView'; +import { WiredActionKickFromRoomView } from './WiredActionKickFromRoomView'; +import { WiredActionLeaveTeamView } from './WiredActionLeaveTeamView'; +import { WiredActionMoveAndRotateFurniView } from './WiredActionMoveAndRotateFurniView'; +import { WiredActionMoveFurniToView } from './WiredActionMoveFurniToView'; +import { WiredActionMoveFurniView } from './WiredActionMoveFurniView'; +import { WiredActionMuteUserView } from './WiredActionMuteUserView'; +import { WiredActionResetView } from './WiredActionResetView'; +import { WiredActionSetFurniStateToView } from './WiredActionSetFurniStateToView'; +import { WiredActionTeleportView } from './WiredActionTeleportView'; +import { WiredActionToggleFurniStateView } from './WiredActionToggleFurniStateView'; + +export const WiredActionLayoutView = (code: number) => +{ + switch(code) + { + case WiredActionLayoutCode.BOT_CHANGE_FIGURE: + return ; + case WiredActionLayoutCode.BOT_FOLLOW_AVATAR: + return ; + case WiredActionLayoutCode.BOT_GIVE_HAND_ITEM: + return ; + case WiredActionLayoutCode.BOT_MOVE: + return ; + case WiredActionLayoutCode.BOT_TALK: + return ; + case WiredActionLayoutCode.BOT_TALK_DIRECT_TO_AVTR: + return ; + case WiredActionLayoutCode.BOT_TELEPORT: + return ; + case WiredActionLayoutCode.CALL_ANOTHER_STACK: + return ; + case WiredActionLayoutCode.CHASE: + return ; + case WiredActionLayoutCode.CHAT: + return ; + case WiredActionLayoutCode.FLEE: + return ; + case WiredActionLayoutCode.GIVE_REWARD: + return ; + case WiredActionLayoutCode.GIVE_SCORE: + return ; + case WiredActionLayoutCode.GIVE_SCORE_TO_PREDEFINED_TEAM: + return ; + case WiredActionLayoutCode.JOIN_TEAM: + return ; + case WiredActionLayoutCode.KICK_FROM_ROOM: + return ; + case WiredActionLayoutCode.LEAVE_TEAM: + return ; + case WiredActionLayoutCode.MOVE_FURNI: + return ; + case WiredActionLayoutCode.MOVE_AND_ROTATE_FURNI: + return ; + case WiredActionLayoutCode.MOVE_FURNI_TO: + return ; + case WiredActionLayoutCode.MUTE_USER: + return ; + case WiredActionLayoutCode.RESET: + return ; + case WiredActionLayoutCode.SET_FURNI_STATE: + return ; + case WiredActionLayoutCode.TELEPORT: + return ; + case WiredActionLayoutCode.TOGGLE_FURNI_STATE: + return ; + } + + return null; +} diff --git a/src/components/wired/views/actions/WiredActionMoveAndRotateFurniView.tsx b/src/components/wired/views/actions/WiredActionMoveAndRotateFurniView.tsx index dd57422a..62801af8 100644 --- a/src/components/wired/views/actions/WiredActionMoveAndRotateFurniView.tsx +++ b/src/components/wired/views/actions/WiredActionMoveAndRotateFurniView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; const directionOptions: { value: number, icon: string }[] = [ @@ -29,7 +29,7 @@ export const WiredActionMoveAndRotateFurniView: FC<{}> = props => { const [ movement, setMovement ] = useState(-1); const [ rotation, setRotation ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ movement, rotation ]); diff --git a/src/components/wired/views/actions/WiredActionMoveFurniToView.tsx b/src/components/wired/views/actions/WiredActionMoveFurniToView.tsx index 834313de..56bdb6b4 100644 --- a/src/components/wired/views/actions/WiredActionMoveFurniToView.tsx +++ b/src/components/wired/views/actions/WiredActionMoveFurniToView.tsx @@ -2,7 +2,7 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; const directionOptions: { value: number, icon: string }[] = [ @@ -28,7 +28,7 @@ export const WiredActionMoveFurniToView: FC<{}> = props => { const [ spacing, setSpacing ] = useState(-1); const [ movement, setMovement ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ movement, spacing ]); diff --git a/src/components/wired/views/actions/WiredActionMoveFurniView.tsx b/src/components/wired/views/actions/WiredActionMoveFurniView.tsx index f97c975d..b5a08887 100644 --- a/src/components/wired/views/actions/WiredActionMoveFurniView.tsx +++ b/src/components/wired/views/actions/WiredActionMoveFurniView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; const directionOptions: { value: number, icon: string }[] = [ @@ -41,7 +41,7 @@ export const WiredActionMoveFurniView: FC<{}> = props => { const [ movement, setMovement ] = useState(-1); const [ rotation, setRotation ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ movement, rotation ]); diff --git a/src/components/wired/views/actions/WiredActionMuteUserView.tsx b/src/components/wired/views/actions/WiredActionMuteUserView.tsx index 09b396eb..e34bd60a 100644 --- a/src/components/wired/views/actions/WiredActionMuteUserView.tsx +++ b/src/components/wired/views/actions/WiredActionMuteUserView.tsx @@ -2,14 +2,14 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionMuteUserView: FC<{}> = props => { const [ time, setTime ] = useState(-1); const [ message, setMessage ] = useState(''); - const { trigger = null, setIntParams = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setIntParams = null, setStringParam = null } = useWired(); const save = () => { diff --git a/src/components/wired/views/actions/WiredActionSetFurniStateToView.tsx b/src/components/wired/views/actions/WiredActionSetFurniStateToView.tsx index 5f2ca70a..587254c8 100644 --- a/src/components/wired/views/actions/WiredActionSetFurniStateToView.tsx +++ b/src/components/wired/views/actions/WiredActionSetFurniStateToView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredActionBaseView } from './WiredActionBaseView'; export const WiredActionSetFurniStateToView: FC<{}> = props => @@ -9,7 +9,7 @@ export const WiredActionSetFurniStateToView: FC<{}> = props => const [ stateFlag, setStateFlag ] = useState(0); const [ directionFlag, setDirectionFlag ] = useState(0); const [ positionFlag, setPositionFlag ] = useState(0); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ stateFlag, directionFlag, positionFlag ]); diff --git a/src/components/wired/views/conditions/WiredConditionActorHasHandItem.tsx b/src/components/wired/views/conditions/WiredConditionActorHasHandItem.tsx index fb50fd1b..24e89ed1 100644 --- a/src/components/wired/views/conditions/WiredConditionActorHasHandItem.tsx +++ b/src/components/wired/views/conditions/WiredConditionActorHasHandItem.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; const ALLOWED_HAND_ITEM_IDS: number[] = [ 2, 5, 7, 8, 9, 10, 27 ]; @@ -9,7 +9,7 @@ const ALLOWED_HAND_ITEM_IDS: number[] = [ 2, 5, 7, 8, 9, 10, 27 ]; export const WiredConditionActorHasHandItemView: FC<{}> = props => { const [ handItemId, setHandItemId ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ handItemId ]); diff --git a/src/components/wired/views/conditions/WiredConditionActorIsTeamMemberView.tsx b/src/components/wired/views/conditions/WiredConditionActorIsTeamMemberView.tsx index 31bad9d9..20db3ac3 100644 --- a/src/components/wired/views/conditions/WiredConditionActorIsTeamMemberView.tsx +++ b/src/components/wired/views/conditions/WiredConditionActorIsTeamMemberView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; const teamIds: number[] = [ 1, 2, 3, 4 ]; @@ -9,7 +9,7 @@ const teamIds: number[] = [ 1, 2, 3, 4 ]; export const WiredConditionActorIsTeamMemberView: FC<{}> = props => { const [ selectedTeam, setSelectedTeam ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ selectedTeam ]); diff --git a/src/components/wired/views/conditions/WiredConditionActorIsWearingBadgeView.tsx b/src/components/wired/views/conditions/WiredConditionActorIsWearingBadgeView.tsx index f06175d7..01e6d3b1 100644 --- a/src/components/wired/views/conditions/WiredConditionActorIsWearingBadgeView.tsx +++ b/src/components/wired/views/conditions/WiredConditionActorIsWearingBadgeView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionActorIsWearingBadgeView: FC<{}> = props => { const [ badge, setBadge ] = useState(''); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam(badge); diff --git a/src/components/wired/views/conditions/WiredConditionActorIsWearingEffectView.tsx b/src/components/wired/views/conditions/WiredConditionActorIsWearingEffectView.tsx index f715d3cc..0909018e 100644 --- a/src/components/wired/views/conditions/WiredConditionActorIsWearingEffectView.tsx +++ b/src/components/wired/views/conditions/WiredConditionActorIsWearingEffectView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionActorIsWearingEffectView: FC<{}> = props => { const [ effect, setEffect ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ effect ]); diff --git a/src/components/wired/views/conditions/WiredConditionDateRangeView.tsx b/src/components/wired/views/conditions/WiredConditionDateRangeView.tsx index c0d9b14c..36832e11 100644 --- a/src/components/wired/views/conditions/WiredConditionDateRangeView.tsx +++ b/src/components/wired/views/conditions/WiredConditionDateRangeView.tsx @@ -1,14 +1,14 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredDateToString, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionDateRangeView: FC<{}> = props => { const [ startDate, setStartDate ] = useState(''); const [ endDate, setEndDate ] = useState(''); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => { diff --git a/src/components/wired/views/conditions/WiredConditionFurniHasFurniOnView.tsx b/src/components/wired/views/conditions/WiredConditionFurniHasFurniOnView.tsx index 33a450a8..1a9d0ef6 100644 --- a/src/components/wired/views/conditions/WiredConditionFurniHasFurniOnView.tsx +++ b/src/components/wired/views/conditions/WiredConditionFurniHasFurniOnView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionFurniHasFurniOnView: FC<{}> = props => { const [ requireAll, setRequireAll ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ requireAll ]); diff --git a/src/components/wired/views/conditions/WiredConditionFurniHasNotFurniOnView.tsx b/src/components/wired/views/conditions/WiredConditionFurniHasNotFurniOnView.tsx index 9852542f..031ec08f 100644 --- a/src/components/wired/views/conditions/WiredConditionFurniHasNotFurniOnView.tsx +++ b/src/components/wired/views/conditions/WiredConditionFurniHasNotFurniOnView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionFurniHasNotFurniOnView: FC<{}> = props => { const [ requireAll, setRequireAll ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ requireAll ]); diff --git a/src/components/wired/views/conditions/WiredConditionFurniMatchesSnapshotView.tsx b/src/components/wired/views/conditions/WiredConditionFurniMatchesSnapshotView.tsx index 8fceb690..47a555e5 100644 --- a/src/components/wired/views/conditions/WiredConditionFurniMatchesSnapshotView.tsx +++ b/src/components/wired/views/conditions/WiredConditionFurniMatchesSnapshotView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionFurniMatchesSnapshotView: FC<{}> = props => @@ -9,7 +9,7 @@ export const WiredConditionFurniMatchesSnapshotView: FC<{}> = props => const [ stateFlag, setStateFlag ] = useState(0); const [ directionFlag, setDirectionFlag ] = useState(0); const [ positionFlag, setPositionFlag ] = useState(0); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ stateFlag, directionFlag, positionFlag ]); diff --git a/src/components/wired/common/GetWiredConditionLayout.tsx b/src/components/wired/views/conditions/WiredConditionLayoutView.tsx similarity index 56% rename from src/components/wired/common/GetWiredConditionLayout.tsx rename to src/components/wired/views/conditions/WiredConditionLayoutView.tsx index 4ea22f77..c7c49b2a 100644 --- a/src/components/wired/common/GetWiredConditionLayout.tsx +++ b/src/components/wired/views/conditions/WiredConditionLayoutView.tsx @@ -1,21 +1,21 @@ -import { WiredConditionlayout } from '../../../api'; -import { WiredConditionActorHasHandItemView } from '../views/conditions/WiredConditionActorHasHandItem'; -import { WiredConditionActorIsGroupMemberView } from '../views/conditions/WiredConditionActorIsGroupMemberView'; -import { WiredConditionActorIsOnFurniView } from '../views/conditions/WiredConditionActorIsOnFurniView'; -import { WiredConditionActorIsTeamMemberView } from '../views/conditions/WiredConditionActorIsTeamMemberView'; -import { WiredConditionActorIsWearingBadgeView } from '../views/conditions/WiredConditionActorIsWearingBadgeView'; -import { WiredConditionActorIsWearingEffectView } from '../views/conditions/WiredConditionActorIsWearingEffectView'; -import { WiredConditionDateRangeView } from '../views/conditions/WiredConditionDateRangeView'; -import { WiredConditionFurniHasAvatarOnView } from '../views/conditions/WiredConditionFurniHasAvatarOnView'; -import { WiredConditionFurniHasFurniOnView } from '../views/conditions/WiredConditionFurniHasFurniOnView'; -import { WiredConditionFurniHasNotFurniOnView } from '../views/conditions/WiredConditionFurniHasNotFurniOnView'; -import { WiredConditionFurniIsOfTypeView } from '../views/conditions/WiredConditionFurniIsOfTypeView'; -import { WiredConditionFurniMatchesSnapshotView } from '../views/conditions/WiredConditionFurniMatchesSnapshotView'; -import { WiredConditionTimeElapsedLessView } from '../views/conditions/WiredConditionTimeElapsedLessView'; -import { WiredConditionTimeElapsedMoreView } from '../views/conditions/WiredConditionTimeElapsedMoreView'; -import { WiredConditionUserCountInRoomView } from '../views/conditions/WiredConditionUserCountInRoomView'; +import { WiredConditionlayout } from '../../../../api'; +import { WiredConditionActorHasHandItemView } from './WiredConditionActorHasHandItem'; +import { WiredConditionActorIsGroupMemberView } from './WiredConditionActorIsGroupMemberView'; +import { WiredConditionActorIsOnFurniView } from './WiredConditionActorIsOnFurniView'; +import { WiredConditionActorIsTeamMemberView } from './WiredConditionActorIsTeamMemberView'; +import { WiredConditionActorIsWearingBadgeView } from './WiredConditionActorIsWearingBadgeView'; +import { WiredConditionActorIsWearingEffectView } from './WiredConditionActorIsWearingEffectView'; +import { WiredConditionDateRangeView } from './WiredConditionDateRangeView'; +import { WiredConditionFurniHasAvatarOnView } from './WiredConditionFurniHasAvatarOnView'; +import { WiredConditionFurniHasFurniOnView } from './WiredConditionFurniHasFurniOnView'; +import { WiredConditionFurniHasNotFurniOnView } from './WiredConditionFurniHasNotFurniOnView'; +import { WiredConditionFurniIsOfTypeView } from './WiredConditionFurniIsOfTypeView'; +import { WiredConditionFurniMatchesSnapshotView } from './WiredConditionFurniMatchesSnapshotView'; +import { WiredConditionTimeElapsedLessView } from './WiredConditionTimeElapsedLessView'; +import { WiredConditionTimeElapsedMoreView } from './WiredConditionTimeElapsedMoreView'; +import { WiredConditionUserCountInRoomView } from './WiredConditionUserCountInRoomView'; -export const GetWiredConditionLayout = (code: number) => +export const WiredConditionLayoutView = (code: number) => { switch(code) { diff --git a/src/components/wired/views/conditions/WiredConditionTimeElapsedLessView.tsx b/src/components/wired/views/conditions/WiredConditionTimeElapsedLessView.tsx index ab180b79..31d6d79c 100644 --- a/src/components/wired/views/conditions/WiredConditionTimeElapsedLessView.tsx +++ b/src/components/wired/views/conditions/WiredConditionTimeElapsedLessView.tsx @@ -2,13 +2,13 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { GetWiredTimeLocale, LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionTimeElapsedLessView: FC<{}> = props => { const [ time, setTime ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ time ]); diff --git a/src/components/wired/views/conditions/WiredConditionTimeElapsedMoreView.tsx b/src/components/wired/views/conditions/WiredConditionTimeElapsedMoreView.tsx index 43e5559e..cb158e68 100644 --- a/src/components/wired/views/conditions/WiredConditionTimeElapsedMoreView.tsx +++ b/src/components/wired/views/conditions/WiredConditionTimeElapsedMoreView.tsx @@ -2,13 +2,13 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { GetWiredTimeLocale, LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionTimeElapsedMoreView: FC<{}> = props => { const [ time, setTime ] = useState(-1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ time ]); diff --git a/src/components/wired/views/conditions/WiredConditionUserCountInRoomView.tsx b/src/components/wired/views/conditions/WiredConditionUserCountInRoomView.tsx index 3bcab89e..824d7ae8 100644 --- a/src/components/wired/views/conditions/WiredConditionUserCountInRoomView.tsx +++ b/src/components/wired/views/conditions/WiredConditionUserCountInRoomView.tsx @@ -2,14 +2,14 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredConditionBaseView } from './WiredConditionBaseView'; export const WiredConditionUserCountInRoomView: FC<{}> = props => { const [ min, setMin ] = useState(1); const [ max, setMax ] = useState(1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ min, max ]); diff --git a/src/components/wired/views/triggers/WiredTriggerAvatarEnterRoomView.tsx b/src/components/wired/views/triggers/WiredTriggerAvatarEnterRoomView.tsx index 5129b610..b14eafb6 100644 --- a/src/components/wired/views/triggers/WiredTriggerAvatarEnterRoomView.tsx +++ b/src/components/wired/views/triggers/WiredTriggerAvatarEnterRoomView.tsx @@ -1,14 +1,14 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredTriggerBaseView } from './WiredTriggerBaseView'; export const WiredTriggerAvatarEnterRoomView: FC<{}> = props => { const [ username, setUsername ] = useState(''); const [ avatarMode, setAvatarMode ] = useState(0); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam((avatarMode === 1) ? username : ''); diff --git a/src/components/wired/views/triggers/WiredTriggerAvatarSaysSomethingView.tsx b/src/components/wired/views/triggers/WiredTriggerAvatarSaysSomethingView.tsx index f8e2cd12..d8bc6210 100644 --- a/src/components/wired/views/triggers/WiredTriggerAvatarSaysSomethingView.tsx +++ b/src/components/wired/views/triggers/WiredTriggerAvatarSaysSomethingView.tsx @@ -1,14 +1,14 @@ import { FC, useEffect, useState } from 'react'; import { GetSessionDataManager, LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredTriggerBaseView } from './WiredTriggerBaseView'; export const WiredTriggerAvatarSaysSomethingView: FC<{}> = props => { const [ message, setMessage ] = useState(''); const [ triggererAvatar, setTriggererAvatar ] = useState(-1); - const { trigger = null, setStringParam = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setStringParam = null, setIntParams = null } = useWired(); const save = () => { diff --git a/src/components/wired/views/triggers/WiredTriggerBotReachedAvatarView.tsx b/src/components/wired/views/triggers/WiredTriggerBotReachedAvatarView.tsx index c3d4c3e0..6984dc6d 100644 --- a/src/components/wired/views/triggers/WiredTriggerBotReachedAvatarView.tsx +++ b/src/components/wired/views/triggers/WiredTriggerBotReachedAvatarView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredTriggerBaseView } from './WiredTriggerBaseView'; export const WiredTriggerBotReachedAvatarView: FC<{}> = props => { const [ botName, setBotName ] = useState(''); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam(botName); diff --git a/src/components/wired/views/triggers/WiredTriggerBotReachedStuffView.tsx b/src/components/wired/views/triggers/WiredTriggerBotReachedStuffView.tsx index 8a5fabba..9cde1737 100644 --- a/src/components/wired/views/triggers/WiredTriggerBotReachedStuffView.tsx +++ b/src/components/wired/views/triggers/WiredTriggerBotReachedStuffView.tsx @@ -1,13 +1,13 @@ import { FC, useEffect, useState } from 'react'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredTriggerBaseView } from './WiredTriggerBaseView'; export const WiredTriggerBotReachedStuffView: FC<{}> = props => { const [ botName, setBotName ] = useState(''); - const { trigger = null, setStringParam = null } = useWiredContext(); + const { trigger = null, setStringParam = null } = useWired(); const save = () => setStringParam(botName); diff --git a/src/components/wired/views/triggers/WiredTriggerExecuteOnceView.tsx b/src/components/wired/views/triggers/WiredTriggerExecuteOnceView.tsx index 6b465261..ea3d61bf 100644 --- a/src/components/wired/views/triggers/WiredTriggerExecuteOnceView.tsx +++ b/src/components/wired/views/triggers/WiredTriggerExecuteOnceView.tsx @@ -2,13 +2,13 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { GetWiredTimeLocale, LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredTriggerBaseView } from './WiredTriggerBaseView'; export const WiredTriggeExecuteOnceView: FC<{}> = props => { const [ time, setTime ] = useState(1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ time ]); diff --git a/src/components/wired/views/triggers/WiredTriggerExecutePeriodicallyLongView.tsx b/src/components/wired/views/triggers/WiredTriggerExecutePeriodicallyLongView.tsx index e13241dc..d9bc6bc4 100644 --- a/src/components/wired/views/triggers/WiredTriggerExecutePeriodicallyLongView.tsx +++ b/src/components/wired/views/triggers/WiredTriggerExecutePeriodicallyLongView.tsx @@ -3,13 +3,13 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredTriggerBaseView } from './WiredTriggerBaseView'; export const WiredTriggeExecutePeriodicallyLongView: FC<{}> = props => { const [ time, setTime ] = useState(1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ time ]); diff --git a/src/components/wired/views/triggers/WiredTriggerExecutePeriodicallyView.tsx b/src/components/wired/views/triggers/WiredTriggerExecutePeriodicallyView.tsx index 64540a98..b77e642f 100644 --- a/src/components/wired/views/triggers/WiredTriggerExecutePeriodicallyView.tsx +++ b/src/components/wired/views/triggers/WiredTriggerExecutePeriodicallyView.tsx @@ -2,13 +2,13 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { GetWiredTimeLocale, LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredTriggerBaseView } from './WiredTriggerBaseView'; export const WiredTriggeExecutePeriodicallyView: FC<{}> = props => { const [ time, setTime ] = useState(1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ time ]); diff --git a/src/components/wired/common/GetWiredTriggerLayout.tsx b/src/components/wired/views/triggers/WiredTriggerLayoutView.tsx similarity index 50% rename from src/components/wired/common/GetWiredTriggerLayout.tsx rename to src/components/wired/views/triggers/WiredTriggerLayoutView.tsx index 4e6d2fa2..e45b2eac 100644 --- a/src/components/wired/common/GetWiredTriggerLayout.tsx +++ b/src/components/wired/views/triggers/WiredTriggerLayoutView.tsx @@ -1,20 +1,20 @@ -import { WiredTriggerLayout } from '../../../api'; -import { WiredTriggerAvatarEnterRoomView } from '../views/triggers/WiredTriggerAvatarEnterRoomView'; -import { WiredTriggerAvatarSaysSomethingView } from '../views/triggers/WiredTriggerAvatarSaysSomethingView'; -import { WiredTriggerAvatarWalksOffFurniView } from '../views/triggers/WiredTriggerAvatarWalksOffFurniView'; -import { WiredTriggerAvatarWalksOnFurniView } from '../views/triggers/WiredTriggerAvatarWalksOnFurni'; -import { WiredTriggerBotReachedAvatarView } from '../views/triggers/WiredTriggerBotReachedAvatarView'; -import { WiredTriggerBotReachedStuffView } from '../views/triggers/WiredTriggerBotReachedStuffView'; -import { WiredTriggerCollisionView } from '../views/triggers/WiredTriggerCollisionView'; -import { WiredTriggeExecuteOnceView } from '../views/triggers/WiredTriggerExecuteOnceView'; -import { WiredTriggeExecutePeriodicallyLongView } from '../views/triggers/WiredTriggerExecutePeriodicallyLongView'; -import { WiredTriggeExecutePeriodicallyView } from '../views/triggers/WiredTriggerExecutePeriodicallyView'; -import { WiredTriggerGameEndsView } from '../views/triggers/WiredTriggerGameEndsView'; -import { WiredTriggerGameStartsView } from '../views/triggers/WiredTriggerGameStartsView'; -import { WiredTriggeScoreAchievedView } from '../views/triggers/WiredTriggerScoreAchievedView'; -import { WiredTriggerToggleFurniView } from '../views/triggers/WiredTriggerToggleFurniView'; +import { WiredTriggerLayout } from '../../../../api'; +import { WiredTriggerAvatarEnterRoomView } from './WiredTriggerAvatarEnterRoomView'; +import { WiredTriggerAvatarSaysSomethingView } from './WiredTriggerAvatarSaysSomethingView'; +import { WiredTriggerAvatarWalksOffFurniView } from './WiredTriggerAvatarWalksOffFurniView'; +import { WiredTriggerAvatarWalksOnFurniView } from './WiredTriggerAvatarWalksOnFurni'; +import { WiredTriggerBotReachedAvatarView } from './WiredTriggerBotReachedAvatarView'; +import { WiredTriggerBotReachedStuffView } from './WiredTriggerBotReachedStuffView'; +import { WiredTriggerCollisionView } from './WiredTriggerCollisionView'; +import { WiredTriggeExecuteOnceView } from './WiredTriggerExecuteOnceView'; +import { WiredTriggeExecutePeriodicallyLongView } from './WiredTriggerExecutePeriodicallyLongView'; +import { WiredTriggeExecutePeriodicallyView } from './WiredTriggerExecutePeriodicallyView'; +import { WiredTriggerGameEndsView } from './WiredTriggerGameEndsView'; +import { WiredTriggerGameStartsView } from './WiredTriggerGameStartsView'; +import { WiredTriggeScoreAchievedView } from './WiredTriggerScoreAchievedView'; +import { WiredTriggerToggleFurniView } from './WiredTriggerToggleFurniView'; -export const GetWiredTriggerLayout = (code: number) => +export const WiredTriggerLayoutView = (code: number) => { switch(code) { diff --git a/src/components/wired/views/triggers/WiredTriggerScoreAchievedView.tsx b/src/components/wired/views/triggers/WiredTriggerScoreAchievedView.tsx index 473641bc..883503b8 100644 --- a/src/components/wired/views/triggers/WiredTriggerScoreAchievedView.tsx +++ b/src/components/wired/views/triggers/WiredTriggerScoreAchievedView.tsx @@ -2,13 +2,13 @@ import { FC, useEffect, useState } from 'react'; import ReactSlider from 'react-slider'; import { LocalizeText, WiredFurniType } from '../../../../api'; import { Column, Text } from '../../../../common'; -import { useWiredContext } from '../../WiredContext'; +import { useWired } from '../../../../hooks'; import { WiredTriggerBaseView } from './WiredTriggerBaseView'; export const WiredTriggeScoreAchievedView: FC<{}> = props => { const [ points, setPoints ] = useState(1); - const { trigger = null, setIntParams = null } = useWiredContext(); + const { trigger = null, setIntParams = null } = useWired(); const save = () => setIntParams([ points ]); diff --git a/src/hooks/camera/index.ts b/src/hooks/camera/index.ts new file mode 100644 index 00000000..20bea9c8 --- /dev/null +++ b/src/hooks/camera/index.ts @@ -0,0 +1 @@ +export * from './useCamera'; diff --git a/src/hooks/camera/useCamera.ts b/src/hooks/camera/useCamera.ts new file mode 100644 index 00000000..e2449c80 --- /dev/null +++ b/src/hooks/camera/useCamera.ts @@ -0,0 +1,42 @@ +import { InitCameraMessageEvent, IRoomCameraWidgetEffect, RequestCameraConfigurationComposer, RoomCameraWidgetManagerEvent } from '@nitrots/nitro-renderer'; +import { useEffect, useState } from 'react'; +import { useBetween } from 'use-between'; +import { CameraPicture, GetRoomCameraWidgetManager, SendMessageComposer } from '../../api'; +import { useCameraEvent, useMessageEvent } from '../events'; + +const useCameraState = () => +{ + const [ availableEffects, setAvailableEffects ] = useState([]); + const [ cameraRoll, setCameraRoll ] = useState([]); + const [ selectedPictureIndex, setSelectedPictureIndex ] = useState(-1); + const [ myLevel, setMyLevel ] = useState(10); + const [ price, setPrice ] = useState<{ credits: number, duckets: number, publishDucketPrice: number }>(null); + + useCameraEvent(RoomCameraWidgetManagerEvent.INITIALIZED, event => + { + setAvailableEffects(Array.from(GetRoomCameraWidgetManager().effects.values())); + }); + + useMessageEvent(InitCameraMessageEvent, event => + { + const parser = event.getParser(); + + setPrice({ credits: parser.creditPrice, duckets: parser.ducketPrice, publishDucketPrice: parser.publishDucketPrice }); + }); + + useEffect(() => + { + if(!GetRoomCameraWidgetManager().isLoaded) + { + GetRoomCameraWidgetManager().init(); + + SendMessageComposer(new RequestCameraConfigurationComposer()); + + return; + } + }, []); + + return { availableEffects, cameraRoll, setCameraRoll, selectedPictureIndex, setSelectedPictureIndex, myLevel, price }; +} + +export const useCamera = () => useBetween(useCameraState); diff --git a/src/hooks/chat-history/index.ts b/src/hooks/chat-history/index.ts new file mode 100644 index 00000000..970d90f2 --- /dev/null +++ b/src/hooks/chat-history/index.ts @@ -0,0 +1 @@ +export * from './useChatHistory'; diff --git a/src/hooks/chat-history/useChatHistory.ts b/src/hooks/chat-history/useChatHistory.ts new file mode 100644 index 00000000..7fcc529a --- /dev/null +++ b/src/hooks/chat-history/useChatHistory.ts @@ -0,0 +1,84 @@ +import { GetGuestRoomResultEvent, RoomSessionChatEvent, RoomSessionEvent } from '@nitrots/nitro-renderer'; +import { useState } from 'react'; +import { useBetween } from 'use-between'; +import { ChatEntryType, ChatHistoryCurrentDate, GetRoomSession, IChatEntry, IRoomHistoryEntry } from '../../api'; +import { useMessageEvent, useRoomSessionManagerEvent } from '../events'; + +const CHAT_HISTORY_MAX = 1000; +const ROOM_HISTORY_MAX = 10; + +let CHAT_HISTORY_COUNTER: number = 0; + +const useChatHistoryState = () => +{ + const [ chatHistory, setChatHistory ] = useState([]); + const [ roomHistory, setRoomHistory ] = useState([]); + const [ needsRoomInsert, setNeedsRoomInsert ] = useState(false); + + const addChatEntry = (entry: IChatEntry) => + { + entry.id = CHAT_HISTORY_COUNTER++; + + setChatHistory(prevValue => + { + const newValue = [ ...prevValue ]; + + newValue.push(entry); + + if(newValue.length > CHAT_HISTORY_MAX) newValue.shift(); + + return newValue; + }); + } + + const addRoomHistoryEntry = (entry: IRoomHistoryEntry) => + { + setRoomHistory(prevValue => + { + const newValue = [ ...prevValue ]; + + newValue.push(entry); + + if(newValue.length > ROOM_HISTORY_MAX) newValue.shift(); + + return newValue; + }); + } + + useRoomSessionManagerEvent(RoomSessionChatEvent.CHAT_EVENT, event => + { + const roomSession = GetRoomSession(); + + if(!roomSession) return; + + const userData = roomSession.userDataManager.getUserDataByIndex(event.objectId); + + if(!userData) return; + + addChatEntry({ id: -1, entityId: userData.webID, name: userData.name, look: userData.figure, entityType: userData.type, message: event.message, timestamp: ChatHistoryCurrentDate(), type: ChatEntryType.TYPE_CHAT, roomId: roomSession.roomId }); + }); + + useRoomSessionManagerEvent(RoomSessionEvent.STARTED, event => setNeedsRoomInsert(true)); + + useMessageEvent(GetGuestRoomResultEvent, event => + { + if(!needsRoomInsert) return; + + const parser = event.getParser(); + + if(roomHistory.length) + { + if(roomHistory[(roomHistory.length - 1)].id === parser.data.roomId) return; + } + + addChatEntry({ id: -1, entityId: parser.data.roomId, name: parser.data.roomName, timestamp: ChatHistoryCurrentDate(), type: ChatEntryType.TYPE_ROOM_INFO, roomId: parser.data.roomId }); + + addRoomHistoryEntry({ id: parser.data.roomId, name: parser.data.roomName }); + + setNeedsRoomInsert(false); + }); + + return { chatHistory, roomHistory }; +} + +export const useChatHistory = () => useBetween(useChatHistoryState); diff --git a/src/hooks/groups/index.ts b/src/hooks/groups/index.ts new file mode 100644 index 00000000..95ef7334 --- /dev/null +++ b/src/hooks/groups/index.ts @@ -0,0 +1 @@ +export * from './useGroup'; diff --git a/src/hooks/groups/useGroup.ts b/src/hooks/groups/useGroup.ts new file mode 100644 index 00000000..b9303fcf --- /dev/null +++ b/src/hooks/groups/useGroup.ts @@ -0,0 +1,55 @@ +import { GroupBadgePartsComposer, GroupBadgePartsEvent } from '@nitrots/nitro-renderer'; +import { useEffect, useState } from 'react'; +import { useBetween } from 'use-between'; +import { IGroupCustomize, SendMessageComposer } from '../../api'; +import { useMessageEvent } from '../events'; + +const CompareId = (a, b) => +{ + if(a.id < b.id) return -1; + + if(a.id > b.id) return 1; + + return 0; +} + +const useGroupState = () => +{ + const [ groupCustomize, setGroupCustomize ] = useState(null); + + useMessageEvent(GroupBadgePartsEvent, event => + { + const parser = event.getParser(); + + const customize: IGroupCustomize = { + badgeBases: [], + badgeSymbols: [], + badgePartColors: [], + groupColorsA: [], + groupColorsB: [] + }; + + parser.bases.forEach((images, id) => customize.badgeBases.push({ id, images })); + parser.symbols.forEach((images, id) => customize.badgeSymbols.push({ id, images })); + parser.partColors.forEach((color, id) => customize.badgePartColors.push({ id, color })); + parser.colorsA.forEach((color, id) => customize.groupColorsA.push({ id, color })); + parser.colorsB.forEach((color, id) => customize.groupColorsB.push({ id, color })); + + customize.badgeBases.sort(CompareId); + customize.badgeSymbols.sort(CompareId); + customize.badgePartColors.sort(CompareId); + customize.groupColorsA.sort(CompareId); + customize.groupColorsB.sort(CompareId); + + setGroupCustomize(customize); + }); + + useEffect(() => + { + SendMessageComposer(new GroupBadgePartsComposer()); + }, []); + + return { groupCustomize }; +} + +export const useGroup = () => useBetween(useGroupState); diff --git a/src/hooks/index.ts b/src/hooks/index.ts index ffc85f5e..e28adade 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1,9 +1,12 @@ export * from './achievements'; +export * from './camera'; export * from './catalog'; +export * from './chat-history'; export * from './events'; export * from './events/core'; export * from './events/nitro'; export * from './friends'; +export * from './groups'; export * from './inventory'; export * from './navigator'; export * from './purse'; @@ -12,3 +15,4 @@ export * from './session'; export * from './useLocalStorage'; export * from './UseMountEffect'; export * from './useSharedVisibility'; +export * from './wired'; diff --git a/src/hooks/wired/index.ts b/src/hooks/wired/index.ts new file mode 100644 index 00000000..dc790208 --- /dev/null +++ b/src/hooks/wired/index.ts @@ -0,0 +1 @@ +export * from './useWired'; diff --git a/src/hooks/wired/useWired.ts b/src/hooks/wired/useWired.ts new file mode 100644 index 00000000..1d126658 --- /dev/null +++ b/src/hooks/wired/useWired.ts @@ -0,0 +1,105 @@ +import { ConditionDefinition, Triggerable, TriggerDefinition, UpdateActionMessageComposer, UpdateConditionMessageComposer, UpdateTriggerMessageComposer, WiredActionDefinition, WiredFurniActionEvent, WiredFurniConditionEvent, WiredFurniTriggerEvent } from '@nitrots/nitro-renderer'; +import { useState } from 'react'; +import { useBetween } from 'use-between'; +import { IsOwnerOfFloorFurniture, LocalizeText, NotificationUtilities, SendMessageComposer, WiredSelectionVisualizer } from '../../api'; +import { WiredSelectObjectEvent } from '../../events'; +import { useMessageEvent, useUiEvent } from '../events'; + +const useWiredState = () => +{ + const [ trigger, setTrigger ] = useState(null); + const [ intParams, setIntParams ] = useState([]); + const [ stringParam, setStringParam ] = useState(''); + const [ furniIds, setFurniIds ] = useState([]); + const [ actionDelay, setActionDelay ] = useState(0); + + const saveWired = () => + { + const save = (trigger: Triggerable) => + { + if(!trigger) return; + + if(trigger instanceof WiredActionDefinition) + { + SendMessageComposer(new UpdateActionMessageComposer(trigger.id, intParams, stringParam, furniIds, actionDelay, trigger.stuffTypeSelectionCode)); + } + + else if(trigger instanceof TriggerDefinition) + { + SendMessageComposer(new UpdateTriggerMessageComposer(trigger.id, intParams, stringParam, furniIds, trigger.stuffTypeSelectionCode)); + } + + else if(trigger instanceof ConditionDefinition) + { + SendMessageComposer(new UpdateConditionMessageComposer(trigger.id, intParams, stringParam, furniIds, trigger.stuffTypeSelectionCode)); + } + } + + if(!IsOwnerOfFloorFurniture(trigger.id)) + { + NotificationUtilities.confirm(LocalizeText('wiredfurni.nonowner.change.confirm.body'), () => + { + save(trigger) + }, null, null, null, LocalizeText('wiredfurni.nonowner.change.confirm.title')); + } + else + { + save(trigger); + } + } + + useUiEvent(WiredSelectObjectEvent.SELECT_OBJECT, event => + { + const furniId = event.objectId; + + if(furniId <= 0) return; + + setFurniIds(prevValue => + { + const newFurniIds = [ ...prevValue ]; + + const index = prevValue.indexOf(furniId); + + if(index >= 0) + { + newFurniIds.splice(index, 1); + + WiredSelectionVisualizer.hide(furniId); + } + + else if(newFurniIds.length < trigger.maximumItemSelectionCount) + { + newFurniIds.push(furniId); + + WiredSelectionVisualizer.show(furniId); + } + + return newFurniIds; + }); + }); + + useMessageEvent(WiredFurniActionEvent, event => + { + const parser = event.getParser(); + + setTrigger(parser.definition); + }); + + useMessageEvent(WiredFurniConditionEvent, event => + { + const parser = event.getParser(); + + setTrigger(parser.definition); + }); + + useMessageEvent(WiredFurniTriggerEvent, event => + { + const parser = event.getParser(); + + setTrigger(parser.definition); + }); + + return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, saveWired }; +} + +export const useWired = () => useBetween(useWiredState);