mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-31 10:22:36 +01:00
Updates
This commit is contained in:
parent
dd354e9e74
commit
aa2fb1b11c
@ -1,16 +1,21 @@
|
|||||||
import { FurnitureListAddOrUpdateEvent, FurnitureListEvent, FurnitureListInvalidateEvent, FurnitureListItemParser, FurnitureListRemovedEvent, FurniturePostItPlacedEvent } from 'nitro-renderer';
|
import { BadgesEvent, BotAddedToInventoryEvent, BotInventoryMessageEvent, BotRemovedFromInventoryEvent, FurnitureListAddOrUpdateEvent, FurnitureListEvent, FurnitureListInvalidateEvent, FurnitureListItemParser, FurnitureListRemovedEvent, FurniturePostItPlacedEvent, PetAddedToInventoryEvent, PetData, PetInventoryEvent, PetRemovedFromInventory } from 'nitro-renderer';
|
||||||
import { FC, useCallback } from 'react';
|
import { FC, useCallback } from 'react';
|
||||||
import { CreateMessageHook } from '../../hooks/messages/message-event';
|
import { CreateMessageHook } from '../../hooks/messages/message-event';
|
||||||
import { useInventoryContext } from './context/InventoryContext';
|
import { useInventoryContext } from './context/InventoryContext';
|
||||||
import { InventoryMessageHandlerProps } from './InventoryMessageHandler.types';
|
import { InventoryMessageHandlerProps } from './InventoryMessageHandler.types';
|
||||||
|
import { InventoryBadgeActions } from './reducers/InventoryBadgeReducer';
|
||||||
|
import { InventoryBotActions } from './reducers/InventoryBotReducer';
|
||||||
import { InventoryFurnitureActions } from './reducers/InventoryFurnitureReducer';
|
import { InventoryFurnitureActions } from './reducers/InventoryFurnitureReducer';
|
||||||
import { mergeFragments } from './utils/FurnitureUtilities';
|
import { InventoryPetActions } from './reducers/InventoryPetReducer';
|
||||||
|
import { mergeFurniFragments } from './utils/FurnitureUtilities';
|
||||||
|
import { mergePetFragments } from './utils/PetUtilities';
|
||||||
|
|
||||||
let furniMsgFragments: Map<number, FurnitureListItemParser>[] = null;
|
let furniMsgFragments: Map<number, FurnitureListItemParser>[] = null;
|
||||||
|
let petMsgFragments: Map<number, PetData>[] = null;
|
||||||
|
|
||||||
export const InventoryMessageHandler: FC<InventoryMessageHandlerProps> = props =>
|
export const InventoryMessageHandler: FC<InventoryMessageHandlerProps> = props =>
|
||||||
{
|
{
|
||||||
const { dispatchFurnitureState = null } = useInventoryContext();
|
const { dispatchFurnitureState = null, dispatchBotState = null, dispatchPetState = null, dispatchBadgeState = null } = useInventoryContext();
|
||||||
|
|
||||||
const onFurnitureListAddOrUpdateEvent = useCallback((event: FurnitureListAddOrUpdateEvent) =>
|
const onFurnitureListAddOrUpdateEvent = useCallback((event: FurnitureListAddOrUpdateEvent) =>
|
||||||
{
|
{
|
||||||
@ -30,7 +35,7 @@ export const InventoryMessageHandler: FC<InventoryMessageHandlerProps> = props =
|
|||||||
|
|
||||||
if(!furniMsgFragments) furniMsgFragments = new Array(parser.totalFragments);
|
if(!furniMsgFragments) furniMsgFragments = new Array(parser.totalFragments);
|
||||||
|
|
||||||
const fragment = mergeFragments(parser.fragment, parser.totalFragments, parser.fragmentNumber, furniMsgFragments);
|
const fragment = mergeFurniFragments(parser.fragment, parser.totalFragments, parser.fragmentNumber, furniMsgFragments);
|
||||||
|
|
||||||
if(!fragment) return;
|
if(!fragment) return;
|
||||||
|
|
||||||
@ -67,11 +72,107 @@ export const InventoryMessageHandler: FC<InventoryMessageHandlerProps> = props =
|
|||||||
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const onBotInventoryMessageEvent = useCallback((event: BotInventoryMessageEvent) =>
|
||||||
|
{
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
const fragment = Array.from(parser.items.values());
|
||||||
|
|
||||||
|
dispatchBotState({
|
||||||
|
type: InventoryBotActions.PROCESS_FRAGMENT,
|
||||||
|
payload: { fragment }
|
||||||
|
});
|
||||||
|
}, [ dispatchBotState ]);
|
||||||
|
|
||||||
|
const onBotAddedToInventoryEvent = useCallback((event: BotAddedToInventoryEvent) =>
|
||||||
|
{
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
dispatchBotState({
|
||||||
|
type: InventoryBotActions.ADD_BOT,
|
||||||
|
payload: {
|
||||||
|
botData: parser.item
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [ dispatchBotState ]);
|
||||||
|
|
||||||
|
const onBotRemovedFromInventoryEvent = useCallback((event: BotRemovedFromInventoryEvent) =>
|
||||||
|
{
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
dispatchBotState({
|
||||||
|
type: InventoryBotActions.REMOVE_BOT,
|
||||||
|
payload: {
|
||||||
|
botId: parser.itemId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [ dispatchBotState ]);
|
||||||
|
|
||||||
|
const onPetInventoryEvent = useCallback((event: PetInventoryEvent) =>
|
||||||
|
{
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
if(!petMsgFragments) petMsgFragments = new Array(parser.totalFragments);
|
||||||
|
|
||||||
|
const fragment = mergePetFragments(parser.fragment, parser.totalFragments, parser.fragmentNumber, petMsgFragments);
|
||||||
|
|
||||||
|
if(!fragment) return;
|
||||||
|
|
||||||
|
dispatchPetState({
|
||||||
|
type: InventoryPetActions.PROCESS_FRAGMENT,
|
||||||
|
payload: { fragment }
|
||||||
|
});
|
||||||
|
}, [dispatchPetState ]);
|
||||||
|
|
||||||
|
const onPetAddedToInventoryEvent = useCallback((event: PetAddedToInventoryEvent) =>
|
||||||
|
{
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
dispatchPetState({
|
||||||
|
type: InventoryPetActions.ADD_PET,
|
||||||
|
payload: {
|
||||||
|
petData: parser.pet
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [ dispatchPetState ]);
|
||||||
|
|
||||||
|
const onPetRemovedFromInventory = useCallback((event: PetRemovedFromInventory) =>
|
||||||
|
{
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
dispatchPetState({
|
||||||
|
type: InventoryPetActions.REMOVE_PET,
|
||||||
|
payload: {
|
||||||
|
petId: parser.petId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [ dispatchPetState ]);
|
||||||
|
|
||||||
|
const onBadgesEvent = useCallback((event: BadgesEvent) =>
|
||||||
|
{
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
dispatchBadgeState({
|
||||||
|
type: InventoryBadgeActions.SET_BADGES,
|
||||||
|
payload: {
|
||||||
|
badgeCodes: parser.getAllBadgeCodes(),
|
||||||
|
activeBadgeCodes: parser.getActiveBadgeCodes()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [ dispatchBadgeState ]);
|
||||||
|
|
||||||
CreateMessageHook(FurnitureListAddOrUpdateEvent, onFurnitureListAddOrUpdateEvent);
|
CreateMessageHook(FurnitureListAddOrUpdateEvent, onFurnitureListAddOrUpdateEvent);
|
||||||
CreateMessageHook(FurnitureListEvent, onFurnitureListEvent);
|
CreateMessageHook(FurnitureListEvent, onFurnitureListEvent);
|
||||||
CreateMessageHook(FurnitureListInvalidateEvent, onFurnitureListInvalidateEvent);
|
CreateMessageHook(FurnitureListInvalidateEvent, onFurnitureListInvalidateEvent);
|
||||||
CreateMessageHook(FurnitureListRemovedEvent, onFurnitureListRemovedEvent);
|
CreateMessageHook(FurnitureListRemovedEvent, onFurnitureListRemovedEvent);
|
||||||
CreateMessageHook(FurniturePostItPlacedEvent, onFurniturePostItPlacedEvent);
|
CreateMessageHook(FurniturePostItPlacedEvent, onFurniturePostItPlacedEvent);
|
||||||
|
CreateMessageHook(BotInventoryMessageEvent, onBotInventoryMessageEvent);
|
||||||
|
CreateMessageHook(BotRemovedFromInventoryEvent, onBotRemovedFromInventoryEvent);
|
||||||
|
CreateMessageHook(BotAddedToInventoryEvent, onBotAddedToInventoryEvent);
|
||||||
|
CreateMessageHook(PetInventoryEvent, onPetInventoryEvent);
|
||||||
|
CreateMessageHook(PetRemovedFromInventory, onPetRemovedFromInventory);
|
||||||
|
CreateMessageHook(PetAddedToInventoryEvent, onPetAddedToInventoryEvent);
|
||||||
|
CreateMessageHook(BadgesEvent, onBadgesEvent);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import { LocalizeText } from '../../utils/LocalizeText';
|
|||||||
import { InventoryContextProvider } from './context/InventoryContext';
|
import { InventoryContextProvider } from './context/InventoryContext';
|
||||||
import { InventoryMessageHandler } from './InventoryMessageHandler';
|
import { InventoryMessageHandler } from './InventoryMessageHandler';
|
||||||
import { InventoryTabs, InventoryViewProps } from './InventoryView.types';
|
import { InventoryTabs, InventoryViewProps } from './InventoryView.types';
|
||||||
import { initialInventoryBadge, inventoryBadgeReducer } from './reducers/InventortBadgeReducer';
|
import { initialInventoryBadge, inventoryBadgeReducer } from './reducers/InventoryBadgeReducer';
|
||||||
import { initialInventoryBot, inventoryBotReducer } from './reducers/InventoryBotReducer';
|
import { initialInventoryBot, inventoryBotReducer } from './reducers/InventoryBotReducer';
|
||||||
import { initialInventoryFurniture, inventoryFurnitureReducer } from './reducers/InventoryFurnitureReducer';
|
import { initialInventoryFurniture, inventoryFurnitureReducer } from './reducers/InventoryFurnitureReducer';
|
||||||
import { initialInventoryPet, inventoryPetReducer } from './reducers/InventoryPetReducer';
|
import { initialInventoryPet, inventoryPetReducer } from './reducers/InventoryPetReducer';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Dispatch, ProviderProps } from 'react';
|
import { Dispatch, ProviderProps } from 'react';
|
||||||
import { IInventoryBadgeAction, IInventoryBadgeState } from '../reducers/InventortBadgeReducer';
|
import { IInventoryBadgeAction, IInventoryBadgeState } from '../reducers/InventoryBadgeReducer';
|
||||||
import { IInventoryBotAction, IInventoryBotState } from '../reducers/InventoryBotReducer';
|
import { IInventoryBotAction, IInventoryBotState } from '../reducers/InventoryBotReducer';
|
||||||
import { IInventoryFurnitureAction, IInventoryFurnitureState } from '../reducers/InventoryFurnitureReducer';
|
import { IInventoryFurnitureAction, IInventoryFurnitureState } from '../reducers/InventoryFurnitureReducer';
|
||||||
import { IInventoryPetAction, IInventoryPetState } from '../reducers/InventoryPetReducer';
|
import { IInventoryPetAction, IInventoryPetState } from '../reducers/InventoryPetReducer';
|
||||||
|
@ -1 +1,4 @@
|
|||||||
|
@import './badge/InventoryBadgeView';
|
||||||
|
@import './bot/InventoryBotView';
|
||||||
@import './furniture/InventoryFurnitureView';
|
@import './furniture/InventoryFurnitureView';
|
||||||
|
@import './pet/InventoryPetView';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user