From 25a301b07079903c03f45ea3ea4b47435a385898 Mon Sep 17 00:00:00 2001 From: twanvl Date: Mon, 11 Aug 2008 15:48:20 +0000 Subject: [PATCH] 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 --- src/data/add_cards_script.cpp | 52 ++++++++++++++++++++++++++++++++ src/data/add_cards_script.hpp | 38 ++++++++++++++++++++++++ src/data/game.cpp | 2 ++ src/data/game.hpp | 2 ++ src/gui/set/cards_panel.cpp | 6 ++++ src/gui/set/cards_panel.hpp | 3 +- src/mse.vcproj | 6 ++++ src/util/window_id.hpp | 56 +++++++++++++++++++---------------- 8 files changed, 138 insertions(+), 27 deletions(-) create mode 100644 src/data/add_cards_script.cpp create mode 100644 src/data/add_cards_script.hpp diff --git a/src/data/add_cards_script.cpp b/src/data/add_cards_script.cpp new file mode 100644 index 00000000..6b4ad2ad --- /dev/null +++ b/src/data/add_cards_script.cpp @@ -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 +#include +#include +#include +#include +#include + +// ----------------------------------------------------------------------------- : AddCardsScript + +IMPLEMENT_REFLECTION_NO_SCRIPT(AddCardsScript) { + REFLECT(name); + REFLECT(description); + REFLECT(enabled); + REFLECT(script); +} + + +void AddCardsScript::perform(Set& set, vector& 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(item); + // is this a new card? + if (contains(set.cards,card) || contains(out,card)) { + // make copy + card = new_intrusive1(*card); + } + out.push_back(card); + } +} + +void AddCardsScript::perform(Set& set) { + // Perform script + vector 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)); + } +} diff --git a/src/data/add_cards_script.hpp b/src/data/add_cards_script.hpp new file mode 100644 index 00000000..fb36d5af --- /dev/null +++ b/src/data/add_cards_script.hpp @@ -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 +#include