Storyscreen/Parser: don't keep parsing if special action was already executed

Just realized this was a small regresison in e97b992 , since the entire function wasn't handled by one
large if/else if/else block anymore.
This commit is contained in:
Charles Dang 2017-05-04 01:24:06 +11:00
parent 4b9463a6ff
commit c9d484e2c4
6 changed files with 19 additions and 6 deletions

View file

@ -41,8 +41,10 @@ controller::controller(const vconfig& data, const std::string& scenario_name)
resolve_wml(data);
}
void controller::resolve_wml_helper(const std::string& key, const vconfig& node)
bool controller::resolve_wml_helper(const std::string& key, const vconfig& node)
{
bool found = false;
if(key == "part" && !node.empty()) {
part_pointer_type const story_part(new part(node));
// Use scenario name as part title if the WML doesn't supply a custom one.
@ -51,7 +53,10 @@ void controller::resolve_wml_helper(const std::string& key, const vconfig& node)
}
parts_.push_back(story_part);
found = true;
}
return found;
}
} // end namespace storyscreen

View file

@ -50,7 +50,7 @@ public:
private:
/** Inherited from story_parser. */
virtual void resolve_wml_helper(const std::string& key, const vconfig& node) override;
virtual bool resolve_wml_helper(const std::string& key, const vconfig& node) override;
std::string scenario_name_;

View file

@ -34,7 +34,9 @@ void story_parser::resolve_wml(const vconfig& cfg)
const vconfig node = i->second;
// Execute any special actions derived classes provide.
resolve_wml_helper(key, node);
if(resolve_wml_helper(key, node)) {
continue;
}
// [if]
if(key == "if") {

View file

@ -40,7 +40,7 @@ public:
* May be implemented by derived classes to perform additional actions
* When executing @ref resolve_wml.
*/
virtual void resolve_wml_helper(const std::string& key, const vconfig& node) = 0;
virtual bool resolve_wml_helper(const std::string& key, const vconfig& node) = 0;
};
} // namespace storyscreen

View file

@ -230,16 +230,22 @@ void part::resolve_wml(const vconfig& cfg)
story_parser::resolve_wml(cfg);
}
void part::resolve_wml_helper(const std::string& key, const vconfig& node)
bool part::resolve_wml_helper(const std::string& key, const vconfig& node)
{
bool found = false;
// [background_layer]
if(key == "background_layer") {
background_layers_.push_back(node.get_parsed_config());
found = true;
}
// [image]
else if(key == "image") {
floating_images_.push_back(node.get_parsed_config());
found = true;
}
return found;
}
} // end namespace storyscreen

View file

@ -328,7 +328,7 @@ private:
virtual void resolve_wml(const vconfig& cfg) override;
/** Inherited from story_parser. */
virtual void resolve_wml_helper(const std::string& key, const vconfig& node) override;
virtual bool resolve_wml_helper(const std::string& key, const vconfig& node) override;
static BLOCK_LOCATION string_tblock_loc(const std::string& s);