Browse Source

Checkpoint

Nikatlas 6 years ago
parent
commit
b08bc5ceba

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

@@ -16,12 +16,12 @@ class GameService {
     init(game) {
     init(game) {
         this.GameMachine = new Game.GameMachine();
         this.GameMachine = new Game.GameMachine();
         this.stack = [];
         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;
         this.state.setup = game.setup;
 
 
         if(this.onInit) this.onInit();
         if(this.onInit) this.onInit();
-        SocketService.on('move', this.move);
+        SocketService.on('move', (data) => this.move(data));
     }
     }
 
 
     move(data) {
     move(data) {

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

@@ -2,41 +2,41 @@ import UserService from './UserService';
 
 
 function checkIt(resp) {
 function checkIt(resp) {
     if ( Math.parseInt(resp.status / 100, 10) === 2) {
     if ( Math.parseInt(resp.status / 100, 10) === 2) {
-	    return resp;
-	} else {
-  		throw resp;
-	}
+        return resp;
+    } else {
+        throw resp;
+    }
 }
 }
 
 
 function catchIt(err) {
 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 {
 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/');
 export default new Net('/api/');

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

@@ -8,8 +8,11 @@ class SocketService {
         if(this.socket)
         if(this.socket)
             this.socket.disconnect();
             this.socket.disconnect();
         this.socket = openSocket('http://localhost:3555/' + channel);
         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();
 export default new SocketService();

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

@@ -127,7 +127,7 @@ class Card extends GuiableContainer{
     }
     }
 
 
     loadCard(number) {
     loadCard(number) {
-        number = parseInt(number+0.5, 10);
+        number = parseInt(number+0.5, 10) % 4;
         this.card = number;
         this.card = number;
         this.imageURL = Deck.Filenames[number];
         this.imageURL = Deck.Filenames[number];
         this.sprite.texture = Deck.Textures[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() {
     lock() {
         this.cards.forEach((c,i) => {
         this.cards.forEach((c,i) => {
             if(!c.isEmpty()){
             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"}});
         let play = new Button({  y:-100 , Text: {text: "Play"}});
         play.onClick((e) => {
         play.onClick((e) => {
             SocketService.openSocket('randomFree');
             SocketService.openSocket('randomFree');
+            SocketService.on('test', () => {
+                console.log("TESTING");
+            });
             SocketService.on('joinGame', (game) => {
             SocketService.on('joinGame', (game) => {
                 console.log('Joining Game...');
                 console.log('Joining Game...');
+                console.log(game);
                 Injector.getByName('Navigator').goToGame();
                 Injector.getByName('Navigator').goToGame();
                 GameService.init(game);
                 GameService.init(game);
             });
             });

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

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

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

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

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

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