* added min() and max() funcions for parsing SpellTooltips

* fixed error, when creating ItemTooltips for certain recipes
* fixed logic error when generating jsGlobals and id-array was empty
This commit is contained in:
Sarjuuk
2013-08-21 09:18:49 +02:00
parent 73cdce784e
commit 8ffbf13e03
3 changed files with 28 additions and 19 deletions

View File

@@ -675,25 +675,31 @@ class ItemList extends BaseType
// recipe handling (some stray Techniques have subclass == 0), place at bottom of tooltipp
if ($this->curTpl['class'] == ITEM_CLASS_RECIPE && ($this->curTpl['subclass'] || $this->curTpl['BagFamily'] == 16))
{
$craftSpell = new SpellList(array(['s.id', (int)$this->curTpl['spellid_2']]));
$craftItem = new ItemList(array(['i.entry', (int)$craftSpell->curTpl["effect1CreateItemId"]]));
$reagentItems = [];
$spell = $this->curTpl['spellid_1'] == 483 ? (int)$this->curTpl['spellid_2'] : (int)$this->curTpl['spellid_1'];
$craftSpell = new SpellList(array(['s.id', $spell]));
$craftItem = new ItemList(array(['i.entry', (int)$craftSpell->curTpl['effect1CreateItemId']]));
if ($desc = $this->getField('description', true))
$x .= '<span class="q2">'.Lang::$item['trigger'][0].' <a href="?spell='.$spell.'">'.$desc.'</a></span><br />';
if ($itemTT = $craftItem->renderTooltip(null, $interactive))
$xCraft = '<div><br />'.$itemTT.'</div>';
$reagentItems = [];
for ($i = 1; $i <= 8; $i++)
if ($rId = $craftSpell->getField('reagent'.$i))
$reagentItems[$rId] = $craftSpell->getField('reagentCount'.$i);
if (isset($xCraft) && $reagentItems)
{
$reagents = new ItemList(array(['i.entry', array_keys($reagentItems)]));
$reqReag = [];
$x .= '<span class="q2">'.Lang::$item['trigger'][0].' <a href="?spell='.$this->curTpl['spellid_2'].'">'.$this->getField('description', true).'</a></span><br />';
$xCraft = '<div><br />'.$craftItem->renderTooltip(null, $interactive).'</div><br />';
foreach ($reagents->iterate() as $__)
$reqReag[] = '<a href="?item='.$reagents->id.'">'.$reagents->getField('name', true).'</a> ('.$reagentItems[$reagents->id].')';
$xCraft .= '<span class="q1">'.Lang::$game['requires2']." ".implode(", ", $reqReag).'</span>';
$xCraft .= '<br /><span class="q1">'.Lang::$game['requires2'].' '.implode(', ', $reqReag).'</span>';
}
}

View File

@@ -501,6 +501,8 @@ class SpellList extends BaseType
$gt = $GT = function($a, $b) { return $a > $b; };
$gte = $GTE = function($a, $b) { return $a <= $b; };
$floor = $FLOOR = function($a) { return floor($a); };
$max = $MAX = function($a, $b) { return max($a, $b); };
$min = $MIN = function($a, $b) { return min($a, $b); };
if (preg_match_all('/\$[a-z]+\b/i', $formula, $vars))
{
@@ -526,6 +528,8 @@ class SpellList extends BaseType
$gt = $GT = !$this->interactive ? 'GT' : sprintf(Util::$dfnString, 'GT(<span class=\'q1\'>a</span>, <span class=\'q1\'>b</span>)<br /> <span class=\'q1\'>a</span> > <span class=\'q1\'>b</span>', 'GT');
$gte = $GTE = !$this->interactive ? 'GTE' : sprintf(Util::$dfnString, 'GTE(<span class=\'q1\'>a</span>, <span class=\'q1\'>b</span>)<br /> <span class=\'q1\'>a</span> <= <span class=\'q1\'>b</span>', 'GT');
$floor = $FLOOR = !$this->interactive ? 'FLOOR' : sprintf(Util::$dfnString, 'FLOOR(<span class=\'q1\'>a</span>)', 'FLOOR');
$min = $MIN = !$this->interactive ? 'MIN' : sprintf(Util::$dfnString, 'MIN(<span class=\'q1\'>a</span>, <span class=\'q1\'>b</span>)', 'MIN');
$max = $MAX = !$this->interactive ? 'MAX' : sprintf(Util::$dfnString, 'MAX(<span class=\'q1\'>a</span>, <span class=\'q1\'>b</span>)', 'MAX');
$pl = $PL = !$this->interactive ? 'PL' : sprintf(Util::$dfnString, 'LANG.level', 'PL');
// note the " !

View File

@@ -172,8 +172,7 @@ abstract class BaseType
foreach ($rows as $k => $tpl)
$this->templates[$k] = $tpl;
$this->curTpl = reset($this->templates);
$this->id = key($this->templates);
$this->reset(); // push first element for instant use
$this->error = false;
}
@@ -198,7 +197,7 @@ abstract class BaseType
protected function reset()
{
unset($this->curTpl); // kill reference or it will 'bleed' into the next iteration
unset($this->curTpl); // kill reference or strange stuff will happen
$this->curTpl = reset($this->templates);
$this->id = key($this->templates);
}
@@ -785,15 +784,15 @@ class SmartyAoWoW extends Smarty
{
foreach ($this->jsGlobals as $type => $ids)
{
foreach ($ids as $k => $id) // filter already generated data, maybe we can save a lookup or two
if (isset($this->_tpl_vars['jsGlobals'][$type][1][$id]))
unset($ids[$k]);
if (!$ids)
continue;
$this->initJSGlobal($type);
foreach ($ids as $k => $id) // filter already generated data, maybe we can save a lookup or two
if (isset($this->_tpl_vars['jsGlobals'][$type][1][$id]))
unset($ids[$k]);
switch ($type)
{
case TYPE_NPC: (new CreatureList(array(['ct.entry', $ids], 0)))->addGlobalsToJscript($this, GLOBALINFO_SELF); break;