Skip to content

Commit

Permalink
LoW: merged two lua files and cleaned up contents
Browse files Browse the repository at this point in the history
This drops preload events for the [shift_labels] WML tag, now putting it cleanly
in the global campaign "namespace"
  • Loading branch information
Vultraz committed Aug 18, 2015
1 parent d6c67db commit d13d249
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion data/campaigns/Legend_of_Wesmere/_main.cfg
Expand Up @@ -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

Expand Down
20 changes: 0 additions & 20 deletions data/campaigns/Legend_of_Wesmere/lua/label.lua

This file was deleted.

32 changes: 0 additions & 32 deletions data/campaigns/Legend_of_Wesmere/lua/replace_map.lua

This file was deleted.

63 changes: 63 additions & 0 deletions data/campaigns/Legend_of_Wesmere/lua/wml_tags.lua
@@ -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
9 changes: 0 additions & 9 deletions data/campaigns/Legend_of_Wesmere/maps/Kalian_map.cfg
Expand Up @@ -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

Expand Down

0 comments on commit d13d249

Please sign in to comment.