Merge branch '@update/inventory' into @update/friends

This commit is contained in:
Bill 2022-04-01 16:13:05 -04:00
commit 86d8ba31f5
17 changed files with 454 additions and 446 deletions

View File

@ -3,8 +3,8 @@
"version": "2.0.0",
"private": true,
"scripts": {
"start": "cross-env BROWSER=none IMAGE_INLINE_SIZE_LIMIT=100000 craco start",
"build": "cross-env GENERATE_SOURCEMAP=false IMAGE_INLINE_SIZE_LIMIT=100000 craco build",
"start": "cross-env SKIP_PREFLIGHT_CHECK=true BROWSER=none IMAGE_INLINE_SIZE_LIMIT=100000 craco start",
"build": "cross-env SKIP_PREFLIGHT_CHECK=true GENERATE_SOURCEMAP=false IMAGE_INLINE_SIZE_LIMIT=100000 craco build",
"build:prod": "npx browserslist@latest --update-db && yarn build",
"test": "craco test",
"eject": "react-scripts eject"
@ -14,7 +14,7 @@
"@fortawesome/fontawesome-svg-core": "^6.1.0",
"@fortawesome/free-solid-svg-icons": "^6.1.0",
"@fortawesome/react-fontawesome": "^0.1.17",
"@nitrots/nitro-renderer": "^1.1.20",
"@nitrots/nitro-renderer": "^1.1.21",
"animate.css": "^4.1.1",
"classnames": "^2.3.1",
"cross-env": "^7.0.3",

View File

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

View File

@ -1,9 +1,12 @@
export class TradingNotificationType
{
public static ALERT_SCAM: number = 0;
public static ALERT_OTHER_CANCELLED: number = 1;
public static ALERT_ALREADY_OPEN: number = 2;
public static ALERT_OTHER_DISABLED: number = 3;
public static ERROR_WHILE_COMMIT: number = 4;
public static YOU_NOT_ALLOWED: number = 5;
public static HOTEL_TRADING_DISABLED = 1;
public static YOU_NOT_ALLOWED: number = 2;
public static THEY_NOT_ALLOWED: number = 4;
public static ROOM_DISABLED: number = 6;
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 () =>
{
setRoomPreviewer(prevValue =>
{
prevValue.dispose();
{
prevValue.dispose();
return null;
});
return null;
});
}
}, []);
@ -129,15 +129,15 @@ export const InventoryView: FC<{}> = props =>
<>
<NitroCardTabsView>
{ TABS.map((name, index) =>
{
const unseenCount = getCount(UNSEEN_CATEGORIES[index]);
{
const unseenCount = getCount(UNSEEN_CATEGORIES[index]);
return (
<NitroCardTabsItemView key={ index } isActive={ (currentTab === name) } onClick={ event => setCurrentTab(name) } count={ unseenCount }>
{ LocalizeText(name) }
</NitroCardTabsItemView>
);
}) }
return (
<NitroCardTabsItemView key={ index } isActive={ (currentTab === name) } onClick={ event => setCurrentTab(name) } count={ unseenCount }>
{ LocalizeText(name) }
</NitroCardTabsItemView>
);
}) }
</NitroCardTabsView>
<NitroCardContentView>
{ (currentTab === TAB_FURNITURE ) &&

View File

@ -48,11 +48,11 @@ export const InventoryBadgeView: FC<{}> = props =>
<Column size={ 7 } overflow="hidden">
<AutoGrid columnCount={ 4 }>
{ 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>
</Column>
<Column className="justify-content-between" size={ 5 } overflow="auto">

View File

@ -23,14 +23,14 @@ export const InventoryFurnitureSearchView: FC<InventoryFurnitureSearchViewProps>
const comparison = searchValue.toLocaleLowerCase();
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);

View File

@ -16,8 +16,8 @@ interface InventoryFurnitureViewProps
export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
{
const { roomSession = null, roomPreviewer = null } = props;
const { groupItems = [], selectedItem = null, selectItem = null } = useInventoryFurni();
const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>(groupItems);
const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>([]);
const { groupItems = [], selectedItem = null, selectItem = null, activate = null, deactivate = null } = useInventoryFurni();
const { getCount = null, resetCategory = null } = useInventoryUnseenTracker();
useEffect(() =>
@ -86,6 +86,13 @@ export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
}
}, [ 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') } />;
const InventoryFurnitureItemView: FC<{ groupItem: GroupItem }> = props =>

View File

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

View File

@ -94,7 +94,7 @@ export const UserSettingsView: FC<{}> = props =>
if(doUpdate) setUserSettings(clone);
DispatchMainEvent(clone)
}, [userSettings]);
}, [ userSettings ]);
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)));
break;
}
}, [userSettings]);
}, [ userSettings ]);
useEffect(() =>
{
if(!userSettings) return;
DispatchUiEvent(userSettings);
}, [userSettings]);
}, [ userSettings ]);
if(!isVisible) return null;

