Skip to content

Commit

Permalink
GH-230 Move combat stats to own component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 17, 2022
1 parent d46de52 commit ce3c8f3
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 50 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php');
include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php');
include($includePath . './screens/Overview/components/CombatStatsList/CombatStatsList.component.php');
include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php');
include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php');
include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\CombatStatsList;

/**
* @param array $props
* @param array $props['stats']
*/
function render($props) {
global $_Lang;

$stats = $props['stats'];

$localTemplateLoader = createLocalTemplateLoader(__DIR__);
$tplBodyCache = [
'body' => $localTemplateLoader('body'),
'statCategoryRow' => $localTemplateLoader('statCategoryRow'),
];

$categories = [
'allBattles' => [
'label' => $_Lang['Box_battlesAll'],
'statsTableKeys' => [
'ustat_raids_won',
'ustat_raids_draw',
'ustat_raids_lost',
'ustat_raids_inAlly',
],
],
'battlesWon' => [
'label' => $_Lang['Box_battlesWon'],
'statsTableKeys' => [
'ustat_raids_won',
],
],
'battlesWonUnited' => [
'label' => $_Lang['Box_battlesACSWon'],
'statsTableKeys' => [
'ustat_raids_acs_won',
],
'colorClass' => 'orange',
],
'battlesDrawn' => [
'label' => $_Lang['Box_battlesDraw'],
'statsTableKeys' => [
'ustat_raids_draw',
],
],
'battlesLost' => [
'label' => $_Lang['Box_battlesLost'],
'statsTableKeys' => [
'ustat_raids_lost',
],
],
'battlesInAlly' => [
'label' => $_Lang['Box_battlesInAlly'],
'statsTableKeys' => [
'ustat_raids_inAlly',
],
],
'missileStrikes' => [
'label' => $_Lang['Box_missileAttacks'],
'statsTableKeys' => [
'ustat_raids_missileAttack',
],
],
];

$categoriesHTML = [];

foreach ($categories as $categoryKey => $category) {
$categorySubValues = array_map_withkeys($category['statsTableKeys'], function ($key) use ($stats) {
return $stats[$key];
});
$categoryTotalValue = array_sum($categorySubValues);

$categoryTplBodyParams = [
'statCategoryColorClass' => (
!empty($category['colorClass']) ?
$category['colorClass'] :
''
),
'statCategoryLabel' => $category['label'],
'statCategoryValue' => prettyNumber($categoryTotalValue),
];

$categoriesHTML[$categoryKey] = parsetemplate(
$tplBodyCache['statCategoryRow'],
$categoryTplBodyParams
);
}

$tplBodyParams = [
'categoryRow_allBattles' => $categoriesHTML['allBattles'],
'categoryRow_battlesWon' => $categoriesHTML['battlesWon'],
'categoryRow_battlesWonUnited' => $categoriesHTML['battlesWonUnited'],
'categoryRow_battlesDrawn' => $categoriesHTML['battlesDrawn'],
'categoryRow_battlesLost' => $categoriesHTML['battlesLost'],
'categoryRow_battlesInAlly' => $categoriesHTML['battlesInAlly'],
'categoryRow_missileStrikes' => $categoriesHTML['missileStrikes'],
];
$tplBodyParams = array_merge($_Lang, $tplBodyParams);

$componentHTML = parsetemplate(
$tplBodyCache['body'],
$tplBodyParams
);

return [
'componentHTML' => $componentHTML,
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<table width="100%" align="center">
<tr>
<td colspan="2" class="c pad3">{YourBattles}</td>
</tr>
{categoryRow_allBattles}
<tr>
<th class="invNF">&nbsp;</th>
</tr>
{categoryRow_battlesWon}
{categoryRow_battlesWonUnited}
{categoryRow_battlesDrawn}
{categoryRow_battlesLost}
{categoryRow_battlesInAlly}
<tr>
<th class="invNF">&nbsp;</th>
</tr>
{categoryRow_missileStrikes}
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<tr>
<th class="{statCategoryColorClass}">{statCategoryLabel}</th>
<th>{statCategoryValue}</th>
</tr>
17 changes: 6 additions & 11 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,17 @@
$parse['RefferedCounter'] = prettyNumber((($Referred['count'] > 0) ? $Referred['count'] : '0'));

// --- Render UserStats ---
$GetStats_Fields = '`ustat_raids_won`, `ustat_raids_draw`, `ustat_raids_lost`, `ustat_raids_acs_won`, `ustat_raids_inAlly`, `ustat_raids_missileAttack`';

$StatRecord = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `id_owner` = {$_User['id']} LIMIT 1;", 'statpoints', true);
$GetStats = doquery("SELECT {$GetStats_Fields} FROM {{table}} WHERE `A_UserID` = {$_User['id']} LIMIT 1;", 'achievements_stats', true);

$parse['Component_StatsList'] = Overview\Screens\Overview\Components\StatsList\render([
'stats' => $StatRecord,
])['componentHTML'];

// Get User Achievements
$GetStats_Fields = '`ustat_raids_won`, `ustat_raids_draw`, `ustat_raids_lost`, `ustat_raids_acs_won`, `ustat_raids_inAlly`, `ustat_raids_missileAttack`';
$GetStats = doquery("SELECT {$GetStats_Fields} FROM {{table}} WHERE `A_UserID` = {$_User['id']} LIMIT 1;", 'achievements_stats', true);
$parse['raids'] = prettyNumber($GetStats['ustat_raids_won'] + $GetStats['ustat_raids_draw'] + $GetStats['ustat_raids_lost'] + $GetStats['ustat_raids_inAlly']);
$parse['raidswin'] = prettyNumber($GetStats['ustat_raids_won']);
$parse['raidsdraw'] = prettyNumber($GetStats['ustat_raids_draw']);
$parse['raidsloose'] = prettyNumber($GetStats['ustat_raids_lost']);
$parse['raidacswin'] = prettyNumber($GetStats['ustat_raids_acs_won']);
$parse['raidsinally'] = prettyNumber($GetStats['ustat_raids_inAlly']);
$parse['raidsmissileattacks'] = prettyNumber($GetStats['ustat_raids_missileAttack']);
$parse['Component_CombatStatsList'] = Overview\Screens\Overview\Components\CombatStatsList\render([
'stats' => $GetStats,
])['componentHTML'];

// --- Planet Data ---------
if($_Planet['planet_type'] == 1)
Expand Down
40 changes: 1 addition & 39 deletions templates/default_template/overview_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -158,45 +158,7 @@ $(document).ready(function()
<th width="215">
{Component_StatsList}
<br/>
<table width="100%" align="center">
<tr>
<td colspan="2" class="c pad3">{YourBattles}</td>
</tr>
<tr>
<th>{Box_battlesAll}</th>
<th>{raids}</th>
</tr>
<tr>
<th class="invNF">&nbsp;</th>
</tr>
<tr>
<th>{Box_battlesWon}</th>
<th>{raidswin}</th>
</tr>
<tr>
<th class="orange">{Box_battlesACSWon}</th>
<th>{raidacswin}</th>
</tr>
<tr>
<th>{Box_battlesDraw}</th>
<th>{raidsdraw}</th>
</tr>
<tr>
<th>{Box_battlesLost}</th>
<th>{raidsloose}</th>
</tr>
<tr>
<th>{Box_battlesInAlly}</th>
<th>{raidsinally}</th>
</tr>
<tr>
<th class="invNF">&nbsp;</th>
</tr>
<tr>
<th>{Box_missileAttacks}</th>
<th>{raidsmissileattacks}</th>
</tr>
</table>
{Component_CombatStatsList}
</th>
</tr>
<tr style="visibility: none;"><td></td></tr>
Expand Down

0 comments on commit ce3c8f3

Please sign in to comment.