Skip to content

Commit

Permalink
Heavy refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanfrans committed May 20, 2016
1 parent def854b commit 60ed7e3
Show file tree
Hide file tree
Showing 35 changed files with 1,296 additions and 1,071 deletions.
8 changes: 5 additions & 3 deletions client/components/Game.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use strict';

const React = require('react');
const Renderer = require('../game/view');
const Renderer = require('../game/view/Renderer');

class Game extends React.Component {
componentDidMount () {
const game = this.props.gameClient;
const canvas = this.refs.canvas;
const ctx = canvas.getContext('2d');

ctx.font = '11px "Helvetica"';

const renderer = Renderer(ctx, this.props.gameClient.options);
const renderer = Renderer.create(ctx, game, this.props.gameClient.getOptions());

this.props.gameClient.start(renderer);
game.setRenderer(renderer);
game.start();
}

render () {
Expand Down
12 changes: 6 additions & 6 deletions client/components/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Stats extends React.Component {
componentWillMount () {
const game = this.props.game;

game.addAfterViewLoopHook('stats', () => {
game.addAfterViewLoopHook('stats', (data) => {
this.setState({
serverTime: game.server_time.toFixed(3),
clientTime: game.client_time.toFixed(3),
localTime: game.local_time.toFixed(3),
networkLatency: game._network.netLatency,
networkPing: game._network.netPing
serverTime: data.serverTime.toFixed(3),
clientTime: data.clientTime.toFixed(3),
localTime: data.time.toFixed(3),
networkLatency: data.netLatency,
networkPing: data.netPing
});
});
}
Expand Down
2 changes: 0 additions & 2 deletions client/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ class App extends React.Component {
<div className="tabnav mb-0 border-bottom-0">
<div className="tabnav-tabs">
<a
href="#"
className={ 'tabnav-tab' + (this.state.selectedTab === 'help' ? ' selected' : '') }
onClick={ this.onSelectedTab('help').bind(this) }
>
Help
</a>
<a
href="#"
className={ 'tabnav-tab' + (this.state.selectedTab === 'settings' ? ' selected' : '') }
onClick={ this.onSelectedTab('settings').bind(this) }
>
Expand Down
15 changes: 13 additions & 2 deletions client/containers/Lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const React = require('react');
const SocketClient = require('socket.io-client');
const RoomList = require('../components/RoomList');
const Game = require('../components/Game');
const GameClient = require('../game/GameClient');
const Network = require('../game/network');
const ClientGame = require('../game/ClientGame');
const Stats = require('../components/Stats');
const debugMode = require('../debug').debugMode;

Expand All @@ -31,7 +32,17 @@ class Lobby extends React.Component {

socket.on('connect', () => {
socket.on('onConnected', (data) => {
const gameClient = new GameClient(this.props.gameSettings, socket);
const gameClient = ClientGame.create({
options: this.props.gameSettings
});

const network = Network.create({
game: gameClient,
pingTimeout: this.props.gameSettings.pingTimeout,
socket
});

gameClient.setNetwork(network);

this.setState({
user: data.user,
Expand Down
Loading

0 comments on commit 60ed7e3

Please sign in to comment.