commit | author | age
|
888906
|
1 |
<?php |
FÁ |
2 |
|
|
3 |
namespace EOG\Models; |
|
4 |
|
|
5 |
class Stripe |
|
6 |
{ |
812087
|
7 |
const TEAM_BLUE = 'blue'; |
FÁ |
8 |
const TEAM_ORANGE = 'orange'; |
888906
|
9 |
|
812087
|
10 |
private $allowedColors = [self::TEAM_BLUE, self::TEAM_ORANGE]; |
FÁ |
11 |
private $allowedStripeClasses = ['team', 'simple', 'team-ban']; |
|
12 |
private $allowedOperators = [ |
|
13 |
'alibi', 'amaru', 'ash', 'bandit', 'blackbeard', 'blitz', 'buck', 'capitao', 'castle', |
|
14 |
'caveira', 'clash', 'doc', 'dokkaebi', 'echo', 'ela', 'finka', 'frost', 'fuze', |
|
15 |
'glaz', 'goyo', 'gridlock', 'hibana', 'iq', 'jackal', 'jager', 'kaid', 'kapkan', |
|
16 |
'lesion', 'lion', 'maestro', 'maverick', 'mira', 'montagne', 'mozzie', 'mute', 'nokk', |
|
17 |
'nomad', 'pulse', 'rook', 'sledge', 'smoke', 'tachanka', 'thatcher', 'thermite', 'twitch', |
35a0a8
|
18 |
'valkyrie', 'vigil', 'warden', 'ying', 'zofia', 'wamai', 'kali', 'iana', 'oryx', 'no-ban', 'no-ban2']; |
812087
|
19 |
protected $state = [ |
FÁ |
20 |
'stripe' => [ |
|
21 |
'class' => 'team', |
|
22 |
], |
|
23 |
'cup' => [ |
cc3ac8
|
24 |
'number' => '#76', |
812087
|
25 |
'name' => '5on5 Open Cup', |
ffa7c6
|
26 |
'bestof' => '5', |
812087
|
27 |
], |
FÁ |
28 |
'team' => [ |
|
29 |
'orange' => |
|
30 |
[ |
ffa7c6
|
31 |
'name' => 'Narancs Csapat', |
FÁ |
32 |
'ban' => [ |
812087
|
33 |
'mira', |
FÁ |
34 |
'jackal' |
b15810
|
35 |
], |
FÁ |
36 |
'score' => [ |
ffa7c6
|
37 |
true, |
b15810
|
38 |
true, |
FÁ |
39 |
true |
812087
|
40 |
] |
b15810
|
41 |
|
812087
|
42 |
], |
FÁ |
43 |
'blue' => [ |
ffa7c6
|
44 |
'name' => 'Kék csapat', |
FÁ |
45 |
'ban' => [ |
812087
|
46 |
'rook', |
FÁ |
47 |
'blitz' |
b15810
|
48 |
], |
FÁ |
49 |
'score' => [ |
ffa7c6
|
50 |
true, |
b15810
|
51 |
true, |
FÁ |
52 |
true |
812087
|
53 |
] |
FÁ |
54 |
] |
|
55 |
] |
|
56 |
]; |
888906
|
57 |
|
812087
|
58 |
public function setClass(string $class): self |
FÁ |
59 |
{ |
|
60 |
if (!in_array($class, $this->allowedStripeClasses)) |
|
61 |
{ |
|
62 |
throw new \InvalidArgumentException("Given class " . $class . " not allowed. Allowed classes: " . implode(', ', $this->allowedStripeClasses)); |
|
63 |
} |
888906
|
64 |
|
812087
|
65 |
$this->state['stripe']['class'] = $class; |
888906
|
66 |
|
812087
|
67 |
return $this; |
FÁ |
68 |
} |
888906
|
69 |
|
812087
|
70 |
private function setSimpleStripe() |
FÁ |
71 |
{ |
|
72 |
unset($this->state['team']); |
b15810
|
73 |
} |
FÁ |
74 |
|
|
75 |
public function setScore(string $team, int $number, bool $score) |
|
76 |
{ |
|
77 |
$this->state['team'][$team]['score'][$number] = $score; |
812087
|
78 |
} |
888906
|
79 |
|
ffa7c6
|
80 |
public function setCup(string $number, string $name, int $bestOf = 1) |
812087
|
81 |
{ |
FÁ |
82 |
$this->state['cup']['number'] = $number; |
|
83 |
$this->state['cup']['name'] = $name; |
ffa7c6
|
84 |
$this->state['cup']['bestof'] = $bestOf; |
812087
|
85 |
} |
888906
|
86 |
|
812087
|
87 |
/** |
FÁ |
88 |
* @param string $color Csapat szín validáció |
|
89 |
* |
|
90 |
* Dob egy Exception-t ha nem orange / blue |
|
91 |
*/ |
|
92 |
private function testColor(string $color) |
|
93 |
{ |
|
94 |
if (!in_array($color, $this->allowedColors)) |
|
95 |
{ |
f6a0dc
|
96 |
throw new \InvalidArgumentException("Given colour " . $color . " not allowed. Allowed colours: " . implode(', ', $this->allowedColors)); |
812087
|
97 |
} |
FÁ |
98 |
} |
888906
|
99 |
|
ffa7c6
|
100 |
public function setTeamName(string $team_color = self::TEAM_BLUE, $name = '') |
812087
|
101 |
{ |
FÁ |
102 |
$this->testColor($team_color); |
|
103 |
$this->state['team'][$team_color]['name'] = $name; |
|
104 |
} |
888906
|
105 |
|
f6a0dc
|
106 |
public function addTeamBan(string $team_color = self::TEAM_BLUE, $operator = '') |
812087
|
107 |
{ |
FÁ |
108 |
$this->testColor($team_color); |
|
109 |
if (!in_array($operator, $this->allowedOperators)) |
|
110 |
{ |
|
111 |
//FIXME: védő és támadó operátorok külön |
|
112 |
throw new \InvalidArgumentException("Given operator not allowed: " . $operator . " Allowed operators: " . implode(', ', $this->allowedOperators)); |
|
113 |
} |
cc3ac8
|
114 |
|
FÁ |
115 |
if (isset($this->state['team'][$team_color]['ban']) && count($this->state['team'][$team_color]['ban']) > 1) |
|
116 |
{ |
|
117 |
throw new \InvalidArgumentException("Team " . $team_color . " already has 2 operators."); |
|
118 |
} |
|
119 |
|
|
120 |
$this->state['team'][$team_color]['ban'][] = $operator; |
812087
|
121 |
} |
888906
|
122 |
|
812087
|
123 |
public function __get($name) |
FÁ |
124 |
{ |
|
125 |
if ($this->__isset($name)) |
|
126 |
{ |
|
127 |
return $this->state[$name]; |
|
128 |
} |
888906
|
129 |
|
812087
|
130 |
return null; |
FÁ |
131 |
} |
888906
|
132 |
|
812087
|
133 |
public function __isset($name) |
FÁ |
134 |
{ |
|
135 |
return isset($this->state[$name]); |
|
136 |
} |
888906
|
137 |
|
cc3ac8
|
138 |
public function loadFromJson(string $json) |
812087
|
139 |
{ |
FÁ |
140 |
$state = json_decode($json); |
cc3ac8
|
141 |
$this->loadFromArray($state); |
FÁ |
142 |
} |
|
143 |
|
|
144 |
public function loadFromArray(array $state) |
|
145 |
{ |
812087
|
146 |
unset($this->state); |
FÁ |
147 |
$this->state = []; |
888906
|
148 |
|
ffa7c6
|
149 |
if (!empty($state['team']['orange']['score'][0])) |
FÁ |
150 |
{ |
|
151 |
$this->setScore('orange', 0, true); |
b15810
|
152 |
} |
FÁ |
153 |
|
ffa7c6
|
154 |
if (!empty($state['team']['orange']['score'][1])) |
FÁ |
155 |
{ |
|
156 |
$this->setScore('orange', 1, true); |
b15810
|
157 |
} |
FÁ |
158 |
|
ffa7c6
|
159 |
if (!empty($state['team']['orange']['score'][2])) |
FÁ |
160 |
{ |
|
161 |
$this->setScore('orange', 2, true); |
b15810
|
162 |
} |
FÁ |
163 |
|
ffa7c6
|
164 |
if (!empty($state['team']['blue']['score'][0])) |
FÁ |
165 |
{ |
|
166 |
$this->setScore('blue', 0, true); |
|
167 |
} |
|
168 |
|
|
169 |
if (!empty($state['team']['blue']['score'][1])) |
|
170 |
{ |
|
171 |
$this->setScore('blue', 1, true); |
|
172 |
} |
|
173 |
|
|
174 |
if (!empty($state['team']['blue']['score'][2])) |
|
175 |
{ |
|
176 |
$this->setScore('blue', 2, true); |
b15810
|
177 |
} |
FÁ |
178 |
|
812087
|
179 |
if (!empty($state['stripe']["class"])) |
FÁ |
180 |
{ |
|
181 |
$this->setClass($state['stripe']["class"]); |
|
182 |
} |
888906
|
183 |
|
ffa7c6
|
184 |
if (!empty($state['cup']['name']) || !empty($state['cup']['number']) || !empty($state['cup']['bestof'])) |
812087
|
185 |
{ |
c5946f
|
186 |
$cupNum = $state['cup']['number'] ?? ''; |
FÁ |
187 |
$cupName = $state['cup']['name'] ?? ''; |
ffa7c6
|
188 |
$bestOf = (int) $state['cup']['bestof'] ?? 1; |
FÁ |
189 |
$this->setCup($cupNum, $cupName, $bestOf); |
812087
|
190 |
} |
FÁ |
191 |
|
|
192 |
if (!empty($state['team'])) |
|
193 |
{ |
|
194 |
foreach ([self::TEAM_BLUE, self::TEAM_ORANGE] as $color) |
|
195 |
{ |
|
196 |
if (!empty($state['team'][$color]['name'])) |
|
197 |
{ |
|
198 |
$this->setTeamName($color, $state['team'][$color]['name']); |
|
199 |
} |
|
200 |
|
|
201 |
if (!empty($state['team'][$color]['ban']) && is_array($state['team'][$color]['ban'])) |
|
202 |
{ |
|
203 |
foreach ($state['team'][$color]['ban'] as $operator) |
|
204 |
{ |
|
205 |
$this->addTeamBan($color, $operator); |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
public function getJson() |
|
213 |
{ |
|
214 |
return json_encode($this->state); |
|
215 |
} |
|
216 |
|
cc3ac8
|
217 |
public function getOperators() |
FÁ |
218 |
{ |
812087
|
219 |
return $this->allowedOperators; |
FÁ |
220 |
} |
cc3ac8
|
221 |
|
FÁ |
222 |
public function getState() |
|
223 |
{ |
|
224 |
return $this->state; |
|
225 |
} |
1867e1
|
226 |
|
FÁ |
227 |
public function getType() |
|
228 |
{ |
|
229 |
if (empty($this->state['stripe']['class'])) |
|
230 |
{ |
|
231 |
return null; |
|
232 |
} |
|
233 |
|
|
234 |
return $this->state['stripe']['class']; |
|
235 |
} |
888906
|
236 |
} |