Passed
Push — master ( 0a90eb...366c47 )
by Nico
23:43
created

WarpDriveSystemData::getWarpDriveStatusBarBig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Ship\System\Data;
6
7
use Stu\Component\Ship\System\ShipSystemTypeEnum;
8
use Stu\Module\Tal\StatusBarColorEnum;
9
use Stu\Orm\Repository\ShipSystemRepositoryInterface;
10
11
class WarpDriveSystemData extends AbstractSystemData
12
{
13
    // warpdrive fields
14
    public int $wd = 0;
15
    public int $maxwd = 0;
16
    public int $split = 100;
17
    public bool $autoCarryOver = false;
18
19
    private ShipSystemRepositoryInterface $shipSystemRepository;
20
21
    public function __construct(ShipSystemRepositoryInterface $shipSystemRepository)
22
    {
23
        $this->shipSystemRepository = $shipSystemRepository;
24
    }
25
26
    public function update(): void
27
    {
28
        // Überprüfe und begrenze den Wert zwischen 0 und 100
29
        $this->split = max(0, min(100, $this->split));
30
31
        $this->updateSystemData(
32
            ShipSystemTypeEnum::SYSTEM_WARPDRIVE,
33
            $this,
34
            $this->shipSystemRepository
35
        );
36
    }
37
38
    public function getWarpDrive(): int
39
    {
40
        return $this->wd;
41
    }
42
43
    public function setWarpDrive(int $wd): WarpDriveSystemData
44
    {
45
        $this->wd = $wd;
46
        return $this;
47
    }
48
49
    public function lowerWarpDrive(int $amount): WarpDriveSystemData
50
    {
51
        $this->wd -= $amount;
52
        return $this;
53
    }
54
55
    public function setMaxWarpDrive(int $maxwd): WarpDriveSystemData
56
    {
57
        $this->maxwd = $maxwd;
58
        return $this;
59
    }
60
61
    public function getTheoreticalMaxWarpdrive(): int
62
    {
63
        return $this->maxwd;
64
    }
65
66
    /**
67
     * proportional to warpdrive system status
68
     */
69
    public function getMaxWarpDrive(): int
70
    {
71
        return (int) (ceil($this->maxwd
72
            * $this->ship->getShipSystem(ShipSystemTypeEnum::SYSTEM_WARPDRIVE)->getStatus() / 100));
73
    }
74
75
    public function getWarpDriveSplit(): int
76
    {
77
        return $this->split;
78
    }
79
80
    public function setWarpDriveSplit(int $split): WarpDriveSystemData
81
    {
82
        $this->split = $split;
83
        return $this;
84
    }
85
86
    public function getAutoCarryOver(): bool
87
    {
88
        return $this->autoCarryOver;
89
    }
90
91
    public function setAutoCarryOver(bool $autoCarryOver): WarpDriveSystemData
92
    {
93
        $this->autoCarryOver = $autoCarryOver;
94
        return $this;
95
    }
96
97
    public function getWarpDriveStatusBar(): string
98
    {
99
        return $this->getTalStatusBar(
100
            _('Warpantrieb'),
101
            $this->getWarpDrive(),
102
            $this->getMaxWarpDrive(),
103
            StatusBarColorEnum::STATUSBAR_BLUE
104
        )
105
            ->render();
106
    }
107
108
    public function getWarpDriveStatusBarBig(): string
109
    {
110
        return $this->getTalStatusBar(
111
            _('Warpantrieb'),
112
            $this->getWarpDrive(),
113
            $this->getMaxWarpDrive(),
114
            StatusBarColorEnum::STATUSBAR_BLUE
115
        )
116
            ->setSizeModifier(1.6)
117
            ->render();
118
    }
119
}
120