add unit tests

saveload fixes
This commit is contained in:
2025-09-27 12:17:14 +04:00
parent 3e960a955c
commit dd0c1a123c
31 changed files with 3400 additions and 282 deletions

View File

@@ -1,7 +1,7 @@
# Skelly - Project Structure Map
## Overview
Skelly is a Godot 4.4 game project featuring multiple gameplay modes with skeleton character themes. The project supports match-3 puzzle gameplay with planned clickomania gameplay through a modular gameplay architecture. It follows a modular structure with clear separation between scenes, autoloads, assets, and data.
Skelly is a Godot 4.4 game project featuring multiple gameplay modes. The project supports match-3 puzzle gameplay with planned clickomania gameplay through a modular gameplay architecture. It follows a modular structure with clear separation between scenes, autoloads, assets, and data.
## Project Root Structure
@@ -25,43 +25,8 @@ skelly/
### Autoloads (Global Singletons)
Located in `src/autoloads/`, these scripts are automatically loaded when the game starts:
1. **SettingsManager** (`src/autoloads/SettingsManager.gd`)
- Manages game settings and user preferences with comprehensive error handling
- Robust configuration file I/O with fallback mechanisms
- Input validation for all setting values and range checking
- JSON parsing with detailed error recovery and default language fallback
- Provides language selection functionality with validation
- Dependencies: `localization/languages.json`
2. **AudioManager** (`src/autoloads/AudioManager.gd`)
- Controls music and sound effects
- Manages audio bus configuration
- Uses: `data/default_bus_layout.tres`
3. **GameManager** (`src/autoloads/GameManager.gd`)
- Central game state management and gameplay mode coordination with race condition protection
- Safe scene transitions with concurrent change prevention and validation
- Gameplay mode selection and launching with input validation (match3, clickomania)
- Error handling for scene loading failures and fallback mechanisms
- Navigation flow control with state protection
- References: main.tscn, game.tscn and individual gameplay scenes
4. **LocalizationManager** (`src/autoloads/LocalizationManager.gd`)
- Language switching functionality
- Works with Godot's built-in internationalization system
- Uses translation files in `localization/`
5. **DebugManager** (`src/autoloads/DebugManager.gd`)
- Global debug state management and centralized logging system
- Debug UI visibility control
- F12 toggle functionality
- Signal-based debug system
- Structured logging with configurable log levels (TRACE, DEBUG, INFO, WARN, ERROR, FATAL)
- Timestamp-based log formatting with category support
- Runtime log level filtering for development and production builds
6. **SaveManager** (`src/autoloads/SaveManager.gd`)
- Persistent game data management with comprehensive validation
1. **SaveManager** (`src/autoloads/SaveManager.gd`)
- Persistent game data management with validation
- High score tracking and current score management
- Game statistics (games played, total score)
- Grid state persistence for match-3 gameplay continuity
@@ -70,6 +35,42 @@ Located in `src/autoloads/`, these scripts are automatically loaded when the gam
- Robust error handling with backup restoration capabilities
- Uses: `user://savegame.save` for persistent storage
2. **SettingsManager** (`src/autoloads/SettingsManager.gd`)
- Manages game settings and user preferences
- Configuration file I/O
- input validation
- JSON parsing
- Provides language selection functionality
- Dependencies: `localization/languages.json`
3. **AudioManager** (`src/autoloads/AudioManager.gd`)
- Controls music and sound effects
- Manages audio bus configuration
- Uses: `data/default_bus_layout.tres`
4. **GameManager** (`src/autoloads/GameManager.gd`)
- Game state management and gameplay mode coordination with race condition protection
- Scene transitions with concurrent change prevention and validation
- Gameplay mode selection and launching with input validation (match3, clickomania)
- Error handling for scene loading failures and fallback mechanisms
- Navigation flow control with state protection
- References: main.tscn, game.tscn and individual gameplay scenes
5. **LocalizationManager** (`src/autoloads/LocalizationManager.gd`)
- Language switching functionality
- Works with Godot's built-in internationalization system
- Uses translation files in `localization/`
6. **DebugManager** (`src/autoloads/DebugManager.gd`)
- Global debug state management and centralized logging system
- Debug UI visibility control
- F12 toggle functionality
- Signal-based debug system
- Structured logging with configurable log levels (TRACE, DEBUG, INFO, WARN, ERROR, FATAL)
- Timestamp-based log formatting with category support
- Runtime log level filtering
## Scene Hierarchy & Flow
### Main Scenes
@@ -130,12 +131,12 @@ scenes/ui/
└── SettingsMenu.tscn + SettingsMenu.gd # With comprehensive input validation
```
**Code Quality Improvements:**
**Quality Improvements:**
- **ValueStepper Component**: Reusable arrow-based selector for discrete values (language, resolution, difficulty)
- **DebugMenuBase.gd**: Eliminates 90% code duplication between debug menu classes
- **Input Validation**: All user inputs are validated and sanitized before processing
- **Error Recovery**: Robust error handling with fallback mechanisms throughout UI
- **Navigation Support**: Full gamepad/keyboard navigation across all menus
- **Input Validation**: User inputs are validated and sanitized before processing
- **Error Recovery**: Error handling with fallback mechanisms throughout UI
- **Navigation Support**: Gamepad/keyboard navigation across menus
## Modular Gameplay System
@@ -152,12 +153,12 @@ The game now uses a modular gameplay architecture where different game modes can
#### Match-3 Mode (`scenes/game/gameplays/match3_gameplay.tscn`)
1. **Match3 Controller** (`scenes/game/gameplays/match3_gameplay.gd`)
- Grid management (8x8 default) with memory-safe node cleanup
- Match detection algorithms with bounds checking and null validation
- Tile dropping and refilling with proper signal connections
- Match detection algorithms with bounds checking and validation
- Tile dropping and refilling with signal connections
- Gem pool management (3-8 gem types) with instance-based architecture
- Debug UI integration with input validation
- Debug UI integration with validation
- Score reporting via `score_changed` signal
- **Memory Safety**: Uses `queue_free()` with proper frame waiting to prevent crashes
- **Memory Safety**: Uses `queue_free()` with frame waiting to prevent crashes
- **Gem Movement System**: Keyboard and gamepad input for tile selection and swapping
- State machine: WAITING → SELECTING → SWAPPING → PROCESSING
- Adjacent tile validation (horizontal/vertical neighbors only)
@@ -166,29 +167,29 @@ The game now uses a modular gameplay architecture where different game modes can
- Cursor-based navigation with visual highlighting and bounds checking
2. **Tile System** (`scenes/game/gameplays/tile.gd` + `Tile.tscn`)
- Individual tile behavior with instance-based architecture (no global state)
- Gem type management with input validation and bounds checking
- Visual representation with scaling and color modulation
- Tile behavior with instance-based architecture (no global state)
- Gem type management with validation and bounds checking
- Visual representation with scaling and color
- Group membership for coordination
- **Visual Feedback System**: Multi-state display for game interaction
- Selection visual feedback (scale and color modulation)
- State management (normal, highlighted, selected)
- Signal-based communication with gameplay controller
- Smooth animations with Tween system
- **Memory Safety**: Proper resource management and cleanup
- **Memory Safety**: Resource management and cleanup
#### Clickomania Mode (`scenes/game/gameplays/clickomania_gameplay.tscn`)
- Planned implementation for clickomania-style gameplay
- Will integrate with same scoring and UI systems as match-3
### Debug System
- Global debug state via DebugManager with proper initialization
- Global debug state via DebugManager with initialization
- Debug toggle available on all major scenes (MainMenu, SettingsMenu, PressAnyKeyScreen, Game)
- Match-3 specific debug UI panel with gem count controls and difficulty presets
- Gem count controls (+/- buttons) with difficulty presets (Easy: 3, Normal: 5, Hard: 8)
- Board reroll functionality for testing
- F12 toggle support across all scenes
- Debug prints reduced in production code
- Fewer debug prints in production code
## Asset Organization
@@ -262,8 +263,12 @@ sprites:
### Testing & Validation (`tests/`)
- `test_logging.gd` - DebugManager logging system validation
- **`test_checksum_issue.gd`** - SaveManager checksum validation and deterministic hashing
- **`test_migration_compatibility.gd`** - SaveManager version migration and backward compatibility
- **`test_save_system_integration.gd`** - Complete save/load workflow integration testing
- **`test_checksum_fix_verification.gd`** - JSON serialization checksum fix verification
- `README.md` - Brief directory overview (see docs/TESTING.md for full guidelines)
- Future test scripts for individual components and integration testing
- Comprehensive test scripts for save system security and data integrity validation
- Temporary test utilities for development and debugging
### Project Configuration