Spells/PageTexts

* fixed numeric & gender switch for russian locale
 * treat $| like a $l-switch (only one case iirc)
 * remived output for unhandled text variables
 * fixed display of pageText for items
This commit is contained in:
Sarjuuk
2016-10-04 21:09:19 +02:00
parent 568677ff32
commit e2ab00b4ba
2 changed files with 41 additions and 11 deletions

View File

@@ -1147,7 +1147,7 @@ class SpellList extends BaseType
if ($formula[$pos] == '$')
$pos++;
if (!preg_match('/^(([\+\-\*\/])(\d+);)?(\d*)(([g])([\w\s]*:[\w\s]*);|([a-z])([123]?)\b)/i', substr($formula, $pos), $result))
if (!preg_match('/^(([\+\-\*\/])(\d+);)?(\d*)(([lg])([^:]*:[^;]*);|([a-z])([123]?)\b)/i', substr($formula, $pos), $result))
{
$str .= '#'; // mark as done, reset below
continue;
@@ -1325,10 +1325,43 @@ class SpellList extends BaseType
$data = $this->handleVariables($data, $scaling, true);
// step 5: variable-dependant variable-text
// special case $lONE:ELSE;
// todo (low): russian uses THREE (wtf?! oO) cases ($l[singular]:[plural1]:[plural2]) .. explode() chooses always the first plural option :/
while (preg_match('/([\d\.]+)([^\d]*)(\$l:*)([^:]*):([^;]*);/i', $data, $m))
$data = str_ireplace($m[1].$m[2].$m[3].$m[4].':'.$m[5].';', $m[1].$m[2].($m[1] == 1 ? $m[4] : explode(':', $m[5])[0]), $data);
// special case $lONE:ELSE[:ELSE2]; or $|ONE:ELSE[:ELSE2];
while (preg_match('/([\d\.]+)([^\d]*)(\$[l|]:*)([^:]*):([^;]*);/i', $data, $m))
{
$plurals = explode(':', $m[5]);
$replace = '';
if (count($plurals) == 2) // special case: ruRU
{
switch (substr($m[1], -1)) // check last digit of number
{
case 1:
// but not 11 (teen number)
if (!in_array($m[1], [11]))
{
$replace = $m[4];
break;
}
case 2:
case 3:
case 4:
// but not 12, 13, 14 (teen number) [11 is passthrough]
if (!in_array($m[1], [11, 12, 13, 14]))
{
$replace = $plurals[0];
break;
}
break;
default:
$replace = $plurals[1];
}
}
else
$replace = ($m[1] == 1 ? $m[4] : $plurals[0]);
$data = str_ireplace($m[1].$m[2].$m[3].$m[4].':'.$m[5].';', $m[1].$m[2].$replace, $data);
}
// step 6: HTMLize
// colors
@@ -1408,8 +1441,8 @@ class SpellList extends BaseType
if ($data[$pos] == '$')
$pos++;
// ( (op) (oparg); )? (refSpell) ( ([g]ifText:elseText; | (var) (effIdx) )
if (!preg_match('/^(([\+\-\*\/])(\d+);)?(\d*)(([g])([\w\s]*:[\w\s]*);|([a-z])([123]?)\b)/i', substr($data, $pos), $result))
// ( (op) (oparg); )? (refSpell) ( ([lg]ifText:elseText; | (var) (effIdx) )
if (!preg_match('/^(([\+\-\*\/])(\d+);)?(\d*)(([lg])([^:]*:[^;]*);|([a-z])([123]?)\b)/i', substr($data, $pos), $result))
{
$str .= '#'; // mark as done, reset below
continue;
@@ -1436,9 +1469,6 @@ class SpellList extends BaseType
$resolved .= isset($var[3]) ? sprintf($var[3], $_) : $_;
}
if ($var[0] === null && $topLevel) // {Unknown}
$resolved .= '{'.Lang::game('sources', 0).'}';
$str .= $resolved;
}
$str .= substr($data, $pos);

View File

@@ -337,7 +337,7 @@ class ItemPage extends genericPage
if ($row = DB::World()->selectRow('SELECT *, Text as Text_loc0 FROM page_text pt LEFT JOIN locales_page_text lpt ON pt.ID = lpt.entry WHERE pt.ID = ?d', $next))
{
$next = $row['NextPageID'];
$pageText = Util::parseHtmlText(Util::localizedString($row, 'Text'));
$pageText[] = Util::parseHtmlText(Util::localizedString($row, 'Text'));
}
else
{