|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\Column; |
|
8
|
|
|
use Doctrine\ORM\Mapping\Entity; |
|
9
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
|
10
|
|
|
use Doctrine\ORM\Mapping\Id; |
|
11
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
|
12
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
|
13
|
|
|
use Doctrine\ORM\Mapping\Table; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @Entity(repositoryClass="Stu\Orm\Repository\TorpedoHullRepository") |
|
17
|
|
|
* @Table( |
|
18
|
|
|
* name="stu_torpedo_hull") |
|
19
|
|
|
**/ |
|
20
|
|
|
class TorpedoHull implements TorpedoHullInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @Id |
|
24
|
|
|
* @Column(type="integer") |
|
25
|
|
|
* @GeneratedValue(strategy="IDENTITY") |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
private int $id; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @Column(type="integer") |
|
32
|
|
|
* |
|
33
|
|
|
*/ |
|
34
|
|
|
private int $module_id = 0; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @Column(type="integer") |
|
38
|
|
|
* |
|
39
|
|
|
*/ |
|
40
|
|
|
private int $torpedo_type = 0; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @Column(type="integer") |
|
44
|
|
|
* |
|
45
|
|
|
*/ |
|
46
|
|
|
private int $modificator = 0; |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var ?TorpedoType |
|
51
|
|
|
* |
|
52
|
|
|
* @ManyToOne(targetEntity="TorpedoType") |
|
53
|
|
|
* @JoinColumn(name="torpedo_type", referencedColumnName="id") |
|
54
|
|
|
*/ |
|
55
|
|
|
private $torpedo; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var ?Module |
|
59
|
|
|
* |
|
60
|
|
|
* @ManyToOne(targetEntity="Module") |
|
61
|
|
|
* @JoinColumn(name="module_id", referencedColumnName="id") |
|
62
|
|
|
*/ |
|
63
|
|
|
private $module; |
|
64
|
|
|
|
|
65
|
|
|
public function getId(): int |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->id; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getModuleId(): int |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->module_id; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function setModuleId(int $moduleId): TorpedoHullInterface |
|
76
|
|
|
{ |
|
77
|
|
|
$this->module_id = $moduleId; |
|
78
|
|
|
|
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getTorpedoType(): int |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->torpedo_type; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function setTorpedoType(int $torpedoType): TorpedoHullInterface |
|
88
|
|
|
{ |
|
89
|
|
|
$this->torpedo_type = $torpedoType; |
|
90
|
|
|
|
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getModificator(): int |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->modificator; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function setModificator(int $Modificator): TorpedoHullInterface |
|
100
|
|
|
{ |
|
101
|
|
|
$this->modificator = $Modificator; |
|
102
|
|
|
|
|
103
|
|
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function getTorpedo(): ?TorpedoTypeInterface |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->torpedo; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getModule(): ?ModuleInterface |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->module; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function calculateGradientColor() |
|
117
|
|
|
{ |
|
118
|
|
|
$color1 = '#00ff00'; |
|
119
|
|
|
$color2 = '#FF0000'; |
|
120
|
|
|
$percent = 100 / 29 * ($this->getModificator() - 88); |
|
121
|
|
|
|
|
122
|
|
|
// Konvertiere die Hex-Farbcodes in RGB-Werte |
|
123
|
|
|
$rgb1 = $this->hexToRgb($color1); |
|
124
|
|
|
$rgb2 = $this->hexToRgb($color2); |
|
125
|
|
|
|
|
126
|
|
|
// Berechne den RGB-Wert für den gegebenen Prozentwert |
|
127
|
|
|
$gradientRgb = $this->calculateGradientRgb($rgb1, $rgb2, $percent); |
|
128
|
|
|
|
|
129
|
|
|
// Konvertiere den RGB-Wert zurück in einen Hex-Farbcode |
|
130
|
|
|
$gradientColor = $this->rgbToHex($gradientRgb); |
|
131
|
|
|
|
|
132
|
|
|
return $gradientColor; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function hexToRgb($color) |
|
136
|
|
|
{ |
|
137
|
|
|
$color = ltrim($color, '#'); |
|
138
|
|
|
$length = strlen($color); |
|
139
|
|
|
|
|
140
|
|
|
if ($length == 3) { |
|
141
|
|
|
$r = hexdec(substr($color, 0, 1) . substr($color, 0, 1)); |
|
142
|
|
|
$g = hexdec(substr($color, 1, 1) . substr($color, 1, 1)); |
|
143
|
|
|
$b = hexdec(substr($color, 2, 1) . substr($color, 2, 1)); |
|
144
|
|
|
} elseif ($length == 6) { |
|
145
|
|
|
$r = hexdec(substr($color, 0, 2)); |
|
146
|
|
|
$g = hexdec(substr($color, 2, 2)); |
|
147
|
|
|
$b = hexdec(substr($color, 4, 2)); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
return array($r, $g, $b); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function calculateGradientRgb($rgb1, $rgb2, $percent) |
|
154
|
|
|
{ |
|
155
|
|
|
$r = intval($rgb1[0] + ($rgb2[0] - $rgb1[0]) * $percent / 100); |
|
156
|
|
|
$g = intval($rgb1[1] + ($rgb2[1] - $rgb1[1]) * $percent / 100); |
|
157
|
|
|
$b = intval($rgb1[2] + ($rgb2[2] - $rgb1[2]) * $percent / 100); |
|
158
|
|
|
|
|
159
|
|
|
return array($r, $g, $b); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function rgbToHex($rgb) |
|
163
|
|
|
{ |
|
164
|
|
|
$r = str_pad(dechex($rgb[0]), 2, '0', STR_PAD_LEFT); |
|
165
|
|
|
$g = str_pad(dechex($rgb[1]), 2, '0', STR_PAD_LEFT); |
|
166
|
|
|
$b = str_pad(dechex($rgb[2]), 2, '0', STR_PAD_LEFT); |
|
167
|
|
|
|
|
168
|
|
|
return '#' . $r . $g . $b; |
|
169
|
|
|
} |
|
170
|
|
|
} |