App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div id="app" class="appBackground">
  3. <div class="container-fluid">
  4. <div class="row">
  5. <div
  6. class="col-2"
  7. v-if="!hideTest"
  8. style="background-color:lightgreen;"
  9. >
  10. <span class="title-medieval">For tests</span>
  11. <br />
  12. <button
  13. class="btn btn-primary custom-button"
  14. @click="test = 'app-menu'"
  15. >
  16. Enter Menu
  17. </button>
  18. <br />
  19. <br />
  20. <button
  21. class="btn btn-primary custom-button"
  22. @click="test = 'app-game'"
  23. >
  24. Enter Game
  25. </button>
  26. </div>
  27. <div class="col">
  28. <button
  29. style="font-size:8px"
  30. @click="
  31. hideTest = !hideTest;
  32. if (hideTest) test = '';
  33. "
  34. >
  35. Test
  36. </button>
  37. <keep-alive>
  38. <component :is="choseDisplay"></component>
  39. </keep-alive>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import AppMenu from './menu/AppMenu';
  47. import AppGame from './game/AppGame';
  48. import { mapGetters } from 'vuex';
  49. export default {
  50. name: 'App',
  51. data() {
  52. return {
  53. hideTest: true,
  54. test: ''
  55. };
  56. },
  57. components: {
  58. AppMenu,
  59. AppGame
  60. },
  61. computed: {
  62. ...mapGetters({
  63. isGameRunning: 'isGameRunning'
  64. }),
  65. choseDisplay() {
  66. if (this.test !== '') {
  67. return this.test;
  68. }
  69. if (!this.isGameRunning) {
  70. return 'app-menu';
  71. } else {
  72. return 'app-game';
  73. }
  74. }
  75. },
  76. beforeMount() {
  77. let user = localStorage.getItem('username');
  78. if (user) {
  79. console.log('user in storage, try to connect ! : ', user);
  80. this.$store
  81. .dispatch('menu/connect', user)
  82. .then(() => {
  83. let gameId = localStorage.getItem('gameId');
  84. if (gameId && gameId > -1) {
  85. console.log('gameId in storage, try to join ! : ', gameId);
  86. this.$store.dispatch('menu/joinOnlineGame', {
  87. id: gameId,
  88. isNew: false
  89. });
  90. }
  91. })
  92. .catch(() => {});
  93. }
  94. },
  95. created() {
  96. this.$store.watch(
  97. () => this.$store.getters['messages'],
  98. messages => {
  99. if (messages.length > 0) {
  100. let message = messages.pop();
  101. this.$bvToast.toast(message.text, {
  102. title: message.from,
  103. toaster: 'b-toaster-top-right',
  104. solid: true,
  105. variant: 'info',
  106. autoHideDelay: 10000,
  107. appendToast: true
  108. });
  109. }
  110. }
  111. );
  112. }
  113. };
  114. </script>
  115. <style scoped lang="scss">
  116. @import './styles/fonts/fonts.scss';
  117. .appBackground {
  118. position: absolute;
  119. height: 100%;
  120. width: 100%;
  121. background: url(./assets/Background.png) no-repeat center center fixed;
  122. -webkit-background-size: cover;
  123. -moz-background-size: cover;
  124. -o-background-size: cover;
  125. background-size: cover;
  126. overflow: hidden;
  127. }
  128. </style>