|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is the **Talo Godot Plugin** - a self-hostable game development backend plugin for the Godot Engine (v4.4+). Talo provides leaderboards, player authentication, event tracking, game saves, stats, channels, live config, and more. The plugin is distributed via the Godot Asset Library and GitHub releases. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Building & Testing |
| 12 | +```bash |
| 13 | +# Export for all platforms (runs on push via CI) |
| 14 | +godot --headless --export-release 'Windows Desktop' |
| 15 | +godot --headless --export-release 'macOS' |
| 16 | +godot --headless --export-release 'Linux' |
| 17 | +godot --headless --export-release 'Web' |
| 18 | + |
| 19 | +# The CI checks for SCRIPT ERROR in build output and fails if found |
| 20 | +``` |
| 21 | + |
| 22 | +### Running Samples |
| 23 | +The project includes sample scenes demonstrating plugin features. The main scene is configured as `res://addons/talo/samples/playground/playground.tscn`. To test samples, change the main scene in [project.godot](project.godot) or run scenes directly from the editor. |
| 24 | + |
| 25 | +Available samples: |
| 26 | +- **Playground**: Text-based playground for testing identify, events, stats, leaderboards |
| 27 | +- **Authentication**: Registration/login/account management flow |
| 28 | +- **Leaderboards**: Basic leaderboard UI |
| 29 | +- **Multi-scene saves**: Persist save data across multiple scenes |
| 30 | +- **Persistent buttons**: Simple save/load demo |
| 31 | +- **Chat**: Real-time messaging using channels |
| 32 | +- **Channel storage**: Shared player data storage |
| 33 | + |
| 34 | +## Architecture |
| 35 | + |
| 36 | +### Core Structure |
| 37 | + |
| 38 | +The plugin is an **autoload singleton** called `Talo` (defined in [talo_manager.gd](addons/talo/talo_manager.gd:20)) that initializes on `_ready()` and provides access to all APIs, settings, and utilities. |
| 39 | + |
| 40 | +**Key architectural components:** |
| 41 | + |
| 42 | +1. **TaloManager** ([talo_manager.gd](addons/talo/talo_manager.gd)) - Main autoload singleton |
| 43 | + - Initializes all API instances, crypto manager, continuity manager, and socket |
| 44 | + - Manages current player/alias state |
| 45 | + - Emits `init_completed`, `connection_lost`, and `connection_restored` signals |
| 46 | + - Handles app quit and focus events to flush pending data |
| 47 | + |
| 48 | +2. **TaloClient** ([talo_client.gd](addons/talo/talo_client.gd)) - HTTP client wrapper |
| 49 | + - Used by all API classes (via [apis/api.gd](addons/talo/apis/api.gd)) |
| 50 | + - Builds authenticated requests with proper headers (access key, player/alias/session tokens) |
| 51 | + - Logs requests/responses if enabled in settings |
| 52 | + - Triggers continuity system on failed requests |
| 53 | + - Version: Auto-updated by pre-commit hook |
| 54 | + |
| 55 | +3. **TaloSettings** ([talo_settings.gd](addons/talo/talo_settings.gd)) - Configuration management |
| 56 | + - Reads/writes [settings.cfg](addons/talo/settings.cfg) |
| 57 | + - Key settings: `access_key`, `api_url`, `socket_url`, `auto_connect_socket`, `continuity_enabled`, `debounce_timer_seconds` |
| 58 | + - Auto-creates settings.cfg with defaults if missing |
| 59 | + - Feature tags: `talo_dev` (force debug), `talo_live` (force release) |
| 60 | + |
| 61 | +4. **Continuity System** ([utils/continuity_manager.gd](addons/talo/utils/continuity_manager.gd)) - Offline resilience |
| 62 | + - Automatically retries failed POST/PUT/PATCH/DELETE requests |
| 63 | + - Excludes: health checks, auth, identify, socket tickets |
| 64 | + - Stores encrypted requests in `user://tc.bin` |
| 65 | + - Replays up to 10 requests every 10 seconds when online |
| 66 | + - Ignores time scale for reliability |
| 67 | + |
| 68 | +5. **TaloSocket** ([talo_socket.gd](addons/talo/talo_socket.gd)) - WebSocket communication |
| 69 | + - Connects to `wss://api.trytalo.com` by default |
| 70 | + - Requires ticket creation via [socket_tickets_api.gd](addons/talo/apis/socket_tickets_api.gd) |
| 71 | + - Handles player identification with socket token |
| 72 | + - Polls in `_process()` loop |
| 73 | + - Used by channels, player presence, and custom real-time features |
| 74 | + |
| 75 | +### API Layer |
| 76 | + |
| 77 | +All API classes extend `TaloAPI` ([apis/api.gd](addons/talo/apis/api.gd)), which provides a `TaloClient` instance. There are 14 API classes: |
| 78 | + |
| 79 | +- [players_api.gd](addons/talo/apis/players_api.gd) - Player identification and management |
| 80 | +- [player_auth_api.gd](addons/talo/apis/player_auth_api.gd) - Authentication and sessions |
| 81 | +- [events_api.gd](addons/talo/apis/events_api.gd) - Event tracking |
| 82 | +- [stats_api.gd](addons/talo/apis/stats_api.gd) - Player and global stats |
| 83 | +- [leaderboards_api.gd](addons/talo/apis/leaderboards_api.gd) - Leaderboard management |
| 84 | +- [saves_api.gd](addons/talo/apis/saves_api.gd) - Game save operations |
| 85 | +- [feedback_api.gd](addons/talo/apis/feedback_api.gd) - Player feedback collection |
| 86 | +- [game_config_api.gd](addons/talo/apis/game_config_api.gd) - Live config |
| 87 | +- [health_check_api.gd](addons/talo/apis/health_check_api.gd) - Connectivity checks (debounced) |
| 88 | +- [player_groups_api.gd](addons/talo/apis/player_groups_api.gd) - Player grouping |
| 89 | +- [channels_api.gd](addons/talo/apis/channels_api.gd) - Real-time messaging |
| 90 | +- [socket_tickets_api.gd](addons/talo/apis/socket_tickets_api.gd) - Socket authentication |
| 91 | +- [player_presence_api.gd](addons/talo/apis/player_presence_api.gd) - Online status |
| 92 | + |
| 93 | +### Entity System |
| 94 | + |
| 95 | +18 entity classes in [addons/talo/entities/](addons/talo/entities/) represent API data models. Key entities: |
| 96 | +- `TaloPlayer` - Player data with props |
| 97 | +- `TaloPlayerAlias` - Player identity/device association |
| 98 | +- `TaloLeaderboardEntry` - Leaderboard scores |
| 99 | +- `TaloGameSave` - Saved game state |
| 100 | +- `TaloLiveConfig` - Dynamic configuration |
| 101 | +- `TaloChannel` - Real-time messaging channels |
| 102 | + |
| 103 | +Most entities extend `TaloLoadable` ([entities/loadable.gd](addons/talo/entities/loadable.gd)) which provides JSON serialization and `from_api()` factory methods. |
| 104 | + |
| 105 | +### Utilities |
| 106 | + |
| 107 | +Key utilities in [addons/talo/utils/](addons/talo/utils/): |
| 108 | +- **SavesManager** - Handles save CRUD, caching, offline support |
| 109 | +- **LeaderboardEntriesManager** - Manages leaderboard entry state |
| 110 | +- **ChannelStorageManager** - Manages channel-based shared storage |
| 111 | +- **CryptoManager** - Encryption key generation/storage for offline data |
| 112 | +- **SessionManager** - Session token persistence |
| 113 | +- **DebounceTimer** - Debounces health checks, player updates, save updates (1s default, configurable via `debounce_timer_seconds`) |
| 114 | + |
| 115 | +## GDScript Standards |
| 116 | + |
| 117 | +This project enforces **strict type safety** - all warnings are set to error level (2) in [project.godot](project.godot:24-58): |
| 118 | +- All variables must be explicitly typed (`var foo: String`) unless their type can be easily inferred using the `:=` operator |
| 119 | +- No unsafe property/method access |
| 120 | +- No unsafe casts or call arguments |
| 121 | +- All function parameters and return types must be typed |
| 122 | + |
| 123 | +When writing code: |
| 124 | +- Always use explicit type annotations |
| 125 | +- Use `class_name` for all classes |
| 126 | +- Prefer `await` for async operations (avoid `yield`) |
| 127 | +- Follow existing patterns in API/entity/utility files |
| 128 | + |
| 129 | +## Plugin Configuration |
| 130 | + |
| 131 | +The plugin autoload is configured in [project.godot](project.godot:20): |
| 132 | +``` |
| 133 | +Talo="*res://addons/talo/talo_manager.gd" |
| 134 | +``` |
| 135 | + |
| 136 | +Settings are in [addons/talo/settings.cfg](addons/talo/settings.cfg) - this file is auto-generated and should be filled with the user's access key. |
| 137 | + |
| 138 | +## CI/CD |
| 139 | + |
| 140 | +GitHub Actions workflows in [.github/workflows/](/.github/workflows/): |
| 141 | +- **ci.yml** - Runs on every push, exports for all platforms, fails on script errors |
| 142 | +- **create-release.yml** - Automates releases |
| 143 | +- **tag.yml** - Handles version tagging |
| 144 | +- **claude-code-review.yml** - Automated code review |
| 145 | + |
| 146 | +## Important Notes |
| 147 | + |
| 148 | +- **Process mode**: TaloManager uses `PROCESS_MODE_ALWAYS` ([talo_manager.gd](addons/talo/talo_manager.gd:48)) |
| 149 | +- **Auto accept quit**: Disabled to ensure proper flush on exit ([talo_manager.gd](addons/talo/talo_manager.gd:47)) |
| 150 | +- **Identity checks**: Most API operations require `Talo.players.identify()` first |
| 151 | +- **Offline mode**: Setting `offline_mode = true` simulates no internet for testing |
| 152 | +- **Debouncing**: Health checks, player updates, and save updates are debounced (configurable via `debounce_timer_seconds`) |
| 153 | +- **Time scale**: Continuity manager and debounce timer ignore time scale for reliability |
0 commit comments