diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2015-01-06 17:31:21 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2015-01-22 23:33:13 -0800 |
commit | 2cd52ab17ee1b830bc53321b112411122dddc1c8 (patch) | |
tree | 43666d3295c55ae6b395c5d8cd3fd026e71468a3 /src/map/battle.cpp | |
parent | e1418f378c66343a35db3791cbf0d54a4be3fbd3 (diff) | |
download | tmwa-2cd52ab17ee1b830bc53321b112411122dddc1c8.tar.gz tmwa-2cd52ab17ee1b830bc53321b112411122dddc1c8.tar.bz2 tmwa-2cd52ab17ee1b830bc53321b112411122dddc1c8.tar.xz tmwa-2cd52ab17ee1b830bc53321b112411122dddc1c8.zip |
Use Spanned<T> while parsing config
Diffstat (limited to 'src/map/battle.cpp')
-rw-r--r-- | src/map/battle.cpp | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/src/map/battle.cpp b/src/map/battle.cpp index a04e402..983eac3 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -33,6 +33,7 @@ #include "../io/cxxstdio.hpp" #include "../io/read.hpp" +#include "../io/span.hpp" #include "../mmo/config_parse.hpp" #include "../mmo/cxxstdio_enums.hpp" @@ -2278,18 +2279,9 @@ Battle_Config init_battle_config() return battle_config; } -bool battle_config_read(ZString cfgName) +static +bool battle_config_(io::Spanned<XString> w1, io::Spanned<ZString> w2) { - bool rv = true; - io::ReadFile in(cfgName); - if (!in.is_open()) - { - PRINTF("file not found: %s\n"_fmt, cfgName); - return false; - } - - AString line; - while (in.getline(line)) { #define BATTLE_CONFIG_VAR(name) {#name##_s, &battle_config.name} const struct @@ -2395,38 +2387,24 @@ bool battle_config_read(ZString cfgName) BATTLE_CONFIG_VAR(mob_splash_radius), }; - if (is_comment(line)) - continue; - XString w1; - ZString w2; - if (!config_split(line, &w1, &w2)) - { - PRINTF("Bad config line: %s\n"_fmt, line); - rv = false; - continue; - } - - if (w1 == "import"_s) - { - battle_config_read(w2); - continue; - } - for (auto datum : data) - if (w1 == datum.str) + { + if (w1.data == datum.str) { - *datum.val = config_switch(w2); - goto continue_outer; + *datum.val = config_switch(w2.data); + return true; } + } - PRINTF("WARNING: unknown battle conf key: %s\n"_fmt, AString(w1)); - rv = false; + PRINTF("WARNING: unknown battle conf key: %s\n"_fmt, AString(w1.data)); + return false; - continue_outer: - ; } +} - return rv; +bool battle_config_read(ZString cfgName) +{ + return load_config_file(cfgName, battle_config_); } void battle_config_check() |