migrat assets.txt a assets.yaml

This commit is contained in:
2025-11-18 08:23:49 +01:00
parent 6a18d880f2
commit f9b8edc23c
10 changed files with 756 additions and 452 deletions

View File

@@ -261,7 +261,7 @@ source/
└── main.cpp # Application entry point
config/ # Configuration files
└── assets.txt # Asset registry (text-based configuration)
└── assets.yaml # Asset registry (text-based configuration)
data/ # Game assets
├── font/ # Bitmap fonts + descriptors
@@ -469,7 +469,7 @@ Game::run() {
```
Director::setFileList()
├─ Asset::loadFromFile(config_path, PREFIX, system_folder_)
│ ├─ Read config/assets.txt - Parse text configuration file
│ ├─ Read config/assets.yaml - Parse text configuration file
│ ├─ Parse each line: TYPE|PATH|OPTIONS - Extract asset information
│ ├─ Replace variables (${PREFIX}, ${SYSTEM_FOLDER})
│ └─ Store in unordered_map (O(1) lookup) - Fast asset path retrieval
@@ -654,7 +654,7 @@ Achievements trigger notifications on unlock.
| `Input` | Keyboard & gamepad input | Singleton |
| `Audio` | Music and SFX playback | Singleton |
| `Resource` | Asset caching and loading | Singleton |
| `Asset` | Asset path registry from config/assets.txt, O(1) lookups, variable substitution | Singleton |
| `Asset` | Asset path registry from config/assets.yaml, O(1) lookups, variable substitution | Singleton |
| `Debug` | Debug overlay information | Singleton |
| `globalEvents` | Global SDL event handling (quit, device reset, mouse) | Namespace |
@@ -717,16 +717,25 @@ Achievements trigger notifications on unlock.
### Adding Game Assets
1. Place file in `data/` directory
2. Add entry to `config/assets.txt`:
2. Add entry to `config/assets.yaml` under the appropriate category:
```yaml
assets:
category_name: # e.g., player, enemies, music, etc.
- type: BITMAP
path: ${PREFIX}/data/path/file.ext
```
TYPE|${PREFIX}/data/path/file.ext
Available types: `DATA`, `BITMAP`, `ANIMATION`, `MUSIC`, `SOUND`, `FONT`, `ROOM`, `PALETTE`
3. Optional flags can be added:
```yaml
- type: DATA
path: ${SYSTEM_FOLDER}/file.txt
required: false # Don't fail if missing
absolute: true # Path is absolute
```
Available types: `DATA`, `BITMAP`, `ANIMATION`, `MUSIC`, `SOUND`, `FONT`, `ROOM`, `TILEMAP`, `PALETTE`
3. Optional flags can be added: `TYPE|${PREFIX}/path/file.ext|optional,absolute`
4. Resource loads automatically during `Resource::init()`
5. Access via: `Resource::Cache::get()->getSurface("name")`
**Note:** No recompilation needed when adding/removing/modifying assets in `config/assets.txt`
**Note:** No recompilation needed when adding/removing/modifying assets in `config/assets.yaml`
### Modifying Collision Detection
@@ -782,36 +791,58 @@ In debug builds (`#ifdef DEBUG`), renders:
## 11. File Format Reference
### Asset Configuration File (config/assets.txt)
Text-based asset registry with pipe-delimited format:
```
# Format: TYPE|PATH [|OPTIONS]
# Comments start with # or ;
### Asset Configuration File (config/assets.yaml)
YAML-based asset registry with grouped structure:
```yaml
# JailDoctor's Dilemma - Asset Configuration
# Variables: ${PREFIX}, ${SYSTEM_FOLDER}
# Options: optional, absolute (comma-separated)
# Example entries:
BITMAP|${PREFIX}/data/player/player.gif
ANIMATION|${PREFIX}/data/player/player.ani
MUSIC|${PREFIX}/data/music/title.ogg
DATA|${SYSTEM_FOLDER}/config.txt|optional,absolute
assets:
# FONTS
fonts:
- type: BITMAP
path: ${PREFIX}/data/font/smb2.gif
- type: FONT
path: ${PREFIX}/data/font/smb2.txt
# PLAYER
player:
- type: BITMAP
path: ${PREFIX}/data/player/player.gif
- type: ANIMATION
path: ${PREFIX}/data/player/player.yaml
# MUSIC
music:
- type: MUSIC
path: ${PREFIX}/data/music/title.ogg
# SYSTEM FILES (optional, absolute paths)
system:
- type: DATA
path: ${SYSTEM_FOLDER}/config.txt
required: false
absolute: true
```
**Asset Structure:**
- Assets are organized into categories (fonts, palettes, shaders, player, enemies, etc.)
- Each asset entry contains:
- `type` - Asset type (required)
- `path` - File path with variable substitution (required)
- `required` - Whether file must exist (optional, default: `true`)
- `absolute` - Whether path is absolute (optional, default: `false`)
**Available Asset Types:**
- `DATA` - General data files (text, JSON, etc.)
- `BITMAP` - Images (GIF, PNG)
- `ANIMATION` - Animation definition files (.ani)
- `ANIMATION` - Animation definition files (.yaml)
- `MUSIC` - Music files (OGG)
- `SOUND` - Sound effects (WAV)
- `FONT` - Font definition files
- `ROOM` - Room data files (.room)
- `TILEMAP` - Tilemap files (.tmx)
- `ROOM` - Room data files (.yaml)
- `PALETTE` - Color palette files (.pal)
**Options:**
- `optional` - File is not required (won't fail check if missing)
- `absolute` - Path is absolute (not relative to executable)
**Variables:**
- `${PREFIX}` - Replaced with `/../Resources` on macOS bundles, empty otherwise
- `${SYSTEM_FOLDER}` - Replaced with user's system config folder
@@ -865,7 +896,7 @@ Binary 256-color palette format (256 × 4 bytes RGBA).
- `Player::update()` - Physics and movement
### For Asset Management
- `config/assets.txt` - Asset configuration file (text-based, no recompilation needed)
- `config/assets.yaml` - Asset configuration file (text-based, no recompilation needed)
- `Asset::loadFromFile()` - Loads assets from config file
- `Resource::List::get()` - Retrieves asset path (O(1) lookup with unordered_map)
- `Resource::load()` - Asset loading