Skip to content

Commit 282dc32

Browse files
authored
Merge pull request #81 from gurpreet241092/feature/match_pause_time_support
Feature added to track pause timings during the game
2 parents 0f6bdd6 + b4f4ffc commit 282dc32

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

processors/createParsedDataBlob.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import processParsedData from './processParsedData.mjs';
66
import processMetadata from './processMetadata.mjs';
77
import processExpand from './processExpand.mjs';
88
import processDraftTimings from './processDraftTimings.mjs';
9+
import processPauses from './processPauses.mjs';
910
import parseSchema from './parseSchema.mjs';
1011

1112
function createParsedDataBlob(entries, matchId) {
@@ -26,6 +27,9 @@ function createParsedDataBlob(entries, matchId) {
2627
logConsole.time('draft');
2728
parsedData.draft_timings = processDraftTimings(entries, meta);
2829
logConsole.timeEnd('draft');
30+
logConsole.time('pauses');
31+
parsedData.pauses = processPauses(entries);
32+
logConsole.timeEnd('pauses');
2933
logConsole.time('processAllPlayers');
3034
const ap = processAllPlayers(entries, meta);
3135
logConsole.timeEnd('processAllPlayers');

processors/parseSchema.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
chat: [],
88
radiant_gold_adv: [],
99
radiant_xp_adv: [],
10+
pauses: [],
1011
cosmetics: {},
1112
players: Array(...new Array(10)).map(() => ({
1213
player_slot: 0,

processors/processPauses.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* This processor grabs the game pause times from the parsed replay.
3+
* The output is:
4+
* time: the game time when the pause started (in seconds)
5+
* duration: the duration of the pause (in seconds)
6+
*/
7+
function processPauses(entries) {
8+
const pauses = [];
9+
10+
for (let i = 0; i < entries.length; i += 1) {
11+
const e = entries[i];
12+
13+
if (e.type === 'game_paused' && e.key === 'pause_duration' && e.value > 0) {
14+
pauses.push({
15+
time: e.time,
16+
duration: e.value,
17+
});
18+
}
19+
}
20+
21+
return pauses;
22+
}
23+
24+
export default processPauses;

src/main/java/opendota/Parse.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ public UnknownAbilityFoundException(String message) {
200200

201201
boolean isDotaPlusProcessed = false;
202202

203+
// Variables to track pause timings
204+
boolean wasPaused = false;
205+
int pauseStartTime = 0;
206+
int pauseStartGameTime = 0;
207+
203208
public Parse(InputStream input, OutputStream output) throws IOException {
204209
greevilsGreedVisitor = new GreevilsGreedVisitor(name_to_slot);
205210
trackVisitor = new TrackVisitor();
@@ -562,6 +567,26 @@ public void onTickStart(Context ctx, boolean synthetic) {
562567
int timeTick = isPaused ? getEntityProperty(grp, "m_pGameRules.m_nPauseStartTick", null) : serverTick;
563568
int pausedTicks = getEntityProperty(grp, "m_pGameRules.m_nTotalPausedTicks", null);
564569
time = Math.round((float) (timeTick - pausedTicks) / 30);
570+
571+
// Tracking game pauses
572+
if (isPaused && !wasPaused) {
573+
// Game just got paused
574+
pauseStartTime = timeTick;
575+
pauseStartGameTime = time;
576+
wasPaused = true;
577+
} else if (!isPaused && wasPaused) {
578+
// Game just got unpaused
579+
int pauseDuration = Math.round((float) (timeTick - pauseStartTime) / 30);
580+
if (pauseDuration > 0) {
581+
Entry pauseEntry = new Entry(pauseStartGameTime);
582+
pauseEntry.type = "game_paused";
583+
pauseEntry.key = "pause_duration";
584+
pauseEntry.value = pauseDuration;
585+
output(pauseEntry);
586+
}
587+
wasPaused = false;
588+
}
589+
565590
} else {
566591
time = Math.round(oldTime);
567592
}

0 commit comments

Comments
 (0)