36 lines
1.6 KiB
Markdown
Executable File
36 lines
1.6 KiB
Markdown
Executable File
# Asset Loader
|
||
|
||
## Current state
|
||
|
||
TGA loading is implemented in `client/src/assets.rs`. `Image::from_tga(path)` reads the file,
|
||
parses the 18-byte header, skips the colormap block, and returns an `Image` — supporting
|
||
type 1 (uncompressed) and type 9 (RLE) via the private `decode_rle()` function in the same
|
||
module. `game.rs` uses it directly: `Image::from_tga("assets/tilesets/overworld.tga")`.
|
||
|
||
`Image` also provides `to_tileset() -> Vec<[u8; 64]>`, which splits the image into 8×8
|
||
tiles row-major. Every tile is emitted; tile ID is the flat row-major index into the Vec,
|
||
so tiles are never skipped or reordered. (Transparency is a per-pixel concern handled at
|
||
blit time by `blit_tile`, not by the splitter.)
|
||
|
||
`AssetStore` (a named registry) is **not yet implemented**. Assets are currently loaded
|
||
inline in `Game::start()`.
|
||
|
||
## Goal
|
||
|
||
Add an `AssetStore` so that game code can ask for an asset by name rather than loading
|
||
files directly at the call site.
|
||
|
||
## Design notes
|
||
|
||
- `Image` struct: `width: u32`, `height: u32`, `pixels: Vec<u8>` — done.
|
||
- A simple `AssetStore` could be a `HashMap<&'static str, Image>` loaded at startup.
|
||
- No streaming needed — the whole game is small enough to load everything upfront in `start()`.
|
||
- Palette index 0 is transparent when blitting sprites. This convention is enforced by
|
||
`blit_tile()` in `pixelhelper.rs`; the loader itself does not need to handle it.
|
||
- Pixel assets are stored as flat `Vec<u8>` of palette indices, row-major, width × height bytes.
|
||
- Future: consider embedding assets with `include_bytes!` to produce a single binary.
|
||
|
||
## Open questions
|
||
|
||
- Should `AssetStore` hold pre-split tilesets too, or just raw `Image` values?
|