|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Colony\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use Stu\Lib\ColonyProduction\ColonyProduction; |
|
8
|
|
|
use Stu\Orm\Entity\BuildingInterface; |
|
9
|
|
|
|
|
10
|
|
|
class ColonyProductionPreviewWrapper |
|
11
|
|
|
{ |
|
12
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory; |
|
13
|
|
|
|
|
14
|
|
|
private BuildingInterface $building; |
|
15
|
|
|
|
|
16
|
|
|
/** @var array<ColonyProduction> */ |
|
17
|
|
|
private array $production = []; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param array<ColonyProduction> $production |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct( |
|
23
|
|
|
ColonyLibFactoryInterface $colonyLibFactory, |
|
24
|
|
|
BuildingInterface $building, |
|
25
|
|
|
array $production |
|
26
|
|
|
) { |
|
27
|
|
|
$this->colonyLibFactory = $colonyLibFactory; |
|
28
|
|
|
$this->building = $building; |
|
29
|
|
|
$this->production = $production; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** @return array<ColonyProduction> */ |
|
33
|
|
|
public function getPreview(): array |
|
34
|
|
|
{ |
|
35
|
|
|
$bcommodities = $this->building->getCommodities(); |
|
36
|
|
|
|
|
37
|
|
|
$ret = []; |
|
38
|
|
|
foreach ($bcommodities as $commodityId => $prod) { |
|
39
|
|
|
$commodityId = $prod->getCommodityId(); |
|
40
|
|
|
if (array_key_exists($commodityId, $this->production)) { |
|
41
|
|
|
|
|
42
|
|
|
$ret[$commodityId] = clone $this->production[$commodityId]; |
|
43
|
|
|
$ret[$commodityId]->upperProduction($prod->getAmount()); |
|
44
|
|
|
} else { |
|
45
|
|
|
|
|
46
|
|
|
$obj = $this->colonyLibFactory->createColonyProduction( |
|
47
|
|
|
$prod->getCommodity(), |
|
48
|
|
|
$prod->getAmount() |
|
49
|
|
|
); |
|
50
|
|
|
$ret[$commodityId] = $obj; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$ret[$commodityId]->setPreviewProduction($prod->getAmount()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $ret; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|