Nikatlas 6 роки тому
батько
коміт
b08bc5ceba

+ 3 - 3
src/Game/services/GameService.js

@@ -16,12 +16,12 @@ class GameService {
     init(game) {
         this.GameMachine = new Game.GameMachine();
         this.stack = [];
-        this.state.cards = game.mycards.ids;
-        this.state.salts = game.mycards.salts;
+        this.state.cards = game.cards.playerCardsArray;
+        this.state.salts = game.cards.saltArray;
         this.state.setup = game.setup;
 
         if(this.onInit) this.onInit();
-        SocketService.on('move', this.move);
+        SocketService.on('move', (data) => this.move(data));
     }
 
     move(data) {

+ 27 - 27
src/Game/services/Net.js

@@ -2,41 +2,41 @@ import UserService from './UserService';
 
 function checkIt(resp) {
     if ( Math.parseInt(resp.status / 100, 10) === 2) {
-	    return resp;
-	} else {
-  		throw resp;
-	}
+        return resp;
+    } else {
+        throw resp;
+    }
 }
 
 function catchIt(err) {
-	if ( Math.parseInt(err.status / 500, 10) === 5 ){
-		return err;
-	} else {
-		throw err;
-	}
+    if ( Math.parseInt(err.status / 500, 10) === 5 ){
+        return err;
+    } else {
+        throw err;
+    }
 }
 
 class Net {
-	constructor(baseURL) {
-		this.baseURL = baseURL;
-	}
+    constructor(baseURL) {
+        this.baseURL = baseURL;
+    }
 
-	get(url) {
-		url = this.baseURL + url;
-		return window.fetch(url, {method: 'GET'}).then(checkIt).catch(catchIt);
-	}
+    get(url) {
+        url = this.baseURL + url;
+        return window.fetch(url, {method: 'GET'}).then(checkIt).catch(catchIt);
+    }
 
-	post(url, body) {
-		let urb = this.baseURL + url;
-		return window.fetch(urb, {
-			method: 'POST',
-			headers: {
-				'Content-Type':'application/json',
-				'Token' : UserService.getToken() || ''
-			},
-			body: JSON.stringify(body)
-		});
-	}
+    post(url, body) {
+        let urb = this.baseURL + url;
+        return window.fetch(urb, {
+            method: 'POST',
+            headers: {
+                'Content-Type':'application/json',
+                'Token' : UserService.getToken() || ''
+            },
+            body: JSON.stringify(body)
+        });
+    }
 }
 
 export default new Net('/api/');

+ 4 - 1
src/Game/services/SocketService.js

@@ -8,8 +8,11 @@ class SocketService {
         if(this.socket)
             this.socket.disconnect();
         this.socket = openSocket('http://localhost:3555/' + channel);
-        this.on = this.socket.on;
+        this.on = this.socket.on.bind(this.socket);
+        this.emit = this.socket.emit.bind(this.socket);
     }
+
+
 }
 
 export default new SocketService();

+ 1 - 1
src/Game/views/base/Card.js

@@ -127,7 +127,7 @@ class Card extends GuiableContainer{
     }
 
     loadCard(number) {
-        number = parseInt(number+0.5, 10);
+        number = parseInt(number+0.5, 10) % 4;
         this.card = number;
         this.imageURL = Deck.Filenames[number];
         this.sprite.texture = Deck.Textures[number];

+ 9 - 0
src/Game/views/buildings/Deck.js

@@ -65,6 +65,15 @@ class DeckHandler extends GuiableContainer{
         }
     }
 
+    sync(cards) {
+        if(!cards)return;
+        this.cards.forEach((holder, index) => {
+            const card = new Card({id: cards[index]});
+            this.addChild(card);
+            card.attach(holder);
+        });
+    }
+
     lock() {
         this.cards.forEach((c,i) => {
             if(!c.isEmpty()){

+ 4 - 0
src/Game/views/buildings/Menu.js

@@ -49,8 +49,12 @@ class Menu extends GuiableContainer{
         let play = new Button({  y:-100 , Text: {text: "Play"}});
         play.onClick((e) => {
             SocketService.openSocket('randomFree');
+            SocketService.on('test', () => {
+                console.log("TESTING");
+            });
             SocketService.on('joinGame', (game) => {
                 console.log('Joining Game...');
+                console.log(game);
                 Injector.getByName('Navigator').goToGame();
                 GameService.init(game);
             });

+ 2 - 1
src/Game/views/demo/Board.js

@@ -31,13 +31,14 @@ class BoardDemo extends PIXI.Container{
         }
 
         GameService.onInit = () => {
-            this.deck.sync(GameService.cards);
+            this.deck.sync(GameService.state.cards);
         }
 
         GameService.onUpdate = () => {
             this.board.sync(GameService.GameMachine.state.board);
         }
     }
+    update() {}
 
     _kill = () => {
 

+ 1 - 0
src/Game/views/demo/BoardPlay.js

@@ -125,6 +125,7 @@ class BoardPlayDemo extends GuiableContainer{
         this.sync();
     }
 
+
     sync() {
 
     }

+ 2 - 0
src/Game/views/demo/Navigation.js

@@ -15,6 +15,7 @@ import Menu from '../buildings/Menu';
 class Navigation extends PIXI.Container{
     constructor(props) {
         super();
+        this.props = props;
         let {GameLayer, Gui} = props;
 
         Injector.saveAs('Navigator',this);
@@ -39,6 +40,7 @@ class Navigation extends PIXI.Container{
     }
 
     goToGame = () => {
+        console.log(this.props);
         this.routes.Board = new BoardPlay(this.props);
         this.go('Board');
     }