elismasilva commited on
Commit
0980a68
·
1 Parent(s): 8865f40

fixing toast

Browse files
Files changed (2) hide show
  1. components.py +23 -13
  2. game_manager.py +2 -1
components.py CHANGED
@@ -50,11 +50,11 @@ class NeonToast(gr.HTML):
50
  toastEl.classList.remove('toast-show');
51
  };
52
 
53
- watch('value', () => {
54
  const toastEl = element.querySelector('#toast-container');
55
  if (!toastEl) return;
56
 
57
- const message = (typeof props.value === "string") ? props.value.trim() : "";
58
  if (!message) {
59
  window.dodClearToast();
60
  return;
@@ -68,13 +68,17 @@ class NeonToast(gr.HTML):
68
 
69
  toastShowTimer = setTimeout(() => {
70
  if (toastToken !== currentToken) return;
71
- toastEl.querySelector('#toast-msg').innerText = props.value;
72
  toastEl.classList.add('toast-show');
73
  toastTimeout = setTimeout(() => {
74
  if (toastToken !== currentToken) return;
75
  window.dodClearToast();
76
  }, 5000);
77
  }, 50);
 
 
 
 
78
  });
79
  """
80
  super().__init__(value=value, html_template=html_template, css_template=css_template, js_on_load=js_on_load, **kwargs)
@@ -486,6 +490,16 @@ ${(function() {
486
  return "";
487
  };
488
 
 
 
 
 
 
 
 
 
 
 
489
  const selectLobbyTab = () => {
490
  setTimeout(() => {
491
  const tabButtons = document.querySelectorAll('#main_tabs > .tab-nav > button');
@@ -556,7 +570,7 @@ ${(function() {
556
 
557
  const handleServerResponse = (response) => {
558
  if (response) {
559
- if (response.toast && response.toast !== "") trigger('show_toast', {"msg": response.toast});
560
  if (response.state) {
561
  response.state.viewer_id = getMyId();
562
  props.value = response.state;
@@ -593,10 +607,6 @@ ${(function() {
593
  return;
594
  }
595
 
596
- if (props.value && props.value.game_started && (props.value.turn_handoff_left || 0) > 0) {
597
- return;
598
- }
599
-
600
  const drawPileBtn = e.target.closest('#draw-pile');
601
  if (drawPileBtn) {
602
  const players = (props.value && props.value.players) ? props.value.players : [];
@@ -746,19 +756,19 @@ ${(function() {
746
  window._lastEndToastKey = endToastKey;
747
  if (endReason === "victory") {
748
  if (window.gameAudio) window.gameAudio.play('victory');
749
- trigger('show_toast', {"msg": props.value.i18n.toast_victory});
750
  } else if (endReason === "abandon") {
751
  if (window.gameAudio) window.gameAudio.play('game_over');
752
- trigger('show_toast', {"msg": props.value.i18n.toast_game_over_abandon});
753
  } else if (endReason === "game_over" || endReason === "timeout") {
754
  if (window.gameAudio) window.gameAudio.play('game_over');
755
- trigger('show_toast', {"msg": props.value.i18n.toast_game_over});
756
  } else if (props.value.panic >= 100) {
757
  if (window.gameAudio) window.gameAudio.play('game_over');
758
- trigger('show_toast', {"msg": props.value.i18n.toast_game_over});
759
  } else if (props.value.resolution >= 100) {
760
  if (window.gameAudio) window.gameAudio.play('victory');
761
- trigger('show_toast', {"msg": props.value.i18n.toast_victory});
762
  }
763
  }
764
  scheduleEndGameLobbyReturn();
 
50
  toastEl.classList.remove('toast-show');
51
  };
52
 
53
+ window.dodShowToast = (rawMessage) => {
54
  const toastEl = element.querySelector('#toast-container');
55
  if (!toastEl) return;
56
 
57
+ const message = (typeof rawMessage === "string") ? rawMessage.trim() : "";
58
  if (!message) {
59
  window.dodClearToast();
60
  return;
 
68
 
69
  toastShowTimer = setTimeout(() => {
70
  if (toastToken !== currentToken) return;
71
+ toastEl.querySelector('#toast-msg').innerText = message;
72
  toastEl.classList.add('toast-show');
73
  toastTimeout = setTimeout(() => {
74
  if (toastToken !== currentToken) return;
75
  window.dodClearToast();
76
  }, 5000);
77
  }, 50);
78
+ };
79
+
80
+ watch('value', () => {
81
+ window.dodShowToast(props.value);
82
  });
83
  """
84
  super().__init__(value=value, html_template=html_template, css_template=css_template, js_on_load=js_on_load, **kwargs)
 
490
  return "";
491
  };
492
 
493
+ const emitToast = (message) => {
494
+ const text = (typeof message === "string") ? message.trim() : "";
495
+ if (!text) return;
496
+ if (typeof window.dodShowToast === "function") {
497
+ window.dodShowToast(text);
498
+ } else {
499
+ trigger('show_toast', {"msg": text});
500
+ }
501
+ };
502
+
503
  const selectLobbyTab = () => {
504
  setTimeout(() => {
505
  const tabButtons = document.querySelectorAll('#main_tabs > .tab-nav > button');
 
570
 
571
  const handleServerResponse = (response) => {
572
  if (response) {
573
+ if (response.toast && response.toast !== "") emitToast(response.toast);
574
  if (response.state) {
575
  response.state.viewer_id = getMyId();
576
  props.value = response.state;
 
607
  return;
608
  }
609
 
 
 
 
 
610
  const drawPileBtn = e.target.closest('#draw-pile');
611
  if (drawPileBtn) {
612
  const players = (props.value && props.value.players) ? props.value.players : [];
 
756
  window._lastEndToastKey = endToastKey;
757
  if (endReason === "victory") {
758
  if (window.gameAudio) window.gameAudio.play('victory');
759
+ emitToast(props.value.i18n.toast_victory);
760
  } else if (endReason === "abandon") {
761
  if (window.gameAudio) window.gameAudio.play('game_over');
762
+ emitToast(props.value.i18n.toast_game_over_abandon);
763
  } else if (endReason === "game_over" || endReason === "timeout") {
764
  if (window.gameAudio) window.gameAudio.play('game_over');
765
+ emitToast(props.value.i18n.toast_game_over);
766
  } else if (props.value.panic >= 100) {
767
  if (window.gameAudio) window.gameAudio.play('game_over');
768
+ emitToast(props.value.i18n.toast_game_over);
769
  } else if (props.value.resolution >= 100) {
770
  if (window.gameAudio) window.gameAudio.play('victory');
771
+ emitToast(props.value.i18n.toast_victory);
772
  }
773
  }
774
  scheduleEndGameLobbyReturn();
game_manager.py CHANGED
@@ -848,7 +848,8 @@ class GameManager:
848
  """Block gameplay actions while the table is between turns."""
849
  if not self.is_turn_handoff_active():
850
  return None
851
- return {"state": self.get_state(caller_id), "toast": ""}
 
852
 
853
  def clear_shout_window(self) -> None:
854
  """Close any active Deploy shout window without changing the turn."""
 
848
  """Block gameplay actions while the table is between turns."""
849
  if not self.is_turn_handoff_active():
850
  return None
851
+ lang = self.player_langs.get(caller_id, "en")
852
+ return {"state": self.get_state(caller_id), "toast": UI_I18N[lang]["toast_not_turn"]}
853
 
854
  def clear_shout_window(self) -> None:
855
  """Close any active Deploy shout window without changing the turn."""