LoW: merged two lua files and cleaned up contents

This drops preload events for the [shift_labels] WML tag, now putting it cleanly
in the global campaign "namespace"
This commit is contained in:
Charles Dang 2015-08-19 00:42:31 +11:00
parent d6c67db110
commit d13d249ca9
5 changed files with 64 additions and 62 deletions

View file

@ -23,7 +23,7 @@
[/units]
[lua]
code = "wesnoth.dofile 'campaigns/Legend_of_Wesmere/lua/replace_map.lua'"
code = "wesnoth.dofile 'campaigns/Legend_of_Wesmere/lua/wml_tags.lua'"
[/lua]
#endif

View file

@ -1,20 +0,0 @@
--! #textdomain wesnoth-low
local labels = {}
local wml_label = wesnoth.wml_actions.label
function wesnoth.wml_actions.label(cfg)
table.insert(labels, cfg.__parsed)
wml_label(cfg)
end
function wesnoth.wml_actions.shift_labels(cfg)
for k, v in ipairs(labels) do
wml_label { x = v.x, y = v.y }
end
for k, v in ipairs(labels) do
v.x = v.x + cfg.x
v.y = v.y + cfg.y
wml_label(v)
end
end

View file

@ -1,32 +0,0 @@
--! #textdomain wesnoth-low
local replace_map = wesnoth.wml_actions.replace_map
function wesnoth.wml_actions.replace_map(cfg)
if not cfg.x and not cfg.y then
return replace_map(cfg)
end
local x1,x2 = string.match(cfg.x, "(%d+)-(%d+)")
local y1,y2 = string.match(cfg.y, "(%d+)-(%d+)")
local map = cfg.map_data
x1 = tonumber(x1)
y1 = tonumber(y1)
x2 = x2 + 2
y2 = y2 + 2
local t = {}
local y = 1
for row in string.gmatch(map, "[^\n]+") do
if y >= y1 and y <= y2 then
local r = {}
local x = 1
for tile in string.gmatch(row, "[^,]+") do
if x >= x1 and x <= x2 then r[x - x1 + 1] = tile end
x = x + 1
end
t[y - y1 + 1] = table.concat(r, ',')
end
y = y + 1
end
local new_map = table.concat(t, '\n')
replace_map { map = new_map, expand = true, shrink = true }
end

View file

@ -0,0 +1,63 @@
--! #textdomain wesnoth-low
local labels = {}
local wml_label = wesnoth.wml_actions.label
local replace_map = wesnoth.wml_actions.replace_map
function wesnoth.wml_actions.shift_labels(cfg)
for k, v in ipairs(labels) do
wml_label { x = v.x, y = v.y }
end
for k, v in ipairs(labels) do
v.x = v.x + cfg.x
v.y = v.y + cfg.y
wml_label(v)
end
end
--
-- Overrides of core tags
--
function wesnoth.wml_actions.label(cfg)
table.insert(labels, cfg.__parsed)
wml_label(cfg)
end
function wesnoth.wml_actions.replace_map(cfg)
if not cfg.x and not cfg.y then
return replace_map(cfg)
end
local x1,x2 = string.match(cfg.x, "(%d+)-(%d+)")
local y1,y2 = string.match(cfg.y, "(%d+)-(%d+)")
local map = cfg.map_data
x1 = tonumber(x1)
y1 = tonumber(y1)
x2 = x2 + 2
y2 = y2 + 2
local t = {}
local y = 1
for row in string.gmatch(map, "[^\n]+") do
if y >= y1 and y <= y2 then
local r = {}
local x = 1
for tile in string.gmatch(row, "[^,]+") do
if x >= x1 and x <= x2 then r[x - x1 + 1] = tile end
x = x + 1
end
t[y - y1 + 1] = table.concat(r, ',')
end
y = y + 1
end
local new_map = table.concat(t, '\n')
replace_map { map = new_map, expand = true, shrink = true }
end

View file

@ -6,15 +6,6 @@
# image=items/archery-target-right.png
# [/item]
# Override the [label] WML tag so that labels are properly shifted when the map is replaced.
[event]
name = preload
first_time_only = no
[lua]
code = "wesnoth.dofile 'campaigns/Legend_of_Wesmere/lua/label.lua'"
[/lua]
[/event]
[event]
name=prestart