mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-27 16:53:17 +00:00
Made reports more const-y
Reports should never have side affects. If they do you're doing something wrong.
This commit is contained in:
parent
9e34c3c5ab
commit
dbc980fc65
@ -97,7 +97,7 @@ static std::string flush(std::ostringstream &s)
|
||||
return r;
|
||||
}
|
||||
|
||||
static const time_of_day get_visible_time_of_day_at(reports::context & rc, const map_location & hex)
|
||||
static const time_of_day get_visible_time_of_day_at(const reports::context& rc, const map_location & hex)
|
||||
{
|
||||
const team &viewing_team = rc.teams()[rc.screen().viewing_team()];
|
||||
if (viewing_team.shrouded(hex)) {
|
||||
@ -123,34 +123,34 @@ struct report_generator_helper
|
||||
};
|
||||
|
||||
#define REPORT_GENERATOR(n, cn) \
|
||||
static config report_##n(reports::context & cn); \
|
||||
static config report_##n(const reports::context& cn); \
|
||||
static report_generator_helper reg_gen_##n(#n, &report_##n); \
|
||||
static config report_##n(reports::context & cn)
|
||||
static config report_##n(const reports::context& cn)
|
||||
|
||||
static char const *naps = "</span>";
|
||||
|
||||
static const unit *get_visible_unit(reports::context & rc)
|
||||
static const unit *get_visible_unit(const reports::context& rc)
|
||||
{
|
||||
return rc.dc().get_visible_unit(rc.screen().displayed_unit_hex(),
|
||||
rc.teams()[rc.screen().viewing_team()],
|
||||
rc.screen().show_everything());
|
||||
}
|
||||
|
||||
static const unit *get_selected_unit(reports::context & rc)
|
||||
static const unit *get_selected_unit(const reports::context& rc)
|
||||
{
|
||||
return rc.dc().get_visible_unit(rc.screen().selected_hex(),
|
||||
rc.teams()[rc.screen().viewing_team()],
|
||||
rc.screen().show_everything());
|
||||
}
|
||||
|
||||
static unit_const_ptr get_selected_unit_ptr(reports::context & rc)
|
||||
static unit_const_ptr get_selected_unit_ptr(const reports::context& rc)
|
||||
{
|
||||
return rc.dc().get_visible_unit_shared_ptr(rc.screen().selected_hex(),
|
||||
rc.teams()[rc.screen().viewing_team()],
|
||||
rc.screen().show_everything());
|
||||
}
|
||||
|
||||
static config gray_inactive(reports::context & rc, const std::string &str, const std::string& tooltip = "")
|
||||
static config gray_inactive(const reports::context& rc, const std::string &str, const std::string& tooltip = "")
|
||||
{
|
||||
if ( rc.screen().viewing_side() == rc.screen().playing_side() )
|
||||
return text_report(str, tooltip);
|
||||
@ -242,7 +242,7 @@ static std::string side_tooltip(const team& team)
|
||||
{"color_name", team::get_side_color_name_for_UI(team.side()) }});
|
||||
}
|
||||
|
||||
static config unit_side(reports::context & rc, const unit* u)
|
||||
static config unit_side(const reports::context& rc, const unit* u)
|
||||
{
|
||||
if (!u) return config();
|
||||
|
||||
@ -332,7 +332,7 @@ REPORT_GENERATOR(selected_unit_traits, rc)
|
||||
return unit_traits(u);
|
||||
}
|
||||
|
||||
static config unit_status(reports::context & rc, const unit* u)
|
||||
static config unit_status(const reports::context& rc, const unit* u)
|
||||
{
|
||||
if (!u) return config();
|
||||
config res;
|
||||
@ -374,7 +374,7 @@ REPORT_GENERATOR(selected_unit_status, rc)
|
||||
return unit_status(rc, u);
|
||||
}
|
||||
|
||||
static config unit_alignment(reports::context & rc, const unit* u, const map_location& hex)
|
||||
static config unit_alignment(const reports::context& rc, const unit* u, const map_location& hex)
|
||||
{
|
||||
if (!u) return config();
|
||||
std::ostringstream str, tooltip;
|
||||
@ -474,7 +474,7 @@ REPORT_GENERATOR(selected_unit_abilities, rc)
|
||||
}
|
||||
|
||||
|
||||
static config unit_hp(reports::context& rc, const unit* u)
|
||||
static config unit_hp(const reports::context& rc, const unit* u)
|
||||
{
|
||||
if (!u) return config();
|
||||
std::ostringstream str, tooltip;
|
||||
@ -574,7 +574,7 @@ REPORT_GENERATOR(selected_unit_advancement_options, rc)
|
||||
return unit_advancement_options(u);
|
||||
}
|
||||
|
||||
static config unit_defense(reports::context & rc, const unit* u, const map_location& displayed_unit_hex)
|
||||
static config unit_defense(const reports::context& rc, const unit* u, const map_location& displayed_unit_hex)
|
||||
{
|
||||
if(!u) {
|
||||
return config();
|
||||
@ -668,7 +668,7 @@ REPORT_GENERATOR(selected_unit_vision, rc)
|
||||
return unit_vision(u);
|
||||
}
|
||||
|
||||
static config unit_moves(reports::context & rc, const unit* u, bool is_visible_unit)
|
||||
static config unit_moves(const reports::context& rc, const unit* u, bool is_visible_unit)
|
||||
{
|
||||
if (!u) return config();
|
||||
std::ostringstream str, tooltip;
|
||||
@ -774,7 +774,7 @@ static inline const color_t attack_info_percent_color(int resistance)
|
||||
return game_config::red_to_green(50.0 + resistance * 5.0 / 6.0, false);
|
||||
}
|
||||
|
||||
static int attack_info(reports::context & rc, const attack_type &at, config &res, const unit &u, const map_location &hex, const unit* sec_u = nullptr, const_attack_ptr sec_u_weapon = nullptr)
|
||||
static int attack_info(const reports::context& rc, const attack_type &at, config &res, const unit &u, const map_location &hex, const unit* sec_u = nullptr, const_attack_ptr sec_u_weapon = nullptr)
|
||||
{
|
||||
std::ostringstream str, tooltip;
|
||||
int damage = 0;
|
||||
@ -1022,7 +1022,7 @@ static std::string format_hp(unsigned hp)
|
||||
return res.str();
|
||||
}
|
||||
|
||||
static config unit_weapons(reports::context & rc, unit_const_ptr attacker, const map_location &attacker_pos, const unit *defender, bool show_attacker)
|
||||
static config unit_weapons(const reports::context& rc, unit_const_ptr attacker, const map_location &attacker_pos, const unit *defender, bool show_attacker)
|
||||
{
|
||||
if (!attacker || !defender) return config();
|
||||
|
||||
@ -1146,7 +1146,7 @@ static config unit_weapons(reports::context & rc, unit_const_ptr attacker, const
|
||||
* Display the attacks of the displayed unit against the unit passed as argument.
|
||||
* 'hex' is the location the attacker will be at during combat.
|
||||
*/
|
||||
static config unit_weapons(reports::context & rc, const unit *u, const map_location &hex)
|
||||
static config unit_weapons(const reports::context& rc, const unit *u, const map_location &hex)
|
||||
{
|
||||
config res = config();
|
||||
if ((u != nullptr) && (!u->attacks().empty())) {
|
||||
@ -1246,7 +1246,7 @@ REPORT_GENERATOR(unit_profile, rc)
|
||||
return image_report(u->small_profile());
|
||||
}
|
||||
|
||||
static config tod_stats_at(reports::context & rc, const map_location& hex)
|
||||
static config tod_stats_at(const reports::context& rc, const map_location& hex)
|
||||
{
|
||||
std::ostringstream tooltip;
|
||||
std::ostringstream text;
|
||||
@ -1285,7 +1285,7 @@ REPORT_GENERATOR(selected_tod_stats, rc)
|
||||
return tod_stats_at(rc, hex);
|
||||
}
|
||||
|
||||
static config time_of_day_at(reports::context & rc, const map_location& mouseover_hex)
|
||||
static config time_of_day_at(const reports::context& rc, const map_location& mouseover_hex)
|
||||
{
|
||||
std::ostringstream tooltip;
|
||||
time_of_day tod = get_visible_time_of_day_at(rc, mouseover_hex);
|
||||
@ -1337,7 +1337,7 @@ REPORT_GENERATOR(selected_time_of_day, rc)
|
||||
return time_of_day_at(rc, hex);
|
||||
}
|
||||
|
||||
static config unit_box_at(reports::context & rc, const map_location& mouseover_hex)
|
||||
static config unit_box_at(const reports::context& rc, const map_location& mouseover_hex)
|
||||
{
|
||||
std::ostringstream tooltip;
|
||||
time_of_day global_tod = rc.tod().get_time_of_day();
|
||||
@ -1782,7 +1782,7 @@ void reports::register_generator(const std::string &name, reports::generator *g)
|
||||
dynamic_generators_[name].reset(g);
|
||||
}
|
||||
|
||||
config reports::generate_report(const std::string &name, reports::context & rc, bool only_static)
|
||||
config reports::generate_report(const std::string &name, const reports::context& rc, bool only_static)
|
||||
{
|
||||
if (!only_static) {
|
||||
dynamic_report_generators::const_iterator i = dynamic_generators_.find(name);
|
||||
|
@ -46,21 +46,21 @@ public:
|
||||
class context
|
||||
{
|
||||
public:
|
||||
context(const display_context & dc, display & disp, const tod_manager & tod, std::shared_ptr<wb::manager> wb, utils::optional_reference<events::mouse_handler> mhb) : dc_(dc), disp_(disp), tod_(tod), wb_(wb), mhb_(mhb) {}
|
||||
context(const display_context & dc, const display & disp, const tod_manager & tod, std::shared_ptr<wb::manager> wb, utils::optional_reference<events::mouse_handler> mhb) : dc_(dc), disp_(disp), tod_(tod), wb_(wb), mhb_(mhb) {}
|
||||
|
||||
const std::vector<team> & teams() const { return dc_.teams(); }
|
||||
const unit_map & units() const { return dc_.units(); }
|
||||
const gamemap & map() const { return dc_.map(); }
|
||||
|
||||
const display_context & dc() const { return dc_; }
|
||||
display & screen() { return disp_; }
|
||||
const display & screen() const { return disp_; }
|
||||
const tod_manager & tod() const { return tod_; }
|
||||
std::shared_ptr<wb::manager> wb() { return wb_; }
|
||||
utils::optional_reference<events::mouse_handler> mhb() { return mhb_; }
|
||||
std::shared_ptr<wb::manager> wb() const { return wb_; }
|
||||
utils::optional_reference<events::mouse_handler> mhb() const { return mhb_; }
|
||||
|
||||
private:
|
||||
const display_context& dc_;
|
||||
display & disp_;
|
||||
const display& disp_;
|
||||
const tod_manager& tod_;
|
||||
std::shared_ptr<wb::manager> wb_;
|
||||
utils::optional_reference<events::mouse_handler> mhb_;
|
||||
@ -68,17 +68,17 @@ public:
|
||||
|
||||
struct generator
|
||||
{
|
||||
virtual config generate(context & ct) = 0;
|
||||
virtual config generate(const context& ct) = 0;
|
||||
virtual ~generator() {}
|
||||
};
|
||||
|
||||
void register_generator(const std::string &name, generator *);
|
||||
|
||||
config generate_report(const std::string &name, context & ct, bool only_static = false);
|
||||
config generate_report(const std::string &name, const context& ct, bool only_static = false);
|
||||
|
||||
const std::set<std::string> &report_list();
|
||||
|
||||
using generator_function = std::function<config(reports::context&)>;
|
||||
using generator_function = std::function<config(const reports::context&)>;
|
||||
|
||||
typedef std::map<std::string, std::shared_ptr<reports::generator>> dynamic_report_generators;
|
||||
|
||||
|
@ -4527,10 +4527,10 @@ namespace {
|
||||
std::string name;
|
||||
lua_report_generator(lua_State *L, const std::string &n)
|
||||
: mState(L), name(n) {}
|
||||
virtual config generate(reports::context & rc);
|
||||
virtual config generate(const reports::context & rc);
|
||||
};
|
||||
|
||||
config lua_report_generator::generate(reports::context & /*rc*/)
|
||||
config lua_report_generator::generate(const reports::context & /*rc*/)
|
||||
{
|
||||
lua_State *L = mState;
|
||||
config cfg;
|
||||
|
Loading…
x
Reference in New Issue
Block a user