View on GitHub

fighting-game-button-challenge

fighting-game-button-challenge

TOML Hot Reload Feature

Overview

The application now supports hot-reloading of TOML configuration files. When any tracked TOML file is modified, the application automatically detects the change, reloads the configuration, and restarts from Phase 1.

Use Cases

How It Works

Tracked Files

The following TOML files are monitored for changes:

Detection and Reload Process

  1. Monitoring: The application checks for file modifications every 60 frames (approximately once per second at 60fps)
  2. Detection: Modification times of all tracked files are compared to their previous values
  3. Reload: When a change is detected:
    • All configuration files are reloaded
    • Game state is reset (score, fail count, etc.)
    • Challenge phase is reset to Phase 1
    • Mission index is reset to 0
    • User sees message: “=== TOML file changes detected, reloading configuration ===”

Phase Reset Behavior

After hot reload, the game always:

Usage Example

  1. Start the application normally
  2. Edit any TOML file (e.g., change debug_print = false to debug_print = true in config/button_challenge.toml)
  3. Save the file
  4. Within ~1 second, the console will display:
    === TOML file changes detected, reloading configuration ===
    === Configuration reloaded, restarting from Phase 1 ===
    
  5. Continue playing with the new configuration

Technical Details

Implementation

Error Handling

If an error occurs during reload (e.g., invalid TOML syntax):

Performance Impact

Testing

Run the test suite to verify hot reload functionality:

python -m pytest tests/test_toml_hot_reload.py -v

Run the manual test to see hot reload in action:

python tests/manual_test_hot_reload.py