Restored support for [if] tags not containing [else] tags
This commit is contained in:
parent
ea5d219329
commit
729ebd58ff
4 changed files with 48 additions and 70 deletions
|
@ -30,8 +30,8 @@ Version 1.13.0-dev:
|
|||
* Added customizable recall costs for unit types and individual units,
|
||||
using the new recall_cost attribute in [unit_type] and [unit].
|
||||
* Added support for [elseif] tags inside [if]
|
||||
* Implemented checks for missing [then] inside [if], missing [do] inside
|
||||
[while] and missing [case], variable= and value= inside [switch]
|
||||
* Implemented checks for missing [do] inside [while] and missing [case],
|
||||
variable= and value= inside [switch]
|
||||
* Miscellaneous and bug fixes:
|
||||
* Fix Fisher-Yates implemenation of Lua helper.shuffle (bug #21706)
|
||||
* Fixed issues with the ~BG() image path function not always working with
|
||||
|
|
|
@ -335,9 +335,9 @@ wml_actions.command = handle_event_commands
|
|||
|
||||
wml_actions["if"] = function( cfg )
|
||||
-- raise error if [then] is missing
|
||||
if not helper.get_child( cfg, "then" ) then
|
||||
helper.wml_error "[if] missing required [then] tag"
|
||||
end
|
||||
--if not helper.get_child( cfg, "then" ) then
|
||||
-- helper.wml_error "[if] missing required [then] tag"
|
||||
--end
|
||||
|
||||
if wesnoth.eval_conditional( cfg ) then -- evalutate [if] tag
|
||||
for then_child in helper.child_range ( cfg, "then" ) do
|
||||
|
@ -347,9 +347,9 @@ wml_actions["if"] = function( cfg )
|
|||
else
|
||||
for elseif_child in helper.child_range ( cfg, "elseif" ) do
|
||||
-- there's no point in executing [elseif] without [then]
|
||||
if not helper.get_child( elseif_child, "then" ) then
|
||||
helper.wml_error "[elseif] missing required [then] tag"
|
||||
end
|
||||
--if not helper.get_child( elseif_child, "then" ) then
|
||||
-- helper.wml_error "[elseif] missing required [then] tag"
|
||||
--end
|
||||
if wesnoth.eval_conditional( elseif_child ) then -- we'll evalutate the [elseif] tags one by one
|
||||
for then_tag in helper.child_range( elseif_child, "then" ) do
|
||||
handle_event_commands( then_tag )
|
||||
|
|
|
@ -76,42 +76,31 @@ void controller::resolve_wml(const vconfig& cfg)
|
|||
// [if]
|
||||
else if(key == "if") {
|
||||
// check if the [if] tag has a [then] child;
|
||||
// if not, raise a WML error and exit to make the mistake as much evident as possible
|
||||
// if we try to execute a non-existing [then], we get a segfault
|
||||
if (!node.has_child("then")) {
|
||||
lg::wml_error << "[if] missing required [then] tag\n";
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// condition passed, execute [then]
|
||||
if (game_events::conditional_passed(node)) {
|
||||
if (game_events::conditional_passed(node)) {
|
||||
if (node.has_child("then")) {
|
||||
resolve_wml(node.child("then"));
|
||||
}
|
||||
// condition not passed, check [elseif] and [else]
|
||||
else {
|
||||
// get all [elseif] children and set a flag
|
||||
vconfig::child_list elseif_children = node.get_children("elseif");
|
||||
bool elseif_flag = false;
|
||||
// for each [elseif]: test if it has a [then] child
|
||||
// if not, raise a WML error and exit
|
||||
// if yes, check condition; if matches, execute [then] and raise flag
|
||||
for (vconfig::child_list::const_iterator elseif = elseif_children.begin(); elseif != elseif_children.end(); ++elseif) {
|
||||
if (!elseif->has_child("then")) {
|
||||
lg::wml_error << "[elseif] missing required [then] tag\n";
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (game_events::conditional_passed(*elseif)) {
|
||||
resolve_wml(elseif->child("then"));
|
||||
elseif_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// condition not passed, check [elseif] and [else]
|
||||
else {
|
||||
// get all [elseif] children and set a flag
|
||||
vconfig::child_list elseif_children = node.get_children("elseif");
|
||||
bool elseif_flag = false;
|
||||
// for each [elseif]: test if it has a [then] child
|
||||
// if the condition matches, execute [then] and raise flag
|
||||
for (vconfig::child_list::const_iterator elseif = elseif_children.begin(); elseif != elseif_children.end(); ++elseif) {
|
||||
if (game_events::conditional_passed(*elseif)) {
|
||||
if (elseif->has_child("then")) {
|
||||
resolve_wml(elseif->child("then"));
|
||||
}
|
||||
elseif_flag = true;
|
||||
break;
|
||||
}
|
||||
// if we have an [else] tag and no [elseif] was successful (flag not raised), execute it
|
||||
if (node.has_child("else") && !elseif_flag) {
|
||||
resolve_wml(node.child("else"));
|
||||
}
|
||||
}
|
||||
// if we have an [else] tag and no [elseif] was successful (flag not raised), execute it
|
||||
if (node.has_child("else") && !elseif_flag) {
|
||||
resolve_wml(node.child("else"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,42 +269,31 @@ void part::resolve_wml(const vconfig &cfg)
|
|||
// [if]
|
||||
else if(key == "if") {
|
||||
// check if the [if] tag has a [then] child;
|
||||
// if not, raise a WML error and exit to make the mistake as much evident as possible
|
||||
// if we try to execute a non-existing [then], we get a segfault
|
||||
if (!node.has_child("then")) {
|
||||
lg::wml_error << "[if] missing required [then] tag\n";
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// condition passed, execute [then]
|
||||
if (game_events::conditional_passed(node)) {
|
||||
if (game_events::conditional_passed(node)) {
|
||||
if (node.has_child("then")) {
|
||||
resolve_wml(node.child("then"));
|
||||
}
|
||||
// condition not passed, check [elseif] and [else]
|
||||
else {
|
||||
// get all [elseif] children and set a flag
|
||||
vconfig::child_list elseif_children = node.get_children("elseif");
|
||||
bool elseif_flag = false;
|
||||
// for each [elseif]: test if it has a [then] child
|
||||
// if not, raise a WML error and exit
|
||||
// if yes, check condition; if matches, execute [then] and raise flag
|
||||
for (vconfig::child_list::const_iterator elseif = elseif_children.begin(); elseif != elseif_children.end(); ++elseif) {
|
||||
if (!elseif->has_child("then")) {
|
||||
lg::wml_error << "[elseif] missing required [then] tag\n";
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (game_events::conditional_passed(*elseif)) {
|
||||
resolve_wml(elseif->child("then"));
|
||||
elseif_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// condition not passed, check [elseif] and [else]
|
||||
else {
|
||||
// get all [elseif] children and set a flag
|
||||
vconfig::child_list elseif_children = node.get_children("elseif");
|
||||
bool elseif_flag = false;
|
||||
// for each [elseif]: test if it has a [then] child
|
||||
// if the condition matches, execute [then] and raise flag
|
||||
for (vconfig::child_list::const_iterator elseif = elseif_children.begin(); elseif != elseif_children.end(); ++elseif) {
|
||||
if (game_events::conditional_passed(*elseif)) {
|
||||
if (elseif->has_child("then")) {
|
||||
resolve_wml(elseif->child("then"));
|
||||
}
|
||||
elseif_flag = true;
|
||||
break;
|
||||
}
|
||||
// if we have an [else] tag and no [elseif] was successful (flag not raised), execute it
|
||||
if (node.has_child("else") && !elseif_flag) {
|
||||
resolve_wml(node.child("else"));
|
||||
}
|
||||
}
|
||||
// if we have an [else] tag and no [elseif] was successful (flag not raised), execute it
|
||||
if (node.has_child("else") && !elseif_flag) {
|
||||
resolve_wml(node.child("else"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue