Private
Public Access
1
0

add player names to UI

This commit is contained in:
2016-11-01 10:52:39 +01:00
parent a566ba8cf8
commit a4f9b603a2
7 changed files with 79 additions and 26 deletions

View File

@@ -26,4 +26,4 @@ security:
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, role: ROLE_SUPER_ADMIN } - { path: ^/admin, role: ROLE_SUPER_ADMIN }
- { path: ^/, role: ROLE_SUPER_ADMIN } # - { path: ^/, role: ROLE_SUPER_ADMIN }

View File

@@ -33,6 +33,7 @@ services:
arguments: arguments:
clientManipulator: "@gos_web_socket.websocket.client_manipulator" clientManipulator: "@gos_web_socket.websocket.client_manipulator"
doctrine: '@doctrine.orm.entity_manager' doctrine: '@doctrine.orm.entity_manager'
requestStack: '@request_stack'
acme_hello.rpc_sample_service: acme_hello.rpc_sample_service:
class: Mine\SeekerBundle\Rpc\AcmeRpc class: Mine\SeekerBundle\Rpc\AcmeRpc

View File

@@ -177,14 +177,18 @@
#mine-wrapper .game-wrapper .users .user-container .user-name { #mine-wrapper .game-wrapper .users .user-container .user-name {
font-weight: normal; font-weight: normal;
text-align: center; text-align: center;
white-space: nowrap;
text-overflow: ellipsis;
padding: 3px 0; padding: 3px 0;
margin: 0 5px; margin: 0 5px;
overflow: hidden;
} }
#mine-wrapper .game-wrapper .users .user-container.user-blue .user-name { #mine-wrapper .game-wrapper .users .user-container.user-blue .user-name {
color: #0b3776;
border-top: 1px dashed #0b3776; border-top: 1px dashed #0b3776;
border-bottom: 1px dashed #0b3776; border-bottom: 1px dashed #0b3776;
color: #0b3776;
} }
#mine-wrapper .game-wrapper .users .user-container.user-red .user-name { #mine-wrapper .game-wrapper .users .user-container.user-red .user-name {

View File

@@ -4,7 +4,6 @@ import MineSeeker from './mine-seeker/app';
ReactDOM.render( ReactDOM.render(
<MineSeeker env={document.getElementById('mine-wrapper').dataset.env} <MineSeeker env={document.getElementById('mine-wrapper').dataset.env}
gameId={document.getElementById('mine-wrapper').dataset.gameId} gameId={document.getElementById('mine-wrapper').dataset.gameId}/>,
userName={document.getElementById('mine-wrapper').dataset.userName}/>,
document.getElementById('mine-wrapper') document.getElementById('mine-wrapper')
); );

View File

@@ -8,13 +8,11 @@ class MineSeeker extends React.Component {
var gameAssoc = props.gameId !== '' ? props.gameId : this.makeGameAssoc(50); var gameAssoc = props.gameId !== '' ? props.gameId : this.makeGameAssoc(50);
var channel = "acme/channel/" + gameAssoc; var channel = "acme/channel/" + gameAssoc;
var userName = props.userName;
this.state = { this.state = {
gameInherited: props.gameId !== '', gameInherited: props.gameId !== '',
gameAssoc: gameAssoc, gameAssoc: gameAssoc,
channel: channel, channel: channel,
userName: userName,
session: null, session: null,
createGrid: false, createGrid: false,
stepCache: null stepCache: null
@@ -70,14 +68,12 @@ class MineSeeker extends React.Component {
overlayTitle: "We are waiting for your opponent..." overlayTitle: "We are waiting for your opponent..."
}); });
/** setup the web player && save player name */ /** setup the web player */
if (this.refs.gridControl.state.webPlayer === null) { if (this.refs.gridControl.state.webPlayer === null) {
if (this.state.gameInherited) { if (this.state.gameInherited) {
this.refs.gridControl.state.webPlayer = 'blue'; this.refs.gridControl.state.webPlayer = 'blue';
this.refs.gridControl.refs.userControl.refs.blue.setState({name: this.state.userName});
} else { } else {
this.refs.gridControl.state.webPlayer = 'red'; this.refs.gridControl.state.webPlayer = 'red';
this.refs.gridControl.refs.userControl.refs.red.setState({name: this.state.userName});
} }
} }
@@ -99,19 +95,27 @@ class MineSeeker extends React.Component {
this.refs.gridControl.stepEvent(payload.data.coords); this.refs.gridControl.stepEvent(payload.data.coords);
} }
} else { } else {
/** It is subscribe or unsubscribe */
if (isNotUnsubscribe) {
console.info( console.info(
(typeof payload.user !== 'undefined' ? payload.user : 'user') + " has been subscribed to the channel!" (typeof payload.user !== 'undefined' ? payload.user : 'user') + " has been subscribed to the channel!"
); );
/** remove overlay when every user has been came */ /** remove overlay when every user has been came */
if (isNotUnsubscribe) {
this.refs.gridControl.setState({overlay: payload.userCnt < 2}); this.refs.gridControl.setState({overlay: payload.userCnt < 2});
}
// /** Save the opponent's player name */ /** Set up player names w/ server data */
// if (this.state.gameInherited) { this.refs.gridControl.refs.userControl.refs.red.setState({
// this.refs.gridControl.refs.userControl.refs.blue.setState({name: payload.user}); name: payload.users.red !== '' ? payload.users.red : payload.users.redAnon
// } });
this.refs.gridControl.refs.userControl.refs.blue.setState({
name: payload.users.blue !== '' ? payload.users.blue : payload.users.blueAnon
});
} else {
console.info(payload.msg);
}
} }
} }
); );

