More inventory changes

This commit is contained in:
Bill 2022-04-01 16:12:46 -04:00
parent cf47ff8f23
commit cf5c46213a
15 changed files with 447 additions and 439 deletions

View File

@ -1,28 +1,26 @@
import { LocalizeText, NotificationUtilities } from '..'; import { LocalizeText, NotificationUtilities } from '..';
import { TradingNotificationType } from './TradingNotificationType'; import { TradingNotificationType } from './TradingNotificationType';
export const TradingNotificationMessage = (type: number) => export const TradingNotificationMessage = (type: number, otherUsername: string = '') =>
{ {
switch(type) switch(type)
{ {
case TradingNotificationType.ALERT_SCAM: case TradingNotificationType.ALERT_SCAM:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.other_not_offering'), null, null, null, LocalizeText('inventory.trading.notification.title')); NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.other_not_offering'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return; return;
case TradingNotificationType.ALERT_OTHER_CANCELLED: case TradingNotificationType.HOTEL_TRADING_DISABLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.closed'), null, null, null, LocalizeText('inventory.trading.notification.title')); case TradingNotificationType.YOU_NOT_ALLOWED:
return; case TradingNotificationType.THEY_NOT_ALLOWED:
case TradingNotificationType.ALERT_ALREADY_OPEN: case TradingNotificationType.ROOM_DISABLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.already_open'), null, null, null, LocalizeText('inventory.trading.notification.title')); case TradingNotificationType.YOU_OPEN:
return; case TradingNotificationType.THEY_OPEN:
case TradingNotificationType.ALERT_OTHER_DISABLED: NotificationUtilities.simpleAlert(LocalizeText(`inventory.trading.openfail.${ type }`, [ 'otherusername' ], [ otherUsername ]), null, null, null, LocalizeText('inventory.trading.openfail.title'));
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.others_account_disabled'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return; return;
case TradingNotificationType.ERROR_WHILE_COMMIT: case TradingNotificationType.ERROR_WHILE_COMMIT:
NotificationUtilities.simpleAlert(`${ LocalizeText('inventory.trading.notification.caption') }, ${ LocalizeText('inventory.trading.notification.commiterror.info') }`, null, null, null, LocalizeText('inventory.trading.notification.title')); NotificationUtilities.simpleAlert(`${ LocalizeText('inventory.trading.notification.caption') }, ${ LocalizeText('inventory.trading.notification.commiterror.info') }`, null, null, null, LocalizeText('inventory.trading.notification.title'));
return; return;
case TradingNotificationType.YOU_NOT_ALLOWED: case TradingNotificationType.THEY_CANCELLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.own_account_disabled'), null, null, null, LocalizeText('inventory.trading.notification.title')); NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.closed'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return; return;
} }
} }

View File

@ -1,9 +1,12 @@
export class TradingNotificationType export class TradingNotificationType
{ {
public static ALERT_SCAM: number = 0; public static ALERT_SCAM: number = 0;
public static ALERT_OTHER_CANCELLED: number = 1; public static HOTEL_TRADING_DISABLED = 1;
public static ALERT_ALREADY_OPEN: number = 2; public static YOU_NOT_ALLOWED: number = 2;
public static ALERT_OTHER_DISABLED: number = 3; public static THEY_NOT_ALLOWED: number = 4;
public static ERROR_WHILE_COMMIT: number = 4; public static ROOM_DISABLED: number = 6;
public static YOU_NOT_ALLOWED: number = 5; public static YOU_OPEN: number = 7;
public static THEY_OPEN: number = 8;
public static ERROR_WHILE_COMMIT: number = 9;
public static THEY_CANCELLED: number = 10;
} }

View File

@ -107,11 +107,11 @@ export const InventoryView: FC<{}> = props =>
return () => return () =>
{ {
setRoomPreviewer(prevValue => setRoomPreviewer(prevValue =>
{ {
prevValue.dispose(); prevValue.dispose();
return null; return null;
}); });
} }
}, []); }, []);
@ -129,15 +129,15 @@ export const InventoryView: FC<{}> = props =>
<> <>
<NitroCardTabsView> <NitroCardTabsView>
{ TABS.map((name, index) => { TABS.map((name, index) =>
{ {
const unseenCount = getCount(UNSEEN_CATEGORIES[index]); const unseenCount = getCount(UNSEEN_CATEGORIES[index]);
return ( return (
<NitroCardTabsItemView key={ index } isActive={ (currentTab === name) } onClick={ event => setCurrentTab(name) } count={ unseenCount }> <NitroCardTabsItemView key={ index } isActive={ (currentTab === name) } onClick={ event => setCurrentTab(name) } count={ unseenCount }>
{ LocalizeText(name) } { LocalizeText(name) }
</NitroCardTabsItemView> </NitroCardTabsItemView>
); );
}) } }) }
</NitroCardTabsView> </NitroCardTabsView>
<NitroCardContentView> <NitroCardContentView>
{ (currentTab === TAB_FURNITURE ) && { (currentTab === TAB_FURNITURE ) &&

View File

@ -48,11 +48,11 @@ export const InventoryBadgeView: FC<{}> = props =>
<Column size={ 7 } overflow="hidden"> <Column size={ 7 } overflow="hidden">
<AutoGrid columnCount={ 4 }> <AutoGrid columnCount={ 4 }>
{ badgeCodes && (badgeCodes.length > 0) && badgeCodes.map((badgeCode, index) => { badgeCodes && (badgeCodes.length > 0) && badgeCodes.map((badgeCode, index) =>
{ {
if(activeBadgeCodes.indexOf(badgeCode) >= 0) return null; if(activeBadgeCodes.indexOf(badgeCode) >= 0) return null;
return <InventoryBadgeItemView key={ index } badgeCode={ badgeCode } /> return <InventoryBadgeItemView key={ index } badgeCode={ badgeCode } />
}) } }) }
</AutoGrid> </AutoGrid>
</Column> </Column>
<Column className="justify-content-between" size={ 5 } overflow="auto"> <Column className="justify-content-between" size={ 5 } overflow="auto">

View File

@ -23,14 +23,14 @@ export const InventoryFurnitureSearchView: FC<InventoryFurnitureSearchViewProps>
const comparison = searchValue.toLocaleLowerCase(); const comparison = searchValue.toLocaleLowerCase();
filteredGroupItems = groupItems.filter(item => filteredGroupItems = groupItems.filter(item =>
{
if(comparison && comparison.length)
{ {
if(comparison && comparison.length) if(item.name.toLocaleLowerCase().includes(comparison)) return item;
{ }
if(item.name.toLocaleLowerCase().includes(comparison)) return item;
}
return null; return null;
}); });
} }
setGroupItems(filteredGroupItems); setGroupItems(filteredGroupItems);

