Skip to content
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
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/client-battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
}, 1000);
} else if (this.battle.kickingInactive > 1) {
this.battle.kickingInactive--;
this.battle.currTurnTimeElapsed++;
if (this.battle.graceTimeLeft) this.battle.graceTimeLeft--;
else if (this.battle.totalTimeLeft) this.battle.totalTimeLeft--;
}
Expand Down
11 changes: 11 additions & 0 deletions src/battle-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ export class BattleLog {

case 'error': case 'inactive': case 'inactiveoff':
divClass = 'chat message-error';
battle = this.scene?.battle;

if (battle?.kickingInactive && battle.timerMessageHighlighted) {
divClass += ' highlighted';
if (this.scene?.battle?.roomid) {
const title = 'Make your move!';
const body = `${battle?.kickingInactive || 'Only a few'} seconds remaining!`;
Copy link
Collaborator

@AnnikaCodes AnnikaCodes Jul 18, 2023

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? (If kickingInactive is 0, we won't even get here.)

const tag = 'highlight';
app.rooms[this.scene?.battle?.roomid].notifyOnce(title, body, tag);
}
}
divHTML = BattleLog.escapeHTML(args[1]);
break;

Expand Down
14 changes: 13 additions & 1 deletion src/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,9 @@ export class Battle {
endLastTurnPending = false;
totalTimeLeft = 0;
graceTimeLeft = 0;
currTurnTimeElapsed = 0;
timerMessageHighlighted = false;
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -3340,6 +3343,7 @@ export class Battle {
break;
}
case 'turn': {
this.currTurnTimeElapsed = 0;
this.setTurn(parseInt(args[1], 10));
this.log(args);
break;
Expand Down Expand Up @@ -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;
Expand All @@ -3448,6 +3459,7 @@ export class Battle {
}
case 'inactiveoff': {
this.kickingInactive = false;
this.timerMessageHighlighted = false;
this.log(args, undefined, preempt);
break;
}
Expand Down