-
Notifications
You must be signed in to change notification settings - Fork 6
/
dmChessJavascriptConfig.php
68 lines (60 loc) · 1.66 KB
/
dmChessJavascriptConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
class dmChessJavascriptConfig
{
protected
$response,
$helper,
$i18n,
$player;
public function __construct(dmWebResponse $response, dmHelper $helper, dmi18n $i18n, DmChessPlayer $player)
{
$this->response = $response;
$this->helper = $helper;
$this->i18n = $i18n;
$this->player = $player;
}
public function execute()
{
$this->response->addJavascriptConfig('dm_chess_game', $this->getJavascriptConfig());
}
protected function getJavascriptConfig()
{
return array(
'player' => array(
'color' => $this->player->color,
'code' => $this->player->code
),
'opponent' => ($opponent = $this->player->Opponent) ? array(
'color' => $opponent->color,
'ai' => $opponent->isAi
) : false,
'targets' => ($this->player->isMyTurn() && $this->player->Game->isStarted) ? $this->player->getTargetKeysByPieces() : null,
'beat' => array(
'url' => $this->helper->link('+/dmChessGame/whatsUp')->param('player', $this->player->code)->getHref(),
'delay' => 2000
),
'game' => array(
'code' => $this->player->Game->code,
'finished' => $this->player->Game->isFinished
),
'i18n' => $this->getTranslatedMessages()
);
}
protected function getTranslatedMessages()
{
$messages = array();
foreach($this->getMessages() as $message)
{
$messages[$message] = $this->i18n->__($message);
}
return $message;
}
protected function getMessages()
{
return array(
'Game over',
'Waiting for opponent',
'Your turn'
);
}
}