View File

@ -16,8 +16,8 @@ interface InventoryFurnitureViewProps
export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props => export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
{ {
const { roomSession = null, roomPreviewer = null } = props; const { roomSession = null, roomPreviewer = null } = props;
const { groupItems = [], selectedItem = null, selectItem = null } = useInventoryFurni(); const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>([]);
const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>(groupItems); const { groupItems = [], selectedItem = null, selectItem = null, activate = null, deactivate = null } = useInventoryFurni();
const { getCount = null, resetCategory = null } = useInventoryUnseenTracker(); const { getCount = null, resetCategory = null } = useInventoryUnseenTracker();
useEffect(() => useEffect(() =>
@ -86,6 +86,13 @@ export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
} }
}, [ groupItems, getCount, resetCategory ]); }, [ groupItems, getCount, resetCategory ]);
useEffect(() =>
{
const id = activate();
return () => deactivate(id);
}, [ activate, deactivate ]);
if(!groupItems || !groupItems.length) return <InventoryCategoryEmptyView title={ LocalizeText('inventory.empty.title') } desc={ LocalizeText('inventory.empty.desc') } />; if(!groupItems || !groupItems.length) return <InventoryCategoryEmptyView title={ LocalizeText('inventory.empty.title') } desc={ LocalizeText('inventory.empty.desc') } />;
const InventoryFurnitureItemView: FC<{ groupItem: GroupItem }> = props => const InventoryFurnitureItemView: FC<{ groupItem: GroupItem }> = props =>

View File

@ -127,13 +127,13 @@ export const InventoryTradeView: FC<InventoryTradeViewProps> = props =>
const interval = setInterval(() => const interval = setInterval(() =>
{ {
setCountdownTick(prevValue => setCountdownTick(prevValue =>
{ {
const newValue = (prevValue - 1); const newValue = (prevValue - 1);
if(newValue === 0) clearInterval(interval); if(newValue === 0) clearInterval(interval);
return newValue; return newValue;
}); });
}, 1000); }, 1000);
return () => clearInterval(interval); return () => clearInterval(interval);
@ -155,18 +155,18 @@ export const InventoryTradeView: FC<InventoryTradeViewProps> = props =>
<Flex column fullHeight justifyContent="between" overflow="hidden" gap={ 2 }> <Flex column fullHeight justifyContent="between" overflow="hidden" gap={ 2 }>
<AutoGrid columnCount={ 3 }> <AutoGrid columnCount={ 3 }>
{ filteredGroupItems && (filteredGroupItems.length > 0) && filteredGroupItems.map((item, index) => { filteredGroupItems && (filteredGroupItems.length > 0) && filteredGroupItems.map((item, index) =>
{ {
const count = item.getUnlockedCount(); const count = item.getUnlockedCount();
return ( return (
<LayoutGridItem key={ index } className={ !count ? 'opacity-0-5 ' : '' } itemImage={ item.iconUrl } itemCount={ count } itemActive={ (groupItem === item) } itemUniqueNumber={ item.stuffData.uniqueNumber } onClick={ event => (count && setGroupItem(item)) }> <LayoutGridItem key={ index } className={ !count ? 'opacity-0-5 ' : '' } itemImage={ item.iconUrl } itemCount={ count } itemActive={ (groupItem === item) } itemUniqueNumber={ item.stuffData.uniqueNumber } onClick={ event => (count && setGroupItem(item)) }>
{ ((count > 0) && (groupItem === item)) && { ((count > 0) && (groupItem === item)) &&
<Button position="absolute" variant="success" className="trade-button bottom-1 end-1" onClick={ event => attemptItemOffer(1) }> <Button position="absolute" variant="success" className="trade-button bottom-1 end-1" onClick={ event => attemptItemOffer(1) }>
<FontAwesomeIcon icon="chevron-right" /> <FontAwesomeIcon icon="chevron-right" />
</Button> } </Button> }
</LayoutGridItem> </LayoutGridItem>
); );
}) } }) }
</AutoGrid> </AutoGrid>
<Base fullWidth className="badge bg-muted"> <Base fullWidth className="badge bg-muted">
{ groupItem ? groupItem.name : LocalizeText('catalog_selectproduct') } { groupItem ? groupItem.name : LocalizeText('catalog_selectproduct') }
@ -182,20 +182,20 @@ export const InventoryTradeView: FC<InventoryTradeViewProps> = props =>
</Flex> </Flex>
<AutoGrid columnCount={ 3 }> <AutoGrid columnCount={ 3 }>
{ Array.from(Array(MAX_ITEMS_TO_TRADE), (e, i) => { Array.from(Array(MAX_ITEMS_TO_TRADE), (e, i) =>
{ {
const item = (ownUser.userItems.getWithIndex(i) || null); const item = (ownUser.userItems.getWithIndex(i) || null);
if(!item) return <LayoutGridItem key={ i } />; if(!item) return <LayoutGridItem key={ i } />;
return ( return (
<LayoutGridItem key={ i } itemActive={ (ownGroupItem === item) } itemImage={ item.iconUrl } itemCount={ item.getTotalCount() } itemUniqueNumber={ item.stuffData.uniqueNumber } onClick={ event => setOwnGroupItem(item) }> <LayoutGridItem key={ i } itemActive={ (ownGroupItem === item) } itemImage={ item.iconUrl } itemCount={ item.getTotalCount() } itemUniqueNumber={ item.stuffData.uniqueNumber } onClick={ event => setOwnGroupItem(item) }>
{ (ownGroupItem === item) && { (ownGroupItem === item) &&
<Button position="absolute" variant="danger" className="trade-button bottom-1 start-1" onClick={ event => removeItem(item) }> <Button position="absolute" variant="danger" className="trade-button bottom-1 start-1" onClick={ event => removeItem(item) }>
<FontAwesomeIcon icon="chevron-left" /> <FontAwesomeIcon icon="chevron-left" />
</Button> } </Button> }
</LayoutGridItem> </LayoutGridItem>
); );
}) } }) }
</AutoGrid> </AutoGrid>
<Base fullWidth className="badge bg-muted"> <Base fullWidth className="badge bg-muted">
{ ownGroupItem ? ownGroupItem.name : LocalizeText('catalog_selectproduct') } { ownGroupItem ? ownGroupItem.name : LocalizeText('catalog_selectproduct') }
@ -208,13 +208,13 @@ export const InventoryTradeView: FC<InventoryTradeViewProps> = props =>
</Flex> </Flex>
<AutoGrid columnCount={ 3 }> <AutoGrid columnCount={ 3 }>
{ Array.from(Array(MAX_ITEMS_TO_TRADE), (e, i) => { Array.from(Array(MAX_ITEMS_TO_TRADE), (e, i) =>
{ {
const item = (otherUser.userItems.getWithIndex(i) || null); const item = (otherUser.userItems.getWithIndex(i) || null);
if(!item) return <LayoutGridItem key={ i } />; if(!item) return <LayoutGridItem key={ i } />;
return <LayoutGridItem key={ i } itemActive={ (otherGroupItem === item) } itemImage={ item.iconUrl } itemCount={ item.getTotalCount() } itemUniqueNumber={ item.stuffData.uniqueNumber } onClick={ event => setOtherGroupItem(item) } />; return <LayoutGridItem key={ i } itemActive={ (otherGroupItem === item) } itemImage={ item.iconUrl } itemCount={ item.getTotalCount() } itemUniqueNumber={ item.stuffData.uniqueNumber } onClick={ event => setOtherGroupItem(item) } />;
}) } }) }
</AutoGrid> </AutoGrid>
<Base fullWidth className="badge bg-muted w-100"> <Base fullWidth className="badge bg-muted w-100">
{ otherGroupItem ? otherGroupItem.name : LocalizeText('catalog_selectproduct') } { otherGroupItem ? otherGroupItem.name : LocalizeText('catalog_selectproduct') }

