mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
fix bugs
- dimensions_of should now work in all contexts - import_image now works in style files, although should be avoided, since it reloads the file every time the code in run, it should be used in one shot scripts, like import scripts and bulk modification scripts - process_english_hints now correctly processes <singular> and <plural> tags
This commit is contained in:
@@ -269,7 +269,9 @@ String process_english_hints(const String& str) {
|
||||
String ret; ret.reserve(str.size());
|
||||
// have we seen a <hint-1/2>?
|
||||
// 1 for singular, 2 for plural
|
||||
int singplur = 0;
|
||||
int singplur = 0;
|
||||
int sing_found = 0;
|
||||
int plur_found = 0;
|
||||
for (size_t i = 0 ; i < str.size() ; ) {
|
||||
Char c = str.GetChar(i);
|
||||
if (is_substr(str, i, _("<hint-"))) {
|
||||
@@ -288,7 +290,7 @@ String process_english_hints(const String& str) {
|
||||
// a -> an, where the a originates from english_number_a(1)
|
||||
size_t after_end = skip_tag(str,after+1);
|
||||
if (after_end == String::npos) {
|
||||
throw Error(_("Incomplete </param> tag"));
|
||||
throw ScriptError(_("Incomplete </param> tag"));
|
||||
}
|
||||
if (after_end != String::npos && after_end + 1 < str.size()
|
||||
&& isSpace(str.GetChar(after_end)) && is_vowel(str.GetChar(after_end+1))) {
|
||||
@@ -313,23 +315,31 @@ String process_english_hints(const String& str) {
|
||||
}
|
||||
ret.append(str,i,min(after,str.size())-i);
|
||||
i = after;
|
||||
} else if (is_substr(str, i, _("<singular>"))) {
|
||||
} else if (is_substr(str, i, _("<singular>"))) {
|
||||
sing_found++;
|
||||
// singular -> keep, plural -> drop
|
||||
size_t start = skip_tag(str, i);
|
||||
size_t end = match_close_tag(str, start);
|
||||
if (singplur == 1 && end != String::npos) {
|
||||
ret += str.substr(start, end - start);
|
||||
size_t end = match_close_tag(str, i);
|
||||
if (end == String::npos) {
|
||||
throw ScriptError(_("<singular> tag found without matching closing tag."));
|
||||
}
|
||||
else if (singplur == 1) {
|
||||
ret += str.substr(start, end - start);
|
||||
singplur = 0;
|
||||
}
|
||||
singplur = 0;
|
||||
i = skip_tag(str, end);
|
||||
} else if (is_substr(str, i, _("<plural>"))) {
|
||||
} else if (is_substr(str, i, _("<plural>"))) {
|
||||
plur_found++;
|
||||
// singular -> drop, plural -> keep
|
||||
size_t start = skip_tag(str, i);
|
||||
size_t end = match_close_tag(str, start);
|
||||
if (singplur == 2 && end != String::npos) {
|
||||
ret += str.substr(start, end - start);
|
||||
size_t end = match_close_tag(str, i);
|
||||
if (end == String::npos) {
|
||||
throw ScriptError(_("<plural> tag found without matching closing tag."));
|
||||
}
|
||||
else if (singplur == 2) {
|
||||
ret += str.substr(start, end - start);
|
||||
singplur = 0;
|
||||
}
|
||||
singplur = 0;
|
||||
i = skip_tag(str, end);
|
||||
} else if (c == _('(') && singplur) {
|
||||
// singular -> drop (...), plural -> keep it
|
||||
@@ -352,6 +362,12 @@ String process_english_hints(const String& str) {
|
||||
ret += c;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (sing_found > plur_found) {
|
||||
throw ScriptError(_("<singular> tag found without matching <plural> tag."));
|
||||
}
|
||||
else if (sing_found < plur_found) {
|
||||
throw ScriptError(_("<plural> tag found without matching <singular> tag."));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -81,28 +81,22 @@ SCRIPT_FUNCTION(set_metadata) {
|
||||
|
||||
SCRIPT_FUNCTION(width_of) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(CardP, card);
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
StyleSheet* stylesheet = card && card->stylesheet ? card->stylesheet.get() : set->stylesheet.get();
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, stylesheet));
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, set, set));
|
||||
SCRIPT_RETURN(image.GetWidth());
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(height_of) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(CardP, card);
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
StyleSheet* stylesheet = card && card->stylesheet ? card->stylesheet.get() : set->stylesheet.get();
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, stylesheet));
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, set, set));
|
||||
SCRIPT_RETURN(image.GetHeight());
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(dimensions_of) {
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_PARAM(CardP, card);
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
StyleSheet* stylesheet = card && card->stylesheet ? card->stylesheet.get() : set->stylesheet.get();
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, stylesheet));
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
Image image = input->generate(GeneratedImage::Options(0, 0, set, set));
|
||||
ScriptCustomCollectionP ret(new ScriptCustomCollection());
|
||||
ret->value.push_back(to_script(image.GetWidth()));
|
||||
ret->value.push_back(to_script(image.GetHeight()));
|
||||
|
||||
Reference in New Issue
Block a user