View File

@ -21,30 +21,30 @@ const useInventoryBadgesState = () =>
const toggleBadge = (badgeCode: string) =>
{
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)
{
if(!canWearBadges()) return prevValue;
const composer = new SetActivatedBadgesComposer();
newValue.push(badgeCode);
}
else
{
newValue.splice(index, 1);
}
for(let i = 0; i < maxBadgeCount; i++) composer.addActivatedBadge(newValue[i] || null);
const composer = new SetActivatedBadgesComposer();
SendMessageComposer(composer);
for(let i = 0; i < maxBadgeCount; i++) composer.addActivatedBadge(newValue[i] || null);
SendMessageComposer(composer);
return newValue;
});
return newValue;
});
}
const selectBadge = (badgeCode: string) =>
@ -89,22 +89,22 @@ const useInventoryBadgesState = () =>
BatchUpdates(() =>
{
setBadgeCodes(prevValue =>
{
const newValue = [ ...prevValue ];
{
const newValue = [ ...prevValue ];
newValue.push(parser.badgeCode);
newValue.push(parser.badgeCode);
return newValue;
});
return newValue;
});
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;
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 ]);
useEffect(() =>

View File

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

View File

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

View File

@ -31,13 +31,13 @@ const useInventoryPetsState = () =>
if(!fragment) return;
setPetItems(prevValue =>
{
const newValue = [ ...prevValue ];
{
const newValue = [ ...prevValue ];
processPetFragment(newValue, fragment, isUnseen);
processPetFragment(newValue, fragment, isUnseen);
return newValue;
});
return newValue;
});
petMsgFragments = null;
}, [ isUnseen ]);
@ -49,13 +49,13 @@ const useInventoryPetsState = () =>
const parser = event.getParser();
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);
@ -65,13 +65,13 @@ const useInventoryPetsState = () =>
const parser = event.getParser();
setPetItems(prevValue =>
{
const newValue = [ ...prevValue ];
{
const newValue = [ ...prevValue ];
removePetItemById(parser.petId, newValue);
removePetItemById(parser.petId, newValue);
return newValue;
});
return newValue;
});
}, []);
UseMessageEventHook(PetRemovedFromInventory, onPetRemovedFromInventory);
@ -81,15 +81,15 @@ const useInventoryPetsState = () =>
if(!petItems || !petItems.length) return;
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 ]);
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 { useCallback, useState } from 'react';
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, useEffect, useState } from 'react';
import { useBetween } from 'use-between';
import { useInventoryFurni } from '.';
import { BatchUpdates, UseMessageEventHook } from '..';
@ -13,7 +13,7 @@ const useInventoryTradeState = () =>
const [ ownUser, setOwnUser ] = useState<TradeUserData>(null);
const [ otherUser, setOtherUser ] = useState<TradeUserData>(null);
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 progressTrade = () =>
@ -90,25 +90,25 @@ const useInventoryTradeState = () =>
if(ownUser.userId === parser.userID)
{
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)
{
setOtherUser(prevValue =>
{
const newValue = CloneObject(prevValue);
{
const newValue = CloneObject(prevValue);
newValue.accepts = parser.userAccepts;
newValue.accepts = parser.userAccepts;
return newValue;
});
return newValue;
});
}
}, [ ownUser, otherUser ]);
@ -126,7 +126,7 @@ const useInventoryTradeState = () =>
{
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);
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;
newValue.itemCount = parser.firstUserNumItems;
newValue.userItems = firstUserItems;
}
else
{
newValue.creditsCount = parser.secondUserNumCredits;
newValue.itemCount = parser.secondUserNumItems;
newValue.userItems = secondUserItems;
const item = groupItem.getItemByIndex(i);
if(item) tradeIds.push(item.ref);
i++;
}
}
const tradeIds: number[] = [];
setGroupItems(prevValue =>
{
const newValue = [ ...prevValue ];
for(const groupItem of newValue.userItems.getValues())
{
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;
});
for(const groupItem of newValue) groupItem.lockItemIds(tradeIds);
return newValue;
});
return newValue;
});
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)
{
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;
});
return newValue;
});
}, [ setGroupItems ]);
UseMessageEventHook(TradingListItemEvent, onTradingListItemEvent);
@ -294,9 +294,7 @@ const useInventoryTradeState = () =>
{
const parser = event.getParser();
if((parser.reason !== TradingOpenFailedParser.REASON_YOU_ARE_ALREADY_TRADING && (parser.reason !== TradingOpenFailedParser.REASON_OTHER_USER_ALREADY_TRADING))) return;
TradingNotificationMessage(TradingNotificationType.ALERT_ALREADY_OPEN);
TradingNotificationMessage(parser.reason, parser.otherUserName);
}, []);
UseMessageEventHook(TradingOpenFailedEvent, onTradingOpenFailedEvent);
@ -305,7 +303,7 @@ const useInventoryTradeState = () =>
{
const parser = event.getParser();
TradingNotificationMessage(TradingNotificationType.ALERT_OTHER_DISABLED);
TradingNotificationMessage(TradingNotificationType.THEY_NOT_ALLOWED);
}, []);
UseMessageEventHook(TradingOtherNotAllowedEvent, onTradingOtherNotAllowedEvent);
@ -319,6 +317,15 @@ const useInventoryTradeState = () =>
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 };
}

