You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

328 lines
10 KiB

  1. export default class Style {
  2. constructor(gameInstanz) {
  3. this._game = gameInstanz;
  4. this._cardOnDeck = null;
  5. this._drawCardRunnig = false;
  6. this._firstDraw = $('#first-draw');
  7. this._firstPut = $('#first-put');
  8. this._firstPutAnim = $('#first-put-anim');
  9. this._unohover = false;
  10. this._unoClicked = false;
  11. $('#sayUno').on('mouseenter', () => {
  12. if (this._unoClicked) return;
  13. this.unoHover = true;
  14. $('.uno').css('width', '28vw');
  15. $('#sayUno-glow').css('opacity', 1);
  16. })
  17. $('#sayUno').on('mouseleave', () => {
  18. if (this._unoClicked) return;
  19. this.unoHover = false;
  20. $('.uno').css('width', '25vw');
  21. $('#sayUno-glow').css('opacity', 0.3);
  22. this.startUnoLoop();
  23. })
  24. $('#sayUno').on('click', () => {
  25. this.unoHover = true;
  26. this._unoClicked = true;
  27. $('.uno').css('transition', 'width ease-out 0.2s, filter 0.1s');
  28. $('.uno').css('width', '22vw');
  29. $('.uno').css('filter', 'grayscale(80%)');
  30. $('#sayUno-glow').css('opacity', 1);
  31. this.game.currentPlayerInstanz.sayUno();
  32. })
  33. $('#drawCard').on('click', () => {
  34. if(this.game.currentPlayerInstanz.mustSayUno){
  35. this.game.currentPlayerInstanz.mustSayUno = false;
  36. console.log(this.game.currentPlayerInstanz.mustSayUno)
  37. }
  38. this.game.currentPlayerInstanz.drawCard(1, true, true);
  39. this.refreshDebug();
  40. });
  41. this.firstDraw.on('mouseenter', () => {
  42. this.drawCardAnim(true, false);
  43. });
  44. this.firstDraw.on('mouseleave', () => {
  45. this.drawCardAnim(false, false);
  46. });
  47. this.firstDraw.on('click', () => {
  48. if(this.game.currentPlayerInstanz.mustSayUno){
  49. this.game.currentPlayerInstanz.mustSayUno = false;
  50. this.game.style.hideUnoButton();
  51. }
  52. let playerInstanz = this.game.currentPlayerInstanz;
  53. this.drawCardAnim(false, true);
  54. playerInstanz.drawCard(1, true, true);
  55. });
  56. this.startUnoLoop();
  57. }
  58. refreshHtml() {
  59. this.refreshCardOnDeck();
  60. this.showPlayerDeck(this.game.currentPlayerInstanz, true, false, true)
  61. this.refreshDebug();
  62. }
  63. refreshCardOnDeck() {
  64. if (this._cardOnDeck !== this.game.cardOnDeck) {
  65. console.log(" ewfw")
  66. this.putCardAnim();
  67. this._cardOnDeck = this.game.cardOnDeck;
  68. } else {
  69. this.firstPut.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  70. this.firstPutAnim.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  71. }
  72. }
  73. refreshDebug() {
  74. $('#drawCard').css('background-color', 'white');
  75. $("#player").html("Spieler: " + this.game.currentPlayerInstanz.name);
  76. $("#playerCards").html("Karten: ");
  77. for (let i = 0; i < this.game.currentPlayerInstanz.hand.length; i++) {
  78. $('#playerCards').append(this.game.currentPlayerInstanz.hand[i].name + " - " + this.game.currentPlayerInstanz.hand[i].color);
  79. $('#playerCards').append('<button id="button' + i + '">+</button> | ');
  80. $('#button' + i).on('click', () => {
  81. this.game.currentPlayerInstanz.putCard(i);
  82. setTimeout(() => {
  83. this.showPlayerDeck(this.game.currentPlayerInstanz, false, true, false);
  84. }, 100);
  85. });
  86. if (this.game.currentPlayerInstanz.hand[i].canPut) $('#button' + i).css('background-color', 'green');
  87. }
  88. $('#playerCards').append("" + this.game.currentPlayerInstanz.hand.length)
  89. $("#cardOnDeck").html("Karte auf dem Tisch: " + this.game.cardOnDeck.name + " - " + this.game.cardOnDeck.color);
  90. $("#playerInGame").html("Spieler im Spiel: " + this.game.players.length);
  91. if (!this.game.currentPlayerInstanz.canPlay) $('#drawCard').css('background-color', 'red');
  92. }
  93. showUnoButton(){
  94. $('.uno').css('transition', 'width ease-in-out 0.5s');
  95. $('#sayUno-glow').css('transition', 'width ease-in-out 0.5s, opacity 0.5s');
  96. $('.uno').css('filter', 'grayscale(0%)');
  97. $('#sayUno').css('opacity', 1);
  98. this.unoHover = false;
  99. this._unoClicked = false;
  100. this.startUnoLoop();
  101. }
  102. hideUnoButton(){
  103. $('#sayUno').css('opacity', 0);
  104. }
  105. startUnoLoop() {
  106. if (!this.unoHover && !this._unoClicked) setTimeout(() => {
  107. $('.uno').css('width', '28vw');
  108. $('#sayUno-glow').css('opacity', 0.8);
  109. setTimeout(() => {
  110. if (!this.unoHover && !this._unoClicked) {
  111. $('.uno').css('width', '25vw');
  112. $('#sayUno-glow').css('opacity', 0.3);
  113. this.startUnoLoop();
  114. }
  115. }, 500);
  116. }, 500);
  117. }
  118. stopUnoLoop(){
  119. this._unoClicked = true;
  120. this.unoHover = true;
  121. }
  122. putCardAnim() {
  123. this.firstPutAnim.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  124. this.firstPutAnim.css('transition', 'top 0.5s, opacity 0.3s');
  125. this.firstPutAnim.css('top', '47vh');
  126. this.firstPutAnim.css('opacity', '1');
  127. setTimeout(() => {
  128. this.firstPutAnim.css('transition', '');
  129. this.firstPutAnim.css('top', '30vh');
  130. this.firstPutAnim.css('opacity', '0');
  131. this.firstPut.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  132. this.firstPut.css('opacity', '1');
  133. }, 500);
  134. }
  135. showPlayerDeck(player, click, lastDraw, anim) {
  136. $('#playerDeck').html("");
  137. let currentPlayerHand = player.hand;
  138. let width = window.innerWidth;
  139. let height = window.innerHeight;
  140. let percent = 0;
  141. let top = window.innerHeight * 0.68;
  142. let cardAmount = currentPlayerHand.length;
  143. for (let i = 0; i < cardAmount; i++) {
  144. currentPlayerHand.xPos = 0;
  145. currentPlayerHand.yPos = 0;
  146. $('#playerDeck').append('<div id="card' + i + '" class="pictureCard">' + '<img src="./img/cards/' + currentPlayerHand[i].color + '/' + currentPlayerHand[i].name + '.png' + '"></div>');
  147. currentPlayerHand[i].xPos = (width * (((43 + cardAmount / 2 * 5) - percent)) / 100);
  148. currentPlayerHand[i].yPos = top;
  149. console.log(i + ' ' + currentPlayerHand[i].yPos);
  150. let card = $('#card' + i);
  151. let put = false;
  152. if (click) {
  153. let yPos = currentPlayerHand[i].yPos;
  154. card.on('mouseenter', () => {
  155. if (!put && !anim) card.css('top', yPos - 60 + 'px');
  156. })
  157. card.on('mouseleave', () => {
  158. if (!put && !anim) card.css('top', yPos);
  159. })
  160. card.on('click', () => {
  161. if (!this.game.players[this.game.currentPlayer].hand[i].canPut || anim) return;
  162. put = true
  163. let lastPlayer = player;
  164. player.putCard(i);
  165. card.css('top', yPos - height * 0.2);
  166. card.css('opacity', 0);
  167. setTimeout(() => {
  168. this.refreshCardOnDeck();
  169. }, 400);
  170. })
  171. }
  172. if (anim) {
  173. card.css('top', height);
  174. setTimeout(() => {
  175. card.css('top', top + 'px')
  176. card.css('left', (width * 45 / 100));
  177. setTimeout(() => {
  178. card.css('left', currentPlayerHand[i].xPos + 'px');
  179. card.css('top', top + 'px')
  180. anim = false;
  181. }, 250);
  182. }, 100);
  183. } else {
  184. card.css('left', currentPlayerHand[i].xPos + 'px');
  185. card.css('top', top + 'px')
  186. }
  187. if (lastDraw && i === cardAmount - 1) {
  188. card.css('opacity', 0);
  189. card.css('top', currentPlayerHand[i].yPos - 100);
  190. setTimeout(() => {
  191. card.css('left', currentPlayerHand[i].xPos + 'px');
  192. card.css('top', top + 'px')
  193. card.css('opacity', 1);
  194. }, 50);
  195. }
  196. percent += 5;
  197. }
  198. }
  199. drawCardAnim(enable, playerDraw) {
  200. if (this.drawCardRunning) return;
  201. this.drawCardRunning = true;
  202. if (playerDraw) {
  203. this.firstDraw.css('transition', 'min-width 0.5s, top 0.5s, opacity 0.5s');
  204. this.firstDraw.css('min-width', '35vh');
  205. this.firstDraw.css('top', '60vh');
  206. this.firstDraw.css('opacity', 0);
  207. setTimeout(() => {
  208. this.firstDraw.css('transition', '');
  209. this.firstDraw.css('top', '47vh');
  210. this.firstDraw.css('min-width', '20vh');
  211. this.firstDraw.css('opacity', '1');
  212. this.drawCardRunning = false;
  213. }, 500);
  214. } else {
  215. if (enable) {
  216. this.firstDraw.css('transition', 'min-width 0.35s, top 0.5s');
  217. this.firstDraw.css('min-width', '27vh');
  218. this.firstDraw.css('top', '50vh');
  219. } else {
  220. this.firstDraw.css('transition', 'min-width 1s, top 0.5s');
  221. this.firstDraw.css('top', '47vh');
  222. this.firstDraw.css('min-width', '20vh');
  223. }
  224. this.drawCardRunning = false;
  225. }
  226. }
  227. showDebug() {
  228. $('#debug').show();
  229. this.refreshDebug();
  230. }
  231. hideDebug() {
  232. $('#debug').hide();
  233. }
  234. get game() {
  235. return this._game;
  236. }
  237. get firstDraw() {
  238. return this._firstDraw;
  239. }
  240. get firstPut() {
  241. return this._firstPut;
  242. }
  243. get firstPutAnim() {
  244. return this._firstPutAnim;
  245. }
  246. get drawCardRunning() {
  247. return this._drawCardRunnig;
  248. }
  249. set drawCardRunning(bool) {
  250. this._drawCardRunnig = bool;
  251. }
  252. get unoHover() {
  253. return this._unohover;
  254. }
  255. set unoHover(bool) {
  256. this._unohover = bool;
  257. }
  258. }