mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
8dcda6fd93
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@95 0fc631ac-6414-0410-93d0-97cfa31319b6
86 lines
3.4 KiB
C++
86 lines
3.4 KiB
C++
//+----------------------------------------------------------------------------+
|
|
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
|
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
|
//| 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);
|
|
|
|
// ----------------------------------------------------------------------------- : ScriptManager
|
|
|
|
/// 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_ptr, because the set
|
|
* itself owns this object.
|
|
*/
|
|
class ScriptManager : public ActionListener {
|
|
public:
|
|
ScriptManager(Set& set);
|
|
~ScriptManager();
|
|
|
|
/// 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&);
|
|
|
|
// Update all styles for a particular card
|
|
void updateStyles(const CardP& card);
|
|
|
|
private:
|
|
Set& set; ///< Set for which we are managing scripts
|
|
map<const StyleSheet*,Context*> contexts; ///< Context for evaluating scripts that use a given stylesheet
|
|
|
|
void initDependencies(Context&, Game&);
|
|
void initDependencies(Context&, StyleSheet&);
|
|
|
|
/// Updates scripts, starting at some value
|
|
/** if the value changes any dependend values are updated as well */
|
|
void updateValue(Value& value, const CardP& card);
|
|
/// Update all fields of all cards
|
|
/** Update all set info fields
|
|
* Doesn't update styles
|
|
*/
|
|
void updateAll();
|
|
// Update all values with a specific dependency
|
|
void updateAllDependend(const vector<Dependency>& dependent_scripts);
|
|
|
|
// 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(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, deque<ToUpdate>& to_update, Age starting_age);
|
|
/// Schedule all things in deps to be updated by adding them to to_update
|
|
void alsoUpdate(deque<ToUpdate>& to_update, const vector<Dependency>& deps, const CardP& card);
|
|
|
|
protected:
|
|
/// Respond to actions by updating scripts
|
|
void onAction(const Action&, bool undone);
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------- : EOF
|
|
#endif
|