Files
Ratdoku/scripts/Guests.gd
Ratdoku Builder f4b4a773f3 v0.1.0-alpha: first playable
20 rooms, Crumb board token, Home and Game screens only.
2026-12-02 10:31:42 -06:00

48 lines
1.0 KiB
GDScript

class_name Guests
extends RefCounted
const PATH := "res://data/guests.json"
static var _cache: Array = []
static func all() -> Array:
if _cache.is_empty():
if not FileAccess.file_exists(PATH):
return []
var file := FileAccess.open(PATH, FileAccess.READ)
if file == null:
return []
var parsed = JSON.parse_string(file.get_as_text())
file.close()
if typeof(parsed) == TYPE_ARRAY:
_cache = parsed
return _cache
static func by_id(id: String) -> Dictionary:
for guest in all():
if str(guest.get("id", "")) == id:
return guest
return {}
static func ids() -> Array:
var out: Array = []
for guest in all():
out.append(str(guest.get("id", "")))
return out
static func for_room(room_number: int) -> Dictionary:
for guest in all():
if int(guest.get("unlock_room", -1)) == room_number:
return guest
return {}
static func portrait(id: String, size: String = "thumbs") -> String:
if size == "full":
return "res://art/guests/cards/%s.png" % id
return "res://art/guests/%s/%s.png" % [size, id]