minor beautifications for compare

This commit is contained in:
Sarjuuk
2013-01-20 00:06:34 +01:00
parent e67d0a3dae
commit faabdee2a6
3 changed files with 51 additions and 47 deletions

View File

@@ -7,11 +7,9 @@ require_once('includes/class.item.php');
require_once('includes/class.spell.php'); require_once('includes/class.spell.php');
require_once('includes/class.faction.php'); // items may require a faction to use/own require_once('includes/class.faction.php'); // items may require a faction to use/own
// prefer $_GET over $_COOKIE
$compareString = '';
$doneSummary = '';
$pageData['items'] = array(); $pageData['items'] = array();
// prefer $_GET over $_COOKIE
if (!empty($_GET['compare'])) if (!empty($_GET['compare']))
$compareString = $_GET['compare']; $compareString = $_GET['compare'];
else if (!empty($_COOKIE['compare_groups'])) else if (!empty($_COOKIE['compare_groups']))
@@ -19,7 +17,7 @@ else if (!empty($_COOKIE['compare_groups']))
if ($compareString) if ($compareString)
{ {
$sets = explode(";", $compareString); $sets = explode(";", $compareString);
$items = array(); $items = array();
foreach ($sets as $set) foreach ($sets as $set)
{ {
@@ -27,10 +25,10 @@ if ($compareString)
$outString = array(); $outString = array();
foreach ($itemsting as $substring) foreach ($itemsting as $substring)
{ {
$params = explode(".", $substring); $params = explode(".", $substring);
$items[] = (int)$params[0]; $items[] = (int)$params[0];
while (sizeof($params) < 7) while (sizeof($params) < 7)
$params[] = 0; $params[] = 0;
$outString[] = "[".implode(',', $params)."]"; $outString[] = "[".implode(',', $params)."]";
@@ -47,7 +45,7 @@ if ($compareString)
} }
$outSet[] = "[".implode(',', $outString)."]"; $outSet[] = "[".implode(',', $outString)."]";
} }
$doneSummary = implode(',', $outSet); $pageData['summary'] = "[".implode(',', $outSet)."]";
$iList = new ItemList(array(['i.entry', $items])); $iList = new ItemList(array(['i.entry', $items]));
foreach ($iList->container as $item) foreach ($iList->container as $item)
@@ -55,18 +53,22 @@ if ($compareString)
$item->getJsonStats(); $item->getJsonStats();
$stats = array(); $stats = array();
foreach ($item->json as $k => $v) foreach ($item->json as $k => $v)
$stats[] = is_numeric($v) || $v[0] == "{" ? '"'.$k.'":'.$v.'' : '"'.$k.'":"'.$v.'"'; $stats[] = is_numeric($v) || $v[0] == "{" ? '"'.$k.'":'.$v.'' : '"'.$k.'":"'.$v.'"';
foreach ($item->itemMods as $k => $v) foreach ($item->itemMods as $k => $v)
if ($v) if ($v)
$stats[] = '"'.Util::$itemMods[$k].'":'.$v; $stats[] = '"'.Util::$itemMods[$k].'":'.$v;
$pageData['items'][] = "g_items.add(".$item->json['id'].", {name_".User::$localeString.":'".Util::jsEscape(Util::localizedString($item->template, 'name'))."', quality:".$item->template['Quality'].", icon:'".$item->template['icon']."', jsonequip:{".implode(",", $stats)."}});"; $pageData['items'][] = [
$item->Id,
Util::jsEscape(Util::localizedString($item->template, 'name')),
$item->template['Quality'],
$item->template['icon'],
"{".implode(",", $stats)."}"
];
} }
} }
$pageData['summary'] = "new Summary({template:'compare',id:'compare',parent:'compare-generic',groups:[".$doneSummary."]});";
// Announcements // Announcements
$announcements = DB::Aowow()->Select('SELECT * FROM ?_announcements WHERE flags & 0x10 AND (page = "compare" OR page = "*")'); $announcements = DB::Aowow()->Select('SELECT * FROM ?_announcements WHERE flags & 0x10 AND (page = "compare" OR page = "*")');
foreach ($announcements as $k => $v) foreach ($announcements as $k => $v)

View File

@@ -1,17 +1,18 @@
{math equation="abs(x)" x=$an.Id assign="pId"} {strip}
{math equation="(x & 0xF)" x=$an.flags assign="mode"} {math equation="abs(x)" x=$an.Id assign="pId"}
{math equation="(x & 0xF0) >> 4" x=$an.flags assign="status"} {math equation="(x & 0xF)" x=$an.flags assign="mode"}
{math equation="(x & 0xF00) >> 8" x=$an.flags assign="jsVar"} {math equation="(x & 0xF0) >> 4" x=$an.flags assign="status"}
{math equation="(x & 0xF00) >> 8" x=$an.flags assign="jsVar"}
<div id="announcement-{$pId}"></div> {/strip}
<script type="text/javascript"> <div id="announcement-{$pId}"></div>
new Announcement({ldelim} <script type="text/javascript">
parent: 'announcement-{$pId}', new Announcement({ldelim}
id: {$an.Id}, parent: 'announcement-{$pId}',
text: {if $jsVar}{$an.text}{else}'{$an.text}'{/if}, id: {$an.Id},
name: '{$an.name}', text: {if $jsVar}{$an.text}{else}'{$an.text}'{/if},
style: '{$an.style}', name: '{$an.name}',
status: {$status}, style: '{$an.style}',
mode: {$mode} status: {$status},
{rdelim}); mode: {$mode}
</script> {rdelim});
</script>

View File

@@ -1,25 +1,26 @@
{include file='header.tpl'} {include file='header.tpl'}
<div id="main"> <div id="main">
<div id="main-precontents"></div> <div id="main-precontents"></div>
<div id="main-contents" class="main-contents"> <div id="main-contents" class="main-contents">
{if !empty($announcements)} {if !empty($announcements)}
{foreach from=$announcements item=item} {foreach from=$announcements item=item}
{include file='bricks/announcement.tpl' an=$item} {include file='bricks/announcement.tpl' an=$item}
{/foreach} {/foreach}
{/if} {/if}
<script type="text/javascript">g_initPath([1,3])</script>
<div class="text"> <script type="text/javascript">g_initPath([1,3])</script>
<div id="compare-generic"></div> <div class="text">
<script type="text/javascript">//<![CDATA[ <div id="compare-generic"></div>
{foreach name=cmpItems from=$data.items item=curr} <script type="text/javascript">//<![CDATA[
{$curr} {foreach name=cmpItems from=$data.items item=curr}
{/foreach} g_items.add({$curr[0]}, {ldelim}name_{$user.language}:'{$curr[1]}', quality:{$curr[2]}, icon:'{$curr[3]}', jsonequip:{$curr[4]}{rdelim});
{$data.summary} {/foreach}
//]]></script> new Summary({ldelim}template:'compare',id:'compare',parent:'compare-generic',groups:{$data.summary}{rdelim});
//]]></script>
</div>
<div class="clear"></div>
</div> </div>
<div class="clear"></div>
</div> </div>
</div>
{include file='footer.tpl'} {include file='footer.tpl'}