Server: - Add GetBoardTemplatesRequest/Response + BoardTemplateDto to ContentMessages.cs - ContentBoardTemplatesHandler: content.board_templates → returns all enabled templates (id, name, dimensions, player range, flags, tilesJson, startingZonesJson) - Register AddGameDatabase + ContentBoardTemplatesHandler in SOR.Content Client: - BoardTemplateCache.gd autoload: fetches content.board_templates on demand, exposes get_templates_for_custom(), get_templates_for_ranked(), get_template_by_id() - rules_editor_dialog.gd: add Board Template OptionButton in the BOARD section; uses _option_ids map so confirmed() emits the template GUID (not label text) - project.godot: register BoardTemplateCache autoload Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
71 lines
2.6 KiB
GDScript
71 lines
2.6 KiB
GDScript
extends Node
|
|
## Board template cache.
|
|
##
|
|
## Fetches all enabled board templates from the server (content.board_templates)
|
|
## and keeps them in memory. No disk persistence — templates are lightweight and
|
|
## server-managed; a fresh fetch on login is sufficient.
|
|
##
|
|
## Call fetch() after login (e.g. from main_screen or init_screen) so the list is
|
|
## ready before the player opens a custom lobby or the matchmaking screen.
|
|
##
|
|
## Usage:
|
|
## BoardTemplateCache.fetch()
|
|
## BoardTemplateCache.get_templates_for_custom() → Array of Dictionary
|
|
## BoardTemplateCache.get_templates_for_ranked() → Array of Dictionary
|
|
## BoardTemplateCache.get_template_by_id("guid") → Dictionary or {}
|
|
## BoardTemplateCache.templates_ready signal
|
|
|
|
signal templates_ready(templates: Array)
|
|
|
|
var _templates: Array = []
|
|
|
|
|
|
# ── Public API ────────────────────────────────────────────────────────────────
|
|
|
|
## Fetch (or refresh) the full enabled template list from the server.
|
|
## Emits templates_ready when done. Safe to call multiple times.
|
|
func fetch() -> void:
|
|
Network.request(
|
|
"content.board_templates",
|
|
{},
|
|
func(_type: String, p: Variant): _on_response(p),
|
|
func(code: String, msg: String):
|
|
push_warning("BoardTemplateCache: fetch failed — %s %s" % [code, msg])
|
|
)
|
|
|
|
|
|
## All templates eligible for custom lobbies (IsAvailableForCustom = true).
|
|
func get_templates_for_custom() -> Array:
|
|
return _templates.filter(func(t: Dictionary) -> bool:
|
|
return bool(t.get("isAvailableForCustom", false)))
|
|
|
|
|
|
## All templates eligible for ranked games (IsAvailableForRanked = true).
|
|
func get_templates_for_ranked() -> Array:
|
|
return _templates.filter(func(t: Dictionary) -> bool:
|
|
return bool(t.get("isAvailableForRanked", false)))
|
|
|
|
|
|
## Return the template Dictionary for a given GUID, or {} if not cached.
|
|
func get_template_by_id(id: String) -> Dictionary:
|
|
for t: Dictionary in _templates:
|
|
if str(t.get("id", "")) == id:
|
|
return t
|
|
return {}
|
|
|
|
|
|
## True if the cache has been populated at least once.
|
|
func is_loaded() -> bool:
|
|
return not _templates.is_empty()
|
|
|
|
|
|
# ── Private ───────────────────────────────────────────────────────────────────
|
|
|
|
func _on_response(payload: Variant) -> void:
|
|
var p := payload as Dictionary
|
|
_templates.clear()
|
|
for item in p.get("templates", []):
|
|
if typeof(item) == TYPE_DICTIONARY:
|
|
_templates.append(item as Dictionary)
|
|
templates_ready.emit(_templates)
|