View File

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

View File

@ -11,15 +11,15 @@ export const useSharedVisibility = () =>
let id = -1;
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;
}, []);
@ -27,17 +27,17 @@ export const useSharedVisibility = () =>
const deactivate = useCallback((id: number) =>
{
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 };

View File

@ -1426,10 +1426,10 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"
"@nitrots/nitro-renderer@^1.1.20":
version "1.1.20"
resolved "https://registry.yarnpkg.com/@nitrots/nitro-renderer/-/nitro-renderer-1.1.20.tgz#13fd468028542f777d2c1c7902f2247769ffd98d"
integrity sha512-DVwM4M0Iofsgd94dVPoNmzPbt7YzVG5liupULIe+WHo2vhR8fEyq3E+cdQleXtr/MBODGXTHBrU0yL67YDpIRQ==
"@nitrots/nitro-renderer@^1.1.21":
version "1.1.21"
resolved "https://registry.yarnpkg.com/@nitrots/nitro-renderer/-/nitro-renderer-1.1.21.tgz#8d527d63510fb4c3003e7d48347cdd50b67bb5b1"
integrity sha512-futoNgDy+wD1il7gEnKly/VlRdESJZrPkG9m+jDy3bswdpRZ0RAph1XYNpNzkSchpxXib2yuKMME6ePPct/l1A==
dependencies:
"@pixi/canvas-renderer" "^6.3.0"
"@pixi/extract" "^6.3.0"