View File

@@ -10,8 +10,7 @@
{% block body %} {% block body %}
<div id="mine-wrapper" <div id="mine-wrapper"
data-env="{{ env }}" data-env="{{ env }}"
data-game-id="{{ app.request.get('gameAssoc') }}" data-game-id="{{ app.request.get('gameAssoc') }}">
data-user-name="{{ app.user.username }}">
</div> </div>
{% endblock %} {% endblock %}

View File

@@ -6,8 +6,11 @@ use Doctrine\ORM\EntityManager;
use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface; use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface;
use Gos\Bundle\WebSocketBundle\Topic\TopicInterface; use Gos\Bundle\WebSocketBundle\Topic\TopicInterface;
use Gos\Bundle\WebSocketBundle\Router\WampRequest; use Gos\Bundle\WebSocketBundle\Router\WampRequest;
use Guzzle\Http\Message\Request;
use Mine\SeekerBundle\Entity\Gamer;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use Ratchet\Wamp\Topic; use Ratchet\Wamp\Topic;
use Symfony\Component\HttpFoundation\RequestStack;
class AcmeTopic implements TopicInterface class AcmeTopic implements TopicInterface
{ {
@@ -15,18 +18,23 @@ class AcmeTopic implements TopicInterface
protected $clientManipulator; protected $clientManipulator;
/** @var EntityManager */ /** @var EntityManager */
protected $entityManager; protected $em;
/** @var RequestStack */
protected $requestStack;
/** /**
* AcmeTopic constructor. * AcmeTopic constructor.
* *
* @param $clientManipulator ClientManipulatorInterface * @param $clientManipulator ClientManipulatorInterface
* @param EntityManager $entityManager * @param EntityManager $entityManager
* @param RequestStack $requestStack
*/ */
public function __construct(ClientManipulatorInterface $clientManipulator, EntityManager $entityManager) public function __construct(ClientManipulatorInterface $clientManipulator, EntityManager $entityManager, RequestStack $requestStack)
{ {
$this->clientManipulator = $clientManipulator; $this->clientManipulator = $clientManipulator;
$this->entityManager = $entityManager; $this->em = $entityManager;
$this->requestStack = $requestStack;
} }
/** /**
@@ -47,11 +55,14 @@ class AcmeTopic implements TopicInterface
if ($topic->count() > 2) { if ($topic->count() > 2) {
$topic->remove($connection); $topic->remove($connection);
} else { } else {
$users = $this->saveUserToDb($topic, $userName, $user, $topic->count());
$topic->broadcast([ $topic->broadcast([
'userTopicId' => $connection->resourceId, 'userTopicId' => $connection->resourceId,
'channel' => $topic->getId(), 'channel' => $topic->getId(),
'user' => $userName, 'user' => $userName,
'userCnt' => $topic->count() 'userCnt' => $topic->count(),
'users' => $users
]); ]);
} }
} }
@@ -105,4 +116,39 @@ class AcmeTopic implements TopicInterface
{ {
return 'acme.topic'; return 'acme.topic';
} }
private function saveUserToDb($topic, $userName, $user, $count)
{
$gameAssoc = explode('/', $topic->getId())[2];
$playedGame = $this->em
->getRepository('MineSeekerBundle:PlayedGame')
->findOneByGameAssoc($gameAssoc);
if (!is_string($user)) {
$FOSUser = $this->em
->getRepository('JotunheimrUserBundle:User')
->findOneByUsername($userName);
$count == 1 ? $playedGame->setRed($FOSUser) : $playedGame->setBlue($FOSUser);
} else {
// $request = $this->requestStack->getCurrentRequest(); // TODO nem megy...
$anon = new Gamer();
$anon->setUserName($userName);
$this->em->persist($anon);
$count == 1 ? $playedGame->setRedAnon($anon) : $playedGame->setBlueAnon($anon);
}
$this->em->persist($playedGame);
$this->em->flush();
return array(
'red' => $playedGame->getRed() !== null ? $playedGame->getRed()->getUsername() : '',
'blue' => $playedGame->getBlue() !== null ? $playedGame->getBlue()->getUsername() : '',
'redAnon' => $playedGame->getRedAnon() !== null ? $playedGame->getRedAnon()->getUserName() : '',
'blueAnon' => $playedGame->getBlueAnon() !== null ? $playedGame->getBlueAnon()->getUserName() : ''
);
}
} }