Add the frame width/height to SpriteTexture. Closes #13

This commit is contained in:
Zed A. Shaw 2025-06-27 01:21:50 -04:00
parent ea92dcc3c4
commit 19682fd0bc
4 changed files with 39 additions and 12 deletions

View file

@ -23,9 +23,14 @@ namespace textures {
int width = settings["frame_width"];
int height = settings["frame_height"];
sprite->setTextureRect({{0,0}, {width, height}});
dbc::check(width % 2 == 0,
fmt::format("sprite {} has invalid frame size", name));
TMGR.sprite_textures.try_emplace(name, sprite, texture);
sf::Vector2i frame_size{width, height};
sprite->setTextureRect({{0,0}, frame_size});
TMGR.sprite_textures.try_emplace(name, sprite, texture, frame_size);
}
}
@ -46,6 +51,11 @@ namespace textures {
auto &config = el.value();
const std::string& texture_fname = config["texture"];
size_t surface_i = config["id"];
dbc::check(!TMGR.name_to_id.contains(el.key()),
fmt::format("duplicate key in textures {}",
(std::string)el.key()));
TMGR.name_to_id.insert_or_assign(el.key(), surface_i);
if(surface_i >= tiles.size()) {