2026-07-25 11:05:37 -04:00
|
|
|
class_name FishInventory
|
|
|
|
|
extends Node
|
|
|
|
|
|
2026-07-25 15:15:24 -04:00
|
|
|
const FishCatchType = preload("res://fish/fish_catch.gd")
|
2026-07-25 11:05:37 -04:00
|
|
|
|
|
|
|
|
signal contents_changed(fish_id: StringName, count: int)
|
|
|
|
|
|
2026-07-25 15:15:24 -04:00
|
|
|
var _catches: Array[FishCatchType] = []
|
2026-07-25 11:05:37 -04:00
|
|
|
|
|
|
|
|
|
2026-07-25 15:15:24 -04:00
|
|
|
func add_catch(fish_catch: FishCatchType) -> void:
|
|
|
|
|
if fish_catch == null or not fish_catch.is_valid():
|
2026-07-25 11:05:37 -04:00
|
|
|
return
|
2026-07-25 15:15:24 -04:00
|
|
|
_catches.append(fish_catch)
|
|
|
|
|
contents_changed.emit(
|
|
|
|
|
fish_catch.fish_id,
|
|
|
|
|
get_count(fish_catch.fish_id)
|
|
|
|
|
)
|
2026-07-25 11:05:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func get_count(fish_id: StringName) -> int:
|
2026-07-25 15:15:24 -04:00
|
|
|
return get_catches_by_fish_id(fish_id).size()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func get_all_catches() -> Array[FishCatchType]:
|
|
|
|
|
return _catches.duplicate()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func get_catches_by_fish_id(fish_id: StringName) -> Array[FishCatchType]:
|
|
|
|
|
var matching: Array[FishCatchType] = []
|
|
|
|
|
for fish_catch: FishCatchType in _catches:
|
|
|
|
|
if fish_catch.fish_id == fish_id:
|
|
|
|
|
matching.append(fish_catch)
|
|
|
|
|
return matching
|