Added support for scripts to determine word lists;

Added 'trim' and 'remove_tags' script functions;
Simplified safety improvements of locale checker;
Added 'is_targeted' function to magic game to replace the contains(..) calls

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@635 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-08-28 18:33:38 +00:00
parent ccaea98a67
commit fcc89b64d6
16 changed files with 479 additions and 225 deletions
+17 -24
View File
@@ -210,26 +210,16 @@ void Locale::validate(Version ver) {
r.handle_greedy(v);
// validate
String errors;
// For efficiency, this needs to be parallel to LocaleCategory's values.
String sublocales[10] = {
_("menu"),
_("help"),
_("tool"),
_("tooltip"),
_("label"),
_("button"),
_("title"),
_("type"),
_("action"),
_("error")
};
for (String * current = sublocales; current < sublocales + 10; ++current) {
if (v.sublocales[*current])
errors += translations[current - sublocales].validate(*current, *v.sublocales[*current]);
else
errors += _("\nError validating local file: expected keys file missing \"") + *current + _("\" section.");
}
errors += translations[LOCALE_CAT_MENU ].validate(_("menu"), v.sublocales[_("menu") ]);
errors += translations[LOCALE_CAT_HELP ].validate(_("help"), v.sublocales[_("help") ]);
errors += translations[LOCALE_CAT_TOOL ].validate(_("tool"), v.sublocales[_("tool") ]);
errors += translations[LOCALE_CAT_TOOLTIP].validate(_("tooltip"), v.sublocales[_("tooltip")]);
errors += translations[LOCALE_CAT_LABEL ].validate(_("label"), v.sublocales[_("label") ]);
errors += translations[LOCALE_CAT_BUTTON ].validate(_("button"), v.sublocales[_("button") ]);
errors += translations[LOCALE_CAT_TITLE ].validate(_("title"), v.sublocales[_("title") ]);
errors += translations[LOCALE_CAT_ACTION ].validate(_("action"), v.sublocales[_("action") ]);
errors += translations[LOCALE_CAT_ERROR ].validate(_("error"), v.sublocales[_("error") ]);
errors += translations[LOCALE_CAT_TYPE ].validate(_("type"), v.sublocales[_("type") ]);
// errors?
if (!errors.empty()) {
if (ver != app_version) {
@@ -242,10 +232,13 @@ void Locale::validate(Version ver) {
}
}
String SubLocale::validate(const String& name, const SubLocaleValidator& v) const {
String SubLocale::validate(const String& name, const SubLocaleValidatorP& v) const {
if (!v) {
return _("\nInternal error validating local file: expected keys file missing for \"") + name + _("\" section.");
}
String errors;
// 1. keys in v but not in this, check arg count
FOR_EACH_CONST(kc, v.keys) {
FOR_EACH_CONST(kc, v->keys) {
map<String,String>::const_iterator it = translations.find(kc.first);
if (it == translations.end()) {
if (!kc.second.optional) {
@@ -258,8 +251,8 @@ String SubLocale::validate(const String& name, const SubLocaleValidator& v) cons
}
// 2. keys in this but not in v
FOR_EACH_CONST(kv, translations) {
map<String,KeyValidator>::const_iterator it = v.keys.find(kv.first);
if (it == v.keys.end() && !kv.second.empty()) {
map<String,KeyValidator>::const_iterator it = v->keys.find(kv.first);
if (it == v->keys.end() && !kv.second.empty()) {
// allow extra keys with empty values as a kind of documentation
// for example in the help stirngs:
// help:
+2 -2
View File
@@ -16,7 +16,7 @@
DECLARE_POINTER_TYPE(Locale);
DECLARE_POINTER_TYPE(SubLocale);
class SubLocaleValidator;
DECLARE_POINTER_TYPE(SubLocaleValidator);
// ----------------------------------------------------------------------------- : Locale class
@@ -31,7 +31,7 @@ class SubLocale : public IntrusivePtrBase<SubLocale> {
String tr(const String& key, const String& def);
/// Is this a valid sublocale? Returns errors
String validate(const String& name, const SubLocaleValidator&) const;
String validate(const String& name, const SubLocaleValidatorP&) const;
DECLARE_REFLECTION();
};
+2 -1
View File
@@ -16,12 +16,13 @@ WordListWord::WordListWord()
{}
IMPLEMENT_REFLECTION_NO_SCRIPT(WordListWord) {
if (line_below || is_prefix || isGroup() || (tag.reading() && tag.isComplex())) {
if (line_below || is_prefix || isGroup() || script || (tag.reading() && tag.isComplex())) {
// complex value
REFLECT(name);
REFLECT(line_below);
REFLECT(is_prefix);
REFLECT(words);
REFLECT(script);
} else {
REFLECT_NAMELESS(name);
}
+2
View File
@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <util/reflect.hpp>
#include <script/scriptable.hpp>
DECLARE_POINTER_TYPE(WordListWord);
DECLARE_POINTER_TYPE(WordList);
@@ -27,6 +28,7 @@ class WordListWord : public IntrusivePtrBase<WordListWord> {
bool line_below; ///< Line below in the list?
bool is_prefix; ///< Is this a prefix before other words?
vector<WordListWordP> words; ///< Sublist
OptionalScript script; ///< Generate words using a script
inline bool isGroup() const { return !words.empty(); }