1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Colony\Lib\Gui\Component; |
4
|
|
|
|
5
|
|
|
use Stu\Lib\Colony\PlanetFieldHostInterface; |
6
|
|
|
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface; |
7
|
|
|
use Stu\Module\Commodity\CommodityTypeEnum; |
8
|
|
|
use Stu\Module\Commodity\Lib\CommodityCacheInterface; |
9
|
|
|
use Stu\Module\Control\GameControllerInterface; |
10
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
11
|
|
|
|
12
|
|
|
final class EffectsProvider implements GuiComponentProviderInterface |
13
|
|
|
{ |
14
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory; |
15
|
|
|
|
16
|
|
|
private CommodityCacheInterface $commodityCache; |
17
|
|
|
|
18
|
|
|
public function __construct( |
19
|
|
|
ColonyLibFactoryInterface $colonyLibFactory, |
20
|
|
|
CommodityCacheInterface $commodityCache |
21
|
|
|
) { |
22
|
|
|
$this->colonyLibFactory = $colonyLibFactory; |
23
|
|
|
$this->commodityCache = $commodityCache; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function setTemplateVariables( |
27
|
|
|
PlanetFieldHostInterface $host, |
28
|
|
|
GameControllerInterface $game |
29
|
|
|
): void { |
30
|
|
|
$commodities = $this->commodityCache->getAll(CommodityTypeEnum::COMMODITY_TYPE_EFFECT); |
31
|
|
|
$depositMinings = $host instanceof ColonyInterface ? $host->getUserDepositMinings() : []; |
32
|
|
|
$prod = $this->colonyLibFactory->createColonyCommodityProduction($host)->getProduction(); |
33
|
|
|
|
34
|
|
|
$effects = []; |
35
|
|
|
foreach ($commodities as $value) { |
36
|
|
|
$commodityId = $value->getId(); |
37
|
|
|
|
38
|
|
|
//skip deposit effects on asteroid |
39
|
|
|
if (array_key_exists($commodityId, $depositMinings)) { |
40
|
|
|
continue; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if (!array_key_exists($commodityId, $prod) || $prod[$commodityId]->getProduction() == 0) { |
44
|
|
|
continue; |
45
|
|
|
} |
46
|
|
|
$effects[$commodityId]['commodity'] = $value; |
47
|
|
|
$effects[$commodityId]['production'] = $prod[$commodityId]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$game->setTemplateVar('EFFECTS', $effects); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|