View File

@ -94,7 +94,7 @@ export const UserSettingsView: FC<{}> = props =>
if(doUpdate) setUserSettings(clone); if(doUpdate) setUserSettings(clone);
DispatchMainEvent(clone) DispatchMainEvent(clone)
}, [userSettings]); }, [ userSettings ]);
const saveRangeSlider = useCallback((type: string) => const saveRangeSlider = useCallback((type: string) =>
{ {
@ -104,14 +104,14 @@ export const UserSettingsView: FC<{}> = props =>
SendMessageComposer(new UserSettingsSoundComposer(Math.round(userSettings.volumeSystem), Math.round(userSettings.volumeFurni), Math.round(userSettings.volumeTrax))); SendMessageComposer(new UserSettingsSoundComposer(Math.round(userSettings.volumeSystem), Math.round(userSettings.volumeFurni), Math.round(userSettings.volumeTrax)));
break; break;
} }
}, [userSettings]); }, [ userSettings ]);
useEffect(() => useEffect(() =>
{ {
if(!userSettings) return; if(!userSettings) return;
DispatchUiEvent(userSettings); DispatchUiEvent(userSettings);
}, [userSettings]); }, [ userSettings ]);
if(!isVisible) return null; if(!isVisible) return null;

View File

@ -21,30 +21,30 @@ const useInventoryBadgesState = () =>
const toggleBadge = (badgeCode: string) => const toggleBadge = (badgeCode: string) =>
{ {
setActiveBadgeCodes(prevValue => setActiveBadgeCodes(prevValue =>
{
const newValue = [ ...prevValue ];
const index = newValue.indexOf(badgeCode);
if(index === -1)
{ {
const newValue = [ ...prevValue ]; if(!canWearBadges()) return prevValue;
const index = newValue.indexOf(badgeCode); newValue.push(badgeCode);
}
else
{
newValue.splice(index, 1);
}
if(index === -1) const composer = new SetActivatedBadgesComposer();
{
if(!canWearBadges()) return prevValue;
newValue.push(badgeCode); for(let i = 0; i < maxBadgeCount; i++) composer.addActivatedBadge(newValue[i] || null);
}
else
{
newValue.splice(index, 1);
}
const composer = new SetActivatedBadgesComposer(); SendMessageComposer(composer);
for(let i = 0; i < maxBadgeCount; i++) composer.addActivatedBadge(newValue[i] || null); return newValue;
});
SendMessageComposer(composer);
return newValue;
});
} }
const selectBadge = (badgeCode: string) => const selectBadge = (badgeCode: string) =>
@ -89,22 +89,22 @@ const useInventoryBadgesState = () =>
BatchUpdates(() => BatchUpdates(() =>
{ {
setBadgeCodes(prevValue => setBadgeCodes(prevValue =>
{ {
const newValue = [ ...prevValue ]; const newValue = [ ...prevValue ];
newValue.push(parser.badgeCode); newValue.push(parser.badgeCode);
return newValue; return newValue;
}); });
setBadgeIds(prevValue => setBadgeIds(prevValue =>
{ {
const newValue = [ ...prevValue ]; const newValue = [ ...prevValue ];
newValue.push(parser.badgeId); newValue.push(parser.badgeId);
return newValue; return newValue;
}) })
}); });
}, []); }, []);
@ -115,15 +115,15 @@ const useInventoryBadgesState = () =>
if(!badgeCodes || !badgeCodes.length) return; if(!badgeCodes || !badgeCodes.length) return;
setSelectedBadgeCode(prevValue => setSelectedBadgeCode(prevValue =>
{ {
let newValue = prevValue; let newValue = prevValue;
if(newValue && (badgeCodes.indexOf(newValue) === -1)) newValue = null; if(newValue && (badgeCodes.indexOf(newValue) === -1)) newValue = null;
if(!newValue) newValue = badgeCodes[0]; if(!newValue) newValue = badgeCodes[0];
return newValue; return newValue;
}); });
}, [ badgeCodes ]); }, [ badgeCodes ]);
useEffect(() => useEffect(() =>

View File

@ -21,55 +21,55 @@ const useInventoryBotsState = () =>
const parser = event.getParser(); const parser = event.getParser();
setBotItems(prevValue => setBotItems(prevValue =>
{
const newValue = [ ...prevValue ];
const existingIds = newValue.map(item => item.botData.id);
const addedDatas: BotData[] = [];
for(const botData of parser.items.values()) ((existingIds.indexOf(botData.id) === -1) && addedDatas.push(botData));
for(const existingId of existingIds)
{ {
const newValue = [ ...prevValue ]; let remove = true;
const existingIds = newValue.map(item => item.botData.id);
const addedDatas: BotData[] = [];
for(const botData of parser.items.values()) ((existingIds.indexOf(botData.id) === -1) && addedDatas.push(botData)); for(const botData of parser.items.values())
for(const existingId of existingIds)
{ {
let remove = true; if(botData.id === existingId)
for(const botData of parser.items.values())
{ {
if(botData.id === existingId) remove = false;
{
remove = false;
break; break;
}
} }
if(!remove) continue;
const index = newValue.findIndex(item => (item.botData.id === existingId));
const botItem = newValue[index];
if((index === -1) || !botItem) continue;
if(getPlacingItemId() === botItem.botData.id)
{
cancelRoomObjectPlacement();
CreateLinkEvent('inventory/open');
}
newValue.splice(index, 1);
} }
for(const botData of addedDatas) if(!remove) continue;
{
const botItem = { botData } as IBotItem;
const unseen = isUnseen(UnseenItemCategory.BOT, botData.id);
if(unseen) newValue.unshift(botItem); const index = newValue.findIndex(item => (item.botData.id === existingId));
newValue.push(botItem); const botItem = newValue[index];
if((index === -1) || !botItem) continue;
if(getPlacingItemId() === botItem.botData.id)
{
cancelRoomObjectPlacement();
CreateLinkEvent('inventory/open');
} }
return newValue; newValue.splice(index, 1);
}); }
for(const botData of addedDatas)
{
const botItem = { botData } as IBotItem;
const unseen = isUnseen(UnseenItemCategory.BOT, botData.id);
if(unseen) newValue.unshift(botItem);
newValue.push(botItem);
}
return newValue;
});
}, [ isUnseen ]); }, [ isUnseen ]);
UseMessageEventHook(BotInventoryMessageEvent, onBotInventoryMessageEvent); UseMessageEventHook(BotInventoryMessageEvent, onBotInventoryMessageEvent);
@ -79,19 +79,19 @@ const useInventoryBotsState = () =>
const parser = event.getParser(); const parser = event.getParser();
setBotItems(prevValue => setBotItems(prevValue =>
{ {
const newValue = [ ...prevValue ]; const newValue = [ ...prevValue ];
const index = newValue.findIndex(item => (item.botData.id === parser.item.id)); const index = newValue.findIndex(item => (item.botData.id === parser.item.id));
if(index >= 0) return prevValue; if(index >= 0) return prevValue;
const botItem = { botData: parser.item } as IBotItem; const botItem = { botData: parser.item } as IBotItem;
newValue.push(botItem); newValue.push(botItem);
return newValue; return newValue;
}); });
}, []); }, []);
UseMessageEventHook(BotAddedToInventoryEvent, onBotAddedToInventoryEvent); UseMessageEventHook(BotAddedToInventoryEvent, onBotAddedToInventoryEvent);
@ -101,24 +101,24 @@ const useInventoryBotsState = () =>
const parser = event.getParser(); const parser = event.getParser();
setBotItems(prevValue => setBotItems(prevValue =>
{
const newValue = [ ...prevValue ];
const index = newValue.findIndex(item => (item.botData.id === parser.itemId));
if(index === -1) return prevValue;
newValue.splice(index, 1);
if(getPlacingItemId() === parser.itemId)
{ {
const newValue = [ ...prevValue ]; cancelRoomObjectPlacement();
const index = newValue.findIndex(item => (item.botData.id === parser.itemId)); CreateLinkEvent('inventory/show');
}
if(index === -1) return prevValue; return newValue;
});
newValue.splice(index, 1);
if(getPlacingItemId() === parser.itemId)
{
cancelRoomObjectPlacement();
CreateLinkEvent('inventory/show');
}
return newValue;
});
}, []); }, []);
UseMessageEventHook(BotRemovedFromInventoryEvent, onBotRemovedFromInventoryEvent); UseMessageEventHook(BotRemovedFromInventoryEvent, onBotRemovedFromInventoryEvent);
@ -128,15 +128,15 @@ const useInventoryBotsState = () =>
if(!botItems || !botItems.length) return; if(!botItems || !botItems.length) return;
setSelectedBot(prevValue => setSelectedBot(prevValue =>
{ {
let newValue = prevValue; let newValue = prevValue;
if(newValue && (botItems.indexOf(newValue) === -1)) newValue = null; if(newValue && (botItems.indexOf(newValue) === -1)) newValue = null;
if(!newValue) newValue = botItems[0]; if(!newValue) newValue = botItems[0];
return newValue; return newValue;
}); });
}, [ botItems ]); }, [ botItems ]);
useEffect(() => useEffect(() =>

View File

@ -29,63 +29,63 @@ const useInventoryFurniState = () =>
const parser = event.getParser(); const parser = event.getParser();
setGroupItems(prevValue => setGroupItems(prevValue =>
{
const newValue = [ ...prevValue ];
for(const item of parser.items)
{ {
const newValue = [ ...prevValue ]; let i = 0;
let groupItem: GroupItem = null;
for(const item of parser.items) while(i < newValue.length)
{ {
let i = 0; const group = newValue[i];
let groupItem: GroupItem = null;
while(i < newValue.length) let j = 0;
while(j < group.items.length)
{ {
const group = newValue[i]; const furniture = group.items[j];
let j = 0; if(furniture.id === item.itemId)
while(j < group.items.length)
{ {
const furniture = group.items[j]; furniture.update(item);
if(furniture.id === item.itemId) const newFurniture = [ ...group.items ];
{
furniture.update(item);
const newFurniture = [ ...group.items ]; newFurniture[j] = furniture;
newFurniture[j] = furniture; group.items = newFurniture;
group.items = newFurniture; groupItem = group;
groupItem = group; break;
break;
}
j++
} }
if(groupItem) break; j++
i++;
} }
if(groupItem) if(groupItem) break;
{
groupItem.hasUnseenItems = true;
newValue[i] = CloneObject(groupItem); i++;
}
else
{
const furniture = new FurnitureItem(item);
addFurnitureItem(newValue, furniture, isUnseen(UnseenItemCategory.FURNI, item.itemId));
}
} }
return newValue; if(groupItem)
}); {
groupItem.hasUnseenItems = true;
newValue[i] = CloneObject(groupItem);
}
else
{
const furniture = new FurnitureItem(item);
addFurnitureItem(newValue, furniture, isUnseen(UnseenItemCategory.FURNI, item.itemId));
}
}
return newValue;
});
}, [ isUnseen ]); }, [ isUnseen ]);
UseMessageEventHook(FurnitureListAddOrUpdateEvent, onFurnitureListAddOrUpdateEvent); UseMessageEventHook(FurnitureListAddOrUpdateEvent, onFurnitureListAddOrUpdateEvent);
@ -101,65 +101,65 @@ const useInventoryFurniState = () =>
if(!fragment) return; if(!fragment) return;
setGroupItems(prevValue => setGroupItems(prevValue =>
{
const newValue = [ ...prevValue ];
const existingIds = getAllItemIds(newValue);
for(const existingId of existingIds)
{ {
const newValue = [ ...prevValue ]; if(fragment.get(existingId)) continue;
const existingIds = getAllItemIds(newValue);
for(const existingId of existingIds) let index = 0;
while(index < newValue.length)
{ {
if(fragment.get(existingId)) continue; const group = newValue[index];
const item = group.remove(existingId);
let index = 0; if(!item)
while(index < newValue.length)
{ {
const group = newValue[index]; index++;
const item = group.remove(existingId);
if(!item) continue;
{
index++;
continue;
}
if(getPlacingItemId() === item.ref)
{
cancelRoomObjectPlacement();
if(!attemptItemPlacement(group))
{
CreateLinkEvent('inventory/show');
}
}
if(group.getTotalCount() <= 0)
{
newValue.splice(index, 1);
group.dispose();
}
break;
} }
if(getPlacingItemId() === item.ref)
{
cancelRoomObjectPlacement();
if(!attemptItemPlacement(group))
{
CreateLinkEvent('inventory/show');
}
}
if(group.getTotalCount() <= 0)
{
newValue.splice(index, 1);
group.dispose();
}
break;
} }
}
for(const itemId of fragment.keys()) for(const itemId of fragment.keys())
{ {
if(existingIds.indexOf(itemId) >= 0) continue; if(existingIds.indexOf(itemId) >= 0) continue;
const parser = fragment.get(itemId); const parser = fragment.get(itemId);
if(!parser) continue; if(!parser) continue;
const item = new FurnitureItem(parser); const item = new FurnitureItem(parser);
addFurnitureItem(newValue, item, isUnseen(UnseenItemCategory.FURNI, itemId)); addFurnitureItem(newValue, item, isUnseen(UnseenItemCategory.FURNI, itemId));
} }
return newValue; return newValue;
}); });
furniMsgFragments = null; furniMsgFragments = null;
}, [ isUnseen ]); }, [ isUnseen ]);
@ -178,42 +178,42 @@ const useInventoryFurniState = () =>
const parser = event.getParser(); const parser = event.getParser();
setGroupItems(prevValue => setGroupItems(prevValue =>
{
const newValue = [ ...prevValue ];
let index = 0;
while(index < newValue.length)
{ {
const newValue = [ ...prevValue ]; const group = newValue[index];
const item = group.remove(parser.itemId);
let index = 0; if(!item)
while(index < newValue.length)
{ {
const group = newValue[index]; index++;
const item = group.remove(parser.itemId);
if(!item) continue;
{ }
index++;
continue;
}
if(getPlacingItemId() === item.ref) if(getPlacingItemId() === item.ref)
{ {
cancelRoomObjectPlacement(); cancelRoomObjectPlacement();
if(!attemptItemPlacement(group)) CreateLinkEvent('inventory/show'); if(!attemptItemPlacement(group)) CreateLinkEvent('inventory/show');
}
if(group.getTotalCount() <= 0)
{
newValue.splice(index, 1);
group.dispose();
}
break;
} }
return newValue; if(group.getTotalCount() <= 0)
}); {
newValue.splice(index, 1);
group.dispose();
}
break;
}
return newValue;
});
}, []); }, []);
UseMessageEventHook(FurnitureListRemovedEvent, onFurnitureListRemovedEvent); UseMessageEventHook(FurnitureListRemovedEvent, onFurnitureListRemovedEvent);
@ -230,15 +230,15 @@ const useInventoryFurniState = () =>
if(!groupItems || !groupItems.length) return; if(!groupItems || !groupItems.length) return;
setSelectedItem(prevValue => setSelectedItem(prevValue =>
{ {
let newValue = prevValue; let newValue = prevValue;
if(newValue && (groupItems.indexOf(newValue) === -1)) newValue = null; if(newValue && (groupItems.indexOf(newValue) === -1)) newValue = null;
if(!newValue) newValue = groupItems[0]; if(!newValue) newValue = groupItems[0];
return newValue; return newValue;
}); });
}, [ groupItems ]); }, [ groupItems ]);
useEffect(() => useEffect(() =>
@ -258,17 +258,10 @@ export const useInventoryFurni = () =>
const { setIsVisible, ...rest } = useBetween(useInventoryFurniState); const { setIsVisible, ...rest } = useBetween(useInventoryFurniState);
const { isVisible = false, activate = null, deactivate = null } = useSharedVisibility(); const { isVisible = false, activate = null, deactivate = null } = useSharedVisibility();
useEffect(() =>
{
const id = activate();
return () => deactivate(id);
}, [ activate, deactivate ]);
useEffect(() => useEffect(() =>
{ {
setIsVisible(isVisible); setIsVisible(isVisible);
}, [ isVisible, setIsVisible ]); }, [ isVisible, setIsVisible ]);
return { ...rest }; return { activate, deactivate, ...rest };
} }

