mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-30 00:50:50 +01:00
Updates
This commit is contained in:
parent
56daa2bbe6
commit
e50eed14e2
@ -2,6 +2,18 @@
|
||||
width: 475px;
|
||||
// height: 300px;
|
||||
// max-height: 300px;
|
||||
|
||||
.content-area {
|
||||
height: 243.5px;
|
||||
max-height: 243.5px;
|
||||
}
|
||||
|
||||
.empty-image {
|
||||
background: url('../../assets/images/inventory/empty.png');
|
||||
width: 129px;
|
||||
height: 181px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@import './views/InventoryViews';
|
||||
|
@ -11,9 +11,15 @@ import { LocalizeText } from '../../utils/LocalizeText';
|
||||
import { InventoryContextProvider } from './context/InventoryContext';
|
||||
import { InventoryMessageHandler } from './InventoryMessageHandler';
|
||||
import { InventoryTabs, InventoryViewProps } from './InventoryView.types';
|
||||
import { initialInventoryBadge, inventoryBadgeReducer } from './reducers/InventortBadgeReducer';
|
||||
import { initialInventoryBot, inventoryBotReducer } from './reducers/InventoryBotReducer';
|
||||
import { initialInventoryFurniture, inventoryFurnitureReducer } from './reducers/InventoryFurnitureReducer';
|
||||
import { isObjectMoverRequested, setObjectMoverRequested } from './utils/FurnitureUtilities';
|
||||
import { initialInventoryPet, inventoryPetReducer } from './reducers/InventoryPetReducer';
|
||||
import { isObjectMoverRequested, setObjectMoverRequested } from './utils/InventoryUtilities';
|
||||
import { InventoryBadgeView } from './views/badge/InventoryBadgeView';
|
||||
import { InventoryBotView } from './views/bot/InventoryBotView';
|
||||
import { InventoryFurnitureView } from './views/furniture/InventoryFurnitureView';
|
||||
import { InventoryPetView } from './views/pet/InventoryPetView';
|
||||
|
||||
export const InventoryView: FC<InventoryViewProps> = props =>
|
||||
{
|
||||
@ -24,6 +30,9 @@ export const InventoryView: FC<InventoryViewProps> = props =>
|
||||
const [ roomSession, setRoomSession ] = useState<IRoomSession>(null);
|
||||
const [ roomPreviewer, setRoomPreviewer ] = useState<RoomPreviewer>(null);
|
||||
const [ furnitureState, dispatchFurnitureState ] = useReducer(inventoryFurnitureReducer, initialInventoryFurniture);
|
||||
const [ botState, dispatchBotState ] = useReducer(inventoryBotReducer, initialInventoryBot);
|
||||
const [ petState, dispatchPetState ] = useReducer(inventoryPetReducer, initialInventoryPet);
|
||||
const [ badgeState, dispatchBadgeState ] = useReducer(inventoryBadgeReducer, initialInventoryBadge);
|
||||
|
||||
const onInventoryEvent = useCallback((event: InventoryEvent) =>
|
||||
{
|
||||
@ -94,7 +103,7 @@ export const InventoryView: FC<InventoryViewProps> = props =>
|
||||
}
|
||||
|
||||
return (
|
||||
<InventoryContextProvider value={ { furnitureState, dispatchFurnitureState } }>
|
||||
<InventoryContextProvider value={ { furnitureState, dispatchFurnitureState, botState, dispatchBotState, petState, dispatchPetState, badgeState, dispatchBadgeState } }>
|
||||
<InventoryMessageHandler />
|
||||
{ isVisible && <DraggableWindow handle=".drag-handler">
|
||||
<div className="nitro-inventory d-flex flex-column">
|
||||
@ -114,10 +123,15 @@ export const InventoryView: FC<InventoryViewProps> = props =>
|
||||
</li>;
|
||||
}) }
|
||||
</ul>
|
||||
<div className="bg-light rounded-bottom border border-top-0 px-3 py-2 h-100 shadow overflow-hidden">
|
||||
{ (currentTab === InventoryTabs.FURNITURE ) && <InventoryFurnitureView
|
||||
roomSession={ roomSession }
|
||||
roomPreviewer={ roomPreviewer } /> }
|
||||
<div className="bg-light rounded-bottom border border-top-0 px-3 py-2 shadow overflow-hidden content-area">
|
||||
{ (currentTab === InventoryTabs.FURNITURE ) &&
|
||||
<InventoryFurnitureView roomSession={ roomSession } roomPreviewer={ roomPreviewer } /> }
|
||||
{ (currentTab === InventoryTabs.BOTS ) &&
|
||||
<InventoryBotView roomSession={ roomSession } roomPreviewer={ roomPreviewer } /> }
|
||||
{ (currentTab === InventoryTabs.PETS ) &&
|
||||
<InventoryPetView roomSession={ roomSession } roomPreviewer={ roomPreviewer } /> }
|
||||
{ (currentTab === InventoryTabs.BADGES ) &&
|
||||
<InventoryBadgeView /> }
|
||||
</div>
|
||||
</div>
|
||||
</DraggableWindow> }
|
||||
|
@ -3,7 +3,13 @@ import { IInventoryContext, InventoryContextProps } from './InventoryContext.typ
|
||||
|
||||
const InventoryContext = createContext<IInventoryContext>({
|
||||
furnitureState: null,
|
||||
dispatchFurnitureState: null
|
||||
dispatchFurnitureState: null,
|
||||
botState: null,
|
||||
dispatchBotState: null,
|
||||
petState: null,
|
||||
dispatchPetState: null,
|
||||
badgeState: null,
|
||||
dispatchBadgeState: null
|
||||
});
|
||||
|
||||
export const InventoryContextProvider: FC<InventoryContextProps> = props =>
|
||||
|
@ -1,10 +1,19 @@
|
||||
import { Dispatch, ProviderProps } from 'react';
|
||||
import { IInventoryBadgeAction, IInventoryBadgeState } from '../reducers/InventortBadgeReducer';
|
||||
import { IInventoryBotAction, IInventoryBotState } from '../reducers/InventoryBotReducer';
|
||||
import { IInventoryFurnitureAction, IInventoryFurnitureState } from '../reducers/InventoryFurnitureReducer';
|
||||
import { IInventoryPetAction, IInventoryPetState } from '../reducers/InventoryPetReducer';
|
||||
|
||||
export interface IInventoryContext
|
||||
{
|
||||
furnitureState: IInventoryFurnitureState;
|
||||
dispatchFurnitureState: Dispatch<IInventoryFurnitureAction>;
|
||||
botState: IInventoryBotState;
|
||||
dispatchBotState: Dispatch<IInventoryBotAction>;
|
||||
petState: IInventoryPetState;
|
||||
dispatchPetState: Dispatch<IInventoryPetAction>;
|
||||
badgeState: IInventoryBadgeState;
|
||||
dispatchBadgeState: Dispatch<IInventoryBadgeAction>;
|
||||
}
|
||||
|
||||
export interface InventoryContextProps extends ProviderProps<IInventoryContext>
|
||||
|
120
src/views/inventory/utils/BotUtilities.ts
Normal file
120
src/views/inventory/utils/BotUtilities.ts
Normal file
@ -0,0 +1,120 @@
|
||||
import { BotData, RoomObjectCategory, RoomObjectPlacementSource, RoomObjectType } from 'nitro-renderer';
|
||||
import { GetRoomEngine, GetRoomSessionManager } from '../../../api';
|
||||
import { InventoryEvent } from '../../../events';
|
||||
import { dispatchUiEvent } from '../../../hooks/events/ui/ui-event';
|
||||
import { BotItem } from './BotItem';
|
||||
import { getPlacingItemId, setObjectMoverRequested, setPlacingItemId } from './InventoryUtilities';
|
||||
|
||||
export function cancelRoomObjectPlacement(): void
|
||||
{
|
||||
if(getPlacingItemId() === -1) return;
|
||||
|
||||
GetRoomEngine().cancelRoomObjectPlacement();
|
||||
|
||||
setPlacingItemId(-1);
|
||||
setObjectMoverRequested(false);
|
||||
}
|
||||
|
||||
export function attemptBotPlacement(botItem: BotItem, flag: boolean = false): boolean
|
||||
{
|
||||
const botData = botItem.botData;
|
||||
|
||||
if(!botData) return false;
|
||||
|
||||
const session = GetRoomSessionManager().getSession(1);
|
||||
|
||||
if(!session || !session.isRoomOwner) return false;
|
||||
|
||||
dispatchUiEvent(new InventoryEvent(InventoryEvent.HIDE_INVENTORY));
|
||||
|
||||
if(GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, -(botData.id), RoomObjectCategory.UNIT, RoomObjectType.RENTABLE_BOT, botData.figure))
|
||||
{
|
||||
setPlacingItemId(botData.id);
|
||||
setObjectMoverRequested(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getAllItemIds(botItems: BotItem[]): number[]
|
||||
{
|
||||
const itemIds: number[] = [];
|
||||
|
||||
for(const botItem of botItems) itemIds.push(botItem.id);
|
||||
|
||||
return itemIds;
|
||||
}
|
||||
|
||||
export function processBotFragment(set: BotItem[], fragment: BotData[]): BotItem[]
|
||||
{
|
||||
const existingIds = getAllItemIds(set);
|
||||
const addedDatas: BotData[] = [];
|
||||
const removedIds: number[] = [];
|
||||
|
||||
for(const botData of fragment) (existingIds.indexOf(botData.id) === -1) && addedDatas.push(botData);
|
||||
|
||||
for(const itemId of existingIds)
|
||||
{
|
||||
for(const botData of fragment)
|
||||
{
|
||||
if(botData.id === itemId) continue;
|
||||
|
||||
removedIds.push(itemId);
|
||||
}
|
||||
}
|
||||
|
||||
const emptyExistingSet = (existingIds.length === 0);
|
||||
|
||||
for(const id of removedIds) removeBotItemById(id, set);
|
||||
|
||||
for(const botData of addedDatas)
|
||||
{
|
||||
addSingleBotItem(botData, set, true);
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
export function removeBotItemById(id: number, set: BotItem[]): BotItem
|
||||
{
|
||||
let index = 0;
|
||||
|
||||
while(index < set.length)
|
||||
{
|
||||
const botItem = set[index];
|
||||
|
||||
if(botItem && (botItem.id === id))
|
||||
{
|
||||
if(getPlacingItemId() === botItem.id)
|
||||
{
|
||||
cancelRoomObjectPlacement();
|
||||
|
||||
setTimeout(() => dispatchUiEvent(new InventoryEvent(InventoryEvent.SHOW_INVENTORY)), 1);
|
||||
}
|
||||
|
||||
set.splice(index, 1);
|
||||
|
||||
return botItem;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function addSingleBotItem(botData: BotData, set: BotItem[], unseen: boolean = true): BotItem
|
||||
{
|
||||
const botItem = new BotItem(botData);
|
||||
|
||||
if(unseen)
|
||||
{
|
||||
set.unshift(botItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
set.push(botItem);
|
||||
}
|
||||
|
||||
return botItem;
|
||||
}
|
22
src/views/inventory/utils/InventoryUtilities.ts
Normal file
22
src/views/inventory/utils/InventoryUtilities.ts
Normal file
@ -0,0 +1,22 @@
|
||||
let objectMoverRequested = false;
|
||||
let itemIdInPlacing = -1;
|
||||
|
||||
export function isObjectMoverRequested(): boolean
|
||||
{
|
||||
return objectMoverRequested;
|
||||
}
|
||||
|
||||
export function setObjectMoverRequested(flag: boolean)
|
||||
{
|
||||
objectMoverRequested = flag;
|
||||
}
|
||||
|
||||
export function getPlacingItemId(): number
|
||||
{
|
||||
return itemIdInPlacing;
|
||||
}
|
||||
|
||||
export function setPlacingItemId(id: number)
|
||||
{
|
||||
itemIdInPlacing = id;
|
||||
}
|
Loading…
Reference in New Issue
Block a user