Client flow after auth is now:
LoginScreen → auth_success → InitScreen → MainScreen
autoloads/ContentCache.gd
- Cursor-based incremental sync via content.sync (PageSize=200)
- Merges definition DTOs in-memory (id → Dictionary)
- Persists to user://content/defs.json on sync completion
- Incremental on repeat launches: 0 round trips when nothing changed
- Signals: sync_progress(fetched_total), sync_complete(total), sync_failed(error)
scenes/init/InitScreen.tscn + init_screen.gd
- Step 1: version.check (clientVersion="0.1.0", platform="web")
UpdateRequired → show "please refresh" panel, block
UpdateAvailable → soft banner, continue
Ok → continue
DISCONNECTED → wait for Network.connected (one-shot), retry
other error → warn + proceed (don't block player on non-critical check)
- Step 2: ContentCache.start_sync()
Shows running card count while pages arrive
On sync_complete: transition to MainScreen
On sync_failed: show error + Retry button
scenes/login/login_screen.gd
- _go_to_main() now routes to InitScreen instead of MainScreen directly
project.godot
- ContentCache registered as autoload (loads before Auth)
- pointing/emulate_touch_from_mouse=true for desktop browser testing
Caching architecture decision (see plan):
- Layer 1 (definitions/text): always sync all eagerly — no privacy concern
- Layer 2 (2D art): lazy by definition ID, CDN fetch on demand
- Layer 3 (3D models/animations): set-bundle granularity + server-injected
noise during match pre-warm to prevent cache oracle attack
(Layer 2/3 implementation is future work)
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>
127 lines
4.6 KiB
GDScript
127 lines
4.6 KiB
GDScript
extends Control
|
|
## Post-auth initialization screen.
|
|
##
|
|
## Runs on every launch after a successful authentication:
|
|
## 1. version.check — block on UpdateRequired; soft banner on UpdateAvailable
|
|
## 2. content.sync — incremental definition sync via ContentCache
|
|
## 3. Transition — change scene to MainScreen
|
|
##
|
|
## If the network is not yet up when this screen opens, we wait for the
|
|
## Network.connected signal before starting.
|
|
|
|
const CLIENT_VERSION := "0.1.0"
|
|
const PLATFORM := "web" # TODO: detect at runtime for native builds.
|
|
|
|
@onready var status_label : Label = %StatusLabel
|
|
@onready var update_panel : Control = %UpdatePanel
|
|
@onready var update_msg : Label = %UpdateMsg
|
|
@onready var retry_btn : Button = %RetryBtn
|
|
|
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
|
|
|
func _ready() -> void:
|
|
update_panel.visible = false
|
|
retry_btn.visible = false
|
|
|
|
ContentCache.sync_progress.connect(_on_sync_progress)
|
|
ContentCache.sync_complete.connect(_on_sync_complete)
|
|
ContentCache.sync_failed.connect(_on_sync_failed)
|
|
retry_btn.pressed.connect(_start)
|
|
|
|
if Network.is_online():
|
|
_start()
|
|
else:
|
|
_set_status("Connecting to server…")
|
|
Network.connected.connect(_start, CONNECT_ONE_SHOT)
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
if ContentCache.sync_progress.is_connected(_on_sync_progress):
|
|
ContentCache.sync_progress.disconnect(_on_sync_progress)
|
|
if ContentCache.sync_complete.is_connected(_on_sync_complete):
|
|
ContentCache.sync_complete.disconnect(_on_sync_complete)
|
|
if ContentCache.sync_failed.is_connected(_on_sync_failed):
|
|
ContentCache.sync_failed.disconnect(_on_sync_failed)
|
|
|
|
# ── Initialization sequence ───────────────────────────────────────────────────
|
|
|
|
func _start() -> void:
|
|
update_panel.visible = false
|
|
retry_btn.visible = false
|
|
_set_status("Checking for updates…")
|
|
Network.request(
|
|
"version.check",
|
|
{ "clientVersion": CLIENT_VERSION, "platform": PLATFORM },
|
|
func(_type: String, p: Variant): _on_version_ok(p),
|
|
func(code: String, _msg: String): _on_version_error(code)
|
|
)
|
|
|
|
|
|
func _on_version_ok(payload: Variant) -> void:
|
|
var p := payload as Dictionary
|
|
var status := p.get("status", "Ok") as String
|
|
|
|
match status:
|
|
"UpdateRequired":
|
|
var url : String = p.get("downloadUrl", "") as String
|
|
var notes: String = p.get("releaseNotes", "") as String
|
|
update_panel.visible = true
|
|
if url.is_empty():
|
|
update_msg.text = (
|
|
"A required update is available.\n"
|
|
+ "Please refresh your browser to continue."
|
|
)
|
|
else:
|
|
update_msg.text = (
|
|
"A required update is available.\n%s\n\nRefresh your browser or visit:\n%s"
|
|
% [notes, url]
|
|
)
|
|
# Block here — do not proceed to sync.
|
|
|
|
"UpdateAvailable":
|
|
# Non-blocking soft notice, then continue.
|
|
_set_status("Update available (not required) — starting…")
|
|
_do_sync()
|
|
|
|
_: # "Ok" or anything unrecognised
|
|
_do_sync()
|
|
|
|
|
|
func _on_version_error(code: String) -> void:
|
|
if code == "DISCONNECTED":
|
|
# Lost connection before we got a reply — wait for reconnect and retry.
|
|
_set_status("Connection lost. Waiting to reconnect…")
|
|
Network.connected.connect(_start, CONNECT_ONE_SHOT)
|
|
return
|
|
# Any other error (server-side, unknown type, etc.): don't block the player.
|
|
push_warning("InitScreen: version check failed (%s) — proceeding anyway" % code)
|
|
_do_sync()
|
|
|
|
|
|
func _do_sync() -> void:
|
|
var cached := ContentCache.definition_count()
|
|
if cached > 0:
|
|
_set_status("Syncing card database… (%d cached)" % cached)
|
|
else:
|
|
_set_status("Downloading card database…")
|
|
ContentCache.start_sync()
|
|
|
|
# ── ContentCache signal handlers ──────────────────────────────────────────────
|
|
|
|
func _on_sync_progress(fetched_total: int) -> void:
|
|
_set_status("Syncing card database… (%d cards)" % fetched_total)
|
|
|
|
|
|
func _on_sync_complete(_total: int) -> void:
|
|
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
|
|
|
|
|
|
func _on_sync_failed(error: String) -> void:
|
|
_set_status("Sync failed: %s" % error)
|
|
retry_btn.visible = true
|
|
|
|
# ── Helpers ───────────────────────────────────────────────────────────────────
|
|
|
|
func _set_status(text: String) -> void:
|
|
status_label.text = text
|