import UserItem from "./UserItem" ; import { ItemType } from "../imagers/furniture/FurniImager" ; import BobbaEnvironment from "../BobbaEnvironment" ; import BaseItem from "../items/BaseItem" ; export default class Inventory { items : UserItemDictionary ; lastPlacedBaseItem ? : BaseItem ; constructor ( ) { this . items = { } ; } getItem ( id ) { return ( id in this . items ) ? this . items [ id ] : null ; } addItem ( itemId , baseId , state , stackable , itemType ) { if ( this . getItem ( itemId ) == null ) { const newItem = new UserItem ( itemId , baseId , state , stackable , itemType ) ; this . items [ itemId ] = newItem ; this . updateInventory ( ) ; newItem . loadBase ( ) . then ( ( ) => { this . updateInventory ( ) ; } ) ; } } removeItem ( itemId ) { const item = this . getItem ( itemId ) ; if ( item != null ) { delete ( this . items [ itemId ] ) ; this . updateInventory ( ) ; } } tryPlaceItem ( itemId ) { const item = this . getItem ( itemId ) ; const { currentRoom } = BobbaEnvironment . getGame ( ) ; if ( item != null && currentRoom != null && item . baseItem != null ) { BobbaEnvironment . getGame ( ) . uiManager . onCloseInventory ( ) ; currentRoom . roomItemManager . startRoomItemPlacement ( item ) ; this . lastPlacedBaseItem = item . baseItem ; } } findItemByBase ( baseId ) { for ( let userItemId in this . items ) { const currentItem = this . items [ userItemId ] ; if ( currentItem . baseId === baseId ) { return currentItem ; } } return null ; } tryPlaceBaseItem ( baseId ) { const item = this . findItemByBase ( baseId ) ; const { currentRoom } = BobbaEnvironment . getGame ( ) ; if ( item != null && currentRoom != null && item . baseItem != null ) { BobbaEnvironment . getGame ( ) . uiManager . onCloseInventory ( ) ; currentRoom . roomItemManager . startRoomItemPlacement ( item ) ; this . lastPlacedBaseItem = item . baseItem ; } } updateInventory ( ) { BobbaEnvironment . getGame ( ) . uiManager . onUpdateInventory ( Object . values ( this . items ) ) ; } } type UserItemDictionary = { [ id ] : UserItem ; } ;