mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-18 21:36:27 +01:00
Badge updates
This commit is contained in:
parent
936c9ee2b7
commit
5a3d3e5354
6
src/events/inventory/InventoryBadgesRequestEvent.ts
Normal file
6
src/events/inventory/InventoryBadgesRequestEvent.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
|
||||
export class InventoryBadgesRequestEvent extends NitroEvent
|
||||
{
|
||||
public static REQUEST_BADGES: string = 'IBRE_REQUEST_BADGES';
|
||||
}
|
20
src/events/inventory/InventoryBadgesUpdatedEvent.ts
Normal file
20
src/events/inventory/InventoryBadgesUpdatedEvent.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
|
||||
export class InventoryBadgesUpdatedEvent extends NitroEvent
|
||||
{
|
||||
public static BADGES_UPDATED: string = 'IBUE_BADGES_UPDATED';
|
||||
|
||||
private _badges: string[] = [];
|
||||
|
||||
constructor(type: string, badges: string[] = [])
|
||||
{
|
||||
super(type);
|
||||
|
||||
this._badges = badges;
|
||||
}
|
||||
|
||||
public get badges(): string[]
|
||||
{
|
||||
return this._badges;
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
export * from './InventoryBadgesUpdatedEvent';
|
||||
export * from './InventoryEvent';
|
||||
export * from './InventoryTradeRequestEvent';
|
||||
export * from './InventoryTradeStartEvent';
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { AdvancedMap, BadgesEvent, BotAddedToInventoryEvent, BotInventoryMessageEvent, BotRemovedFromInventoryEvent, FurnitureListAddOrUpdateEvent, FurnitureListEvent, FurnitureListInvalidateEvent, FurnitureListItemParser, FurnitureListRemovedEvent, FurniturePostItPlacedEvent, PetAddedToInventoryEvent, PetData, PetInventoryEvent, PetRemovedFromInventory, TradingAcceptEvent, TradingCloseEvent, TradingCompletedEvent, TradingConfirmationEvent, TradingListItemEvent, TradingNotOpenEvent, TradingOpenEvent, TradingOpenFailedEvent, TradingOtherNotAllowedEvent, TradingYouAreNotAllowedEvent, UnseenItemsEvent } from 'nitro-renderer';
|
||||
import { AdvancedMap, BadgeReceivedEvent, BadgesEvent, BotAddedToInventoryEvent, BotInventoryMessageEvent, BotRemovedFromInventoryEvent, FurnitureListAddOrUpdateEvent, FurnitureListEvent, FurnitureListInvalidateEvent, FurnitureListItemParser, FurnitureListRemovedEvent, FurniturePostItPlacedEvent, PetAddedToInventoryEvent, PetData, PetInventoryEvent, PetRemovedFromInventory, RequestBadgesComposer, TradingAcceptEvent, TradingCloseEvent, TradingCompletedEvent, TradingConfirmationEvent, TradingListItemEvent, TradingNotOpenEvent, TradingOpenEvent, TradingOpenFailedEvent, TradingOtherNotAllowedEvent, TradingYouAreNotAllowedEvent, UnseenItemsEvent } from 'nitro-renderer';
|
||||
import { FC, useCallback } from 'react';
|
||||
import { GetRoomSession, GetSessionDataManager } from '../../api';
|
||||
import { CreateMessageHook } from '../../hooks/messages/message-event';
|
||||
import { InventoryBadgesUpdatedEvent } from '../../events';
|
||||
import { InventoryBadgesRequestEvent } from '../../events/inventory/InventoryBadgesRequestEvent';
|
||||
import { dispatchUiEvent, useUiEvent } from '../../hooks';
|
||||
import { CreateMessageHook, SendMessageHook } from '../../hooks/messages/message-event';
|
||||
import { mergeFurniFragments } from './common/FurnitureUtilities';
|
||||
import { mergePetFragments } from './common/PetUtilities';
|
||||
import { TradeState } from './common/TradeState';
|
||||
@ -17,7 +20,7 @@ let petMsgFragments: Map<number, PetData>[] = null;
|
||||
|
||||
export const InventoryMessageHandler: FC<InventoryMessageHandlerProps> = props =>
|
||||
{
|
||||
const { dispatchFurnitureState = null, dispatchBotState = null, dispatchPetState = null, dispatchBadgeState = null, unseenTracker = null } = useInventoryContext();
|
||||
const { dispatchFurnitureState = null, dispatchBotState = null, dispatchPetState = null, badgeState = null, dispatchBadgeState = null, unseenTracker = null } = useInventoryContext();
|
||||
|
||||
const onFurnitureListAddOrUpdateEvent = useCallback((event: FurnitureListAddOrUpdateEvent) =>
|
||||
{
|
||||
@ -163,6 +166,18 @@ export const InventoryMessageHandler: FC<InventoryMessageHandlerProps> = props =
|
||||
});
|
||||
}, [ dispatchBadgeState ]);
|
||||
|
||||
const onBadgeReceivedEvent = useCallback((event: BadgeReceivedEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
dispatchBadgeState({
|
||||
type: InventoryBadgeActions.ADD_BADGE,
|
||||
payload: {
|
||||
badgeCode: parser.badgeCode
|
||||
}
|
||||
});
|
||||
}, [ dispatchBadgeState ]);
|
||||
|
||||
const onTradingAcceptEvent = useCallback((event: TradingAcceptEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
@ -318,6 +333,7 @@ export const InventoryMessageHandler: FC<InventoryMessageHandlerProps> = props =
|
||||
CreateMessageHook(PetRemovedFromInventory, onPetRemovedFromInventory);
|
||||
CreateMessageHook(PetAddedToInventoryEvent, onPetAddedToInventoryEvent);
|
||||
CreateMessageHook(BadgesEvent, onBadgesEvent);
|
||||
CreateMessageHook(BadgeReceivedEvent, onBadgeReceivedEvent);
|
||||
CreateMessageHook(TradingAcceptEvent, onTradingAcceptEvent);
|
||||
CreateMessageHook(TradingCloseEvent, onTradingCloseEvent);
|
||||
CreateMessageHook(TradingCompletedEvent, onTradingCompletedEvent);
|
||||
@ -330,5 +346,19 @@ export const InventoryMessageHandler: FC<InventoryMessageHandlerProps> = props =
|
||||
CreateMessageHook(TradingYouAreNotAllowedEvent, onTradingYouAreNotAllowedEvent);
|
||||
CreateMessageHook(UnseenItemsEvent, onUnseenItemsEvent);
|
||||
|
||||
const onInventoryBadgesRequestEvent = useCallback((event: InventoryBadgesRequestEvent) =>
|
||||
{
|
||||
if(badgeState.needsBadgeUpdate)
|
||||
{
|
||||
SendMessageHook(new RequestBadgesComposer());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
dispatchUiEvent(new InventoryBadgesUpdatedEvent(InventoryBadgesUpdatedEvent.BADGES_UPDATED, badgeState.badges));
|
||||
}, [ badgeState ])
|
||||
|
||||
useUiEvent(InventoryBadgesRequestEvent.REQUEST_BADGES, onInventoryBadgesRequestEvent);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { IRoomSession, RoomEngineObjectEvent, RoomEngineObjectPlacedEvent, RoomPreviewer, RoomSessionEvent, TradingCancelComposer, TradingCloseComposer, TradingOpenComposer } from 'nitro-renderer';
|
||||
import { FC, useCallback, useEffect, useReducer, useState } from 'react';
|
||||
import { GetRoomEngine } from '../../api';
|
||||
import { InventoryEvent, InventoryTradeRequestEvent } from '../../events';
|
||||
import { InventoryBadgesUpdatedEvent, InventoryEvent, InventoryTradeRequestEvent } from '../../events';
|
||||
import { useRoomEngineEvent } from '../../hooks/events/nitro/room/room-engine-event';
|
||||
import { useRoomSessionManagerEvent } from '../../hooks/events/nitro/session/room-session-manager-event';
|
||||
import { useUiEvent } from '../../hooks/events/ui/ui-event';
|
||||
import { dispatchUiEvent, useUiEvent } from '../../hooks/events/ui/ui-event';
|
||||
import { SendMessageHook } from '../../hooks/messages';
|
||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../layout';
|
||||
import { LocalizeText } from '../../utils/LocalizeText';
|
||||
@ -186,6 +186,13 @@ export const InventoryView: FC<InventoryViewProps> = props =>
|
||||
}
|
||||
}, [ furnitureState.tradeData, isVisible ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
if(!badgeState.badges) return;
|
||||
|
||||
dispatchUiEvent(new InventoryBadgesUpdatedEvent(InventoryBadgesUpdatedEvent.BADGES_UPDATED, badgeState.badges));
|
||||
}, [ badgeState.badges ]);
|
||||
|
||||
return (
|
||||
<InventoryContextProvider value={ { furnitureState, dispatchFurnitureState, botState, dispatchBotState, petState, dispatchPetState, badgeState, dispatchBadgeState, unseenTracker } }>
|
||||
<InventoryMessageHandler />
|
||||
|
@ -23,11 +23,12 @@ export interface IInventoryBadgeAction
|
||||
|
||||
export class InventoryBadgeActions
|
||||
{
|
||||
public static SET_NEEDS_UPDATE: string = 'IBDA_SET_NEEDS_UPDATE';
|
||||
public static SET_BADGE: string = 'IBDA_SET_BADGE';
|
||||
public static SET_BADGES: string = 'IBDA_SET_BADGES';
|
||||
public static ADD_ACTIVE_BADGE: string = 'IBDA_ADD_ACTIVE_BADGE';
|
||||
public static REMOVE_ACTIVE_BADGE: string = 'IBDA_REMOVE_ACTIVE_BADGE';
|
||||
public static SET_NEEDS_UPDATE: string = 'IBA_SET_NEEDS_UPDATE';
|
||||
public static SET_BADGE: string = 'IBA_SET_BADGE';
|
||||
public static SET_BADGES: string = 'IBA_SET_BADGES';
|
||||
public static ADD_BADGE: string = 'IBA_ADD_BADGE';
|
||||
public static ADD_ACTIVE_BADGE: string = 'IBA_ADD_ACTIVE_BADGE';
|
||||
public static REMOVE_ACTIVE_BADGE: string = 'IBA_REMOVE_ACTIVE_BADGE';
|
||||
}
|
||||
|
||||
export const initialInventoryBadge: IInventoryBadgeState = {
|
||||
@ -77,6 +78,14 @@ export const InventoryBadgeReducer: Reducer<IInventoryBadgeState, IInventoryBadg
|
||||
|
||||
return { ...state, badges, activeBadges };
|
||||
}
|
||||
case InventoryBadgeActions.ADD_BADGE: {
|
||||
const badges = [ ...state.badges ];
|
||||
const badge = (action.payload.badgeCode);
|
||||
|
||||
if(badges.indexOf(badge) === -1) badges.push(badge);
|
||||
|
||||
return { ...state, badges };
|
||||
}
|
||||
case InventoryBadgeActions.ADD_ACTIVE_BADGE: {
|
||||
const badgeCode = action.payload.badgeCode;
|
||||
|
||||
|
@ -19,6 +19,7 @@ export const InventoryBadgeView: FC<InventoryBadgeViewProps> = props =>
|
||||
{
|
||||
if(needsBadgeUpdate)
|
||||
{
|
||||
console.log('yee')
|
||||
dispatchBadgeState({
|
||||
type: InventoryBadgeActions.SET_NEEDS_UPDATE,
|
||||
payload: {
|
||||
|
Loading…
Reference in New Issue
Block a user