mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Cleaned up Set::Styling/Card::Styling by spliting that functionality into a 'DelayedIndexMaps' class;
Added 'right' and 'bottom' properties to style as an alternative way of specifying width/height; Added content_width, content_height and content_lines properties that give feedback on text rendering; Always show warnings when showing errors and vice-versa, this prevents script errors from appearing before the reader/parse error that caused them; Finally some preliminairy work on export templates git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@428 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -22,6 +22,8 @@ enum DependencyType
|
||||
, DEP_EXTRA_CARD_FIELD ///< dependency of a script in an extra stylesheet specific card field
|
||||
, DEP_CARD_COPY_DEP ///< copy the dependencies from a card field
|
||||
, DEP_SET_COPY_DEP ///< copy the dependencies from a set field
|
||||
, DEP_DUMMY ///< used for other purposes, index and data can be anything
|
||||
// in particular, this is used for determining /if/ there are dependencies
|
||||
};
|
||||
|
||||
/// A 'pointer' to some script that depends on another script
|
||||
@@ -52,6 +54,7 @@ class Dependencies : public vector<Dependency> {
|
||||
public:
|
||||
/// Add a dependency, prevents duplicates
|
||||
inline void add(const Dependency& d) {
|
||||
if (d.type == DEP_DUMMY) return;
|
||||
if (find(begin(),end(),d) == end()) {
|
||||
push_back(d);
|
||||
}
|
||||
|
||||
@@ -9,12 +9,22 @@
|
||||
#include <script/functions/functions.hpp>
|
||||
#include <script/functions/util.hpp>
|
||||
#include <util/tagged_string.hpp>
|
||||
#include <util/error.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/game.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(pair<String COMMA ScriptValueP>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Debugging
|
||||
|
||||
SCRIPT_FUNCTION(trace) {
|
||||
SCRIPT_PARAM(String, input);
|
||||
//handle_warning(_("Trace:\t") + input, false);
|
||||
wxLogDebug(_("Trace:\t") + input);
|
||||
SCRIPT_RETURN(input);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : String stuff
|
||||
|
||||
// convert a string to upper case
|
||||
@@ -607,6 +617,8 @@ SCRIPT_FUNCTION(sort) {
|
||||
// ----------------------------------------------------------------------------- : Init
|
||||
|
||||
void init_script_basic_functions(Context& ctx) {
|
||||
// debugging
|
||||
ctx.setVariable(_("trace"), script_trace);
|
||||
// string
|
||||
ctx.setVariable(_("to upper"), script_to_upper);
|
||||
ctx.setVariable(_("to lower"), script_to_lower);
|
||||
|
||||
@@ -57,6 +57,7 @@ Context& SetScriptContext::getContext(const StyleSheetP& stylesheet) {
|
||||
ctx->setVariable(_("set"), new_intrusive1<ScriptObject<Set*> >(&set));
|
||||
ctx->setVariable(_("game"), to_script(set.game));
|
||||
ctx->setVariable(_("stylesheet"), to_script(stylesheet));
|
||||
ctx->setVariable(_("card style"), to_script(&stylesheet->card_style));
|
||||
ctx->setVariable(_("card"), set.cards.empty() ? script_nil : to_script(set.cards.front())); // dummy value
|
||||
ctx->setVariable(_("styling"), to_script(&set.stylingDataFor(*stylesheet)));
|
||||
try {
|
||||
@@ -130,6 +131,10 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
|
||||
// find dependencies of choice images and other style stuff
|
||||
FOR_EACH(s, stylesheet.card_style) {
|
||||
s->initDependencies(ctx, Dependency(DEP_STYLE, s->fieldP->index, &stylesheet));
|
||||
// are there dependencies of this style on other style properties?
|
||||
Dependency test(DEP_DUMMY, false);
|
||||
s->checkContentDependencies(ctx, test);
|
||||
if (test.index) s->content_dependent = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,11 @@ void store(const ScriptValueP& val, Alignment& var);
|
||||
|
||||
// ----------------------------------------------------------------------------- : OptionalScript
|
||||
|
||||
template <typename T>
|
||||
inline void change(T& v, const T& new_v) { v = new_v; }
|
||||
template <typename T>
|
||||
inline void change(Defaultable<T>& v, const Defaultable<T>& new_v) { v.assignDontChangeDefault(new_v()); }
|
||||
|
||||
/// An optional script
|
||||
class OptionalScript {
|
||||
public:
|
||||
@@ -57,7 +62,7 @@ class OptionalScript {
|
||||
ctx.setVariable(_("value"), to_script(value));
|
||||
store(ctx.eval(*script), new_value);
|
||||
if (value != new_value) {
|
||||
value = new_value;
|
||||
change(value, new_value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -66,9 +71,8 @@ class OptionalScript {
|
||||
/// Invoke the script on a value if it is in the default state
|
||||
template <typename T>
|
||||
bool invokeOnDefault(Context& ctx, Defaultable<T>& value) const {
|
||||
if (value.isDefault() && invokeOn(ctx, value)) {
|
||||
value.makeDefault(); // restore defaultness
|
||||
return true;
|
||||
if (value.isDefault()) {
|
||||
return invokeOn(ctx, value);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ class ScriptObject : public ScriptValue {
|
||||
if (d) {
|
||||
return d->getMember(name);
|
||||
} else {
|
||||
throw ScriptValue::getMember(name);
|
||||
return ScriptValue::getMember(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user