View File

@ -31,13 +31,13 @@ const useInventoryPetsState = () =>
if(!fragment) return; if(!fragment) return;
setPetItems(prevValue => setPetItems(prevValue =>
{ {
const newValue = [ ...prevValue ]; const newValue = [ ...prevValue ];
processPetFragment(newValue, fragment, isUnseen); processPetFragment(newValue, fragment, isUnseen);
return newValue; return newValue;
}); });
petMsgFragments = null; petMsgFragments = null;
}, [ isUnseen ]); }, [ isUnseen ]);
@ -49,13 +49,13 @@ const useInventoryPetsState = () =>
const parser = event.getParser(); const parser = event.getParser();
setPetItems(prevValue => setPetItems(prevValue =>
{ {
const newValue = [ ...prevValue ]; const newValue = [ ...prevValue ];
addSinglePetItem(parser.pet, newValue, true); addSinglePetItem(parser.pet, newValue, true);
return newValue; return newValue;
}); });
}, []); }, []);
UseMessageEventHook(PetAddedToInventoryEvent, onPetAddedToInventoryEvent); UseMessageEventHook(PetAddedToInventoryEvent, onPetAddedToInventoryEvent);
@ -65,13 +65,13 @@ const useInventoryPetsState = () =>
const parser = event.getParser(); const parser = event.getParser();
setPetItems(prevValue => setPetItems(prevValue =>
{ {
const newValue = [ ...prevValue ]; const newValue = [ ...prevValue ];
removePetItemById(parser.petId, newValue); removePetItemById(parser.petId, newValue);
return newValue; return newValue;
}); });
}, []); }, []);
UseMessageEventHook(PetRemovedFromInventory, onPetRemovedFromInventory); UseMessageEventHook(PetRemovedFromInventory, onPetRemovedFromInventory);
@ -81,15 +81,15 @@ const useInventoryPetsState = () =>
if(!petItems || !petItems.length) return; if(!petItems || !petItems.length) return;
setSelectedPet(prevValue => setSelectedPet(prevValue =>
{ {
let newValue = prevValue; let newValue = prevValue;
if(newValue && (petItems.indexOf(newValue) === -1)) newValue = null; if(newValue && (petItems.indexOf(newValue) === -1)) newValue = null;
if(!newValue) newValue = petItems[0]; if(!newValue) newValue = petItems[0];
return newValue; return newValue;
}); });
}, [ petItems ]); }, [ petItems ]);
useEffect(() => useEffect(() =>

View File

@ -1,5 +1,5 @@
import { AdvancedMap, TradingAcceptComposer, TradingAcceptEvent, TradingCancelComposer, TradingCloseComposer, TradingCloseEvent, TradingCloseParser, TradingCompletedEvent, TradingConfirmationComposer, TradingConfirmationEvent, TradingListItemEvent, TradingListItemRemoveComposer, TradingNotOpenEvent, TradingOpenComposer, TradingOpenEvent, TradingOpenFailedEvent, TradingOpenFailedParser, TradingOtherNotAllowedEvent, TradingUnacceptComposer, TradingYouAreNotAllowedEvent } from '@nitrots/nitro-renderer'; import { AdvancedMap, TradingAcceptComposer, TradingAcceptEvent, TradingCancelComposer, TradingCloseComposer, TradingCloseEvent, TradingCloseParser, TradingCompletedEvent, TradingConfirmationComposer, TradingConfirmationEvent, TradingListItemEvent, TradingListItemRemoveComposer, TradingNotOpenEvent, TradingOpenComposer, TradingOpenEvent, TradingOpenFailedEvent, TradingOtherNotAllowedEvent, TradingUnacceptComposer, TradingYouAreNotAllowedEvent } from '@nitrots/nitro-renderer';
import { useCallback, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { useBetween } from 'use-between'; import { useBetween } from 'use-between';
import { useInventoryFurni } from '.'; import { useInventoryFurni } from '.';
import { BatchUpdates, UseMessageEventHook } from '..'; import { BatchUpdates, UseMessageEventHook } from '..';
@ -13,7 +13,7 @@ const useInventoryTradeState = () =>
const [ ownUser, setOwnUser ] = useState<TradeUserData>(null); const [ ownUser, setOwnUser ] = useState<TradeUserData>(null);
const [ otherUser, setOtherUser ] = useState<TradeUserData>(null); const [ otherUser, setOtherUser ] = useState<TradeUserData>(null);
const [ tradeState, setTradeState ] = useState(TradeState.TRADING_STATE_READY); const [ tradeState, setTradeState ] = useState(TradeState.TRADING_STATE_READY);
const { groupItems = [], setGroupItems = null } = useInventoryFurni(); const { groupItems = [], setGroupItems = null, activate = null, deactivate = null } = useInventoryFurni();
const isTrading = (tradeState >= TradeState.TRADING_STATE_RUNNING); const isTrading = (tradeState >= TradeState.TRADING_STATE_RUNNING);
const progressTrade = () => const progressTrade = () =>
@ -90,25 +90,25 @@ const useInventoryTradeState = () =>
if(ownUser.userId === parser.userID) if(ownUser.userId === parser.userID)
{ {
setOwnUser(prevValue => setOwnUser(prevValue =>
{ {
const newValue = CloneObject(prevValue); const newValue = CloneObject(prevValue);
newValue.accepts = parser.userAccepts; newValue.accepts = parser.userAccepts;
return newValue; return newValue;
}); });
} }
else if(otherUser.userId === parser.userID) else if(otherUser.userId === parser.userID)
{ {
setOtherUser(prevValue => setOtherUser(prevValue =>
{ {
const newValue = CloneObject(prevValue); const newValue = CloneObject(prevValue);
newValue.accepts = parser.userAccepts; newValue.accepts = parser.userAccepts;
return newValue; return newValue;
}); });
} }
}, [ ownUser, otherUser ]); }, [ ownUser, otherUser ]);
@ -126,7 +126,7 @@ const useInventoryTradeState = () =>
{ {
if(ownUser && (parser.userID !== ownUser.userId)) if(ownUser && (parser.userID !== ownUser.userId))
{ {
TradingNotificationMessage(TradingNotificationType.ALERT_OTHER_CANCELLED); TradingNotificationMessage(TradingNotificationType.THEY_CANCELLED);
} }
} }
@ -170,69 +170,69 @@ const useInventoryTradeState = () =>
const secondUserItems = parseTradeItems(parser.secondUserItemArray); const secondUserItems = parseTradeItems(parser.secondUserItemArray);
setOwnUser(prevValue => setOwnUser(prevValue =>
{
const newValue = CloneObject(prevValue);
if(newValue.userId === parser.firstUserID)
{ {
const newValue = CloneObject(prevValue); newValue.creditsCount = parser.firstUserNumCredits;
newValue.itemCount = parser.firstUserNumItems;
newValue.userItems = firstUserItems;
}
else
{
newValue.creditsCount = parser.secondUserNumCredits;
newValue.itemCount = parser.secondUserNumItems;
newValue.userItems = secondUserItems;
}
if(newValue.userId === parser.firstUserID) const tradeIds: number[] = [];
for(const groupItem of newValue.userItems.getValues())
{
let i = 0;
while(i < groupItem.getTotalCount())
{ {
newValue.creditsCount = parser.firstUserNumCredits; const item = groupItem.getItemByIndex(i);
newValue.itemCount = parser.firstUserNumItems;
newValue.userItems = firstUserItems; if(item) tradeIds.push(item.ref);
}
else i++;
{
newValue.creditsCount = parser.secondUserNumCredits;
newValue.itemCount = parser.secondUserNumItems;
newValue.userItems = secondUserItems;
} }
}
const tradeIds: number[] = []; setGroupItems(prevValue =>
{
const newValue = [ ...prevValue ];
for(const groupItem of newValue.userItems.getValues()) for(const groupItem of newValue) groupItem.lockItemIds(tradeIds);
{
let i = 0;
while(i < groupItem.getTotalCount())
{
const item = groupItem.getItemByIndex(i);
if(item) tradeIds.push(item.ref);
i++;
}
}
setGroupItems(prevValue =>
{
const newValue = [ ...prevValue ];
for(const groupItem of newValue) groupItem.lockItemIds(tradeIds);
return newValue;
});
return newValue; return newValue;
}); });
return newValue;
});
setOtherUser(prevValue => setOtherUser(prevValue =>
{
const newValue = CloneObject(prevValue);
if(newValue.userId === parser.firstUserID)
{ {
const newValue = CloneObject(prevValue); newValue.creditsCount = parser.firstUserNumCredits;
newValue.itemCount = parser.firstUserNumItems;
newValue.userItems = firstUserItems;
}
else
{
newValue.creditsCount = parser.secondUserNumCredits;
newValue.itemCount = parser.secondUserNumItems;
newValue.userItems = secondUserItems;
}
if(newValue.userId === parser.firstUserID) return newValue;
{ });
newValue.creditsCount = parser.firstUserNumCredits;
newValue.itemCount = parser.firstUserNumItems;
newValue.userItems = firstUserItems;
}
else
{
newValue.creditsCount = parser.secondUserNumCredits;
newValue.itemCount = parser.secondUserNumItems;
newValue.userItems = secondUserItems;
}
return newValue;
});
}, [ setGroupItems ]); }, [ setGroupItems ]);
UseMessageEventHook(TradingListItemEvent, onTradingListItemEvent); UseMessageEventHook(TradingListItemEvent, onTradingListItemEvent);
@ -294,9 +294,7 @@ const useInventoryTradeState = () =>
{ {
const parser = event.getParser(); const parser = event.getParser();
if((parser.reason !== TradingOpenFailedParser.REASON_YOU_ARE_ALREADY_TRADING && (parser.reason !== TradingOpenFailedParser.REASON_OTHER_USER_ALREADY_TRADING))) return; TradingNotificationMessage(parser.reason, parser.otherUserName);
TradingNotificationMessage(TradingNotificationType.ALERT_ALREADY_OPEN);
}, []); }, []);
UseMessageEventHook(TradingOpenFailedEvent, onTradingOpenFailedEvent); UseMessageEventHook(TradingOpenFailedEvent, onTradingOpenFailedEvent);
@ -305,7 +303,7 @@ const useInventoryTradeState = () =>
{ {
const parser = event.getParser(); const parser = event.getParser();
TradingNotificationMessage(TradingNotificationType.ALERT_OTHER_DISABLED); TradingNotificationMessage(TradingNotificationType.THEY_NOT_ALLOWED);
}, []); }, []);
UseMessageEventHook(TradingOtherNotAllowedEvent, onTradingOtherNotAllowedEvent); UseMessageEventHook(TradingOtherNotAllowedEvent, onTradingOtherNotAllowedEvent);
@ -319,6 +317,15 @@ const useInventoryTradeState = () =>
UseMessageEventHook(TradingYouAreNotAllowedEvent, onTradingYouAreNotAllowedEvent); UseMessageEventHook(TradingYouAreNotAllowedEvent, onTradingYouAreNotAllowedEvent);
useEffect(() =>
{
if(tradeState === TradeState.TRADING_STATE_READY) return;
const id = activate();
return () => deactivate(id);
}, [ tradeState, activate, deactivate ]);
return { ownUser, otherUser, tradeState, setTradeState, isTrading, groupItems, progressTrade, removeItem, stopTrading }; return { ownUser, otherUser, tradeState, setTradeState, isTrading, groupItems, progressTrade, removeItem, stopTrading };
} }

View File

@ -27,13 +27,13 @@ const useInventoryUnseenTrackerState = () =>
if(!getCount(category)) return false; if(!getCount(category)) return false;
setUnseenItems(prevValue => setUnseenItems(prevValue =>
{ {
const newValue = new Map(prevValue); const newValue = new Map(prevValue);
newValue.delete(category); newValue.delete(category);
return newValue; return newValue;
}); });
sendResetCategoryMessage(category); sendResetCategoryMessage(category);
@ -45,13 +45,13 @@ const useInventoryUnseenTrackerState = () =>
if(getCount(category)) return false; if(getCount(category)) return false;
setUnseenItems(prevValue => setUnseenItems(prevValue =>
{ {
const newValue = new Map(prevValue); const newValue = new Map(prevValue);
newValue.delete(category); newValue.delete(category);
return newValue; return newValue;
}); });
sendResetCategoryMessage(category); sendResetCategoryMessage(category);
@ -63,14 +63,14 @@ const useInventoryUnseenTrackerState = () =>
if(!getCount(category)) return false; if(!getCount(category)) return false;
setUnseenItems(prevValue => setUnseenItems(prevValue =>
{ {
const newValue = new Map(prevValue); const newValue = new Map(prevValue);
const existing = newValue.get(category); const existing = newValue.get(category);
if(existing) for(const itemId of itemIds) existing.splice(existing.indexOf(itemId), 1); if(existing) for(const itemId of itemIds) existing.splice(existing.indexOf(itemId), 1);
return newValue; return newValue;
}); });
sendResetItemsMessage(category, itemIds); sendResetItemsMessage(category, itemIds);
@ -91,18 +91,18 @@ const useInventoryUnseenTrackerState = () =>
if(!unseenItems.has(category)) return false; if(!unseenItems.has(category)) return false;
setUnseenItems(prevValue => setUnseenItems(prevValue =>
{
const newValue = new Map(prevValue);
const items = newValue.get(category);
const index = items.indexOf(itemId);
if(index >= 0)
{ {
const newValue = new Map(prevValue); items.splice(index, 1);
const items = newValue.get(category); }
const index = items.indexOf(itemId);
if(index >= 0) return newValue;
{ });
items.splice(index, 1);
}
return newValue;
});
} }
const onUnseenItemsEvent = useCallback((event: UnseenItemsEvent) => const onUnseenItemsEvent = useCallback((event: UnseenItemsEvent) =>
@ -110,27 +110,27 @@ const useInventoryUnseenTrackerState = () =>
const parser = event.getParser(); const parser = event.getParser();
setUnseenItems(prevValue => setUnseenItems(prevValue =>
{
const newValue = new Map(prevValue);
for(const category of parser.categories)
{ {
const newValue = new Map(prevValue); let existing = newValue.get(category);
for(const category of parser.categories) if(!existing)
{ {
let existing = newValue.get(category); existing = [];
if(!existing) newValue.set(category, existing);
{
existing = [];
newValue.set(category, existing);
}
const itemIds = parser.getItemsByCategory(category);
for(const itemId of itemIds) ((existing.indexOf(itemId) === -1) && existing.push(itemId));
} }
return newValue; const itemIds = parser.getItemsByCategory(category);
});
for(const itemId of itemIds) ((existing.indexOf(itemId) === -1) && existing.push(itemId));
}
return newValue;
});
}, []); }, []);
UseMessageEventHook(UnseenItemsEvent, onUnseenItemsEvent); UseMessageEventHook(UnseenItemsEvent, onUnseenItemsEvent);

View File

@ -11,15 +11,15 @@ export const useSharedVisibility = () =>
let id = -1; let id = -1;
setActiveIds(prevValue => setActiveIds(prevValue =>
{ {
const newValue = [ ...prevValue ]; const newValue = [ ...prevValue ];
id = newValue.length ? (newValue[(newValue.length - 1)] + 1) : 0; id = newValue.length ? (newValue[(newValue.length - 1)] + 1) : 0;
newValue.push(id); newValue.push(id);
return newValue; return newValue;
}); });
return id; return id;
}, []); }, []);
@ -27,17 +27,17 @@ export const useSharedVisibility = () =>
const deactivate = useCallback((id: number) => const deactivate = useCallback((id: number) =>
{ {
setActiveIds(prevValue => setActiveIds(prevValue =>
{ {
const newValue = [ ...prevValue ]; const newValue = [ ...prevValue ];
const index = newValue.indexOf(id); const index = newValue.indexOf(id);
if(index === -1) return prevValue; if(index === -1) return prevValue;
newValue.splice(index, 1); newValue.splice(index, 1);
return newValue; return newValue;
}); });
}, []); }, []);
return { isVisible, activate, deactivate }; return { isVisible, activate, deactivate };