@@ -44,11 +44,22 @@ interface GameLogLine {
44
44
}
45
45
46
46
interface DougCmpProps {
47
+ /**
48
+ * The stream of game text to display.
49
+ * The stream is additive, so each new line will be appended to the end.
50
+ * The special log line text '__CLEAR_STREAM__' will clear all prior lines.
51
+ */
47
52
stream$ : rxjs . Observable < GameLogLine > ;
53
+ /**
54
+ * Enable to automatically scroll to the bottom of the game stream window
55
+ * as new log lines are added. This effect only occurs if the user
56
+ * is already scrolled to the bottom to ensure they see latest content.
57
+ */
58
+ enableScrollToNewLogLines : boolean ;
48
59
}
49
60
50
61
const DougCmp : React . FC < DougCmpProps > = ( props : DougCmpProps ) : ReactNode => {
51
- const { stream$ } = props ;
62
+ const { stream$, enableScrollToNewLogLines } = props ;
52
63
53
64
useSubscription ( stream$ , ( logLine ) => {
54
65
if ( logLine . text === '__CLEAR_STREAM__' ) {
@@ -60,7 +71,10 @@ const DougCmp: React.FC<DougCmpProps> = (props: DougCmpProps): ReactNode => {
60
71
61
72
const scrollableRef = useRef < HTMLDivElement > ( null ) ;
62
73
const scrollBottomRef = useRef < HTMLSpanElement > ( null ) ;
63
- const [ autoScrollEnabled , setAutoScrollEnabled ] = useState < boolean > ( true ) ;
74
+
75
+ const [ autoScrollEnabled , setAutoScrollEnabled ] = useState < boolean > (
76
+ enableScrollToNewLogLines
77
+ ) ;
64
78
65
79
const [ gameLogLines , setGameLogLines ] = useState < Array < GameLogLine > > ( [ ] ) ;
66
80
@@ -77,6 +91,10 @@ const DougCmp: React.FC<DougCmpProps> = (props: DougCmpProps): ReactNode => {
77
91
} , [ ] ) ;
78
92
79
93
useEffect ( ( ) => {
94
+ if ( ! enableScrollToNewLogLines ) {
95
+ return ;
96
+ }
97
+
80
98
let scrollableElmt = scrollableRef . current ;
81
99
82
100
const onScroll = ( ) => {
@@ -98,7 +116,7 @@ const DougCmp: React.FC<DougCmpProps> = (props: DougCmpProps): ReactNode => {
98
116
return ( ) => {
99
117
scrollableElmt ?. removeEventListener ( 'scroll' , onScroll ) ;
100
118
} ;
101
- } , [ ] ) ;
119
+ } , [ enableScrollToNewLogLines ] ) ;
102
120
103
121
if ( autoScrollEnabled ) {
104
122
scrollBottomRef . current ?. scrollIntoView ( {
@@ -157,8 +175,9 @@ const GridPage: React.FC = (): ReactNode => {
157
175
const { skill, rank, percent, mindState } = gameEvent ;
158
176
const txtSkill = skill . padStart ( 15 ) ;
159
177
const txtRank = String ( rank ) . padStart ( 3 ) ;
160
- const txtPercent = String ( percent ) . padStart ( 2 ) ;
178
+ const txtPercent = String ( percent ) . padStart ( 2 ) + '%' ;
161
179
const txtMindState = mindState . padEnd ( 15 ) ;
180
+ // TODO add option to show mind state as the numbers (x/34)
162
181
return `${ txtSkill } ${ txtRank } ${ txtPercent } ${ txtMindState } ` ;
163
182
} ,
164
183
[ ]
@@ -376,6 +395,7 @@ const GridPage: React.FC = (): ReactNode => {
376
395
title : 'Room' ,
377
396
content : (
378
397
< DougCmp
398
+ enableScrollToNewLogLines = { false }
379
399
stream$ = { gameLogLineSubject$ . pipe (
380
400
rxjs . filter ( ( m ) => m . streamId === 'room' )
381
401
) }
@@ -387,6 +407,7 @@ const GridPage: React.FC = (): ReactNode => {
387
407
title : 'Experience' ,
388
408
content : (
389
409
< DougCmp
410
+ enableScrollToNewLogLines = { false }
390
411
stream$ = { gameLogLineSubject$ . pipe (
391
412
rxjs . filter ( ( m ) => m . streamId === 'experience' )
392
413
) }
@@ -398,6 +419,7 @@ const GridPage: React.FC = (): ReactNode => {
398
419
title : 'Spells' ,
399
420
content : (
400
421
< DougCmp
422
+ enableScrollToNewLogLines = { false }
401
423
stream$ = { gameLogLineSubject$ . pipe (
402
424
rxjs . filter ( ( m ) => m . streamId === 'percWindow' )
403
425
) }
@@ -409,6 +431,7 @@ const GridPage: React.FC = (): ReactNode => {
409
431
title : 'Inventory' ,
410
432
content : (
411
433
< DougCmp
434
+ enableScrollToNewLogLines = { false }
412
435
stream$ = { gameLogLineSubject$ . pipe (
413
436
rxjs . filter ( ( m ) => m . streamId === 'inv' )
414
437
) }
@@ -420,6 +443,7 @@ const GridPage: React.FC = (): ReactNode => {
420
443
title : 'Familiar' ,
421
444
content : (
422
445
< DougCmp
446
+ enableScrollToNewLogLines = { true }
423
447
stream$ = { gameLogLineSubject$ . pipe (
424
448
rxjs . filter ( ( m ) => m . streamId === 'familiar' )
425
449
) }
@@ -431,6 +455,7 @@ const GridPage: React.FC = (): ReactNode => {
431
455
title : 'Thoughts' ,
432
456
content : (
433
457
< DougCmp
458
+ enableScrollToNewLogLines = { true }
434
459
stream$ = { gameLogLineSubject$ . pipe (
435
460
rxjs . filter ( ( m ) => m . streamId === 'thoughts' )
436
461
) }
@@ -442,6 +467,7 @@ const GridPage: React.FC = (): ReactNode => {
442
467
title : 'Combat' ,
443
468
content : (
444
469
< DougCmp
470
+ enableScrollToNewLogLines = { true }
445
471
stream$ = { gameLogLineSubject$ . pipe (
446
472
rxjs . filter ( ( m ) => m . streamId === 'combat' )
447
473
) }
@@ -453,6 +479,7 @@ const GridPage: React.FC = (): ReactNode => {
453
479
title : 'Logons' ,
454
480
content : (
455
481
< DougCmp
482
+ enableScrollToNewLogLines = { true }
456
483
stream$ = { gameLogLineSubject$ . pipe (
457
484
rxjs . filter ( ( m ) => m . streamId === 'logons' )
458
485
) }
@@ -464,6 +491,7 @@ const GridPage: React.FC = (): ReactNode => {
464
491
title : 'Deaths' ,
465
492
content : (
466
493
< DougCmp
494
+ enableScrollToNewLogLines = { true }
467
495
stream$ = { gameLogLineSubject$ . pipe (
468
496
rxjs . filter ( ( m ) => m . streamId === 'death' )
469
497
) }
@@ -475,6 +503,7 @@ const GridPage: React.FC = (): ReactNode => {
475
503
title : 'Main' ,
476
504
content : (
477
505
< DougCmp
506
+ enableScrollToNewLogLines = { true }
478
507
stream$ = { gameLogLineSubject$ . pipe (
479
508
rxjs . filter ( ( m ) => m . streamId === '' )
480
509
) }
0 commit comments