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
|
|
@ -11,7 +11,8 @@ namespace ai {
|
|||
inline void validate_profile(nlohmann::json& profile) {
|
||||
for(auto& [name_key, value] : profile.items()) {
|
||||
check(value < STATE_MAX,
|
||||
fmt::format("profile field {} has value {} greater than STATE_MAX {}", (std::string)name_key, (int)value, STATE_MAX));
|
||||
$F("profile field {} has value {} greater than STATE_MAX {}",
|
||||
(std::string)name_key, (int)value, STATE_MAX));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -22,17 +23,17 @@ namespace ai {
|
|||
Action result(config["name"], config["cost"]);
|
||||
|
||||
check(config.contains("needs"),
|
||||
fmt::format("config_action: no 'needs' field", result.name));
|
||||
$F("config_action: no 'needs' field", result.name));
|
||||
check(config.contains("effects"),
|
||||
fmt::format("config_action: no 'effects' field", result.name));
|
||||
$F("config_action: no 'effects' field", result.name));
|
||||
|
||||
for(auto& [name_key, value] : config["needs"].items()) {
|
||||
check(profile.contains(name_key), fmt::format("config_action({}): profile does not have need named {}", result.name, name_key));
|
||||
check(profile.contains(name_key), $F("config_action({}): profile does not have need named {}", result.name, name_key));
|
||||
result.needs(profile.at(name_key), bool(value));
|
||||
}
|
||||
|
||||
for(auto& [name_key, value] : config["effects"].items()) {
|
||||
check(profile.contains(name_key), fmt::format("config_action({}): profile does not have effect named {}", result.name, name_key));
|
||||
check(profile.contains(name_key), $F("config_action({}): profile does not have effect named {}", result.name, name_key));
|
||||
|
||||
result.effect(profile.at(name_key), bool(value));
|
||||
}
|
||||
|
|
@ -44,7 +45,7 @@ namespace ai {
|
|||
State result;
|
||||
|
||||
for(auto& [name_key, value] : config.items()) {
|
||||
check(profile.contains(name_key), fmt::format("config_state: profile does not have name {}", name_key));
|
||||
check(profile.contains(name_key), $F("config_state: profile does not have name {}", name_key));
|
||||
|
||||
int name_id = profile.at(name_key);
|
||||
result[name_id] = bool(value);
|
||||
|
|
@ -95,7 +96,7 @@ namespace ai {
|
|||
|
||||
for(auto name : action_names) {
|
||||
check(AIMGR.actions.contains(name),
|
||||
fmt::format("ai::init(): script {} uses action {} that doesn't exist",
|
||||
$F("ai::init(): script {} uses action {} that doesn't exist",
|
||||
(std::string)script_name, (std::string)name));
|
||||
|
||||
the_script.push_back(AIMGR.actions.at(name));
|
||||
|
|
@ -111,14 +112,14 @@ namespace ai {
|
|||
|
||||
void check_valid_action(std::string name, std::string msg) {
|
||||
dbc::check(AIMGR.actions.contains(name),
|
||||
fmt::format("{} tried to access action that doesn't exist {}",
|
||||
$F("{} tried to access action that doesn't exist {}",
|
||||
msg, name));
|
||||
}
|
||||
|
||||
State load_state(std::string state_name) {
|
||||
check(initialized, "you forgot to initialize the AI first.");
|
||||
check(AIMGR.states.contains(state_name), fmt::format(
|
||||
"ai::load_state({}): state does not exist in config",
|
||||
check(AIMGR.states.contains(state_name),
|
||||
$F("ai::load_state({}): state does not exist in config",
|
||||
state_name));
|
||||
|
||||
return AIMGR.states.at(state_name);
|
||||
|
|
@ -126,15 +127,15 @@ namespace ai {
|
|||
|
||||
Action load_action(std::string action_name) {
|
||||
check(initialized, "you forgot to initialize the AI first.");
|
||||
check(AIMGR.actions.contains(action_name), fmt::format(
|
||||
"ai::load_action({}): action does not exist in config",
|
||||
check(AIMGR.actions.contains(action_name),
|
||||
$F("ai::load_action({}): action does not exist in config",
|
||||
action_name));
|
||||
return AIMGR.actions.at(action_name);
|
||||
}
|
||||
|
||||
std::vector<Action> load_script(std::string script_name) {
|
||||
check(AIMGR.scripts.contains(script_name), fmt::format(
|
||||
"ai::load_script(): no script named {} configured", script_name));
|
||||
check(AIMGR.scripts.contains(script_name),
|
||||
$F("ai::load_script(): no script named {} configured", script_name));
|
||||
return AIMGR.scripts.at(script_name);
|
||||
}
|
||||
|
||||
|
|
@ -148,9 +149,8 @@ namespace ai {
|
|||
}
|
||||
|
||||
int state_id(std::string name) {
|
||||
check(AIMGR.profile.contains(name), fmt::format(
|
||||
"ai::state_id({}): id is not configured in profile",
|
||||
name));
|
||||
check(AIMGR.profile.contains(name),
|
||||
$F("ai::state_id({}): id is not configured in profile", name));
|
||||
return AIMGR.profile.at(name);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ namespace DinkyECS
|
|||
|
||||
for(auto [eid, is_set] : $constants) {
|
||||
dbc::check(is_set == true, "is_set was not true? WHAT?!");
|
||||
dbc::check(eid <= entity_count, fmt::format(
|
||||
"eid {} is not less than entity_count {}", eid, entity_count));
|
||||
dbc::check(eid <= entity_count,
|
||||
$F("eid {} is not less than entity_count {}", eid, entity_count));
|
||||
|
||||
for(const auto &[tid, eid_map] : $components) {
|
||||
auto &their_map = to_world.$components[tid];
|
||||
|
|
@ -146,8 +146,7 @@ namespace DinkyECS
|
|||
Comp &get_the() {
|
||||
auto comp_id = std::type_index(typeid(Comp));
|
||||
dbc::check($facts->contains(comp_id),
|
||||
fmt::format("!!!! ATTEMPT to access world fact that hasn't "
|
||||
"been set yet: {}",
|
||||
$F("!!!! ATTEMPT to access world fact that hasn't been set yet: {}",
|
||||
typeid(Comp).name()));
|
||||
|
||||
// use .at to get std::out_of_range if fact not set
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t
|
|||
void Pathing::compute_paths(Matrix &walls) {
|
||||
INVARIANT();
|
||||
dbc::check(walls[0].size() == $width,
|
||||
fmt::format("Pathing::compute_paths called with walls.width={} but paths $width={}", walls[0].size(), $width));
|
||||
$F("Pathing::compute_paths called with walls.width={} but paths $width={}", walls[0].size(), $width));
|
||||
|
||||
dbc::check(walls.size() == $height,
|
||||
fmt::format("Pathing::compute_paths called with walls.height={} but paths $height={}", walls[0].size(), $height));
|
||||
$F("Pathing::compute_paths called with walls.height={} but paths $height={}", walls[0].size(), $height));
|
||||
|
||||
// Initialize the new array with every pixel at limit distance
|
||||
matrix::assign($paths, WALL_PATH_LIMIT);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
void Stats::dump(std::string msg)
|
||||
{
|
||||
dbc::log(fmt::format("{}: sum: {}, sumsq: {}, n: {}, "
|
||||
dbc::log($F("{}: sum: {}, sumsq: {}, n: {}, "
|
||||
"min: {}, max: {}, mean: {}, stddev: {}",
|
||||
msg, sum, sumsq, n, min, max, mean(),
|
||||
stddev()));
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace boss {
|
|||
{
|
||||
$host_combat = $world->get_if<components::Combat>(player_id);
|
||||
dbc::check($host_combat,
|
||||
fmt::format("No combat for host with player_id={}", player_id));
|
||||
$F("No combat for host with player_id={}", player_id));
|
||||
$ui.init();
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ namespace boss {
|
|||
using combat::BattleHostState;
|
||||
|
||||
dbc::check(data.type() == typeid(components::CombatResult),
|
||||
fmt::format("Boss Fight wrong any data={}", data.type().name()));
|
||||
$F("Boss Fight wrong any data={}", data.type().name()));
|
||||
|
||||
auto result = std::any_cast<components::CombatResult>(data);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ void dbc::log(const string &message, const std::source_location location) {
|
|||
}
|
||||
|
||||
void dbc::sentinel(const string &message, const std::source_location location) {
|
||||
string err = fmt::format("[SENTINEL!] {}", message);
|
||||
string err = $F("[SENTINEL!] {}", message);
|
||||
dbc::log(err, location);
|
||||
throw dbc::SentinelError{err};
|
||||
}
|
||||
|
||||
void dbc::pre(const string &message, bool test, const std::source_location location) {
|
||||
if(!test) {
|
||||
string err = fmt::format("[PRE!] {}", message);
|
||||
string err = $F("[PRE!] {}", message);
|
||||
dbc::log(err, location);
|
||||
throw dbc::PreCondError{err};
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ void dbc::pre(const string &message, std::function<bool()> tester, const std::so
|
|||
|
||||
void dbc::post(const string &message, bool test, const std::source_location location) {
|
||||
if(!test) {
|
||||
string err = fmt::format("[POST!] {}", message);
|
||||
string err = $F("[POST!] {}", message);
|
||||
dbc::log(err, location);
|
||||
throw dbc::PostCondError{err};
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ void dbc::post(const string &message, std::function<bool()> tester, const std::s
|
|||
|
||||
void dbc::check(bool test, const string &message, const std::source_location location) {
|
||||
if(!test) {
|
||||
string err = fmt::format("[CHECK!] {}\n", message);
|
||||
string err = $F("[CHECK!] {}\n", message);
|
||||
dbc::log(err, location);
|
||||
throw dbc::CheckError{err};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@
|
|||
#include <functional>
|
||||
#include <source_location>
|
||||
|
||||
// AKA the Fuckit macro
|
||||
#define $F(FMT, ...) fmt::format(FMT, ##__VA_ARGS__)
|
||||
|
||||
namespace dbc {
|
||||
using std::string;
|
||||
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ void Autowalker::handle_player_walk(ai::State& start, ai::State& goal) {
|
|||
fsm.autowalking = false;
|
||||
} else {
|
||||
close_status();
|
||||
dbc::log(fmt::format("Unknown action: {}", player_ai.to_string()));
|
||||
dbc::log($F("Unknown action: {}", player_ai.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ namespace components {
|
|||
|
||||
void configure_entity(DinkyECS::World& world, DinkyECS::Entity ent, json& data) {
|
||||
for (auto &i : data) {
|
||||
dbc::check(i.contains("_type") && i["_type"].is_string(), fmt::format("component has no _type: {}", data.dump()));
|
||||
dbc::check(MAP.contains(i["_type"]), fmt::format("MAP doesn't have type {}", std::string(i["_type"])));
|
||||
dbc::check(i.contains("_type") && i["_type"].is_string(), $F("component has no _type: {}", data.dump()));
|
||||
dbc::check(MAP.contains(i["_type"]), $F("MAP doesn't have type {}", std::string(i["_type"])));
|
||||
MAP.at(i["_type"])(world, ent, i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@
|
|||
|
||||
namespace settings {
|
||||
using nlohmann::json;
|
||||
using fmt::format;
|
||||
|
||||
std::filesystem::path Config::BASE_DIR{"."};
|
||||
|
||||
Config::Config(const std::string src_path) : $src_path(src_path) {
|
||||
auto path_to = Config::path_to($src_path);
|
||||
dbc::check(std::filesystem::exists(path_to),
|
||||
fmt::format("requested config file {} doesn't exist", path_to.string()));
|
||||
$F("requested config file {} doesn't exist", path_to.string()));
|
||||
std::ifstream infile(path_to);
|
||||
$config = json::parse(infile);
|
||||
}
|
||||
|
|
@ -21,13 +20,15 @@ namespace settings {
|
|||
}
|
||||
|
||||
json &Config::operator[](const std::string &key) {
|
||||
dbc::check($config.contains(key), fmt::format("ERROR in config, key {} doesn't exist.", key));
|
||||
dbc::check($config.contains(key), $F("ERROR in config, key {} doesn't exist.", key));
|
||||
return $config[key];
|
||||
}
|
||||
|
||||
std::wstring Config::wstring(const std::string main_key, const std::string sub_key) {
|
||||
dbc::check($config.contains(main_key), fmt::format("ERROR wstring main/key in config, main_key {} doesn't exist.", main_key));
|
||||
dbc::check($config[main_key].contains(sub_key), fmt::format("ERROR wstring in config, main_key/key {}/{} doesn't exist.", main_key, sub_key));
|
||||
dbc::check($config.contains(main_key),
|
||||
$F("ERROR wstring main/key in config, main_key {} doesn't exist.", main_key));
|
||||
dbc::check($config[main_key].contains(sub_key),
|
||||
$F("ERROR wstring in config, main_key/key {}/{} doesn't exist.", main_key, sub_key));
|
||||
|
||||
const std::string& str_val = $config[main_key][sub_key];
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||
|
|
@ -58,8 +59,8 @@ namespace settings {
|
|||
} else {
|
||||
auto path = Config::BASE_DIR / fmt::format("assets/{}.json", name);
|
||||
|
||||
dbc::check(std::filesystem::exists(path), fmt::format(
|
||||
"config file {} does not exist", path.string()));
|
||||
dbc::check(std::filesystem::exists(path),
|
||||
$F("config file {} does not exist", path.string()));
|
||||
|
||||
return {path.string()};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace inventory {
|
|||
// NOTE: this was a reference but that caused corruption, just copy
|
||||
auto slot = by_entity.at(ent);
|
||||
|
||||
dbc::log(fmt::format("removing entity {} and slot {}", ent, slot));
|
||||
dbc::log($F("removing entity {} and slot {}", ent, slot));
|
||||
dbc::check(by_slot.contains(slot), "entity is in by_entity but the slot is not in by_slot");
|
||||
|
||||
// NOTE: you have to erase the entity after the slot or else you get corruption
|
||||
|
|
@ -47,16 +47,16 @@ namespace inventory {
|
|||
void Model::invariant() {
|
||||
for(auto& [slot, ent] : by_slot) {
|
||||
dbc::check(by_entity.contains(ent),
|
||||
fmt::format("entity {} in by_slot isn't in by_entity?", ent));
|
||||
$F("entity {} in by_slot isn't in by_entity?", ent));
|
||||
dbc::check(by_entity.at(ent) == slot,
|
||||
fmt::format("mismatched slot {} in by_slot doesn't match entity {}", slot, ent));
|
||||
$F("mismatched slot {} in by_slot doesn't match entity {}", slot, ent));
|
||||
}
|
||||
|
||||
for(auto& [ent, slot] : by_entity) {
|
||||
dbc::check(by_slot.contains(slot),
|
||||
fmt::format("slot {} in by_entity isn't in by_slot?", ent));
|
||||
$F("slot {} in by_entity isn't in by_slot?", ent));
|
||||
dbc::check(by_slot.at(slot) == ent,
|
||||
fmt::format("mismatched entity {} in by_entity doesn't match entity {}", ent, slot));
|
||||
$F("mismatched entity {} in by_entity doesn't match entity {}", ent, slot));
|
||||
}
|
||||
|
||||
dbc::check(by_slot.size() == by_entity.size(), "by_slot and by_entity have differing sizes");
|
||||
|
|
|
|||
|
|
@ -106,10 +106,10 @@ bool Map::INVARIANT() {
|
|||
|
||||
for(auto room : $rooms) {
|
||||
check(int(room.x) >= 0 && int(room.y) >= 0,
|
||||
format("room invalid position {},{}",
|
||||
$F("room invalid position {},{}",
|
||||
room.x, room.y));
|
||||
check(int(room.width) > 0 && int(room.height) > 0,
|
||||
format("room has invalid dims {},{}",
|
||||
$F("room has invalid dims {},{}",
|
||||
room.width, room.height));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace ritual {
|
|||
|
||||
void Engine::set_state(CraftingState& ritual, std::string name, bool setting) {
|
||||
dbc::check($profile.contains(name),
|
||||
fmt::format("ritual action named {} is not in profile, look in {} config",
|
||||
$F("ritual action named {} is not in profile, look in {} config",
|
||||
name, $config.$src_path));
|
||||
|
||||
ritual.start.set($profile.at(name), setting);
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ namespace sound {
|
|||
// get the sound from the sound map
|
||||
return SMGR.sounds.at(name);
|
||||
} else {
|
||||
dbc::log(fmt::format("Attempted to stop {} sound but not available.",
|
||||
name));
|
||||
dbc::log($F("Attempted to stop {} sound but not available.", name));
|
||||
return SMGR.sounds.at("blank");
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +37,7 @@ namespace sound {
|
|||
}
|
||||
|
||||
void load(const std::string& name, const std::string& sound_path) {
|
||||
dbc::check(fs::exists(sound_path), fmt::format("sound file {} does not exist", sound_path));
|
||||
dbc::check(fs::exists(sound_path), $F("sound file {} does not exist", sound_path));
|
||||
|
||||
// create the buffer and keep in the buffer map
|
||||
auto buffer = make_shared<sf::SoundBuffer>(sound_path);
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ void System::collision() {
|
|||
world.send<game::Event>(game::Event::COMBAT_START, entity, entity);
|
||||
}
|
||||
} else {
|
||||
dbc::log(fmt::format("UNKNOWN COLLISION TYPE {}", entity));
|
||||
dbc::log($F("UNKNOWN COLLISION TYPE {}", entity));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -375,7 +375,7 @@ void System::pickup() {
|
|||
|
||||
void System::device(World &world, Entity actor, Entity item) {
|
||||
auto& device = world.get<Device>(item);
|
||||
dbc::log(fmt::format("entity {} INTERACTED WITH DEVICE {}", actor, item));
|
||||
dbc::log($F("entity {} INTERACTED WITH DEVICE {}", actor, item));
|
||||
|
||||
for(auto event : device.events) {
|
||||
if(event == "STAIRS_DOWN") {
|
||||
|
|
@ -387,7 +387,7 @@ void System::device(World &world, Entity actor, Entity item) {
|
|||
} else if(event == "LOOT_CONTAINER") {
|
||||
world.send<game::Event>(game::Event::LOOT_CONTAINER, actor, device);
|
||||
} else {
|
||||
dbc::log(fmt::format(
|
||||
dbc::log($F(
|
||||
"INVALID EVENT {} for device {}",
|
||||
event, (std::string)device.config["name"]));
|
||||
}
|
||||
|
|
@ -621,13 +621,13 @@ bool System::use_item(const string& slot_name) {
|
|||
player_combat.hp = player_combat.max_hp;
|
||||
}
|
||||
|
||||
dbc::log(fmt::format("player health now {}",
|
||||
dbc::log($F("player health now {}",
|
||||
player_combat.hp));
|
||||
|
||||
world.remove<Curative>(what);
|
||||
return true;
|
||||
} else {
|
||||
dbc::log(fmt::format("no usable item at {}", what));
|
||||
dbc::log($F("no usable item at {}", what));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ void WorldBuilder::stylize_rooms() {
|
|||
auto& style = styles[Random::uniform(size_t(0), styles.size() - 1)];
|
||||
|
||||
dbc::check(style.contains("floor"),
|
||||
fmt::format("no floor spec in style {}", (std::string)style["name"]));
|
||||
$F("no floor spec in style {}", (std::string)style["name"]));
|
||||
dbc::check(style.contains("walls"),
|
||||
fmt::format("no walls spec in style {}", (std::string)style["name"]));
|
||||
$F("no walls spec in style {}", (std::string)style["name"]));
|
||||
|
||||
auto& floor_name = style["floor"];
|
||||
auto& wall_name = style["walls"];
|
||||
|
|
@ -79,7 +79,7 @@ bool WorldBuilder::find_open_spot(Point& pos_out) {
|
|||
|
||||
matrix::dump("FAIL PLACE!", $map.walls(), pos_out.x, pos_out.y);
|
||||
|
||||
dbc::sentinel(fmt::format("failed to place entity in the entire map?: i={}; width={};", i, $map.width()));
|
||||
dbc::sentinel($F("failed to place entity in the entire map?: i={}; width={};", i, $map.width()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace gui {
|
|||
auto player_combat = level.world->get<components::Combat>(player.entity);
|
||||
auto map = level.map;
|
||||
|
||||
std::wstring stats = fmt::format(L"STATS\n"
|
||||
std::wstring stats = $F(L"STATS\n"
|
||||
L"HP: {}\n"
|
||||
L"mean:{:>8.5}\n"
|
||||
L"sdev: {:>8.5}\n"
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace gui {
|
|||
FSM_STATE(DNDState, INV_PICKUP, ev, data);
|
||||
FSM_STATE(DNDState, END, ev, data);
|
||||
default:
|
||||
dbc::log(fmt::format("event received with data but state={} is not handled", int($state)));
|
||||
dbc::log($F("event received with data but state={} is not handled", int($state)));
|
||||
}
|
||||
|
||||
return !in_state(DNDState::END);
|
||||
|
|
@ -174,7 +174,7 @@ namespace gui {
|
|||
case TICK: // ignored
|
||||
break;
|
||||
default:
|
||||
dbc::log(fmt::format("invalid event: {}", int(ev)));
|
||||
dbc::log($F("invalid event: {}", int(ev)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ namespace gui {
|
|||
set_event(game::Event::KEY_PRESS);
|
||||
break;
|
||||
default:
|
||||
dbc::sentinel(fmt::format("invalid event: {}", int(ev)));
|
||||
dbc::sentinel($F("invalid event: {}", int(ev)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ namespace gui {
|
|||
break;
|
||||
default:
|
||||
// invalid events: 1
|
||||
dbc::sentinel(fmt::format("invalid events: {}", int(ev)));
|
||||
dbc::sentinel($F("invalid events: {}", int(ev)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ namespace gui {
|
|||
run_systems();
|
||||
} break;
|
||||
default:
|
||||
dbc::log(fmt::format("In ATTACKING state, unhandled event {}", (int)ev));
|
||||
dbc::log($F("In ATTACKING state, unhandled event {}", (int)ev));
|
||||
state(State::IDLE);
|
||||
}
|
||||
}
|
||||
|
|
@ -283,7 +283,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void FSM::END(Event ev) {
|
||||
dbc::log(fmt::format("END: received event after done: {}", int(ev)));
|
||||
dbc::log($F("END: received event after done: {}", int(ev)));
|
||||
}
|
||||
|
||||
sf::Vector2f FSM::mouse_position() {
|
||||
|
|
@ -469,13 +469,13 @@ namespace gui {
|
|||
auto &damage = std::any_cast<components::CombatResult&>(data);
|
||||
|
||||
if(damage.enemy_did > 0) {
|
||||
$map_ui.log(fmt::format(L"Enemy HIT YOU for {} damage!", damage.enemy_did));
|
||||
$map_ui.log($F(L"Enemy HIT YOU for {} damage!", damage.enemy_did));
|
||||
} else {
|
||||
$map_ui.log(L"Enemy MISSED YOU.");
|
||||
}
|
||||
|
||||
if(damage.player_did > 0) {
|
||||
$map_ui.log(fmt::format(L"You HIT enemy for {} damage!", damage.player_did));
|
||||
$map_ui.log($F(L"You HIT enemy for {} damage!", damage.player_did));
|
||||
} else {
|
||||
$map_ui.log(L"You MISSED the enemy.");
|
||||
}
|
||||
|
|
@ -544,11 +544,11 @@ namespace gui {
|
|||
case eGUI::NOOP: {
|
||||
if(data.type() == typeid(std::string)) {
|
||||
auto name = std::any_cast<std::string>(data);
|
||||
$map_ui.log(fmt::format(L"NOOP EVENT! {},{}", evt, entity));
|
||||
$map_ui.log($F(L"NOOP EVENT! {},{}", evt, entity));
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
dbc::log(fmt::format("Unhandled event: evt={}; enemy={}; data={}",
|
||||
dbc::log($F("Unhandled event: evt={}; enemy={}; data={}",
|
||||
evt, entity, data.type().name()));
|
||||
event(game::Event(evt), data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace storyboard {
|
|||
|
||||
std::istringstream is{time};
|
||||
is >> std::chrono::parse("%M:%S", out);
|
||||
dbc::check(!is.fail(), fmt::format("Time parse failed: {}", time));
|
||||
dbc::check(!is.fail(), $F("Time parse failed: {}", time));
|
||||
|
||||
return sf::Time(out);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ namespace arena {
|
|||
$status.set<Rectangle>(button, {});
|
||||
$status.set<Clickable>(button, {
|
||||
[this, name](auto, auto){
|
||||
dbc::log(fmt::format("STATUS: {}", name));
|
||||
dbc::log($F("STATUS: {}", name));
|
||||
}
|
||||
});
|
||||
if(name == "main_status") {
|
||||
|
|
@ -84,7 +84,7 @@ namespace arena {
|
|||
auto region = $overlay.entity(name);
|
||||
$overlay.set<Clickable>(region, {
|
||||
[this, name](auto, auto){
|
||||
dbc::log(fmt::format("OVERLAY: {}", name));
|
||||
dbc::log($F("OVERLAY: {}", name));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue