Added new_card function;

Added parameter to ScriptValue::next to recieve the key of the item.
Finished Add Multiple Cards behaviour.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1147 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-08-11 20:52:33 +00:00
parent ca63496ade
commit f1fe40b4ef
11 changed files with 139 additions and 33 deletions
+59
View File
@@ -0,0 +1,59 @@
//+----------------------------------------------------------------------------+
//| 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 <script/functions/functions.hpp>
#include <script/functions/util.hpp>
#include <data/field.hpp>
#include <data/field/text.hpp>
#include <data/field/choice.hpp>
#include <data/field/package_choice.hpp>
#include <data/field/color.hpp>
#include <data/game.hpp>
#include <data/card.hpp>
#include <util/error.hpp>
// ----------------------------------------------------------------------------- : new_card
SCRIPT_FUNCTION(new_card) {
SCRIPT_PARAM(GameP, game);
CardP new_card = new_intrusive1<Card>(*game);
// set field values
SCRIPT_PARAM(ScriptValueP, input);
ScriptValueP it = input->makeIterator(input);
ScriptValueP key;
while (ScriptValueP v = it->next(&key)) {
assert(key);
String name = key->toString();
// find value to update
IndexMap<FieldP,ValueP>::const_iterator value_it = new_card->data.find(name);
if (value_it == new_card->data.end()) {
throw ScriptError(format_string(_("Card doesn't have a field named '%s'"),name));
}
Value* value = value_it->get();
// set the value
if (TextValue* tvalue = dynamic_cast<TextValue*>(value)) {
tvalue->value = v->toString();
} else if (ChoiceValue* cvalue = dynamic_cast<ChoiceValue*>(value)) {
cvalue->value = v->toString();
} else if (PackageChoiceValue* pvalue = dynamic_cast<PackageChoiceValue*>(value)) {
pvalue->package_name = v->toString();
} else if (ColorValue* cvalue = dynamic_cast<ColorValue*>(value)) {
cvalue->value = (AColor)*v;
} else {
throw ScriptError(format_string(_("Can not set value '%s', it is not of the right type"),name));
}
}
SCRIPT_RETURN(new_card);
}
// ----------------------------------------------------------------------------- : Init
void init_script_construction_functions(Context& ctx) {
ctx.setVariable(_("new card"), script_new_card);
}
+2
View File
@@ -26,6 +26,7 @@ void init_script_image_functions(Context& ctx);
void init_script_editor_functions(Context& ctx);
void init_script_export_functions(Context& ctx);
void init_script_english_functions(Context& ctx);
void init_script_construction_functions(Context& ctx);
/// Initialize all built in functions for a context
inline void init_script_functions(Context& ctx) {
@@ -35,6 +36,7 @@ inline void init_script_functions(Context& ctx) {
init_script_editor_functions(ctx);
init_script_export_functions(ctx);
init_script_english_functions(ctx);
init_script_construction_functions(ctx);
}
// ----------------------------------------------------------------------------- : EOF