Best I can do to simplify the check(fmt::format)crap is to make a little macro to do the format part.
This commit is contained in:
parent
6710469ee1
commit
f0b04107ab
28 changed files with 108 additions and 108 deletions
|
|
@ -216,16 +216,16 @@ namespace animation {
|
|||
|
||||
void Animation::set_form(const std::string& as_form) {
|
||||
dbc::check(forms.contains(as_form),
|
||||
fmt::format("form {} does not exist in animation", as_form));
|
||||
$F("form {} does not exist in animation", as_form));
|
||||
stop();
|
||||
|
||||
const auto& [seq_name, tr_name] = forms.at(as_form);
|
||||
|
||||
dbc::check(sequences.contains(seq_name),
|
||||
fmt::format("sequences do NOT have \"{}\" name", seq_name));
|
||||
$F("sequences do NOT have \"{}\" name", seq_name));
|
||||
|
||||
dbc::check(transforms.contains(tr_name),
|
||||
fmt::format("transforms do NOT have \"{}\" name", tr_name));
|
||||
$F("transforms do NOT have \"{}\" name", tr_name));
|
||||
|
||||
// everything good, do the update
|
||||
form_name = as_form;
|
||||
|
|
@ -255,14 +255,14 @@ namespace animation {
|
|||
auto data = json::parse(infile);
|
||||
|
||||
dbc::check(data.contains(anim_name),
|
||||
fmt::format("{} animation config does not have animation {}", file, anim_name));
|
||||
$F("{} animation config does not have animation {}", file, anim_name));
|
||||
|
||||
Animation anim;
|
||||
animation::from_json(data[anim_name], anim);
|
||||
anim.name = anim_name;
|
||||
|
||||
dbc::check(anim.forms.contains("idle"),
|
||||
fmt::format("animation {} must have 'idle' form", anim_name));
|
||||
$F("animation {} must have 'idle' form", anim_name));
|
||||
|
||||
anim.set_form("idle");
|
||||
|
||||
|
|
@ -271,21 +271,19 @@ namespace animation {
|
|||
|
||||
void Sequence::INVARIANT(const std::source_location location) {
|
||||
dbc::check(frames.size() == durations.size(),
|
||||
fmt::format("frames.size={} doesn't match durations.size={}",
|
||||
$F("frames.size={} doesn't match durations.size={}",
|
||||
frames.size(), durations.size()), location);
|
||||
|
||||
dbc::check(easing_duration > 0.0,
|
||||
fmt::format("bad easing duration: {}", easing_duration), location);
|
||||
dbc::check(easing_duration > 0.0, $F("bad easing duration: {}", easing_duration), location);
|
||||
|
||||
dbc::check(frame_count == frames.size(),
|
||||
fmt::format("frame_count={} doesn't match frames.size={}", frame_count, frames.size()), location);
|
||||
$F("frame_count={} doesn't match frames.size={}", frame_count, frames.size()), location);
|
||||
|
||||
dbc::check(frame_count == durations.size(),
|
||||
fmt::format("frame_count={} doesn't match durations.size={}", frame_count, durations.size()), location);
|
||||
$F("frame_count={} doesn't match durations.size={}", frame_count, durations.size()), location);
|
||||
|
||||
dbc::check(current < durations.size(),
|
||||
fmt::format("current={} went past end of fame durations.size={}",
|
||||
current, durations.size()), location);
|
||||
$F("current={} went past end of fame durations.size={}", current, durations.size()), location);
|
||||
}
|
||||
|
||||
// BUG: BAAADD REMOVE
|
||||
|
|
|
|||
|
|
@ -128,13 +128,13 @@ namespace ease2 {
|
|||
|
||||
EaseFunc get_easing(const std::string& name) {
|
||||
dbc::check(map_of_easings.contains(name),
|
||||
fmt::format("easing name {} does not exist", name));
|
||||
$F("easing name {} does not exist", name));
|
||||
return map_of_easings.at(name);
|
||||
}
|
||||
|
||||
MotionFunc get_motion(const std::string& name) {
|
||||
dbc::check(map_of_motions.contains(name),
|
||||
fmt::format("motion name {} does not exist", name));
|
||||
$F("motion name {} does not exist", name));
|
||||
return map_of_motions.at(name);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace palette {
|
|||
for(auto [value, rgba] : value_specs.items()) {
|
||||
auto color_path = base_key + ":" + value;
|
||||
dbc::check(!COLOR.palettes.contains(color_path),
|
||||
fmt::format("PALLETES config {} already has a color path {}", COLOR.config, color_path));
|
||||
$F("PALLETES config {} already has a color path {}", COLOR.config, color_path));
|
||||
|
||||
if(rgba.type() == json::value_t::string) {
|
||||
COLOR.pending_refs.try_emplace(color_path, rgba);
|
||||
|
|
@ -48,10 +48,10 @@ namespace palette {
|
|||
|
||||
for(auto [color_path, ref] : COLOR.pending_refs) {
|
||||
dbc::check(COLOR.palettes.contains(ref),
|
||||
fmt::format("In {} you have {} referring to {} but {} doesn't exist.",
|
||||
$F("In {} you have {} referring to {} but {} doesn't exist.",
|
||||
COLOR.config, color_path, ref, ref));
|
||||
dbc::check(!COLOR.palettes.contains(color_path),
|
||||
fmt::format("Color {} with ref {} is duplicated.", color_path, ref));
|
||||
$F("Color {} with ref {} is duplicated.", color_path, ref));
|
||||
|
||||
auto color = COLOR.palettes.at(ref);
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ namespace palette {
|
|||
|
||||
sf::Color get(const string& key) {
|
||||
dbc::check(COLOR.palettes.contains(key),
|
||||
fmt::format("COLOR {} is missing from {}", key, COLOR.config));
|
||||
$F("COLOR {} is missing from {}", key, COLOR.config));
|
||||
return COLOR.palettes.at(key);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace scene {
|
|||
for(auto& config : $scene.actors) {
|
||||
auto element = config_scene_element(config, false);
|
||||
dbc::check(!$actor_name_ids.contains(element.name),
|
||||
fmt::format("actors key {} already exists", element.name));
|
||||
$F("actors key {} already exists", element.name));
|
||||
$actors.push_back(element);
|
||||
$actor_name_ids.try_emplace(element.name, $actors.size() - 1);
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ namespace scene {
|
|||
}
|
||||
|
||||
Element& Engine::actor_config(const std::string& actor) {
|
||||
dbc::check($actor_name_ids.contains(actor), fmt::format("scene does not contain actor {}", actor));
|
||||
dbc::check($actor_name_ids.contains(actor), $F("scene does not contain actor {}", actor));
|
||||
return $actors.at($actor_name_ids.at(actor));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ namespace shaders {
|
|||
if(name == "ERROR") continue;
|
||||
|
||||
dbc::check(!SMGR.shaders.contains(name),
|
||||
fmt::format("shader name '{}' duplicated in assets/shaders.json", name));
|
||||
$F("shader name '{}' duplicated in assets/shaders.json", name));
|
||||
good = load_shader(name, settings);
|
||||
|
||||
if(!good) {
|
||||
dbc::log(fmt::format("failed to load shader {}", name));
|
||||
dbc::log($F("failed to load shader {}", name));
|
||||
SMGR.shaders.insert_or_assign(name, SMGR.shaders.at("ERROR"));
|
||||
}
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ namespace shaders {
|
|||
std::shared_ptr<sf::Shader> get(const std::string& name) {
|
||||
dbc::check(INITIALIZED, "you forgot to shaders::init()");
|
||||
dbc::check(SMGR.shaders.contains(name),
|
||||
fmt::format("shader name '{}' not in assets/shaders.json", name));
|
||||
$F("shader name '{}' not in assets/shaders.json", name));
|
||||
auto& rec = SMGR.shaders.at(name);
|
||||
return rec.ptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace textures {
|
|||
void load_sprite_textures(SpriteTextureMap &mapping, json &config, bool smooth) {
|
||||
for(auto& [name, settings] : config.items()) {
|
||||
const string& path = settings["path"];
|
||||
dbc::check(fs::exists(path), fmt::format("texture at {} doesn't exist", path));
|
||||
dbc::check(fs::exists(path), $F("texture at {} doesn't exist", path));
|
||||
auto texture = make_shared<sf::Texture>(path);
|
||||
|
||||
texture->setSmooth(smooth);
|
||||
|
|
@ -28,7 +28,7 @@ namespace textures {
|
|||
int height = settings["frame_height"];
|
||||
|
||||
dbc::check(width % 2 == 0 && height % 2 == 0,
|
||||
fmt::format("sprite {}:{} has invalid frame size {}:{}",
|
||||
$F("sprite {}:{} has invalid frame size {}:{}",
|
||||
path, name, width, height));
|
||||
|
||||
sf::Vector2i frame_size{width, height};
|
||||
|
|
@ -36,7 +36,7 @@ namespace textures {
|
|||
sprite->setTextureRect({{0,0}, frame_size});
|
||||
|
||||
dbc::check(!mapping.contains(name),
|
||||
fmt::format("duplicate sprite/icon name {}", (string)name));
|
||||
$F("duplicate sprite/icon name {}", (string)name));
|
||||
mapping.try_emplace(name, sprite, texture, frame_size);
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ namespace textures {
|
|||
size_t surface_i = config["id"];
|
||||
|
||||
dbc::check(!TMGR.name_to_id.contains(el.key()),
|
||||
fmt::format("duplicate key in textures {}",
|
||||
$F("duplicate key in textures {}",
|
||||
(string)el.key()));
|
||||
|
||||
TMGR.name_to_id.insert_or_assign(el.key(), surface_i);
|
||||
|
|
@ -87,7 +87,7 @@ namespace textures {
|
|||
if(config.contains("ceiling")) {
|
||||
const string& name = config["ceiling"];
|
||||
|
||||
dbc::check(tiles.contains(name), fmt::format("invalid ceiling name {} in tile config {}", name, (string)el.key()));
|
||||
dbc::check(tiles.contains(name), $F("invalid ceiling name {} in tile config {}", name, (string)el.key()));
|
||||
|
||||
auto& ceiling = tiles[name];
|
||||
TMGR.ceilings[surface_i] = ceiling["id"];
|
||||
|
|
@ -109,7 +109,7 @@ namespace textures {
|
|||
wchar_t display = tile["display"];
|
||||
|
||||
dbc::check(!TMGR.map_sprites.contains(display),
|
||||
fmt::format("duplicate tile display {} in map_tiles.json", int(display)));
|
||||
$F("duplicate tile display {} in map_tiles.json", int(display)));
|
||||
|
||||
TMGR.map_sprites.try_emplace(display, sprite);
|
||||
}
|
||||
|
|
@ -134,14 +134,14 @@ namespace textures {
|
|||
SpriteTexture& get(const string& name, SpriteTextureMap& mapping) {
|
||||
dbc::check(initialized, "you forgot to call textures::init()");
|
||||
dbc::check(mapping.contains(name),
|
||||
fmt::format("!!!!! textures do not contain {} sprite", name));
|
||||
$F("!!!!! textures do not contain {} sprite", name));
|
||||
|
||||
auto& result = mapping.at(name);
|
||||
|
||||
dbc::check(result.sprite != nullptr,
|
||||
fmt::format("bad sprite from textures::get named {}", name));
|
||||
$F("bad sprite from textures::get named {}", name));
|
||||
dbc::check(result.texture != nullptr,
|
||||
fmt::format("bad texture from textures::get named {}", name));
|
||||
$F("bad texture from textures::get named {}", name));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ namespace textures {
|
|||
sf::Image load_image(const string& filename) {
|
||||
sf::Image texture;
|
||||
bool good = texture.loadFromFile(filename);
|
||||
dbc::check(good, fmt::format("failed to load {}", filename));
|
||||
dbc::check(good, $F("failed to load {}", filename));
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
|
@ -190,13 +190,13 @@ namespace textures {
|
|||
|
||||
size_t get_id(const string& name) {
|
||||
dbc::check(TMGR.name_to_id.contains(name),
|
||||
fmt::format("there is no texture named {} in tiles.json", name));
|
||||
$F("there is no texture named {} in tiles.json", name));
|
||||
return TMGR.name_to_id.at(name);
|
||||
}
|
||||
|
||||
sf::Sprite& get_map_sprite(wchar_t display) {
|
||||
dbc::check(TMGR.map_sprites.contains(display),
|
||||
fmt::format("map_sprites.json doesn't have {} sprite", int(display)));
|
||||
$F("map_sprites.json doesn't have {} sprite", int(display)));
|
||||
|
||||
return TMGR.map_sprites.at(display);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue