Skip to content

Commit

Permalink
Help: fixed unit section such as the Walking Corpse's not generating
Browse files Browse the repository at this point in the history
I didn't realize that is_valid_id was only meant to check IDs provided in the help config and
not IDs generated dynamically; the latter are always correct. Granted, the old code did actually
call its analogous codepath for race and era generation, but it did not for unit sections. My
refactor made it so this check happened *any* time a section was created, regardless of its source.

To rectify that, I moved ID validation for sections into the static section generation loop like
for topics. I also moved the topic id validation prior to the ToD generation, tweaked the invalid
id message, and renamed a variable for clarity and consistency.
  • Loading branch information
Vultraz committed Apr 3, 2018
1 parent 2ae6c9e commit e8b750f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/help/section.cpp
Expand Up @@ -63,23 +63,23 @@ void section::initialize(const config& section_cfg)
throw max_recursion_reached("Maximum section depth has been reached. Possible circular dependency?");
}

if(recursion_level_ > 0 && !is_valid_id(id)) {
throw parse_error(formatter() << "Invalid ID, used for internal purpose: '" << id << "'");
}

if(section_cfg.empty()) {
return; // TODO: throw something?
}

//
// Parse static sub-sections.
//
for(const std::string& child_section : utils::quoted_split(section_cfg["sections"])) {
if(const config& child_cfg = manager_->get_section_config(child_section)) {
for(const std::string& section_id : utils::quoted_split(section_cfg["sections"])) {
if(const config& child_cfg = manager_->get_section_config(section_id)) {
if(!is_valid_id(section_id)) {
throw parse_error(formatter() << "Invalid ID, used for internal purposes: '" << id << "'");
}

add_section(child_cfg);
} else {
throw parse_error(formatter()
<< "Help section '" << child_section << "' referenced from '" << id << "' but could not be found.");
<< "Help section '" << section_id << "' referenced from '" << id << "' but could not be found.");
}
}

Expand Down Expand Up @@ -117,14 +117,14 @@ void section::initialize(const config& section_cfg)
//
for(const std::string& topic_id : utils::quoted_split(section_cfg["topics"])) {
if(const config& topic_cfg = manager_->get_topic_config(topic_id)) {
if(!is_valid_id(topic_id)) {
throw parse_error(formatter() << "Invalid ID, used for internal purposes: '" << id << "'");
}

std::ostringstream text;
text << topic_cfg["text"];
text << generate_table_of_contents(topic_cfg["generator"]);

if(!is_valid_id(topic_id)) {
throw parse_error(formatter() << "Invalid ID, used for internal purpose: '" << id << "'");
}

// We don't need to use add_topic here since we don't need a special text generator.
topics_.emplace_back(topic_id, topic_cfg["title"], text.str());
} else {
Expand Down

0 comments on commit e8b750f

Please sign in to comment.