Could I segment these functions

Godot Version

4.7.1

Question

I starting to feel like these functions in the inventory data resource and in stats are doing to much and I can segment them into their own functions or cut some redundant parts out, so at least look cleaner for future me.

but the main thing i’m wondering is that is it needed if it works? if so tell me how.

#InventoryData extends Resource

func get_attack_modifiers(modifier_name: StringName, slots: Array[SlotData], item: EquippableItem = null, only_one: bool = true) -> float:
	return get_equipment_mods(EquippmentModifiers.ModType.ATTACK, modifier_name, slots, item, only_one)


func get_defence_modifiers(modifier_name: StringName, slots: Array[SlotData], item: EquippableItem = null, only_one: bool = true) -> float:
	return get_equipment_mods(EquippmentModifiers.ModType.DEFENCE, modifier_name, slots, item, only_one)


func get_equipment_mods(
		modifier_type: EquippmentModifiers.ModType, modifier_name: StringName, slots: Array[SlotData], item: EquippableItem = null, only_one: bool = true) -> float:

	var mod_value: float = 0
	var equipment: EquippableItem

	for slot: SlotData in slots:
		if slot == null:
			continue
		
		equipment = slot.item_data

# If a specific item is wanted, it's set to the equipment var instead
		if item:
			equipment = item

		for mod: EquippmentModifiers in equipment.modifiers:

# Ignore the modifier type thats not wanted
			if not mod.type == modifier_type:
				continue

			match modifier_type:
				EquippmentModifiers.ModType.ATTACK:
					if not mod.attack_modifiers == modifier_name:
						continue

# If one instance of a selected moddifier is needed
					if only_one:
						mod_value = mod.modifier_value
						return mod_value

# Else add one instance to the final value then continue the loop
					mod_value += mod.modifier_value

				EquippmentModifiers.ModType.DEFENCE:
					if not mod.defence_modifiers == modifier_name:
						continue

# If one instance of a selected moddifier is needed
					if only_one:
						mod_value = mod.modifier_value
						return mod_value

# Else add one instance to the final value then continue the loop
					mod_value += mod.modifier_value

#ItemData extends Resource

@export var name: String = ""
@export_multiline() var description: String = ""
@export var texture: Texture
@export var stackable: bool = true


#EquippableItem extends ItemData

@export var modifiers: Array[EquippmentModifiers]


#@tool
#EquippmentModifiers extends Resource

enum ModType {
	DEFENCE = 0,
	ATTACK,
}


#enum AttackMods {
	#DAMAGE = 3,
	#CRIT_CHANCE,
	#CRIT_DAMAGE,
#}

#enum DefenceMods {
	#HEALTH = 6,
#}

@export var type: ModType = ModType.DEFENCE: set = _set_type
@export var modifier_value: float

@export_enum("Damage", "Crit Chance", "Crit Multiplier") var attack_modifiers: String = "Damage"
@export_enum("Health") var defence_modifiers: String = "Health"
#Stats extends PanelContainer


const _DAMAGE_VALUES: DamageValues = preload("uid://obcjebon7ssq")
const _HEALTH_VALUES: HealthValues = preload("uid://cuueg8ovtloqh")
const _INVENTORY_DATA: InventoryData = preload("uid://bjs7dk45y6hkv")

@onready var health_value: Label = %HealthValue
@onready var damage_value: Label = %DamageValue
@onready var crit_chance_value: Label = %CritChanceValue

@onready var crit_chance_value_change: Label = %CritChanceValueChange



func _ready() -> void:
	Inventory.item_previewed.connect(_on_preview_stats_changed)
	_INVENTORY_DATA.equipment_changed.connect(update_stats)



func update_stats() -> void:
	var health_string: String = str(
		_HEALTH_VALUES.base_max_health + _INVENTORY_DATA.get_defence_modifiers(ModifierNames.MAX_HEALTH, _INVENTORY_DATA.equipment_slot_data, null, false))

	var damage_string: String = "%d" %(
		_DAMAGE_VALUES.base_damage + _INVENTORY_DATA.get_attack_modifiers(ModifierNames.DAMAGE, _INVENTORY_DATA.equipment_slot_data, null, false))

	var crit_chance_number: float = (
		_DAMAGE_VALUES.crit_chance + _INVENTORY_DATA.get_attack_modifiers(ModifierNames.CRIT_CHANCE, _INVENTORY_DATA.equipment_slot_data, null , false)) * 100

	var crit_chance_string: String = "%d" %crit_chance_number

	health_value.text = health_string
	damage_value.text = damage_string
	crit_chance_value.text = crit_chance_string + "%"


func _on_preview_stats_changed(slot: PanelContainer, item : ItemData) -> void:
	crit_chance_value_change.text = ""
	
	if item == null:
		crit_chance_value_change.text = ""
		return
	
	if not item is EquippableItem:
		return
	
	var equipment: EquippableItem = item
	#var current_crit_chance: float = _DAMAGE_VALUES.crit_chance
	
	var crit_chance_delta: float
	
	print(str(crit_chance_delta))
	
	match slot.get_script():
		EquipmentSlot:
			crit_chance_delta = _INVENTORY_DATA.get_attack_modifiers(ModifierNames.CRIT_CHANCE, _INVENTORY_DATA.equipment_slot_data, equipment, true)
			crit_chance_delta *= -1
		InventorySlot:
			crit_chance_delta = _INVENTORY_DATA.get_attack_modifiers(ModifierNames.CRIT_CHANCE, _INVENTORY_DATA.inventory_slot_data, equipment, true)

and what some of the code is involved is doing, mainly for the stat text changing and show the increases and decreases equipping it will bring (currently only visual)