48 lines
1.0 KiB
GDScript
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]
|