wesnoth/data/campaigns/tutorial/lua/character_selection.lua
Celtic Minstrel 915fd49ae6 Tutorial: Specify the side of Li'sar in the char select
When a unit data passed to `to_map` either lacks a side or has
side zero, implementation automatically sets it to 1, thus the
existing code worked fine. However:

1. The lack of a `side` could trigger a warning in EmmyLua. It
currently doesn't trigger that, but would with Celtic Minstrel's
planned improvements in Wesnoth's lint hints.

2. The tutorial should be good example code, and the special-case
in the C++ code that made this work is a case of "assume it's a
SP situation, and choose the result that benefits side 1".
2024-02-15 09:57:17 +01:00

39 lines
1.1 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- #textdomain wesnoth-tutorial
-- Allows the player to choose whether they want to play Konrad or Lisar
-- for the tutorial
local T = wml.tag
local wml_actions = wesnoth.wml_actions
local _ = wesnoth.textdomain "wesnoth-tutorial"
function wml_actions.select_character()
local character_selection_dialog = wml.load "campaigns/tutorial/gui/character_selection.cfg"
local dialog_wml = wml.get_child(character_selection_dialog, 'resolution')
local result = wesnoth.sync.evaluate_single(function()
return { value = gui.show_dialog(dialog_wml) }
end)
local character = result.value
local unit = wml.variables.student_store
if character == 2 then
wesnoth.units.to_map({
type = "Fighteress",
side = 1,
id = unit.id,
name = _"Lisar",
unrenamable = true,
profile = "portraits/lisar.webp",
canrecruit = true,
facing = unit.facing,
}, unit.x, unit.y )
wesnoth.sides[1].side_name = _"Lisar"
-- enable the help to display this unit's page
wesnoth.add_known_unit("Fighteress")
else
wesnoth.units.to_map(unit)
end
wesnoth.redraw {}
end