Repository navigation
Expand file tree
/
Copy pathscript_manager.hpp
More file actions
118 lines (96 loc) · 4.41 KB
/
Copy pathscript_manager.hpp
File metadata and controls
118 lines (96 loc) · 4.41 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2012 Twan van Laarhoven and Sean Hunt |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_SCRIPT_SCRIPT_MANAGER
#define HEADER_SCRIPT_SCRIPT_MANAGER
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/action_stack.hpp>
#include <util/age.hpp>
#include <script/context.hpp>
#include <script/dependency.hpp>
#include <queue>
class Set;
class Value;
DECLARE_POINTER_TYPE(Game);
DECLARE_POINTER_TYPE(StyleSheet);
DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Style);
// ----------------------------------------------------------------------------- : SetScriptContext
/// Manager of the script context for a set
class SetScriptContext {
public:
SetScriptContext(Set& set);
virtual ~SetScriptContext();
/// Get a context to use for the set, for a given stylesheet
Context& getContext(const StyleSheetP&);
/// Get a context to use for the set, for a given card
Context& getContext(const CardP&);
protected:
Set& set; ///< Set for which we are managing scripts
map<const StyleSheet*,Context*> contexts; ///< Context for evaluating scripts that use a given stylesheet
/// Called when a new context for a stylesheet is initialized
virtual void onInit(const StyleSheetP& stylesheet, Context* ctx) {}
};
// ----------------------------------------------------------------------------- : SetScriptManager
/// Manager of the script context for a set, keeps scripts up to date
/** Whenever there is an action all necessary scripts are executed.
* Executes both Value scripts and Style scriptables.
*
* The context contains a normal pointer to the set, not a shared/intrusive_ptr, because the set
* itself owns this object.
*/
class SetScriptManager : public SetScriptContext, public ActionListener {
public:
SetScriptManager(Set& set);
~SetScriptManager();
/// Update all styles for a particular card
void updateStyles(const CardP& card, bool only_content_dependent);
/// Update expensive things that were previously delayed
void updateDelayed();
/// Update all fields of all cards
/** Update all set info fields
* Doesn't update styles
*/
void updateAll();
private:
virtual void onInit(const StyleSheetP& stylesheet, Context* ctx);
void initDependencies(Context&, Game&);
void initDependencies(Context&, StyleSheet&);
/// Update a map of styles
void updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles, bool only_content_dependent);
/// Updates scripts, starting at some value
/** if the value changes any dependend values are updated as well
* optionally: action that causes this update
*/
void updateValue(Value& value, const CardP& card, const Action* action);
// Update all values with a specific dependency
void updateAllDependend(const vector<Dependency>& dependent_scripts, const CardP& card = CardP());
// Something that needs to be updated
struct ToUpdate {
ToUpdate(Value* value, CardP card) : value(value), card(card) {}
Value* value; ///< value to update
CardP card; ///< card the value is in, or CadP() if it is not a card field
};
/// Update all things in to_update, and things that depent on them, etc.
/** Only update things that are older than starting_age. */
void updateRecursive(std::deque<ToUpdate>& to_update, Age starting_age);
/// Update a value given by a ToUpdate object, and add things depending on it to to_update
void updateToUpdate(const ToUpdate& u, std::deque<ToUpdate>& to_update, Age starting_age);
/// Schedule all things in deps to be updated by adding them to to_update
void alsoUpdate(std::deque<ToUpdate>& to_update, const vector<Dependency>& deps, const CardP& card);
/// Delayed update for (bitmask)...
enum Delay
{ DELAY_KEYWORDS = 0x01
, DELAY_CARDS = 0x02
};
int delay;
protected:
/// Respond to actions by updating scripts
void onAction(const Action&, bool undone);
};
// ----------------------------------------------------------------------------- : EOF
#endif