Repository navigation
Expand file tree
/
Copy pathconstruction.cpp
More file actions
49 lines (43 loc) · 1.79 KB
/
Copy pathconstruction.cpp
File metadata and controls
49 lines (43 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2012 Twan van Laarhoven and Sean Hunt |
//| 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 = intrusive(new Card(*game));
// set field values
SCRIPT_PARAM(ScriptValueP, input);
ScriptValueP it = input->makeIterator();
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));
}
// set it
Value* value = value_it->get();
value->value = v;
}
SCRIPT_RETURN(new_card);
}
// ----------------------------------------------------------------------------- : Init
void init_script_construction_functions(Context& ctx) {
ctx.setVariable(_("new_card"), script_new_card);
}