-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlight timer messages below 10 seconds #2118
Open
dingdongg
wants to merge
6
commits into
smogon:master
Choose a base branch
from
dingdongg:highlight-10s-timer-warning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+25
−1
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f221006
Highlight timer messages below 10 seconds
dingdongg 6a11955
Fix timer threshold to 10 seconds
dingdongg 403097f
Fix eslint error
dingdongg 325a4a6
Disable highlighting when timer is off
dingdongg 226dc79
Send browser notification
dingdongg 50b0011
Merge remote-tracking branch 'origin' into highlight-10s-timer-warning
dingdongg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1085,6 +1085,9 @@ export class Battle { | |
endLastTurnPending = false; | ||
totalTimeLeft = 0; | ||
graceTimeLeft = 0; | ||
currTurnTimeElapsed = 0; | ||
timerMessageHighlighted = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs two new properties on Battle? Like we're already displaying "User has X seconds left", we can just check how many seconds are left and use that to decide how pushy to make the message, right? |
||
|
||
/** | ||
* true: timer on, state unknown | ||
* false: timer off | ||
|
@@ -3340,6 +3343,7 @@ export class Battle { | |
break; | ||
} | ||
case 'turn': { | ||
this.currTurnTimeElapsed = 0; | ||
this.setTurn(parseInt(args[1], 10)); | ||
this.log(args); | ||
break; | ||
|
@@ -3438,7 +3442,14 @@ export class Battle { | |
let hasIndex = args[1].indexOf(' has '); | ||
let userid = window.app?.user?.get('userid'); | ||
if (toID(args[1].slice(0, hasIndex)) === userid) { | ||
this.kickingInactive = parseInt(args[1].slice(hasIndex + 5), 10) || true; | ||
const timerValue = parseInt(args[1].slice(hasIndex + 5), 10) || true; | ||
this.kickingInactive = timerValue; | ||
|
||
if (typeof timerValue === "number") { | ||
this.timerMessageHighlighted = this.currTurnTimeElapsed >= 30 && timerValue <= 10; | ||
} | ||
} else { | ||
this.timerMessageHighlighted = false; | ||
} | ||
} else if (args[1].slice(-27) === ' 15 seconds left this turn.') { | ||
if (this.isBlitz) return; | ||
|
@@ -3448,6 +3459,7 @@ export class Battle { | |
} | ||
case 'inactiveoff': { | ||
this.kickingInactive = false; | ||
this.timerMessageHighlighted = false; | ||
this.log(args, undefined, preempt); | ||
break; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You check
battle?.kickingInactive
in the if statement, so it should always be truthy. Is the "Only a few" fallback just to satisfy TypeScript, or is there a situation where it would be used that I'm not seeing? (IfkickingInactive
is 0, we won't even get here.)