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\Table; |
12
|
|
|
use Stu\Component\Map\MapEnum; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @Entity(repositoryClass="Stu\Orm\Repository\LayerRepository") |
16
|
|
|
* @Table( |
17
|
|
|
* name="stu_layer" |
18
|
|
|
* ) |
19
|
|
|
**/ |
20
|
|
|
class Layer implements LayerInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @Id |
24
|
|
|
* @Column(type="integer") |
25
|
|
|
* @GeneratedValue(strategy="IDENTITY") |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
private int $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @Column(type="string") |
32
|
|
|
* |
33
|
|
|
*/ |
34
|
|
|
private string $name; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @Column(type="integer") |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
|
|
private int $width; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @Column(type="integer") |
44
|
|
|
* |
45
|
|
|
*/ |
46
|
|
|
private int $height; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Column(type="boolean") |
50
|
|
|
* |
51
|
|
|
*/ |
52
|
|
|
private bool $is_hidden; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @Column(type="boolean", nullable=true) |
56
|
|
|
* |
57
|
|
|
*/ |
58
|
|
|
private ?bool $is_finished = null; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Column(type="boolean", nullable=true) |
62
|
|
|
* |
63
|
|
|
*/ |
64
|
|
|
private ?bool $is_encoded = null; |
65
|
|
|
|
66
|
|
|
public function getId(): int |
67
|
|
|
{ |
68
|
|
|
return $this->id; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getName(): string |
72
|
|
|
{ |
73
|
|
|
return $this->name; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getWidth(): int |
77
|
|
|
{ |
78
|
|
|
return $this->width; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getHeight(): int |
82
|
|
|
{ |
83
|
|
|
return $this->height; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function isHidden(): bool |
87
|
|
|
{ |
88
|
|
|
return $this->is_hidden; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function isFinished(): bool |
92
|
|
|
{ |
93
|
|
|
if ($this->is_finished === null) { |
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $this->is_finished; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function isEncoded(): bool |
101
|
|
|
{ |
102
|
|
|
if ($this->is_encoded === null) { |
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->is_encoded; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getSectorsHorizontal(): int |
110
|
|
|
{ |
111
|
|
|
return (int)ceil($this->getWidth() / MapEnum::FIELDS_PER_SECTION); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getSectorsVertical(): int |
115
|
|
|
{ |
116
|
|
|
return (int)ceil($this->getHeight() / MapEnum::FIELDS_PER_SECTION); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getSectorCount(): int |
120
|
|
|
{ |
121
|
|
|
return $this->getSectorsVertical() * $this->getSectorsHorizontal(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getSectorId(int $mapCx, int $mapCy): int |
125
|
|
|
{ |
126
|
|
|
return $mapCx + ($mapCy - 1) * $this->getSectorsHorizontal(); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|