netfishing/ui/logbook_catalog.gd

76 lines
1.8 KiB
GDScript3
Raw Normal View History

2026-07-30 23:16:28 -04:00
class_name LogbookCatalog
extends RefCounted
const FishDataType = preload("res://fish/fish_data.gd")
2026-08-14 22:11:49 -04:00
enum Category {
FRESH_WATER,
SALT_WATER,
OTHER,
SHELLFISH,
}
2026-08-02 09:57:05 -04:00
2026-08-14 22:11:49 -04:00
static func category_for(fish: FishDataType) -> Category:
2026-07-30 23:16:28 -04:00
if fish == null:
2026-08-14 22:11:49 -04:00
return Category.OTHER
if fish.logbook_section == FishDataType.LogbookSection.SHELLFISH:
return Category.SHELLFISH
match fish.get_primary_water_type():
WaterType.Type.FRESH_WATER:
return Category.FRESH_WATER
WaterType.Type.SALT_WATER:
return Category.SALT_WATER
_:
return Category.OTHER
2026-07-30 23:16:28 -04:00
2026-08-14 22:11:49 -04:00
static func category_label(category: Category) -> String:
match category:
Category.FRESH_WATER:
return "Fresh Water"
Category.SALT_WATER:
return "Salt Water"
Category.SHELLFISH:
return "Shellfish"
_:
return "Misc"
2026-07-30 23:16:28 -04:00
2026-08-14 22:11:49 -04:00
static func empty_state(category: Category) -> String:
2026-07-30 23:16:28 -04:00
match category:
2026-08-14 22:11:49 -04:00
Category.FRESH_WATER:
2026-07-30 23:16:28 -04:00
return "No freshwater catches cataloged yet."
2026-08-14 22:11:49 -04:00
Category.SALT_WATER:
2026-07-30 23:16:28 -04:00
return "No saltwater catches cataloged yet."
2026-08-14 22:11:49 -04:00
Category.SHELLFISH:
return "No shellfish cataloged yet."
2026-07-30 23:16:28 -04:00
_:
return "No entries available."
2026-08-14 16:31:28 -04:00
static func catalog_number(fish: FishDataType) -> int:
return fish.catalog_number if fish != null else 0
2026-07-30 23:16:28 -04:00
2026-08-14 16:31:28 -04:00
static func facts_for(fish: FishDataType) -> String:
if fish == null or fish.logbook_fact.strip_edges().is_empty():
return "unknown"
return fish.logbook_fact
2026-08-02 09:57:05 -04:00
2026-07-30 23:16:28 -04:00
static func ordered_species(
candidates: Array[FishDataType],
) -> Array[FishDataType]:
var ordered: Array[FishDataType] = []
2026-08-14 16:31:28 -04:00
for fish: FishDataType in candidates:
if fish != null and fish.active and not fish.id.is_empty():
ordered.append(fish)
ordered.sort_custom(
func(a: FishDataType, b: FishDataType) -> bool:
if a.catalog_number == b.catalog_number:
return String(a.id) < String(b.id)
return a.catalog_number < b.catalog_number
)
2026-07-30 23:16:28 -04:00
return ordered