Skip to content

Commit 860acad

Browse files
committed
Add game timer to UI and ensure persistence and reset
1 parent d284e06 commit 860acad

5 files changed

Lines changed: 71 additions & 7 deletions

File tree

Mythril.Blazor/Pages/Home.razor

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@
5252
<div class="header-row flex-shrink-0 p-2 d-flex align-items-center gap-3">
5353
<div class="d-flex flex-column gap-1">
5454
<button class="btn btn-sm btn-primary" data-testid="theme-toggle" @onclick="ToggleTheme">Toggle Theme</button>
55-
<button class="btn btn-sm btn-outline-danger" data-testid="reset-game" @onclick="ResetGame">Reset Game</button>
55+
<div class="d-flex align-items-center gap-2">
56+
<button class="btn btn-sm btn-outline-danger" data-testid="reset-game" @onclick="ResetGame">Reset Game</button>
57+
@if (resourceManager is not null)
58+
{
59+
<span class="game-timer badge bg-dark text-light border border-secondary" title="Total Play Time">
60+
🕒 @resourceManager.CurrentTimeFormatted
61+
</span>
62+
}
63+
</div>
5664
@if (AuthService.IsAuthenticated)
5765
{
5866
<button class="btn btn-sm @(resourceManager.IsTestMode ? "btn-warning" : "btn-outline-secondary")"
401 Bytes
Binary file not shown.

Mythril.Data/ResourceManager_State.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ public string ActiveTab
126126
public bool ShowMiniLogs => _gameStore.State.ShowMiniLogs;
127127
public void ToggleMiniLogs() => _gameStore.Dispatch(new ToggleMiniLogsAction());
128128

129+
public double CurrentTime => _gameStore.State.CurrentTime;
130+
public string CurrentTimeFormatted
131+
{
132+
get
133+
{
134+
var ts = TimeSpan.FromSeconds(CurrentTime);
135+
return ts.TotalHours >= 1
136+
? $"{(int)ts.TotalHours}:{ts.Minutes:D2}:{ts.Seconds:D2}"
137+
: $"{ts.Minutes}:{ts.Seconds:D2}";
138+
}
139+
}
140+
129141
public HashSet<string> SeenContent => _gameStore.State.SeenContent.ToHashSet();
130142

131143
public void MarkSeen(string contentId) => _gameStore.Dispatch(new MarkContentSeenAction(contentId));

Mythril.Tests/GameTimerTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Mythril.Data;
3+
4+
namespace Mythril.Tests;
5+
6+
[TestClass]
7+
public class GameTimerTests : ResourceManagerTestBase
8+
{
9+
[TestMethod]
10+
public void ResourceManager_Tick_IncrementsCurrentTime()
11+
{
12+
double initialTime = _resourceManager!.CurrentTime;
13+
_resourceManager.Tick(1.0);
14+
Assert.AreEqual(initialTime + 1.0, _resourceManager.CurrentTime);
15+
16+
_resourceManager.Tick(0.5);
17+
Assert.AreEqual(initialTime + 1.5, _resourceManager.CurrentTime);
18+
}
19+
20+
[TestMethod]
21+
public void ResourceManager_Initialize_ResetsCurrentTime()
22+
{
23+
_resourceManager!.Tick(100.0);
24+
Assert.AreEqual(100.0, _resourceManager.CurrentTime);
25+
26+
_resourceManager.Initialize();
27+
Assert.AreEqual(0, _resourceManager.CurrentTime);
28+
}
29+
30+
[TestMethod]
31+
public void ResourceManager_CurrentTimeFormatted_Works()
32+
{
33+
// Reset to 0
34+
_resourceManager!.Initialize();
35+
Assert.AreEqual("0:00", _resourceManager.CurrentTimeFormatted);
36+
37+
_resourceManager.Tick(65.0);
38+
Assert.AreEqual("1:05", _resourceManager.CurrentTimeFormatted);
39+
40+
_resourceManager.Tick(3600.0); // +1 hour
41+
// 1:01:05
42+
Assert.AreEqual("1:01:05", _resourceManager.CurrentTimeFormatted);
43+
}
44+
}

docs/Playtest_Feedback.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- Rework lightning. Currently it's only unlockable very late in the game and the magic itself is vastly outclassed by other options by that point, making it a chain of orphaned content. => Fire and Ice shards both being part of this chain and also pointless.
88
- Review and rework the entire stats system related to task performance. Right now, it's relatively random what requires vitality or speed, etc. I need to map things out and make larger design choices with intention. Just map for now.
99

10-
- Add a clock and record the time when the final upgrade is completed.
10+
- Add a clock and record the time when the final upgrade is completed.
1111

1212
- hunt spiders should be in the mines, not the forest
1313
- hunt slimes should be in the mines, not the plains
@@ -21,10 +21,10 @@
2121

2222
- Consider limiting unlocking an ability to the equiped character. Playtest both ways.
2323

24-
- Toggle in Cadence menu to hide all learned abilities
25-
- Toggle in Cadence menu to hide all fully learned Cadences
26-
- Toggle in Locations to hide once-completed quests
27-
- Toggle in Locations to hide once-completed locations
24+
- Add a UI Toggle in Cadence menu to hide all learned abilities
25+
- Add a UI Toggle in Cadence menu to hide all fully learned Cadences
26+
- Add a UI Toggle in Locations to hide once-completed quests
27+
- Add a UI Toggle in Locations to hide once-completed locations
2828
- Remove Sort by Duration toggle in Locations
2929

3030
- review junction UI drag and drop glitch. Size change causing mouse hover over failure.
@@ -34,7 +34,7 @@
3434
- Consider refining I magic into II magic. Fire/Ice
3535

3636
- remove the "last 3 completed quests" feature
37-
- remove the journal
37+
- remove the journal tab
3838
- Consider a stats page that includes historical production rates
3939

4040
- review Slime vs Spider economies. Maybe slime needs to be refined into something that is then refined into gold.

0 commit comments

Comments
 (0)