Simplified [if] implementation
This commit is contained in:
parent
c0c6f71725
commit
c1e95bcf14
1 changed files with 19 additions and 27 deletions
|
@ -400,41 +400,33 @@ wml_actions.command = handle_event_commands
|
|||
-- instead, we store the following anonymous functions directly into
|
||||
-- the table, using the [] operator, rather than by using the point syntax
|
||||
|
||||
wml_actions["if"] = function( cfg )
|
||||
if wesnoth.eval_conditional( cfg ) then -- evaluate [if] tag
|
||||
local found_something = false
|
||||
for then_child in helper.child_range ( cfg, "then" ) do
|
||||
handle_event_commands( then_child )
|
||||
found_something = true
|
||||
end
|
||||
if not found_something then
|
||||
if not helper.get_child( cfg, "else", nil ) then
|
||||
if not helper.get_child( cfg, "elseif", nil ) then
|
||||
wesnoth.message("WML warning","[if] didn't find any [then], [elseif], or [else] children. Check your {IF_VAR}!")
|
||||
end
|
||||
end
|
||||
wml_actions["if"] = function(cfg)
|
||||
local has_then = helper.get_child(cfg, "then")
|
||||
local has_elseif = helper.get_child(cfg, "elseif")
|
||||
local has_else = helper.get_child(cfg, "else")
|
||||
|
||||
if not (has_then or has_elseif or has_else) then
|
||||
helper.wml_error("[if] didn't find any [then], [elseif], or [else] children.")
|
||||
end
|
||||
|
||||
if wesnoth.eval_conditional(cfg) then -- evaluate [if] tag
|
||||
for then_child in helper.child_range(cfg, "then") do
|
||||
handle_event_commands(then_child)
|
||||
end
|
||||
return -- stop after executing [then] tags
|
||||
else
|
||||
local found_something = false
|
||||
for elseif_child in helper.child_range ( cfg, "elseif" ) do
|
||||
if wesnoth.eval_conditional( elseif_child ) then -- we'll evaluate the [elseif] tags one by one
|
||||
for then_tag in helper.child_range( elseif_child, "then" ) do
|
||||
handle_event_commands( then_tag )
|
||||
for elseif_child in helper.child_range(cfg, "elseif") do
|
||||
if wesnoth.eval_conditional(elseif_child) then -- we'll evaluate the [elseif] tags one by one
|
||||
for then_tag in helper.child_range(elseif_child, "then") do
|
||||
handle_event_commands(then_tag)
|
||||
end
|
||||
return -- stop on first matched condition
|
||||
end
|
||||
found_something = true
|
||||
end
|
||||
|
||||
-- no matched condition, try the [else] tags
|
||||
for else_child in helper.child_range ( cfg, "else" ) do
|
||||
handle_event_commands( else_child )
|
||||
found_something = true
|
||||
end
|
||||
if not found_something then
|
||||
if not helper.get_child( cfg, "then", nil ) then
|
||||
wesnoth.message("WML warning","[if] didn't find any [then], [elseif], or [else] children. Check your {IF_VAR}!")
|
||||
end
|
||||
for else_child in helper.child_range(cfg, "else") do
|
||||
handle_event_commands(else_child)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue