Allow spaces in [object]id= and show error if invalid characters are present
This commit is contained in:
parent
a93ce122ff
commit
03580ed9a9
2 changed files with 15 additions and 3 deletions
|
@ -11,6 +11,17 @@ function utils.split(s)
|
|||
return tostring(s):gmatch("[^%s,][^,]*")
|
||||
end
|
||||
|
||||
function utils.check_key(val, key, tag, convert_spaces)
|
||||
if not val then return nil end
|
||||
if convert_spaces then
|
||||
val = tostring(val):gsub(' ', '_')
|
||||
end
|
||||
if not val:match('^[a-zA-Z0-9_]+$') then
|
||||
helper.wml_error("Invalid " .. key .. "= in [" .. tag .. "]")
|
||||
end
|
||||
return val
|
||||
end
|
||||
|
||||
function utils.vwriter.init(cfg, default_variable)
|
||||
local variable = cfg.variable or default_variable
|
||||
local is_explicit_index = string.sub(variable, string.len(variable)) == "]"
|
||||
|
|
|
@ -10,7 +10,8 @@ function wml_actions.object(cfg)
|
|||
local context = wesnoth.current.event_context
|
||||
|
||||
-- If this item has already been used
|
||||
if cfg.id and used_items[cfg.id] then return end
|
||||
local obj_id = utils.check_key(cfg.id, "id", "object", true)
|
||||
if obj_id and used_items[obj_id] then return end
|
||||
|
||||
local unit
|
||||
local filter = helper.get_child(cfg, "filter")
|
||||
|
@ -37,7 +38,7 @@ function wml_actions.object(cfg)
|
|||
wesnoth.select_hex(unit.x, unit.y)
|
||||
|
||||
-- Mark this item as used up
|
||||
if cfg.id then used_items[cfg.id] = true end
|
||||
if obj_id then used_items[obj_id] = true end
|
||||
else
|
||||
text = tostring(cfg.cannot_use_message or "")
|
||||
command_type = "else"
|
||||
|
@ -80,5 +81,5 @@ function wesnoth.game_events.on_save()
|
|||
end
|
||||
|
||||
function wesnoth.wml_conditionals.found_item(cfg)
|
||||
return used_items[cfg.id]
|
||||
return used_items[utils.check_key(cfg.id, "id", "found_item", true)]
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue