-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
manager.hpp
85 lines (65 loc) · 2.31 KB
/
manager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "game_events/fwd.hpp"
#include "game_events/wmi_manager.hpp"
#include "config.hpp"
#include <functional>
#include <set>
#include <string>
class filter_context;
class game_data;
namespace game_events
{
class wml_event_pump;
class event_handlers;
/**
* The game event manager loads the scenario configuration object,
* and ensures that events are handled according to the
* scenario configuration for its lifetime.
*
* Thus, a manager object should be created when a scenario is played,
* and destroyed at the end of the scenario.
* If a second manager object is created before destroying the previous
* one, the game will crash with an assertion failure.
*/
class manager
{
private:
const std::unique_ptr<event_handlers> event_handlers_;
std::set<std::string> unit_wml_ids_;
const std::unique_ptr<game_events::wml_event_pump> pump_;
game_events::wmi_manager wml_menu_items_;
public:
manager(const manager&) = delete;
manager& operator=(const manager&) = delete;
explicit manager();
void read_scenario(const config& scenario_cfg);
~manager();
/** Create an event handler. */
void add_event_handler(const config& handler, bool is_menu_item = false);
/** Removes an event handler. */
void remove_event_handler(const std::string& id);
/** Gets an event handler by ID */
const handler_ptr get_event_handler_by_id(const std::string& id);
void add_events(const config::const_child_itors& cfgs, const std::string& type = std::string());
void write_events(config& cfg) const;
using event_func_t = std::function<void(game_events::manager&, handler_ptr&)>;
void execute_on_events(const std::string& event_id, event_func_t func);
bool is_event_running() const;
game_events::wml_event_pump& pump();
game_events::wmi_manager& wml_menu_items()
{
return wml_menu_items_;
}
};
}