Skip to content

Commit

Permalink
Merge pull request #79 from frank9999/improvements
Browse files Browse the repository at this point in the history
Fix army and infrastructure pages
  • Loading branch information
frank9999 committed Jan 22, 2019
2 parents 4832e73 + 75fc2dd commit cbb2dbb
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 115 deletions.
48 changes: 38 additions & 10 deletions src/Controller/Game/HeadquarterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,60 @@

namespace FrankProjects\UltimateWarfare\Controller\Game;

use FrankProjects\UltimateWarfare\Entity\GameUnitType;
use FrankProjects\UltimateWarfare\Repository\GameUnitTypeRepository;
use FrankProjects\UltimateWarfare\Repository\ReportRepository;
use FrankProjects\UltimateWarfare\Repository\WorldRegionUnitRepository;
use Symfony\Component\HttpFoundation\Response;

final class HeadquarterController extends BaseGameController
{
/**
* @var GameUnitTypeRepository
*/
private $gameUnitTypeRepository;

/**
* @var ReportRepository
*/
private $reportRepository;

/**
* ReportController constructor.
* @var WorldRegionUnitRepository
*/
private $worldRegionUnitRepository;

/**
* HeadquarterController constructor.
*
* @param GameUnitTypeRepository $gameUnitTypeRepository
* @param ReportRepository $reportRepository
* @param WorldRegionUnitRepository $worldRegionUnitRepository
*/
public function __construct(
ReportRepository $reportRepository
GameUnitTypeRepository $gameUnitTypeRepository,
ReportRepository $reportRepository,
WorldRegionUnitRepository $worldRegionUnitRepository
) {
$this->gameUnitTypeRepository = $gameUnitTypeRepository;
$this->reportRepository = $reportRepository;
$this->worldRegionUnitRepository = $worldRegionUnitRepository;
}

/**
* XXX TODO: Fix me
*
* @return Response
*/
public function army(): Response
{
$gameUnitTypes = [
$this->gameUnitTypeRepository->find(GameUnitType::GAME_UNIT_TYPE_UNITS),
$this->gameUnitTypeRepository->find(GameUnitType::GAME_UNIT_TYPE_SPECIAL_UNITS)
];

return $this->render('game/headquarter/army.html.twig', [
'player' => $this->getPlayer()
'player' => $this->getPlayer(),
'gameUnitTypes' => $gameUnitTypes,
'gameUnitData' => $this->worldRegionUnitRepository->getGameUnitSumByPlayerAndGameUnitTypes($this->getPlayer(), $gameUnitTypes)
]);
}

Expand All @@ -51,8 +75,6 @@ public function headquarter(): Response
}

/**
* XXX TODO: Fix me
*
* @return Response
*/
public function income(): Response
Expand All @@ -64,14 +86,20 @@ public function income(): Response
}

/**
* XXX TODO: Fix me
*
* @return Response
*/
public function infrastructure(): Response
{
$gameUnitTypes = [
$this->gameUnitTypeRepository->find(GameUnitType::GAME_UNIT_TYPE_BUILDINGS),
$this->gameUnitTypeRepository->find(GameUnitType::GAME_UNIT_TYPE_DEFENCE_BUILDINGS),
$this->gameUnitTypeRepository->find(GameUnitType::GAME_UNIT_TYPE_SPECIAL_BUILDINGS)
];

return $this->render('game/headquarter/infrastructure.html.twig', [
'player' => $this->getPlayer()
'player' => $this->getPlayer(),
'gameUnitTypes' => $gameUnitTypes,
'gameUnitData' => $this->worldRegionUnitRepository->getGameUnitSumByPlayerAndGameUnitTypes($this->getPlayer(), $gameUnitTypes)
]);
}
}
6 changes: 6 additions & 0 deletions src/Entity/GameUnitType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
*/
class GameUnitType
{
const GAME_UNIT_TYPE_BUILDINGS = 1;
const GAME_UNIT_TYPE_DEFENCE_BUILDINGS = 2;
const GAME_UNIT_TYPE_SPECIAL_BUILDINGS = 3;
const GAME_UNIT_TYPE_UNITS = 4;
const GAME_UNIT_TYPE_SPECIAL_UNITS = 5;

/**
* @var int
*/
Expand Down
28 changes: 28 additions & 0 deletions src/Repository/Doctrine/DoctrineWorldRegionUnitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use FrankProjects\UltimateWarfare\Entity\GameUnitType;
use FrankProjects\UltimateWarfare\Entity\Player;
use FrankProjects\UltimateWarfare\Entity\WorldRegionUnit;
use FrankProjects\UltimateWarfare\Repository\WorldRegionUnitRepository;
Expand Down Expand Up @@ -58,6 +59,33 @@ public function findAmountAndNetworthByPlayer(Player $player): array
)->getResult();
}

/**
* @param Player $player
* @param GameUnitType[] $gameUnitTypes
* @return array
*/
public function getGameUnitSumByPlayerAndGameUnitTypes(Player $player, array $gameUnitTypes): array
{
$results = $this->entityManager
->createQuery(
'SELECT gu.id, sum(wru.amount) as total
FROM Game:WorldRegionUnit wru
JOIN Game:WorldRegion wr WITH wru.worldRegion = wr
JOIN Game:GameUnit gu WITH wru.gameUnit = gu
WHERE wr.player = :player AND gu.gameUnitType IN (:gameUnitTypes)
GROUP BY gu.id'
)->setParameter('player', $player)
->setParameter('gameUnitTypes', $gameUnitTypes)
->getArrayResult();

$gameUnits = [];
foreach ($results as $result) {
$gameUnits[$result['id']] = $result['total'];
}

return $gameUnits;
}

