mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Basic text rendering working;
Added Font (done) and SymbolFont (skeleton); Added styling to set; Added CountourMap; Some script fixes git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@73 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -156,7 +156,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
|
||||
|
||||
} catch (...) {
|
||||
// cleanup after an exception
|
||||
if (scope) closeScope(scope); // restore scope
|
||||
if (useScope) closeScope(scope); // restore scope
|
||||
stack.resize(stack_size); // restore stack
|
||||
throw; // rethrow
|
||||
}
|
||||
@@ -307,4 +307,9 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
|
||||
// ----------------------------------------------------------------------------- : Simple instructions : ternary
|
||||
|
||||
void instrTernary(TernaryInstructionType i, ScriptValueP& a, const ScriptValueP& b, const ScriptValueP& c) {
|
||||
switch (i) {
|
||||
case I_RGB:
|
||||
a = toScript(Color((int)*a, (int)*b, (int)*c));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,9 +135,10 @@ void TokenIterator::readToken() {
|
||||
input = more.top().input;
|
||||
pos = more.top().pos;
|
||||
more.pop();
|
||||
} else {
|
||||
// EOF
|
||||
addToken(TOK_EOF, _("end of input"));
|
||||
}
|
||||
// EOF
|
||||
addToken(TOK_EOF, _("end of input"));
|
||||
return;
|
||||
}
|
||||
// read a character from the input
|
||||
|
||||
@@ -15,11 +15,17 @@
|
||||
typedef map<String, unsigned int> Variables;
|
||||
Variables variables;
|
||||
DECLARE_TYPEOF(Variables);
|
||||
#ifdef _DEBUG
|
||||
vector<String> variable_names;
|
||||
#endif
|
||||
|
||||
/// Return a unique name for a variable to allow for faster loopups
|
||||
unsigned int string_to_variable(const String& s) {
|
||||
map<String, unsigned int>::iterator it = variables.find(s);
|
||||
if (it == variables.end()) {
|
||||
#ifdef _DEBUG
|
||||
variable_names.push_back(s);
|
||||
#endif
|
||||
unsigned int v = (unsigned int)variables.size();
|
||||
variables.insert(make_pair(s,v));
|
||||
return v;
|
||||
|
||||
@@ -61,7 +61,7 @@ Context& ScriptManager::getContext(const StyleSheetP& stylesheet) {
|
||||
ctx->setVariable(_("game"), toScript(set.game));
|
||||
ctx->setVariable(_("stylesheet"), toScript(stylesheet));
|
||||
ctx->setVariable(_("card"), set.cards.empty() ? script_nil : toScript(set.cards.front())); // dummy value
|
||||
//ctx->setVariable(_("styling"), toScript(set->extraStyleData(style)));
|
||||
ctx->setVariable(_("styling"), toScript(&set.stylingDataFor(*stylesheet)));
|
||||
try {
|
||||
// perform init scripts, don't use a scope, variables stay bound in the context
|
||||
set.game ->init_script.invoke(*ctx, false);
|
||||
|
||||
@@ -18,6 +18,7 @@ void store(const ScriptValueP& val, String& var) { var = static_cas
|
||||
void store(const ScriptValueP& val, int& var) { var = *val; }
|
||||
void store(const ScriptValueP& val, double& var) { var = *val; }
|
||||
void store(const ScriptValueP& val, bool& var) { var = static_cast<int>(*val); }
|
||||
void store(const ScriptValueP& val, Color& var) { var = *val; }
|
||||
void store(const ScriptValueP& val, Defaultable<String>& var) { var.assign(*val); }
|
||||
|
||||
// ----------------------------------------------------------------------------- : OptionalScript
|
||||
|
||||
@@ -25,6 +25,7 @@ void store(const ScriptValueP& val, String& var);
|
||||
void store(const ScriptValueP& val, int& var);
|
||||
void store(const ScriptValueP& val, double& var);
|
||||
void store(const ScriptValueP& val, bool& var);
|
||||
void store(const ScriptValueP& val, Color& var);
|
||||
void store(const ScriptValueP& val, Defaultable<String>& var);
|
||||
|
||||
// ----------------------------------------------------------------------------- : OptionalScript
|
||||
|
||||
@@ -162,6 +162,10 @@ class ScriptString : public ScriptValue {
|
||||
long l;
|
||||
if (value.ToLong(&l)) {
|
||||
return l;
|
||||
} else if (value == _("yes") || value == _("true")) {
|
||||
return true;
|
||||
} else if (value == _("no") || value == _("false")) {
|
||||
return false;
|
||||
} else {
|
||||
throw ScriptError(_("Not a number: '") + value + _("'"));
|
||||
}
|
||||
@@ -193,6 +197,7 @@ class ScriptColor : public ScriptValue {
|
||||
ScriptColor(const Color& v) : value(v) {}
|
||||
virtual ScriptType type() const { return SCRIPT_COLOR; }
|
||||
virtual String typeName() const { return _("color"); }
|
||||
virtual operator Color() const { return value; }
|
||||
private:
|
||||
Color value;
|
||||
};
|
||||
|
||||
@@ -214,6 +214,12 @@ class ScriptMap : public ScriptValue {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Objects
|
||||
|
||||
/// Number of items in some collection like object, can be overloaded
|
||||
template <typename T>
|
||||
int item_count(const T& v) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Script value containing an object (pointer)
|
||||
template <typename T>
|
||||
class ScriptObject : public ScriptValue {
|
||||
@@ -239,6 +245,10 @@ class ScriptObject : public ScriptValue {
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual int itemCount() const {
|
||||
int i = item_count(*value);
|
||||
return i >= 0 ? i : ScriptValue::itemCount();
|
||||
}
|
||||
private:
|
||||
T value; ///< The object
|
||||
ScriptValueP getDefault() const {
|
||||
|
||||
Reference in New Issue
Block a user