Update furniture inventory

This commit is contained in:
Bill 2021-04-29 04:03:16 -04:00
parent f73ddf1add
commit 56daa2bbe6
6 changed files with 43 additions and 52 deletions

View File

@ -1,7 +1,7 @@
import { FurnitureListItemParser } from 'nitro-renderer';
import { Reducer } from 'react';
import { FurnitureItem } from '../utils/FurnitureItem';
import { addFurnitureItem, processFragment, removeItemById } from '../utils/FurnitureUtilities';
import { addFurnitureItem, processFurniFragment, removeFurniItemById } from '../utils/FurnitureUtilities';
import { GroupItem } from '../utils/GroupItem';
export interface IInventoryFurnitureState
@ -27,9 +27,9 @@ export class InventoryFurnitureActions
{
public static SET_NEEDS_UPDATE: string = 'IFA_SET_NEEDS_UPDATE';
public static SET_GROUP_ITEM: string = 'IFA_SET_GROUP_ITEM';
public static PROCESS_FRAGMENT: string = 'IFA_PROCESS_FRAGMENT';
public static ADD_OR_UPDATE_FURNITURE: string = 'IFA_ADD_OR_UPDATE_FURNITURE';
public static REMOVE_FURNITURE: string = 'IFA_REMOVE_FURNITURE';
public static PROCESS_FRAGMENT: string = 'IFA_PROCESS_FRAGMENT';
}
export const initialInventoryFurniture: IInventoryFurnitureState = {
@ -60,6 +60,13 @@ export const inventoryFurnitureReducer: Reducer<IInventoryFurnitureState, IInven
return { ...state, groupItem };
}
case InventoryFurnitureActions.PROCESS_FRAGMENT: {
const groupItems = [ ...state.groupItems ];
processFurniFragment(groupItems, (action.payload.fragment || null));
return { ...state, groupItems };
}
case InventoryFurnitureActions.ADD_OR_UPDATE_FURNITURE: {
const groupItems = [ ...state.groupItems ];
@ -120,14 +127,7 @@ export const inventoryFurnitureReducer: Reducer<IInventoryFurnitureState, IInven
case InventoryFurnitureActions.REMOVE_FURNITURE: {
const groupItems = [ ...state.groupItems ];
removeItemById(action.payload.itemId, groupItems);
return { ...state, groupItems };
}
case InventoryFurnitureActions.PROCESS_FRAGMENT: {
const groupItems = [ ...state.groupItems ];
processFragment(groupItems, (action.payload.fragment || null));
removeFurniItemById(action.payload.itemId, groupItems);
return { ...state, groupItems };
}

View File

@ -6,29 +6,7 @@ import { SendMessageHook } from '../../../hooks/messages/message-event';
import { FurniCategory } from './FurniCategory';
import { FurnitureItem } from './FurnitureItem';
import { GroupItem } from './GroupItem';
let objectMoverRequested = false;
let itemIdInFurniPlacing = -1;
export function isObjectMoverRequested(): boolean
{
return objectMoverRequested;
}
export function setObjectMoverRequested(flag: boolean)
{
objectMoverRequested = flag;
}
export function getPlacingFurnitureId(): number
{
return itemIdInFurniPlacing;
}
export function setPlacingFurnitureId(id: number)
{
itemIdInFurniPlacing = id;
}
import { getPlacingItemId, setObjectMoverRequested, setPlacingItemId } from './InventoryUtilities';
export function attemptItemPlacement(groupItem: GroupItem, flag: boolean = false): boolean
{
@ -67,7 +45,7 @@ export function attemptItemPlacement(groupItem: GroupItem, flag: boolean = false
if(isMoving)
{
setPlacingFurnitureId(item.ref);
setPlacingItemId(item.ref);
setObjectMoverRequested(true);
}
}
@ -77,11 +55,11 @@ export function attemptItemPlacement(groupItem: GroupItem, flag: boolean = false
function cancelRoomObjectPlacement(): void
{
if(getPlacingFurnitureId() === -1) return;
if(getPlacingItemId() === -1) return;
GetRoomEngine().cancelRoomObjectPlacement();
setPlacingFurnitureId(-1);
setPlacingItemId(-1);
setObjectMoverRequested(false);
}
@ -95,7 +73,7 @@ export function getGroupItemForFurnitureId(set: GroupItem[], id: number): GroupI
return null;
}
export function mergeFragments(fragment: Map<number, FurnitureListItemParser>, totalFragments: number, fragmentNumber: number, fragments: Map<number, FurnitureListItemParser>[])
export function mergeFurniFragments(fragment: Map<number, FurnitureListItemParser>, totalFragments: number, fragmentNumber: number, fragments: Map<number, FurnitureListItemParser>[])
{
if(totalFragments === 1) return fragment;
@ -120,7 +98,7 @@ export function mergeFragments(fragment: Map<number, FurnitureListItemParser>, t
return merged;
}
export function getAllItemIds(groupItems: GroupItem[]): number[]
function getAllItemIds(groupItems: GroupItem[]): number[]
{
const itemIds: number[] = [];
@ -143,7 +121,7 @@ export function getAllItemIds(groupItems: GroupItem[]): number[]
return itemIds;
}
export function processFragment(set: GroupItem[], fragment: Map<number, FurnitureListItemParser>): GroupItem[]
export function processFurniFragment(set: GroupItem[], fragment: Map<number, FurnitureListItemParser>): GroupItem[]
{
const existingIds = getAllItemIds(set);
const addedIds: number[] = [];
@ -155,7 +133,7 @@ export function processFragment(set: GroupItem[], fragment: Map<number, Furnitur
const emptyExistingSet = (existingIds.length === 0);
for(const id of removedIds) removeItemById(id, set);
for(const id of removedIds) removeFurniItemById(id, set);
for(const id of addedIds)
{
@ -171,7 +149,7 @@ export function processFragment(set: GroupItem[], fragment: Map<number, Furnitur
return set;
}
export function removeItemById(id: number, set: GroupItem[]): GroupItem
export function removeFurniItemById(id: number, set: GroupItem[]): GroupItem
{
let index = 0;
@ -182,7 +160,7 @@ export function removeItemById(id: number, set: GroupItem[]): GroupItem
if(item)
{
if(getPlacingFurnitureId() === item.ref)
if(getPlacingItemId() === item.ref)
{
cancelRoomObjectPlacement();
@ -224,7 +202,7 @@ export function addFurnitureItem(set: GroupItem[], item: FurnitureItem, flag: bo
if(!flag) groupItem.hasUnseenItems = true;
}
export function addSingleFurnitureItem(set: GroupItem[], item: FurnitureItem, flag: boolean): GroupItem
function addSingleFurnitureItem(set: GroupItem[], item: FurnitureItem, flag: boolean): GroupItem
{
const groupItems: GroupItem[] = [];
@ -257,7 +235,7 @@ export function addSingleFurnitureItem(set: GroupItem[], item: FurnitureItem, fl
return groupItem;
}
export function addGroupableFurnitureItem(set: GroupItem[], item: FurnitureItem, unseen: boolean): GroupItem
function addGroupableFurnitureItem(set: GroupItem[], item: FurnitureItem, unseen: boolean): GroupItem
{
let existingGroup: GroupItem = null;
@ -332,7 +310,7 @@ export function addGroupableFurnitureItem(set: GroupItem[], item: FurnitureItem,
return existingGroup;
}
export function createGroupItem(type: number, category: number, stuffData: IObjectData, extra: number = NaN, flag: boolean = false): GroupItem
function createGroupItem(type: number, category: number, stuffData: IObjectData, extra: number = NaN, flag: boolean = false): GroupItem
{
// const iconImage: HTMLImageElement = null;

View File

@ -16,10 +16,8 @@ import { InventoryFurnitureSearchView } from './search/InventoryFurnitureSearchV
export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
{
const { roomSession = null, roomPreviewer = null } = props;
const { furnitureState = null, dispatchFurnitureState = null } = useInventoryContext();
const { needsFurniUpdate = false, groupItem = null, groupItems = [] } = furnitureState;
const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>(groupItems);
useEffect(() =>
@ -99,6 +97,23 @@ export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
}
}, [ roomPreviewer, groupItem ]);
if(!groupItems || !groupItems.length)
{
return (
<div className="row h-100">
<div className="col-5 d-flex justify-content-center align-items-center">
<div className="empty-image"></div>
</div>
<div className="d-flex flex-column col justify-content-center">
<div className="h5 m-0 text-black fw-bold m-0 mb-2">
{ LocalizeText('inventory.empty.title') }
</div>
<div className="h6 text-black">{ LocalizeText('inventory.empty.desc') }</div>
</div>
</div>
);
}
return (
<div className="row h-100">
<div className="col col-7">

View File

@ -19,9 +19,7 @@ export const InventoryFurnitureItemView: FC<InventoryFurnitureItemViewProps> = p
case MouseEventType.MOUSE_DOWN:
dispatchFurnitureState({
type: InventoryFurnitureActions.SET_GROUP_ITEM,
payload: {
groupItem
}
payload: { groupItem }
});
setMouseDown(true);

View File

@ -1,4 +1,4 @@
.item-container {
.furni-item-container {
height: 192px;
max-height: 192px;
overflow-y: auto;

View File

@ -7,7 +7,7 @@ export const InventoryFurnitureResultsView: FC<InventoryFurnitureResultsViewProp
const { groupItems = [] } = props;
return (
<div className="row row-cols-5 align-content-start g-0 item-container">
<div className="row row-cols-5 align-content-start g-0 fruni-item-container">
{ (groupItems && groupItems.length && groupItems.map((item, index) =>
{
return <InventoryFurnitureItemView key={ index } groupItem={ item } />