Skip to content

Commit 20c24f4

Browse files
committed
Adds CheckUpdatePlayers() logic
1 parent e88bab7 commit 20c24f4

File tree

5 files changed

+126
-78
lines changed

5 files changed

+126
-78
lines changed

Assets/_Project/Scenes/tally-viz.unity

Lines changed: 25 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/_Project/Scripts/Core/ProjectManager.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ public class ProjectManager : Singleton<ProjectManager> {
99
protected ProjectManager () { }
1010
//public static new ProjectManager Instance;
1111

12-
Timeline timeline;
13-
//SettingsManager settingsManager;
14-
15-
public TMP_Dropdown timelineStatusDropdown;
16-
17-
18-
1912

2013

2114

Assets/_Project/Scripts/Data/Timeline.cs

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ protected Timeline () { }
2525

2626

2727
public TMP_Dropdown dataSourceDropdown;
28-
//public TMP_Dropdown timelineStatusDropdown;
2928
public TMP_Text timelineStatusText;
3029
public TMP_Text timelineVizDateTimeText;
3130
public Button startButton;
@@ -49,7 +48,14 @@ public enum TimelineStatus {
4948
[Tooltip ("Time since a data request made active")]
5049
public int waitingForDataProgress;
5150

52-
public int totalEvents;
51+
public int totalEventCount;
52+
53+
[Serializable]
54+
public enum DataSource {
55+
local,
56+
live
57+
}
58+
public DataSource dataSource;
5359

5460

5561
// BUFFER
@@ -133,6 +139,8 @@ private void Awake ()
133139
{
134140
//// populate options in the status dropdown
135141
//Dropdown_PopulateStatus ();
142+
143+
//dataSource = (DataSource)dataSourceDropdown.value;
136144
}
137145

138146
private void Start ()
@@ -158,29 +166,15 @@ private void Start ()
158166
// // add options to list
159167
// timelineStatusDropdown.AddOptions (options);
160168
//}
161-
///**
162-
// * Called from UI to update the game status
163-
// */
164-
//public void Dropdown_Listener (int _status)
165-
//{
166-
// // call in-game logic, cast as Enum
167-
// SetTimelineStatus ((TimelineStatus)_status, true);
168-
//}
169-
170169

171170

172171
/**
173-
* Called from game to update the status
172+
* Called from UI to update the data source
174173
*/
175-
public void SetTimelineStatus (TimelineStatus _status, bool fromUI = false)
174+
public void OnChangeDataSourceDropdown (int _status)
176175
{
177-
//Debug.Log ("Timeline.SetTimelineStatus() status = " + status + ", _status = " + _status);
178-
179-
// update status var
180-
status = _status;
181-
182-
// if the call (note, original status) came from within the game then show in UI
183-
if (!fromUI) timelineStatusText.text = _status.ToString ();
176+
// cast as Enum
177+
dataSource = (DataSource)_status;
184178
}
185179

186180

@@ -230,13 +224,34 @@ void SetStartBtnText (string txt, bool interact)
230224
/////////////////////////////////////////////////////////////
231225

232226

227+
/**
228+
* Called from game and buttons to update the status
229+
*/
230+
public void SetTimelineStatus (TimelineStatus _status, bool fromUI = false)
231+
{
232+
//Debug.Log ("Timeline.SetTimelineStatus() status = " + status + ", _status = " + _status);
233+
234+
// update status var
235+
status = _status;
236+
237+
// if the call (note, original status) came from within the game then show in UI
238+
if (!fromUI) timelineStatusText.text = _status.ToString ();
239+
}
240+
233241
/**
234242
* (stops and then) starts the buffer loop
235243
*/
236244
public void StartBufferLoop ()
237245
{
238246
Debug.Log ("Timeline.StartBufferLoop()");
239247

248+
// update buffer max based on source
249+
if (dataSource == DataSource.local) {
250+
bufferCountMax = 1000;
251+
} else if (dataSource == DataSource.local) {
252+
bufferCountMax = 50;
253+
}
254+
240255
// if coroutine running
241256
if (bufferCoroutine != null) StopCoroutine (bufferCoroutine);
242257
// start buffer, attempt to get new data
@@ -416,14 +431,15 @@ IEnumerator BufferLoop ()
416431

417432
else if (status == TimelineStatus.bufferEmpty) {
418433

419-
// local
420-
if (dataSourceDropdown.value == 0) {
421-
// set to handle end of buffer
434+
// LOCAL
435+
if (dataSource == DataSource.local) {
436+
// we are using prepackaged data archive so move history back to buffer
422437
SetTimelineStatus (TimelineStatus.moveHistory);
423438
}
424-
// live
425-
else if (dataSourceDropdown.value == 1) {
426-
// get new data
439+
// LIVE
440+
else if (dataSource == DataSource.live) {
441+
// attempt to get new data
442+
427443
}
428444

429445
}
@@ -439,11 +455,10 @@ IEnumerator BufferLoop ()
439455

440456
}
441457

442-
458+
// update counts
443459
UpdateCounts ();
444-
445460
// after checking condition
446-
if (bufferCount > 0) {
461+
if (totalEventCount > 0) {
447462
// display
448463
UpdateTimelineLogs ();
449464
}
@@ -517,9 +532,9 @@ IEnumerator HistoryLoop ()
517532
if (historyCount > 0) {
518533
// after update, sort ascending
519534
history.Sort ((x, y) => x.createdAt.CompareTo (y.createdAt));
520-
// display
521-
UpdateTimelineLogs ();
522535
}
536+
// display
537+
UpdateTimelineLogs ();
523538

524539

525540
// log feed item
@@ -561,15 +576,15 @@ void UpdateTimelineLogs ()
561576
int safety = 0;
562577
foreach (var feed in buffer) {
563578
bufferString += feed.eventType + ". " + feed.createdAt + " - " + feed.username + "<br>";
564-
if (++safety > bufferCountMax) {
579+
if (++safety > bufferCount || safety > totalEventCount) {
565580
Debug.Log ("Safety first!");
566581
break;
567582
}
568583
}
569584
safety = 0;
570585
foreach (var feed in history) {
571586
historyString += feed.eventType + ". " + feed.createdAt + " - " + feed.username + "<br>";
572-
if (++safety > bufferCountMax) {
587+
if (++safety > historyCount || safety > totalEventCount) {
573588
Debug.Log ("Safety first!");
574589
break;
575590
}
@@ -594,7 +609,7 @@ void UpdateCounts ()
594609
{
595610
bufferCount = buffer.Count;
596611
historyCount = history.Count;
597-
totalEvents = buffer.Count + history.Count;
612+
totalEventCount = buffer.Count + history.Count;
598613
}
599614

600615
public void UpdateScroll ()

Assets/_Project/Scripts/Data/TimelineViz.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private void Update ()
2727
{
2828

2929
// if there are events and historyCount has been updated
30-
if (timeline.totalEvents > 0 && lastHistoryCount != timeline.historyCount) {
30+
if (timeline.totalEventCount > 0 && lastHistoryCount != timeline.historyCount) {
3131

3232
//Debug.Log ("hi " + timeline.historyCount / (float)timeline.totalEvents);
3333

@@ -37,7 +37,7 @@ private void Update ()
3737
} else {
3838

3939
// get new normalized position
40-
newPosNormalized = new Vector2 (timeline.historyCount / (float)timeline.totalEvents, historyRectTransform.anchorMax.y);
40+
newPosNormalized = new Vector2 (timeline.historyCount / (float)timeline.totalEventCount, historyRectTransform.anchorMax.y);
4141

4242
// start coroutine to lerp from current to new
4343
StartCoroutine (LerpPosition (historyRectTransform, newPosNormalized, 1f));

0 commit comments

Comments
 (0)