migrat Assets a la ultima versió (fitxers no hardcoded)
This commit is contained in:
69
CLAUDE.md
69
CLAUDE.md
@@ -181,6 +181,9 @@ source/
|
||||
│ └── utils.hpp/cpp # Helper functions (colors, math)
|
||||
└── main.cpp # Application entry point
|
||||
|
||||
config/ # Configuration files
|
||||
└── assets.txt # Asset registry (text-based configuration)
|
||||
|
||||
data/ # Game assets
|
||||
├── font/ # Bitmap fonts + descriptors
|
||||
├── palette/ # Color palettes (.pal files)
|
||||
@@ -386,13 +389,17 @@ Game::run() {
|
||||
|
||||
```
|
||||
Director::setFileList()
|
||||
├─ Asset::add(file, type) - Register all assets
|
||||
└─ Asset::check() - Verify files exist
|
||||
├─ Asset::loadFromFile(config_path, PREFIX, system_folder_)
|
||||
│ ├─ Read config/assets.txt - 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
|
||||
└─ Asset::check() - Verify required files exist
|
||||
|
||||
Game Scene initialization
|
||||
└─ Resource::init() - Loads all resources
|
||||
├─ loadSounds() - WAV files
|
||||
├─ loadMusics() - OGG files
|
||||
├─ loadMusics() - OGG files
|
||||
├─ loadSurfaces() - GIF/PNG images
|
||||
├─ loadAnimations() - .ani animation definitions
|
||||
├─ loadTileMaps() - .room tilemap data
|
||||
@@ -568,7 +575,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 | Singleton |
|
||||
| `Asset` | Asset path registry from config/assets.txt, O(1) lookups, variable substitution | Singleton |
|
||||
| `Debug` | Debug overlay information | Singleton |
|
||||
| `globalEvents` | Global SDL event handling (quit, device reset, mouse) | Namespace |
|
||||
|
||||
@@ -631,12 +638,16 @@ Achievements trigger notifications on unlock.
|
||||
### Adding Game Assets
|
||||
|
||||
1. Place file in `data/` directory
|
||||
2. Register in `Director::setFileList()`:
|
||||
```cpp
|
||||
Asset::get()->add("/data/path/file.ext", AssetType::TYPE);
|
||||
2. Add entry to `config/assets.txt`:
|
||||
```
|
||||
3. Resource loads automatically during `Resource::init()`
|
||||
4. Access via: `Resource::get()->getSurface("name")`
|
||||
TYPE|${PREFIX}/data/path/file.ext
|
||||
```
|
||||
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::get()->getSurface("name")`
|
||||
|
||||
**Note:** No recompilation needed when adding/removing/modifying assets in `config/assets.txt`
|
||||
|
||||
### Modifying Collision Detection
|
||||
|
||||
@@ -692,6 +703,40 @@ 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 ;
|
||||
# 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
|
||||
```
|
||||
|
||||
**Available Asset Types:**
|
||||
- `DATA` - General data files (text, JSON, etc.)
|
||||
- `BITMAP` - Images (GIF, PNG)
|
||||
- `ANIMATION` - Animation definition files (.ani)
|
||||
- `MUSIC` - Music files (OGG)
|
||||
- `SOUND` - Sound effects (WAV)
|
||||
- `FONT` - Font definition files
|
||||
- `ROOM` - Room data files (.room)
|
||||
- `TILEMAP` - Tilemap files (.tmx)
|
||||
- `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
|
||||
|
||||
### Animation Files (.ani)
|
||||
List of animation names, one per line:
|
||||
```
|
||||
@@ -741,9 +786,11 @@ Binary 256-color palette format (256 × 4 bytes RGBA).
|
||||
- `Player::update()` - Physics and movement
|
||||
|
||||
### For Asset Management
|
||||
- `Asset::add()` - Asset registration
|
||||
- `config/assets.txt` - Asset configuration file (text-based, no recompilation needed)
|
||||
- `Asset::loadFromFile()` - Loads assets from config file
|
||||
- `Asset::get()` - Retrieves asset path (O(1) lookup with unordered_map)
|
||||
- `Resource::load()` - Asset loading
|
||||
- `Director::setFileList()` - Complete asset registry
|
||||
- `Director::setFileList()` - Calls `Asset::loadFromFile()` with PREFIX and system_folder
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user