Godot Version
Question
I am working on an inventory system and I am trying to limit the type of items i can place into a inventory_slot. As of now I have made the inventory_slot type set to the itemType that is the enum in the item_data script. But now I am struggling to figure out how to include the other item types from other classes that extend from item_data.
What im tyring to accomplish is an inventory slot that is set to a specific item type and its extended types. For example having an inventory slot that is set to equipment type, but more specifically head type equipment.
I have the base item types set in item_data script and the extended types in their own scripts, such as equipment_data, that extends from item_data.
I am not sure how to check the Item_Data.itemType and add the extended types to the inventory_slot class.
I tried so many ways to @export var equipmentType in inventory_slot if Item_Data.ItemType is equal to Item_Data.ItemType.Equipment,i tried matching the EquipmentType to the name of the inventory slot node, but i cant figure out how to get the extended variables to the inventory_slot class. I also kept running into the issue of not being able to export a var in an if statement.
I thought about trying to set the init based off the extended item data but i ran into the same confusion of how to set the item data from the extended class.
class_name InventorySlot
extends PanelContainer
@export var type: Item_Data.ItemType
func init(t: Item_Data.ItemType, cms: Vector2) -> void:
type = t
custom_minimum_size = cms
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
if data is InventoryItem:
if type == Item_Data.ItemType.MAIN:
if get_child_count() == 0:
return true
else:
if type == data.get_parent().type:
return true
return get_child(0).data.type == data.data.type
else:
return data.data.type == type
else:
return false
func _drop_data(at_position: Vector2, data: Variant) -> void:
if get_child_count() > 0:
var item := get_child(0)
if item == data:
return
item.reparent(data.get_parent())
data.reparent(self)
func checkEquipment():
#Check equipment
if get_child_count() > 0:
var item := get_child(0)
match type:
Item_Data.ItemType.WEAPON:
Game.rightHandEquipped = item.data
Game.leftHandEquipped = item.data
Item_Data.ItemType.EQUIPMENT:
Game.headEquipped = item.data
Game.chestEquipped = item.data
Game.legEquipped = item.data
Game.feetEquipped = item.data
func _physics_process(delta: float) -> void:
checkEquipment()
class_name Item_Data
extends Resource
enum ItemType {RESOURCE, CONSUMABLE, EQUIPMENT, WEAPON, KEY, MAIN}
@export var itemType: ItemType
@export var itemName: String
@export var stackable: bool
@export var stackCount: int
@export var itemValue: int
@export var itemTexture: Texture2D
@export_multiline var description: String
class_name Equipment_Data
extends Item_Data
enum EquipmentType {HEAD, CHEST, LEGS, FEET}
var type: Item_Data.ItemType = Item_Data.ItemType.EQUIPMENT
@export var equipmentType: EquipmentType
@export var itemWeight: int
#Damage Negation
@export var physical: int
@export var magic: int
@export var fire: int
@export var ice: int
@export var lightning: int