|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PanicLabCore\Services\Handlers; |
|
6
|
|
|
|
|
7
|
|
|
use PanicLabCore\Structs\Step; |
|
8
|
|
|
use PanicLabCore\Structs\SwitchTile; |
|
9
|
|
|
use PanicLabCore\Structs\Target; |
|
10
|
|
|
use PanicLabCore\Structs\Tile; |
|
11
|
|
|
|
|
12
|
|
|
class SwitchTileHandler implements TileHandlerInterface |
|
13
|
|
|
{ |
|
14
|
6 |
|
public function supports(Tile $tile): bool |
|
15
|
|
|
{ |
|
16
|
6 |
|
return $tile instanceof SwitchTile; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
5 |
|
public function handle(array $tiles, Target $target, Step $stepStruct): void |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var SwitchTile $tile */ |
|
25
|
5 |
|
$tile = $tiles[$stepStruct->getCurrentIndex()]; |
|
26
|
|
|
|
|
27
|
5 |
|
$this->change($tile->getType(), $target); |
|
28
|
5 |
|
} |
|
29
|
|
|
|
|
30
|
8 |
|
public function change(string $switchType, Target $target): void |
|
31
|
|
|
{ |
|
32
|
8 |
|
if ($switchType === 'color') { |
|
33
|
4 |
|
$this->switchColor($target); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
8 |
|
if ($switchType === 'size') { |
|
37
|
4 |
|
$this->switchSize($target); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
8 |
|
if ($switchType !== 'style') { |
|
41
|
7 |
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
2 |
|
$this->switchStyle($target); |
|
45
|
2 |
|
} |
|
46
|
|
|
|
|
47
|
5 |
|
public function switchColor(Target $target): void |
|
48
|
|
|
{ |
|
49
|
5 |
|
if ($target->getGermColor() === 'blue') { |
|
50
|
2 |
|
$target->setGermColor('orange'); |
|
51
|
|
|
} else { |
|
52
|
5 |
|
$target->setGermColor('blue'); |
|
53
|
|
|
} |
|
54
|
5 |
|
} |
|
55
|
|
|
|
|
56
|
5 |
|
public function switchSize(Target $target): void |
|
57
|
|
|
{ |
|
58
|
5 |
|
if ($target->getGermSize() === 'thick') { |
|
59
|
5 |
|
$target->setGermSize('thin'); |
|
60
|
|
|
} else { |
|
61
|
2 |
|
$target->setGermSize('thick'); |
|
62
|
|
|
} |
|
63
|
5 |
|
} |
|
64
|
|
|
|
|
65
|
3 |
|
public function switchStyle(Target $target): void |
|
66
|
|
|
{ |
|
67
|
3 |
|
if ($target->getGermStyle() === 'dotted') { |
|
68
|
3 |
|
$target->setGermStyle('streaked'); |
|
69
|
|
|
} else { |
|
70
|
2 |
|
$target->setGermStyle('dotted'); |
|
71
|
|
|
} |
|
72
|
3 |
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|