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>
121 lines
4.8 KiB
GDScript
121 lines
4.8 KiB
GDScript
extends Control
|
|
## Login / Register screen.
|
|
##
|
|
## Shown as the entry point before authentication. Uses two tabs:
|
|
## "Login" — email + password → auth.login
|
|
## "Register" — email + password + display name → auth.register
|
|
##
|
|
## Listens to Auth.auth_success and Auth.auth_failed.
|
|
## On success: transitions to InitScreen (which runs version check + content sync,
|
|
## then proceeds to MainScreen).
|
|
## On failure: shows an error message and re-enables the form.
|
|
|
|
# ── Node references (unique names set in the .tscn) ──────────────────────────
|
|
|
|
@onready var email_input : LineEdit = %EmailInput
|
|
@onready var password_input : LineEdit = %PasswordInput
|
|
@onready var login_btn : Button = %LoginBtn
|
|
|
|
@onready var reg_email_input : LineEdit = %RegEmailInput
|
|
@onready var reg_password_input : LineEdit = %RegPasswordInput
|
|
@onready var reg_name_input : LineEdit = %RegNameInput
|
|
@onready var register_btn : Button = %RegisterBtn
|
|
|
|
@onready var status_label : Label = %StatusLabel
|
|
|
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
|
|
|
func _ready() -> void:
|
|
# If already authenticated (e.g. scene reloaded), skip straight to main.
|
|
if not Auth.user_id.is_empty():
|
|
_go_to_main()
|
|
return
|
|
|
|
Auth.auth_success.connect(_on_auth_success)
|
|
Auth.auth_failed.connect(_on_auth_failed)
|
|
|
|
login_btn.pressed.connect(_on_login_pressed)
|
|
register_btn.pressed.connect(_on_register_pressed)
|
|
|
|
# Allow pressing Enter to submit the login form.
|
|
password_input.text_submitted.connect(func(_t): _on_login_pressed())
|
|
reg_name_input.text_submitted.connect(func(_t): _on_register_pressed())
|
|
|
|
# Show connection / session-resume status on first open.
|
|
if not Auth.session_token.is_empty():
|
|
_set_status("Resuming session…", false)
|
|
_set_enabled(false)
|
|
elif not Network.is_online():
|
|
_set_status("Connecting…", false)
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
if Auth.auth_success.is_connected(_on_auth_success):
|
|
Auth.auth_success.disconnect(_on_auth_success)
|
|
if Auth.auth_failed.is_connected(_on_auth_failed):
|
|
Auth.auth_failed.disconnect(_on_auth_failed)
|
|
|
|
# ── Button handlers ───────────────────────────────────────────────────────────
|
|
|
|
func _on_login_pressed() -> void:
|
|
var email := email_input.text.strip_edges()
|
|
var pass_ := password_input.text
|
|
if email.is_empty() or pass_.is_empty():
|
|
_set_status("Please enter your email and password.", true)
|
|
return
|
|
_set_status("Signing in…", false)
|
|
_set_enabled(false)
|
|
Auth.login(email, pass_)
|
|
|
|
|
|
func _on_register_pressed() -> void:
|
|
var email := reg_email_input.text.strip_edges()
|
|
var pass_ := reg_password_input.text
|
|
var name_ := reg_name_input.text.strip_edges()
|
|
if email.is_empty() or pass_.is_empty() or name_.is_empty():
|
|
_set_status("Please fill in all fields.", true)
|
|
return
|
|
_set_status("Creating account…", false)
|
|
_set_enabled(false)
|
|
Auth.register(email, pass_, name_)
|
|
|
|
# ── Auth signal handlers ──────────────────────────────────────────────────────
|
|
|
|
func _on_auth_success(_user_id: String, _display_name: String) -> void:
|
|
_go_to_main()
|
|
|
|
|
|
func _on_auth_failed(error_code: String, message: String) -> void:
|
|
if error_code == "DISCONNECTED":
|
|
_set_status("Connection lost. Retrying…", false)
|
|
else:
|
|
_set_status(_friendly_error(error_code, message), true)
|
|
_set_enabled(true)
|
|
|
|
# ── Helpers ───────────────────────────────────────────────────────────────────
|
|
|
|
func _go_to_main() -> void:
|
|
get_tree().change_scene_to_file("res://scenes/init/InitScreen.tscn")
|
|
|
|
|
|
func _set_status(text: String, is_error: bool) -> void:
|
|
status_label.text = text
|
|
status_label.modulate = Color(1.0, 0.4, 0.4) if is_error else Color(0.8, 0.8, 0.8)
|
|
|
|
|
|
func _set_enabled(enabled: bool) -> void:
|
|
login_btn.disabled = not enabled
|
|
register_btn.disabled = not enabled
|
|
|
|
|
|
func _friendly_error(code: String, message: String) -> String:
|
|
match code:
|
|
"INVALID_CREDENTIALS": return "Wrong email or password."
|
|
"EMAIL_TAKEN": return "That email is already in use."
|
|
"WEAK_PASSWORD": return "Password must be at least 8 characters."
|
|
"INVALID_EMAIL": return "Please enter a valid email address."
|
|
"AUTH_FAILED": return "Authentication failed. Please try again."
|
|
_:
|
|
return message if not message.is_empty() \
|
|
else "Something went wrong (%s)." % code
|