Made textures fail harder when given bad config.

This commit is contained in:
Zed A. Shaw 2025-09-23 22:45:13 -04:00
parent 7cdd96ef73
commit a4fdfb779f

View file

@ -13,6 +13,7 @@ namespace textures {
static TextureManager TMGR; static TextureManager TMGR;
static bool initialized = false; static bool initialized = false;
static bool failure = false;
void load_sprite_textures(SpriteTextureMap &mapping, json &config, bool smooth) { void load_sprite_textures(SpriteTextureMap &mapping, json &config, bool smooth) {
for(auto& [name, settings] : config.items()) { for(auto& [name, settings] : config.items()) {
@ -25,8 +26,10 @@ namespace textures {
int width = settings["frame_width"]; int width = settings["frame_width"];
int height = settings["frame_height"]; int height = settings["frame_height"];
dbc::check(width % 2 == 0,
fmt::format("sprite {} has invalid frame size {}", name, width)); dbc::check(width % 2 == 0 && height % 2 == 0,
fmt::format("sprite {}:{} has invalid frame size {}:{}",
path, name, width, height));
sf::Vector2i frame_size{width, height}; sf::Vector2i frame_size{width, height};
@ -113,12 +116,19 @@ namespace textures {
} }
void init() { void init() {
dbc::check(!failure, "YOU HAD A CATASTROPHIC TEXTURES FAILURE, FIX IT");
try {
if(!initialized) { if(!initialized) {
load_tiles(); load_tiles();
load_sprites(); load_sprites();
load_map_tiles(); load_map_tiles();
initialized = true; initialized = true;
} }
} catch(...) {
failure = true;
throw;
}
} }
SpriteTexture& get(const string& name, SpriteTextureMap& mapping) { SpriteTexture& get(const string& name, SpriteTextureMap& mapping) {