Commit aa774e5e authored by twanvl's avatar twanvl

Tweaked the way to use getScript() like functions;

Made condition and default_expand parameters of expand_keywords optional.
parent 4411b167
...@@ -28,12 +28,12 @@ For example, in the case of magic: ...@@ -28,12 +28,12 @@ For example, in the case of magic:
is used. This shows reminder text by default based on a [[type:set]] option, and it combined the keyword as @"keyword (reminder)"@. is used. This shows reminder text by default based on a [[type:set]] option, and it combined the keyword as @"keyword (reminder)"@.
--Parameters-- --Parameters--
! Parameter Type Description ! Parameter Type Default Description
| @input@ [[type:tagged string]] String to expand keywords in. | @input@ [[type:tagged string]] String to expand keywords in.
| @condition@ [[type:function]] DOC_MSE_VERSION: since 0.3.7 | @condition@ [[type:function]] @{true}@ DOC_MSE_VERSION: since 0.3.7
When should a keyword be recognized at all? When should a keyword be recognized at all?
| @default_expand@ [[type:function]] Should reminder text be shown by default? | @default_expand@ [[type:function]] @{true}@ Should reminder text be shown by default?
| @combine@ [[type:function]] How to combine keywords with the reminder text? | @combine@ [[type:function]] How to combine keywords with the reminder text?
--Arguments-- --Arguments--
......
...@@ -53,7 +53,7 @@ void AddKeywordAction::perform(bool to_undo) { ...@@ -53,7 +53,7 @@ void AddKeywordAction::perform(bool to_undo) {
// ----------------------------------------------------------------------------- : Changing keywords // ----------------------------------------------------------------------------- : Changing keywords
KeywordReminderTextValue::KeywordReminderTextValue(Set& set, const TextFieldP& field, Keyword* keyword, bool editable) KeywordReminderTextValue::KeywordReminderTextValue(Set& set, const TextFieldP& field, Keyword* keyword, bool editable)
: KeywordTextValue(field, keyword, &keyword->reminder.getUnparsed(), editable) : KeywordTextValue(field, keyword, &keyword->reminder.getMutableUnparsed(), editable)
, set(set) , set(set)
, keyword(*keyword) , keyword(*keyword)
{} {}
...@@ -72,8 +72,8 @@ void KeywordReminderTextValue::store() { ...@@ -72,8 +72,8 @@ void KeywordReminderTextValue::store() {
// parsed okay // parsed okay
if (checkScript(new_script)) { if (checkScript(new_script)) {
// also runs okay, assign // also runs okay, assign
keyword.reminder.getScriptP() = new_script; keyword.reminder.setScriptP(new_script);
keyword.reminder.getUnparsed() = new_value; keyword.reminder.setUnparsed(new_value);
} }
} else { } else {
// parse errors, report // parse errors, report
......
...@@ -200,9 +200,9 @@ void ChoiceStyle::initImage() { ...@@ -200,9 +200,9 @@ void ChoiceStyle::initImage() {
// OR_ELSE // OR_ELSE
ScriptCustomCollectionP lookup(new ScriptCustomCollection()); ScriptCustomCollectionP lookup(new ScriptCustomCollection());
FOR_EACH(ci, choice_images) { FOR_EACH(ci, choice_images) {
lookup->key_value[ci.first] = ci.second.getScriptP(); lookup->key_value[ci.first] = ci.second.getValidScriptP();
} }
Script& script = image.getScript(); Script& script = image.getMutableScript();
script.addInstruction(I_PUSH_CONST, lookup); script.addInstruction(I_PUSH_CONST, lookup);
script.addInstruction(I_GET_VAR, SCRIPT_VAR_input); script.addInstruction(I_GET_VAR, SCRIPT_VAR_input);
script.addInstruction(I_BINARY, I_MEMBER); script.addInstruction(I_BINARY, I_MEMBER);
......
...@@ -94,7 +94,7 @@ void Game::initCardListColorScript() { ...@@ -94,7 +94,7 @@ void Game::initCardListColorScript() {
if (cf && !cf->choice_colors_cardlist.empty()) { if (cf && !cf->choice_colors_cardlist.empty()) {
// found the field to use // found the field to use
// initialize script: field.colors[card.field-name] or else rgb(0,0,0) // initialize script: field.colors[card.field-name] or else rgb(0,0,0)
Script& s = card_list_color_script.getScript(); Script& s = card_list_color_script.getMutableScript();
s.addInstruction(I_PUSH_CONST, to_script(&cf->choice_colors_cardlist)); s.addInstruction(I_PUSH_CONST, to_script(&cf->choice_colors_cardlist));
s.addInstruction(I_GET_VAR, SCRIPT_VAR_card); s.addInstruction(I_GET_VAR, SCRIPT_VAR_card);
s.addInstruction(I_MEMBER_C, cf->name); s.addInstruction(I_MEMBER_C, cf->name);
......
...@@ -670,7 +670,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw, ...@@ -670,7 +670,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
bool expand = expand_type == _('1'); bool expand = expand_type == _('1');
if (!expand && expand_type != _('0')) { if (!expand && expand_type != _('0')) {
// default expand, determined by script // default expand, determined by script
expand = expand_default && (bool)*expand_default->eval(ctx); expand = expand_default ? (bool)*expand_default->eval(ctx) : true;
expand_type = expand ? _('A') : _('a'); expand_type = expand ? _('A') : _('a');
} }
......
...@@ -51,7 +51,7 @@ StatsDimension::StatsDimension(const Field& field) ...@@ -51,7 +51,7 @@ StatsDimension::StatsDimension(const Field& field)
groups.push_back(g->name); groups.push_back(g->name);
} }
// initialize script: primary_choice(card.{field_name}) // initialize script: primary_choice(card.{field_name})
Script& s = script.getScript(); Script& s = script.getMutableScript();
s.addInstruction(I_PUSH_CONST, script_primary_choice); s.addInstruction(I_PUSH_CONST, script_primary_choice);
s.addInstruction(I_GET_VAR, SCRIPT_VAR_card); s.addInstruction(I_GET_VAR, SCRIPT_VAR_card);
s.addInstruction(I_MEMBER_C, field.name); s.addInstruction(I_MEMBER_C, field.name);
...@@ -59,7 +59,7 @@ StatsDimension::StatsDimension(const Field& field) ...@@ -59,7 +59,7 @@ StatsDimension::StatsDimension(const Field& field)
s.addInstruction(I_NOP, SCRIPT_VAR_input); s.addInstruction(I_NOP, SCRIPT_VAR_input);
} else { } else {
// initialize script, card.{field_name} // initialize script, card.{field_name}
Script& s = script.getScript(); Script& s = script.getMutableScript();
s.addInstruction(I_GET_VAR, SCRIPT_VAR_card); s.addInstruction(I_GET_VAR, SCRIPT_VAR_card);
s.addInstruction(I_MEMBER_C, field.name); s.addInstruction(I_MEMBER_C, field.name);
} }
......
...@@ -183,7 +183,7 @@ void DropDownChoiceListBase::generateThumbnailImages() { ...@@ -183,7 +183,7 @@ void DropDownChoiceListBase::generateThumbnailImages() {
try { try {
String name = cannocial_name_form(field().choices->choiceName(i)); String name = cannocial_name_form(field().choices->choiceName(i));
ctx.setVariable(_("input"), to_script(name)); ctx.setVariable(_("input"), to_script(name));
GeneratedImageP img = image_from_script(style().image.getScript().eval(ctx)); GeneratedImageP img = image_from_script(style().image.getValidScriptP()->eval(ctx));
style().choice_images.insert(make_pair(name, ScriptableImage(img))); style().choice_images.insert(make_pair(name, ScriptableImage(img)));
} catch (const Error& e) { } catch (const Error& e) {
handle_error(Error(e.what() + _("\n while generating choice images for drop down list")),true,false); handle_error(Error(e.what() + _("\n while generating choice images for drop down list")),true,false);
......
...@@ -542,8 +542,8 @@ SCRIPT_FUNCTION(random_select) { ...@@ -542,8 +542,8 @@ SCRIPT_FUNCTION(random_select) {
SCRIPT_FUNCTION_WITH_DEP(expand_keywords) { SCRIPT_FUNCTION_WITH_DEP(expand_keywords) {
SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(String, input);
SCRIPT_PARAM_C(Set*, set); SCRIPT_PARAM_C(Set*, set);
SCRIPT_PARAM_N(ScriptValueP, _("condition"), match_condition); SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("condition"), match_condition);
SCRIPT_PARAM_N(ScriptValueP, _("default expand"), default_expand); SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("default expand"), default_expand);
SCRIPT_PARAM_N(ScriptValueP, _("combine"), combine); SCRIPT_PARAM_N(ScriptValueP, _("combine"), combine);
KeywordDatabase& db = set->keyword_db; KeywordDatabase& db = set->keyword_db;
if (db.empty()) { if (db.empty()) {
...@@ -562,10 +562,10 @@ SCRIPT_FUNCTION_WITH_DEP(expand_keywords) { ...@@ -562,10 +562,10 @@ SCRIPT_FUNCTION_WITH_DEP(expand_keywords) {
} }
SCRIPT_FUNCTION_DEPENDENCIES(expand_keywords) { SCRIPT_FUNCTION_DEPENDENCIES(expand_keywords) {
SCRIPT_PARAM_C(Set*, set); SCRIPT_PARAM_C(Set*, set);
SCRIPT_PARAM_N(ScriptValueP, _("condition"), match_condition); SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("condition"), match_condition);
SCRIPT_PARAM_N(ScriptValueP, _("default expand"), default_expand); SCRIPT_OPTIONAL_PARAM_N_(ScriptValueP, _("default expand"), default_expand);
SCRIPT_PARAM_N(ScriptValueP, _("combine"), combine); SCRIPT_PARAM_N(ScriptValueP, _("combine"), combine);
match_condition->dependencies(ctx,dep); if (match_condition) match_condition->dependencies(ctx,dep);
default_expand ->dependencies(ctx,dep); default_expand ->dependencies(ctx,dep);
combine ->dependencies(ctx,dep); combine ->dependencies(ctx,dep);
set->game->dependent_scripts_keywords.add(dep); // this depends on the set's keywords set->game->dependent_scripts_keywords.add(dep); // this depends on the set's keywords
......
...@@ -77,7 +77,7 @@ bool ScriptableImage::update(Context& ctx) { ...@@ -77,7 +77,7 @@ bool ScriptableImage::update(Context& ctx) {
} }
} }
ScriptP ScriptableImage::getScriptP() { ScriptP ScriptableImage::getValidScriptP() {
if (script) return script.getScriptP(); if (script) return script.getScriptP();
// return value or a blank image // return value or a blank image
ScriptP s(new Script); ScriptP s(new Script);
......
...@@ -54,9 +54,9 @@ class ScriptableImage { ...@@ -54,9 +54,9 @@ class ScriptableImage {
inline bool local() const { return value && value->local(); } inline bool local() const { return value && value->local(); }
/// Get access to the script, be careful /// Get access to the script, be careful
inline Script& getScript() { return script.getScript(); } inline Script& getMutableScript() { return script.getMutableScript(); }
/// Get access to the script, always returns a valid script /// Get access to the script, always returns a valid script
ScriptP getScriptP(); ScriptP getValidScriptP();
protected: protected:
OptionalScript script; ///< The script, not really optional OptionalScript script; ///< The script, not really optional
......
...@@ -75,7 +75,7 @@ void OptionalScript::initDependencies(Context& ctx, const Dependency& dep) const ...@@ -75,7 +75,7 @@ void OptionalScript::initDependencies(Context& ctx, const Dependency& dep) const
} }
} }
Script& OptionalScript::getScript() { Script& OptionalScript::getMutableScript() {
if (!script) script = new_intrusive<Script>(); if (!script) script = new_intrusive<Script>();
return *script; return *script;
} }
......
...@@ -84,11 +84,13 @@ class OptionalScript { ...@@ -84,11 +84,13 @@ class OptionalScript {
void initDependencies(Context&, const Dependency& dep) const; void initDependencies(Context&, const Dependency& dep) const;
/// Get access to the script, be careful /// Get access to the script, be careful
Script& getScript(); Script& getMutableScript();
inline ScriptP& getScriptP() { return script; } inline ScriptP getScriptP() const { return script; }
inline void setScriptP(const ScriptP& new_script) { script = new_script; }
/// Get access to the unparsed value /// Get access to the unparsed value
inline String& getUnparsed() { return unparsed; } inline const String& getUnparsed() const { return unparsed; }
inline const String& getUnparsed() const { return unparsed; } inline String& getMutableUnparsed() { return unparsed; }
inline void setUnparsed(String& new_unparsed) { unparsed = new_unparsed; }
protected: protected:
ScriptP script; ///< The script, may be null if there is no script ScriptP script; ///< The script, may be null if there is no script
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment