menu-controller.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. import MainMenuScene from '../views/main-menu-scene';
  3. import { PhaserScene } from '../../common/utils/const/phaser-scene-enum';
  4. import GameParams from '../../common/game-params';
  5. import GameControllerPnp from '../../game/control/game-controller-pnp';
  6. import SocketService from '../../common/socket-service';
  7. export default class MenuController {
  8. constructor(phaserEngine) {
  9. this.phaserEngine = phaserEngine;
  10. this.socketService = new SocketService();
  11. this.mainMenuScene = new MainMenuScene(this.menuEventListener());
  12. }
  13. displayMainMenu() {
  14. this.phaserEngine.scene.add(PhaserScene.MAIN_MENU,this.mainMenuScene);
  15. this.phaserEngine.scene.start(PhaserScene.MAIN_MENU);
  16. }
  17. tryConnect(username) {
  18. return this.socketService.connect(username);
  19. }
  20. onRequestDisconnection() {
  21. this.socketService.disconnect();
  22. }
  23. menuEventListener() {
  24. return {
  25. onNewPnpGame: this.onNewPnpGame.bind(this),
  26. onOnlineGamesListRequested: this.onOnlineGamesListRequested.bind(this),
  27. onTryConnect: this.tryConnect.bind(this),
  28. onRequestDisconnection: this.onRequestDisconnection.bind(this),
  29. };
  30. }
  31. onNewPnpGame(pBlueName, pRedName, gameMode, advancedRules) {
  32. console.log("onNewPnpGame this : " + this);
  33. let gameParams = new GameParams(pBlueName,pRedName,gameMode,advancedRules);
  34. let gameControllerPnp = new GameControllerPnp(this.phaserEngine, gameParams);
  35. gameControllerPnp.displayDeckBuilding();
  36. }
  37. onOnlineGamesListRequested(playername) {
  38. return this.socketService.getGamesList(playername);
  39. }
  40. }