mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Dependency following now works
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@95 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -208,6 +208,24 @@ SCRIPT_FUNCTION(set_mask) {
|
||||
}
|
||||
}
|
||||
|
||||
bool parse_enum(const String&, ImageCombine& out);
|
||||
|
||||
SCRIPT_FUNCTION(set_combine) {
|
||||
if (last_update_age() == 0) {
|
||||
SCRIPT_PARAM(String, combine);
|
||||
ScriptImageP image = to_script_image(ctx.getVariable(_("input")));
|
||||
// parse and set combine
|
||||
if (!parse_enum(combine, image->combine)) {
|
||||
throw ScriptError(_("Not a valid combine mode: '") + combine + _("'"));
|
||||
}
|
||||
return image;
|
||||
} else {
|
||||
SCRIPT_RETURN(
|
||||
script_image_up_to_date(ctx.getVariable(_("input")))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(buildin_image) {
|
||||
if (last_update_age() == 0) {
|
||||
SCRIPT_PARAM(String, input);
|
||||
@@ -223,5 +241,6 @@ void init_script_image_functions(Context& ctx) {
|
||||
ctx.setVariable(_("linear blend"), script_linear_blend);
|
||||
ctx.setVariable(_("masked blend"), script_masked_blend);
|
||||
ctx.setVariable(_("set mask"), script_set_mask);
|
||||
ctx.setVariable(_("set combine"), script_set_combine);
|
||||
ctx.setVariable(_("buildin image"), script_buildin_image);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <data/game.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/field.hpp>
|
||||
#include <data/action/set.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
#include <util/error.hpp>
|
||||
|
||||
typedef map<const StyleSheet*,Context*> Contexts;
|
||||
@@ -32,7 +34,10 @@ void init_script_image_functions(Context& ctx);
|
||||
|
||||
ScriptManager::ScriptManager(Set& set)
|
||||
: set(set)
|
||||
{}
|
||||
{
|
||||
// add as an action listener for the set, so we receive actions
|
||||
set.actions.addListener(this);
|
||||
}
|
||||
|
||||
ScriptManager::~ScriptManager() {
|
||||
set.actions.removeListener(this);
|
||||
@@ -40,8 +45,6 @@ ScriptManager::~ScriptManager() {
|
||||
FOR_EACH(sc, contexts) {
|
||||
delete sc.second;
|
||||
}
|
||||
// add as an action listener for the set, so we receive actions
|
||||
set.actions.addListener(this);
|
||||
}
|
||||
|
||||
Context& ScriptManager::getContext(const StyleSheetP& stylesheet) {
|
||||
@@ -116,11 +119,19 @@ void ScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
|
||||
// ----------------------------------------------------------------------------- : ScriptManager : updating
|
||||
|
||||
void ScriptManager::onAction(const Action& action, bool undone) {
|
||||
// TODO
|
||||
// TYPE_CASE(action, ValueAction) {
|
||||
// }
|
||||
// TYPE_CASE(action, CardListAction) {
|
||||
// }
|
||||
TYPE_CASE(action, ValueAction) {
|
||||
// find the affected card
|
||||
FOR_EACH(card, set.cards) {
|
||||
if (card->data.contains(action.valueP)) {
|
||||
updateValue(*action.valueP, card);
|
||||
return;
|
||||
}
|
||||
}
|
||||
updateValue(*action.valueP, CardP());
|
||||
}
|
||||
TYPE_CASE_(action, CardListAction) {
|
||||
updateAllDependend(set.game->dependent_scripts_cards);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::updateStyles(const CardP& card) {
|
||||
@@ -196,8 +207,14 @@ void ScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Dependen
|
||||
FOR_EACH_CONST(d, deps) {
|
||||
switch (d.type) {
|
||||
case DEP_SET_FIELD: {
|
||||
ValueP value = set.data.at(d.index);
|
||||
to_update.push_back(ToUpdate(value.get(), CardP()));
|
||||
break;
|
||||
} case DEP_CARD_FIELD: {
|
||||
if (card) {
|
||||
ValueP value = card->data.at(d.index);
|
||||
to_update.push_back(ToUpdate(value.get(), card));
|
||||
}
|
||||
break;
|
||||
} case DEP_CARDS_FIELD: {
|
||||
break;
|
||||
|
||||
@@ -64,6 +64,7 @@ class ScriptManager : public ActionListener {
|
||||
|
||||
// Something that needs to be updated
|
||||
struct ToUpdate {
|
||||
ToUpdate(Value* value, CardP card) : value(value), card(card) {}
|
||||
Value* value; ///< value to update
|
||||
CardP card; ///< card the value is in, or CadP() if it is not a card field
|
||||
};
|
||||
|
||||
@@ -164,7 +164,7 @@ class ScriptString : public ScriptValue {
|
||||
return l;
|
||||
} else if (value == _("yes") || value == _("true")) {
|
||||
return true;
|
||||
} else if (value == _("no") || value == _("false")) {
|
||||
} else if (value == _("no") || value == _("false") || value.empty()) {
|
||||
return false;
|
||||
} else {
|
||||
throw ScriptError(_("Not a number: '") + value + _("'"));
|
||||
|
||||
@@ -220,6 +220,10 @@ int item_count(const T& v) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Mark a dependency on a member of value, can be overloaded
|
||||
template <typename T>
|
||||
void mark_dependency_member(const T& value, const String& name, const Dependency& dep) {}
|
||||
|
||||
/// Script value containing an object (pointer)
|
||||
template <typename T>
|
||||
class ScriptObject : public ScriptValue {
|
||||
@@ -245,6 +249,10 @@ class ScriptObject : public ScriptValue {
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const {
|
||||
mark_dependency_member(value, name, dep);
|
||||
return getMember(name);
|
||||
}
|
||||
virtual int itemCount() const {
|
||||
int i = item_count(*value);
|
||||
return i >= 0 ? i : ScriptValue::itemCount();
|
||||
|
||||
Reference in New Issue
Block a user