extends RefCounted
## Pandolia logo (Boss pick 2026-10-18: painted tile "sunrise", source art/logo/apply on the laptop project).
## The window / taskbar icon is also set at run time (not only application/config/icon in project.godot), so a new
## icon arrives with a patch .pck too. The exe's own icon stays the signed Godot one on purpose (re-signing = a
## full client download).

const ICON := "res://icon.png"
## stacked logo (tile + "Pandolia" + ONLINE), 800 px wide: the dist updater screen (first screen we control)
## Boot splash (2026-10-19, Boss "the logo didn't change in game"): Godot reads application/boot_splash/* and
## config/icon from the BASE pck BEFORE patch_boot.gd mounts the patches (dist v2), so a file a patch added (this
## wordmark, b45) cannot be the splash of a patched client ("Error opening file ... Loading default splash").
## project.godot therefore keeps a plain colour splash (show_image=false, bg = the updater's BG) and the updater shows
## the wordmark instead. Only after the next FULL base (dist_build.ps1: the wordmark is inside its pck) may
## boot_splash/image point at WORDMARK again. The exe / pinned-shortcut icon = the signed Godot exe's: ship
## "Pandolia Online.ico" next to the exe with the full base for shortcuts.
const WORDMARK := "res://assets/ui/logo/pandolia_wordmark.png"
## one-line lockup (tile left, "Pandolia" + ONLINE right): the title screen
const LOGO_WIDE := "res://assets/ui/logo/pandolia_logo_wide.png"


static func set_window_icon() -> bool:
	if DisplayServer.get_name() == "headless" or not ResourceLoader.exists(ICON):
		return false
	var t = load(ICON)
	if not (t is Texture2D):
		return false
	var img: Image = (t as Texture2D).get_image()
	if img == null or img.is_empty():
		return false
	DisplayServer.set_icon(img)
	return true


## The texture at path, or null (not in this build / not imported).
static func texture(path: String) -> Texture2D:
	if not ResourceLoader.exists(path):
		return null
	var t = load(path)
	return t as Texture2D if t is Texture2D else null


## A TextureRect showing a logo at height h (keeps the aspect), or null when the image is missing (callers keep a
## text fallback).
static func logo_rect(path: String, h: float) -> TextureRect:
	var t := texture(path)
	if t == null:
		return null
	var r := TextureRect.new()
	r.name = "LogoImage"
	r.texture = t
	r.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
	r.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
	r.custom_minimum_size = Vector2(0, h)
	r.mouse_filter = Control.MOUSE_FILTER_IGNORE
	return r
