Skip to content

Commit

Permalink
Expose side_name attribute to Lua API and [modify_side]
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 18, 2018
1 parent 4d8035e commit 29942ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog
@@ -1,4 +1,6 @@
Version 1.13.11+dev:
* Lua API:
* Add side_name to unit proxy
* User Interface:
* Improved outro screen.
* Fixed a few cases of data not displaying in the MP Join Game screen.
Expand All @@ -7,6 +9,7 @@ Version 1.13.11+dev:
* WML engine:
* Fixed units shown with [move_units_fake] disappearing between steps
(bug #1516).
* [modify_side] now supports side_name
* Miscellaneous and bug fixes:
* Fixed standing animation toggle not taking immediate effect (bug
#1653).
Expand Down
3 changes: 3 additions & 0 deletions data/lua/wml/modify_side.lua
Expand Up @@ -17,6 +17,9 @@ function wesnoth.wml_actions.modify_side(cfg)
if cfg.user_team_name then
side.user_team_name = cfg.user_team_name
end
if cfg.side_name then
side.side_name = cfg.side_name
end
if cfg.controller then
side.controller = cfg.controller
end
Expand Down
2 changes: 2 additions & 0 deletions src/scripting/lua_team.cpp
Expand Up @@ -87,6 +87,7 @@ static int impl_side_get(lua_State *L)
return_bool_attrib("share_maps", t.share_maps());
return_bool_attrib("share_view", t.share_view());
return_bool_attrib("chose_random", t.chose_random());
return_tstring_attrib("side_name", t.side_name_tstr());

if (strcmp(m, "recruit") == 0) {
const std::set<std::string>& recruits = t.recruits();
Expand Down Expand Up @@ -151,6 +152,7 @@ static int impl_side_set(lua_State *L)
modify_bool_attrib("shroud", t.set_shroud(value));
modify_bool_attrib("fog", t.set_fog(value));
modify_string_attrib("flag_icon", t.set_flag_icon(value));
modify_tstring_attrib("side_name", t.set_side_name(value));
modify_string_attrib("share_vision", {
team::SHARE_VISION v;
if(v.parse(value)) {
Expand Down
2 changes: 2 additions & 0 deletions src/team.hpp
Expand Up @@ -302,6 +302,8 @@ class team
void set_flag_icon(const std::string& flag_icon) { info_.flag_icon = flag_icon; }

const std::string& side_name() const { return info_.side_name.empty() ? info_.current_player : info_.side_name.str(); }
t_string side_name_tstr() const { return info_.side_name.empty() ? info_.current_player : info_.side_name; }

This comment has been minimized.

Copy link
@ilyapopov

ilyapopov Feb 18, 2018

This change breaks build:

../src/team.hpp:305:67: error: operands to ?: have different types ‘const string {aka const std::__cxx11::basic_string<char>}’ and ‘const t_string’
  t_string side_name_tstr() const { return info_.side_name.empty() ? info_.current_player : info_.side_name; }
                                           ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/team.hpp:305:67: note:   and each type can be converted to the other

This comment has been minimized.

Copy link
@CelticMinstrel

CelticMinstrel Feb 18, 2018

Author Member

Kinda surprised that the compiler can't make a decision based on the context (return type being t_string), but at least it's easy to disambiguate this.

void set_side_name(const t_string& new_name) {info_.side_name = new_name;}
const std::string& faction() const { return info_.faction; }
const t_string& faction_name() const { return info_.faction_name; }
//Returns true if the hex is shrouded/fogged for this side, or
Expand Down

0 comments on commit 29942ee

Please sign in to comment.