|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obblm\Core\Twig; |
|
4
|
|
|
|
|
5
|
|
|
use Obblm\Core\Entity\Player; |
|
6
|
|
|
use Obblm\Core\Entity\Team; |
|
7
|
|
|
use Obblm\Core\Helper\CoreTranslation; |
|
8
|
|
|
use Obblm\Core\Helper\PlayerHelper; |
|
9
|
|
|
use Obblm\Core\Helper\RuleHelper; |
|
10
|
|
|
use Obblm\Core\Helper\TeamHelper; |
|
11
|
|
|
use Obblm\Core\Service\ObblmPackage; |
|
12
|
|
|
use Symfony\Component\Routing\Exception\InvalidParameterException; |
|
13
|
|
|
use Twig\Extension\AbstractExtension; |
|
14
|
|
|
use Twig\TwigFilter; |
|
15
|
|
|
use Twig\TwigFunction; |
|
16
|
|
|
|
|
17
|
|
|
class TeamExtension extends AbstractExtension |
|
18
|
|
|
{ |
|
19
|
|
|
protected $ruleHelper; |
|
20
|
|
|
protected $package; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(RuleHelper $ruleHelper, ObblmPackage $package) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->ruleHelper = $ruleHelper; |
|
25
|
|
|
$this->package = $package; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getFilters() |
|
29
|
|
|
{ |
|
30
|
|
|
return [ |
|
31
|
|
|
// Team filters |
|
32
|
|
|
new TwigFilter('rule_key', [$this, 'getRuleKey']), |
|
33
|
|
|
new TwigFilter('roster_name', [$this, 'getRosterName']), |
|
34
|
|
|
new TwigFilter('roster_description', [$this, 'getRosterDescription']), |
|
35
|
|
|
new TwigFilter('tr', [$this, 'getTeamRate']), |
|
36
|
|
|
new TwigFilter('calculate_value', [$this, 'getTeamValue']), |
|
37
|
|
|
new TwigFilter('reroll_cost', [$this, 'getRerollCost']), |
|
38
|
|
|
new TwigFilter('injury_effects', [$this, 'getInjuryEffects']), |
|
39
|
|
|
// Players filters |
|
40
|
|
|
new TwigFilter('type', [$this, 'getType']), |
|
41
|
|
|
new TwigFilter('characteristics', [$this, 'getCharacteristics']), |
|
42
|
|
|
new TwigFilter('skills', [$this, 'getSkills']), |
|
43
|
|
|
new TwigFilter('spp', [$this, 'getSpp']), |
|
44
|
|
|
new TwigFilter('value', [$this, 'getPlayerValue']), |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getFunctions() |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
new TwigFunction('get_team_logo', [$this, 'getLogo']), |
|
52
|
|
|
new TwigFunction('get_team_cover', [$this, 'getCover']), |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getLogo(Team $team):string |
|
57
|
|
|
{ |
|
58
|
|
|
if ($team->getLogoFilename()) { |
|
59
|
|
|
return $this->package->getUrl($team->getId() . '/' . $team->getLogoFilename()); |
|
60
|
|
|
} |
|
61
|
|
|
return "https://placekitten.com/800/800"; |
|
62
|
|
|
//return "@ObblmCore/Resources/public/images/default.png"; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getCover(Team $team) |
|
66
|
|
|
{ |
|
67
|
|
|
if ($team->getCoverFilename()) { |
|
68
|
|
|
return $this->package->getUrl($team->getId() . '/' . $team->getCoverFilename()); |
|
69
|
|
|
} |
|
70
|
|
|
return ""; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getTeamRate(Team $team) |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->ruleHelper->getHelper($team)->calculateTeamRate(TeamHelper::getLastVersion($team)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getRuleKey(Team $team) |
|
79
|
|
|
{ |
|
80
|
|
|
return $team->getRule()->getRuleKey(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getRosterName(Team $team) |
|
84
|
|
|
{ |
|
85
|
|
|
return CoreTranslation::getRosterNameFor($team); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getRosterDescription(Team $team) |
|
89
|
|
|
{ |
|
90
|
|
|
return CoreTranslation::getRosterDescription($team->getRule()->getRuleKey(), $team->getRoster()); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getRerollCost(Team $team) |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->ruleHelper->getHelper($team)->getRerollCost($team); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function getTeamValue(Team $team) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->ruleHelper->getHelper($team)->calculateTeamValue(TeamHelper::getLastVersion($team), true); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getCharacteristics(Player $player, $characteristic) |
|
104
|
|
|
{ |
|
105
|
|
|
if (!$player->getType()) { |
|
106
|
|
|
return ''; |
|
107
|
|
|
} |
|
108
|
|
|
$characteristics = PlayerHelper::getPlayerCharacteristics($player); |
|
109
|
|
|
if (!isset($characteristics[$characteristic])) { |
|
110
|
|
|
throw new InvalidParameterException("The characteristic " . $characteristic . " does not exists"); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $characteristics[$characteristic]; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function getSkills(Player $player) |
|
117
|
|
|
{ |
|
118
|
|
|
if (!$player->getType()) { |
|
119
|
|
|
return null; |
|
120
|
|
|
} |
|
121
|
|
|
return PlayerHelper::getPlayerSkills($player); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getType(Player $player) |
|
125
|
|
|
{ |
|
126
|
|
|
if (!$player->getType()) { |
|
127
|
|
|
return ''; |
|
128
|
|
|
} |
|
129
|
|
|
return CoreTranslation::getPlayerTranslationKey($player); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function getSpp(Player $player) |
|
133
|
|
|
{ |
|
134
|
|
|
if (!$player->getType()) { |
|
135
|
|
|
return ''; |
|
136
|
|
|
} |
|
137
|
|
|
return PlayerHelper::getPlayerSpp($player); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function getPlayerValue(Player $player) |
|
141
|
|
|
{ |
|
142
|
|
|
if (!$player->getType()) { |
|
143
|
|
|
return ''; |
|
144
|
|
|
} |
|
145
|
|
|
return PlayerHelper::getPlayerValue($player); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function getInjuryEffects(Team $team, $injuries) |
|
149
|
|
|
{ |
|
150
|
|
|
$helper = $this->ruleHelper->getHelper($team->getRule()); |
|
151
|
|
|
$arr = [ |
|
152
|
|
|
'dictionary' => $helper->getAttachedRule()->getRuleKey(), |
|
153
|
|
|
'injuries' => [] |
|
154
|
|
|
]; |
|
155
|
|
|
foreach ($injuries as $injury) { |
|
156
|
|
|
$ruleInjury = $helper->getInjury($injury); |
|
157
|
|
|
$arr['injuries'][] = [ |
|
158
|
|
|
'value' => $ruleInjury->value, |
|
159
|
|
|
'label' => $ruleInjury->label, |
|
160
|
|
|
'effect' => $ruleInjury->effectLabel |
|
161
|
|
|
]; |
|
162
|
|
|
} |
|
163
|
|
|
return $arr; |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|