mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Partial support for add multiple cards scripts, not visible to users yet
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1140 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2008 Twan van Laarhoven and "coppro" |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <data/add_cards_script.hpp>
|
||||
#include <data/action/set.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : AddCardsScript
|
||||
|
||||
IMPLEMENT_REFLECTION_NO_SCRIPT(AddCardsScript) {
|
||||
REFLECT(name);
|
||||
REFLECT(description);
|
||||
REFLECT(enabled);
|
||||
REFLECT(script);
|
||||
}
|
||||
|
||||
|
||||
void AddCardsScript::perform(Set& set, vector<CardP>& out) {
|
||||
// Perform script
|
||||
Context& ctx = set.getContext();
|
||||
ScriptValueP result = script.invoke(ctx);
|
||||
// Add cards to out
|
||||
ScriptValueP it = result->makeIterator(result);
|
||||
while (ScriptValueP item = it->next()) {
|
||||
CardP card = from_script<CardP>(item);
|
||||
// is this a new card?
|
||||
if (contains(set.cards,card) || contains(out,card)) {
|
||||
// make copy
|
||||
card = new_intrusive1<Card>(*card);
|
||||
}
|
||||
out.push_back(card);
|
||||
}
|
||||
}
|
||||
|
||||
void AddCardsScript::perform(Set& set) {
|
||||
// Perform script
|
||||
vector<CardP> cards;
|
||||
perform(set,cards);
|
||||
// Add to set
|
||||
if (!cards.empty()) {
|
||||
// TODO: change the name of the action somehow
|
||||
set.actions.addAction(new AddCardAction(ADD, set, cards));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2008 Twan van Laarhoven and "coppro" |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
#ifndef HEADER_DATA_ADD_CARDS_SCRIPT
|
||||
#define HEADER_DATA_ADD_CARDS_SCRIPT
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <script/scriptable.hpp>
|
||||
|
||||
class Set;
|
||||
DECLARE_POINTER_TYPE(Card);
|
||||
|
||||
// ----------------------------------------------------------------------------- : AddCardsScript
|
||||
|
||||
/// A script to add one or more cards to a set
|
||||
class AddCardsScript : public IntrusivePtrBase<AddCardsScript> {
|
||||
public:
|
||||
String name;
|
||||
String description;
|
||||
Scriptable<bool> enabled;
|
||||
OptionalScript script;
|
||||
|
||||
/// Perform the script; return the cards (if any)
|
||||
void perform(Set& set, vector<CardP>& out);
|
||||
/// Perform the script; add cards to the set
|
||||
void perform(Set& set);
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <data/statistics.hpp>
|
||||
#include <data/pack.hpp>
|
||||
#include <data/word_list.hpp>
|
||||
#include <data/add_cards_script.hpp>
|
||||
#include <util/io/package_manager.hpp>
|
||||
#include <script/script.hpp>
|
||||
|
||||
@@ -61,6 +62,7 @@ IMPLEMENT_REFLECTION(Game) {
|
||||
REFLECT(keyword_parameter_types);
|
||||
REFLECT_NO_SCRIPT(keywords);
|
||||
REFLECT_NO_SCRIPT(word_lists);
|
||||
REFLECT_NO_SCRIPT(add_cards_scripts);
|
||||
REFLECT_NO_SCRIPT(auto_replaces);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ DECLARE_POINTER_TYPE(KeywordParam);
|
||||
DECLARE_POINTER_TYPE(KeywordMode);
|
||||
DECLARE_POINTER_TYPE(Keyword);
|
||||
DECLARE_POINTER_TYPE(WordList);
|
||||
DECLARE_POINTER_TYPE(AddCardsScript);
|
||||
DECLARE_POINTER_TYPE(AutoReplace);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Game
|
||||
@@ -48,6 +49,7 @@ class Game : public Packaged {
|
||||
vector<PackItemP> pack_items; ///< Types of cards in packs
|
||||
vector<PackTypeP> pack_types; ///< Types of random card packs to generate
|
||||
vector<WordListP> word_lists; ///< Word lists for editing with a drop down list
|
||||
vector<AddCardsScriptP> add_cards_scripts; ///< Scripts for adding multiple cards to the set
|
||||
vector<AutoReplaceP> auto_replaces; ///< Things to autoreplace in textboxes
|
||||
|
||||
bool has_keywords; ///< Does this game use keywords?
|
||||
|
||||
Reference in New Issue
Block a user