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 bool initialized = false;
static bool failure = false;
void load_sprite_textures(SpriteTextureMap &mapping, json &config, bool smooth) {
for(auto& [name, settings] : config.items()) {
@ -25,8 +26,10 @@ namespace textures {
int width = settings["frame_width"];
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};
@ -113,11 +116,18 @@ namespace textures {
}
void init() {
if(!initialized) {
load_tiles();
load_sprites();
load_map_tiles();
initialized = true;
dbc::check(!failure, "YOU HAD A CATASTROPHIC TEXTURES FAILURE, FIX IT");
try {
if(!initialized) {
load_tiles();
load_sprites();
load_map_tiles();
initialized = true;
}
} catch(...) {
failure = true;
throw;
}
}