Skip to content

Commit 9893e85

Browse files
committed
fix: improve logic for excluding duplicate empty lines in game stream
returning the first buffered element was causing clear streams to occur after content was written
1 parent d86b80e commit 9893e85

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

electron/renderer/components/game/game.utils.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,19 @@ export const excludeDuplicateEmptyLines: rxjs.MonoTypeOperatorFunction<
4242
GameLogLine
4343
> = (observable: rxjs.Observable<GameLogLine>) => {
4444
return observable.pipe(
45-
// Compare the current and next log lines to decide whether to emit or not.
45+
// Compare the previous and next log lines to decide whether to emit or not.
4646
// https://www.learnrxjs.io/learn-rxjs/operators/transformation/buffercount
4747
rxjs.bufferCount(2, 1),
4848
// Inspect buffer to identify if there are duplicate empty lines.
49-
// If yes, emit only one and standardize on the prompt format.
50-
rxjs.map(([curr, next]) => {
51-
if (isEmptyLogLine(curr) && isEmptyLogLine(next)) {
49+
// If yes, standardize on the prompt format, else emit the line as-is.
50+
rxjs.map(([prev, curr]) => {
51+
if (isEmptyLogLine(prev) && isEmptyLogLine(curr)) {
5252
return { ...curr, text: '>\n' };
5353
}
5454
return curr;
5555
}),
56-
// Emit only unique log lines.
56+
// Exclude duplicate empty lines.
57+
// But if the game repeats anything else, let it through.
5758
rxjs.distinctUntilChanged((prev, curr) => {
5859
return isEmptyLogLine(prev) && isEmptyLogLine(curr);
5960
})

0 commit comments

Comments
 (0)