/**
* @param WorldRegionUnit $worldRegionUnit
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Repository/WorldRegionUnitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FrankProjects\UltimateWarfare\Repository;

use FrankProjects\UltimateWarfare\Entity\GameUnitType;
use FrankProjects\UltimateWarfare\Entity\Player;
use FrankProjects\UltimateWarfare\Entity\WorldRegionUnit;

Expand All @@ -21,6 +22,13 @@ public function find(int $id): ?WorldRegionUnit;
*/
public function findAmountAndNetworthByPlayer(Player $player): array;

/**
* @param Player $player
* @param GameUnitType[] $gameUnitTypes
* @return array
*/
public function getGameUnitSumByPlayerAndGameUnitTypes(Player $player, array $gameUnitTypes): array;

/**
* @param WorldRegionUnit $worldRegionUnit
*/
Expand Down
77 changes: 25 additions & 52 deletions templates/game/headquarter/army.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,31 @@

<table class="table text-center">
<tr>
<td class="tabletop" colspan="4"><b>Army</b></td>
</tr>
<tr>
<td width="350" colspan="2" class="tabletop"><b>Units</b></td>
<td width="350" colspan="2" class="tabletop"><b>Special ops</b></td>
</tr>
<tr>
<td width="200"> Soldiers:</td>
<td width="150"></td>
<td width="200"> Guards:</td>
<td width="150"></td>
</tr>
<tr>
<td width="200"> Tanks:</td>
<td width="150"></td>
<td width="200"> Special ops:</td>
<td width="150"></td>
</tr>
<tr>
<td width="200"> Airplanes:</td>
<td width="150"></td>
<td width="200"> Snipers:</td>
<td width="150"></td>
</tr>
<tr>
<td width="200"> Ships:</td>
<td width="150"></td>
<td width="200"> Submarines:</td>
<td width="150"></td>
</tr>
<tr>
<td width="200"> Minesweepers:</td>
<td width="150"></td>
<td width="200"> Stealth bombers:</td>
<td width="150"></td>
</tr>
<tr>
<td width="350" colspan="2" rowspan="4"></td>
<td width="200"> Rockets:</td>
<td width="150"></td>
</tr>
<tr>
<td width="200"> Chemical rockets:</td>
<td width="150"></td>
</tr>
<tr>
<td width="200"> Spies:</td>
<td width="150"></td>
</tr>
<tr>
<td width="200"> Nuclear Missiles:</td>
<td width="150"></td>
<td class="tabletop" colspan="2"><b>Army</b></td>
</tr>
{% for gameUnitType in gameUnitTypes %}
<tr>
<td colspan="2" class="tabletop"><b>{{ gameUnitType.name }}</b></td>
</tr>

{% set gameUnitTypeExist = 0 %}
{% for gameUnit in gameUnitType.gameUnits %}
{% if gameUnitData[gameUnit.id] is defined and gameUnitData[gameUnit.id] > 0 %}
{% set gameUnitTypeExist = 1 %}
<tr>
<td width="350">{{ gameUnit.nameMulti }}:</td>
<td width="350">
{{ gameUnitData[gameUnit.id] }}
</td>
</tr>
{% endif %}
{% endfor %}

{% if gameUnitTypeExist == 0 %}
<tr>
<td colspan="2">You don't have any {{ gameUnitType.name }}</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% endblock %}
76 changes: 23 additions & 53 deletions templates/game/headquarter/infrastructure.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,29 @@
<tr>
<td class="tabletop" colspan="4"><b>Infrastructure</b></td>
</tr>
<tr>
<td width="350" colspan="2" class="tabletop"><b>Buildings</b></td>
<td width="350" colspan="2" class="tabletop"><b>Defences</b></td>
</tr>
<tr>
<td width="200"> Economic Centers:</td>
<td width="150">
</td>
<td width="200"> Land Mines:</td><td width="150">
</td>
</tr>
<tr>
<td width="200"> Farms:</td><td width="150">
</td>
<td width="200"> Sea Mines:</td><td width="150">
</td>
</tr>
<tr>
<td width="200"> Mines:</td><td width="150">
</td>
<td width="200"> Bunkers:</td><td width="150">
</td>
</tr>
<tr>
<td width="200"> Woodcutters:</td><td width="150">
</td>
<td width="200"> Anti Air Missiles:</td><td width="150">
</td>
</tr>
<tr>
<td width="200"> Houses:</td><td width="150">
</td>
<td width="350" colspan="2"></td>
</td>
</tr>
{% for gameUnitType in gameUnitTypes %}
<tr>
<td colspan="2" class="tabletop"><b>{{ gameUnitType.name }}</b></td>
</tr>

<tr>
<td width="350" colspan="2" class="tabletop"><b>Special Buildings</b></td>
<td width="350" colspan="2" class="tabletop"></td>
</tr>
<tr>
<td width="200"> Airports:</td>
<td width="150">
</td>
<td width="350" colspan="2" rowspan="3"></td>
</tr>
<tr>
<td width="200"> Harbors:</td><td width="150">
</td>
</tr>
<tr>
<td width="200"> Train Stations:</td><td width="150">
</td>
</tr>
{% set gameUnitTypeExist = 0 %}
{% for gameUnit in gameUnitType.gameUnits %}
{% if gameUnitData[gameUnit.id] is defined and gameUnitData[gameUnit.id] > 0 %}
{% set gameUnitTypeExist = 1 %}
<tr>
<td width="350">{{ gameUnit.nameMulti }}:</td>
<td width="350">
{{ gameUnitData[gameUnit.id] }}
</td>
</tr>
{% endif %}
{% endfor %}

{% if gameUnitTypeExist == 0 %}
<tr>
<td colspan="2">You don't have any {{ gameUnitType.name }}</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% endblock %}

0 comments on commit cbb2dbb

Please sign in to comment.