Implemented the context management part of the ScriptManager

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@61 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-30 21:39:58 +00:00
parent 0a3a089c98
commit 0caaf01a78
22 changed files with 288 additions and 58 deletions
+8 -1
View File
@@ -71,7 +71,6 @@ shared_ptr<Field> read_new<Field>(Reader& reader) {
}
}
// ----------------------------------------------------------------------------- : Style
Style::Style(const FieldP& field)
@@ -100,6 +99,14 @@ template <> StyleP read_new<Style>(Reader&) {
throw InternalError(_("IndexMap contains nullptr StyleP the application should have crashed already"));
}
void Style::initDependencies(Context& ctx, const Dependency& dep) const {
left .initDependencies(ctx,dep);
top .initDependencies(ctx,dep);
width .initDependencies(ctx,dep);
height .initDependencies(ctx,dep);
visible.initDependencies(ctx,dep);
}
// ----------------------------------------------------------------------------- : Value
Value::~Value() {}
+10 -1
View File
@@ -13,10 +13,13 @@
#include <util/reflect.hpp>
#include <util/alignment.hpp>
#include <script/scriptable.hpp>
#include <script/dependency.hpp>
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Style);
DECLARE_POINTER_TYPE(Value);
class Context;
class Dependency;
// for DataViewer/editor
class DataViewer; class DataEditor;
@@ -44,7 +47,7 @@ class Field {
String card_list_name; ///< Alternate name to use in card list.
Alignment card_list_align; ///< Alignment of the card list colummn.
int tab_index; ///< Tab index in editor
// vector<Dependency> dependentScripts; // scripts that depend on values of this field
vector<Dependency> dependent_scripts; ///< Scripts that depend on values of this field
/// Creates a new Value corresponding to this Field
/** thisP is a smart pointer to this */
@@ -55,6 +58,9 @@ class Field {
/// Type of this field
virtual String typeName() const = 0;
/// Add the given dependency to the dependet_scripts list for the variables this field depends on
virtual void initDependencies(Context&, const Dependency&) const {}
private:
DECLARE_REFLECTION_VIRTUAL();
};
@@ -90,6 +96,9 @@ class Style {
/** thisP is a smart pointer to this */
virtual ValueEditorP makeEditor(DataEditor& parent, const StyleP& thisP) = 0;
/// Add the given dependency to the dependet_scripts list for the variables this style depends on
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION_VIRTUAL();
};
+5 -1
View File
@@ -16,6 +16,10 @@
IMPLEMENT_DYNAMIC_ARG(Game*, game_for_reading, nullptr);
Game::Game()
: dependencies_initialized(false)
{}
GameP Game::byName(const String& name) {
return packages.open<Game>(name + _(".mse-game"));
}
@@ -48,7 +52,7 @@ IMPLEMENT_REFLECTION(Game) {
// REFLECT(word_lists);
}
void Game::validate() {
void Game::validate(Version) {
// a default for the full name
if (full_name.empty()) full_name = name();
}
+8 -1
View File
@@ -12,6 +12,7 @@
#include <util/prec.hpp>
#include <util/io/package.hpp>
#include <script/scriptable.hpp>
#include <script/dependency.hpp>
#include <util/dynamic_arg.hpp>
DECLARE_POINTER_TYPE(Field);
@@ -25,12 +26,18 @@ DECLARE_DYNAMIC_ARG(Game*, game_for_reading);
/// A description of a card game
class Game : public Packaged {
public:
Game();
String full_name; ///< Name of this game, for menus etc.
String icon_filename; ///< Filename of icon to use in NewWindow
OptionalScript init_script; ///< Script of variables available to other scripts in this game
vector<FieldP> set_fields; ///< Fields for set information
vector<FieldP> card_fields; ///< Fields on each card
vector<Dependency> dependent_scripts_cards; ///< scripts that depend on the card list
vector<Dependency> dependent_scripts_keywords; ///< scripts that depend on the keywords
bool dependencies_initialized; ///< are the script dependencies comming from this game all initialized?
/// Loads the game with a particular name, for example "magic"
static GameP byName(const String& name);
@@ -43,7 +50,7 @@ class Game : public Packaged {
virtual InputStreamP openIconFile();
protected:
void validate();
virtual void validate(Version);
DECLARE_REFLECTION();
};
+49 -3
View File
@@ -11,32 +11,78 @@
#include <data/stylesheet.hpp>
#include <data/card.hpp>
#include <data/field.hpp>
#include <data/field/text.hpp> // for 0.2.7 fix
#include <script/value.hpp>
#include <script/script_manager.hpp>
DECLARE_TYPEOF_COLLECTION(CardP);
typedef IndexMap<FieldP,ValueP> IndexMap_FieldP_ValueP;
DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_ValueP);
// ----------------------------------------------------------------------------- : Set
Set::Set() {}
Set::Set()
: script_manager(new ScriptManager(*this))
{}
Set::Set(const GameP& game)
: game(game)
, script_manager(new ScriptManager(*this))
{}
Set::Set(const StyleSheetP& stylesheet)
: stylesheet(stylesheet)
, game(stylesheet->game)
, script_manager(new ScriptManager(*this))
{}
Set::~Set() {}
Context& Set::getContext() {
throw "TODO";
return script_manager->getContext(stylesheet);
}
Context& Set::getContext(const Card& card) {
return script_manager->getContext(card.stylesheet ? card.stylesheet : stylesheet);
}
String Set::typeName() const { return _("set"); }
void Set::validate() {
// fix values for versions < 0.2.7
void fix_value_207(const ValueP& value) {
if (TextValue* v = dynamic_cast<TextValue*>(value.get())) {
// text value -> fix it
// v->value.assign( // don't change defaultness
// fix_old_tags(v->value); // remove tags
// );
}
}
void Set::validate(Version file_app_version) {
// are the
if (!game) {
throw Error(_("No game specified for the set"));
}
if (!stylesheet) {
// TODO : Allow user to select a different style
throw Error(_("No stylesheet specified for the set"));
}
if (stylesheet->game != game) {
throw Error(_("stylesheet and set don't refer to the same game, this is an error in the stylesheet file"));
}
// This is our chance to fix version incompatabilities
if (file_app_version < 207) {
// Since 0.2.7 we use </tag> style close tags, in older versions it was </>
// Walk over all fields and fix...
FOR_EACH(c, cards) {
FOR_EACH(v, c->data) fix_value_207(v);
}
FOR_EACH(v, data) fix_value_207(v);
/* FOR_EACH(s, styleData) {
FOR_EACH(v, s.second->data) fix_value_207(v);
}
*/ }
}
IMPLEMENT_REFLECTION(Set) {
+5 -1
View File
@@ -55,9 +55,13 @@ class Set : public Packaged {
/** Should only be used from the main thread! */
Context& getContext();
/// A context for performing scripts on a particular card
/** Should only be used from the main thread! */
Context& getContext(const Card& card);
protected:
virtual String typeName() const;
virtual void validate();
virtual void validate(Version);
DECLARE_REFLECTION();
private:
+8
View File
@@ -11,11 +11,14 @@
#include <data/field.hpp>
#include <util/io/package_manager.hpp>
DECLARE_TYPEOF_COLLECTION(StyleSheet*);
// ----------------------------------------------------------------------------- : StyleSheet
StyleSheet::StyleSheet()
: card_width(100), card_height(100)
, card_dpi(96), card_background(*wxWHITE)
, dependencies_initialized(false)
{}
StyleSheetP StyleSheet::byGameAndName(const Game& game, const String& name) {
@@ -63,6 +66,11 @@ IMPLEMENT_REFLECTION(StyleSheet) {
// io(_("extra style"), extraInfoStyle);
}
void StyleSheet::validate(Version) {
// a default for the full name
if (full_name.empty()) full_name = name();
}
// special behaviour of reading/writing StyleSheetPs: only read/write the name
+9 -6
View File
@@ -40,18 +40,21 @@ class StyleSheet : public Packaged {
/** The indices should correspond to the set_fields in the Game */
IndexMap<FieldP, StyleP> set_info_style;
bool dependencies_initialized; ///< are the script dependencies comming from this stylesheet all initialized?
/// Load a StyleSheet, given a Game and the name of the StyleSheet
static StyleSheetP byGameAndName(const Game& game, const String& name);
/// name of the package without the game name
String styleName();
static String typeNameStatic();
virtual String typeName() const;
virtual String fullName() const;
virtual InputStreamP openIconFile();
/// Load a StyleSheet, given a Game and the name of the StyleSheet
static StyleSheetP byGameAndName(const Game& game, const String& name);
protected:
virtual void validate(Version);
/// name of the package without the game name
String styleName();
private:
DECLARE_REFLECTION();
};