mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-29 19:02:00 +00:00
Moved handling of toplevel [item] tags to Lua.
This commit is contained in:
parent
05902d29eb
commit
cb92c6d196
@ -1,7 +1,45 @@
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local game_events = wesnoth.game_events
|
||||
|
||||
local scenario_items = {}
|
||||
|
||||
local function add_overlay(x, y, cfg)
|
||||
wesnoth.add_tile_overlay(x, y, cfg)
|
||||
local items = scenario_items[x * 10000 + y]
|
||||
if not items then
|
||||
items = {}
|
||||
scenario_items[x * 10000 + y] = items
|
||||
end
|
||||
table.insert(items, cfg)
|
||||
end
|
||||
|
||||
local old_on_save = game_events.on_save
|
||||
function game_events.on_save()
|
||||
local custom_cfg = old_on_save()
|
||||
for i,v in pairs(scenario_items) do
|
||||
for j,w in pairs(v) do
|
||||
table.insert(custom_cfg, { "item", w })
|
||||
end
|
||||
end
|
||||
return custom_cfg
|
||||
end
|
||||
|
||||
local old_on_load = game_events.on_load
|
||||
function game_events.on_load(cfg)
|
||||
for i = #cfg,1,-1 do
|
||||
local v = cfg[i]
|
||||
if v[1] == "item" then
|
||||
local v2 = v[2]
|
||||
add_overlay(v2.x, v2.y, v2)
|
||||
table.remove(cfg, i)
|
||||
end
|
||||
end
|
||||
old_on_load(cfg)
|
||||
end
|
||||
|
||||
function wml_actions.item(cfg)
|
||||
cfg = helper.parsed(cfg)
|
||||
if not cfg.image and not cfg.halo then
|
||||
helper.wml_error "[item] missing required image= and halo= attributes."
|
||||
end
|
||||
@ -9,7 +47,7 @@ function wml_actions.item(cfg)
|
||||
if not x or not y then
|
||||
helper.wml_error "[item] missing required x= and y= attributes."
|
||||
end
|
||||
wesnoth.add_tile_overlay(x, y, cfg)
|
||||
add_overlay(x, y, cfg)
|
||||
wml_actions.redraw {}
|
||||
end
|
||||
|
||||
@ -21,5 +59,19 @@ function wml_actions.remove_item(cfg)
|
||||
helper.wml_error "[remove_item] missing required x= and y= attributes."
|
||||
y = context.y1
|
||||
end
|
||||
wesnoth.remove_tile_overlay(x, y, cfg.image)
|
||||
local items = scenario_items[x * 10000 + y]
|
||||
if not items then return end
|
||||
local name = cfg.image
|
||||
wesnoth.remove_tile_overlay(x, y, name)
|
||||
if name then
|
||||
for i = #items,1,-1 do
|
||||
local item = items[i]
|
||||
if item.image == name or item.halo == name then
|
||||
table.remove(items, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
if not name or #items == 0 then
|
||||
scenario_items[x * 10000 + y] = nil
|
||||
end
|
||||
end
|
||||
|
@ -1056,18 +1056,6 @@ void game_display::remove_single_overlay(const map_location& loc, const std::str
|
||||
}
|
||||
}
|
||||
|
||||
void game_display::write_overlays(config& cfg) const
|
||||
{
|
||||
for(overlay_map::const_iterator i = overlays_.begin(); i != overlays_.end(); ++i) {
|
||||
config& item = cfg.add_child("item");
|
||||
i->first.write(item);
|
||||
item["image"] = i->second.image;
|
||||
item["halo"] = i->second.halo;
|
||||
item["team_name"] = i->second.team_name;
|
||||
item["visible_in_fog"] = i->second.visible_in_fog;
|
||||
}
|
||||
}
|
||||
|
||||
void game_display::parse_team_overlays()
|
||||
{
|
||||
const team& curr_team = teams_[playing_team()];
|
||||
|
@ -237,9 +237,6 @@ public:
|
||||
/** remove_single_overlay will remove a single overlay from a tile */
|
||||
void remove_single_overlay(const map_location& loc, const std::string& toDelete);
|
||||
|
||||
/** Function to serialize overlay data. */
|
||||
void write_overlays(config& cfg) const;
|
||||
|
||||
/**
|
||||
* Check the overlay_map for proper team-specific overlays to be
|
||||
* displayed/hidden
|
||||
|
@ -3175,9 +3175,6 @@ namespace game_events {
|
||||
if (resources::soundsources)
|
||||
resources::soundsources->write_sourcespecs(cfg);
|
||||
|
||||
if (resources::screen)
|
||||
resources::screen->write_overlays(cfg);
|
||||
|
||||
resources::lua_kernel->save_game(cfg);
|
||||
}
|
||||
|
||||
|
@ -334,15 +334,6 @@ LEVEL_RESULT playsingle_controller::play_scenario(
|
||||
}
|
||||
gui_->labels().read(level_);
|
||||
|
||||
// Find a list of 'items' (i.e. overlays) on the level, and add them
|
||||
foreach (const config &overlay, level_.child_range("item"))
|
||||
{
|
||||
gui_->add_overlay(
|
||||
map_location(overlay, resources::state_of_game),
|
||||
overlay["image"], overlay["halo"], overlay["team_name"],
|
||||
overlay["visible_in_fog"].to_bool(true));
|
||||
}
|
||||
|
||||
// Read sound sources
|
||||
assert(soundsources_manager_ != NULL);
|
||||
foreach (const config &s, level_.child_range("sound_source")) {
|
||||
|
@ -158,15 +158,6 @@ void replay_controller::reset_replay(){
|
||||
|
||||
gui_->labels().read(level_);
|
||||
|
||||
// Find a list of 'items' (i.e. overlays) on the level, and add them
|
||||
foreach (const config &overlay, level_.child_range("item"))
|
||||
{
|
||||
gui_->add_overlay(
|
||||
map_location(overlay, resources::state_of_game),
|
||||
overlay["image"], overlay["halo"], overlay["team_name"],
|
||||
overlay["visible_in_fog"].to_bool(true));
|
||||
}
|
||||
|
||||
statistics::fresh_stats();
|
||||
set_victory_when_enemies_defeated(level_["victory_when_enemies_defeated"].to_bool(true));
|
||||
|
||||
|
@ -2928,7 +2928,7 @@ void LuaKernel::initialize()
|
||||
}
|
||||
|
||||
static char const *handled_file_tags[] = {
|
||||
"color_palette", "color_range", "event", "item", "label", "lua",
|
||||
"color_palette", "color_range", "event", "label", "lua",
|
||||
"menu_item", "music", "side", "sound_source", "teleport", "time",
|
||||
"time_area", "variables"
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user