@quenty/saveslot 2.13.0 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +8 -7
- package/src/Client/Binders/HasSaveSlotsClient.lua +7 -0
- package/src/Server/Binders/HasSaveSlots.lua +8 -0
- package/src/Server/Binders/HasSaveSlots.spec.lua +22 -0
- package/src/Server/HasSaveSlotsDataStore.lua +7 -2
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.lua +25 -37
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.spec.lua +2 -2
- package/src/Shared/Data/SaveSlotData.lua +1 -1
- package/src/Shared/HasSaveSlotsInterface.lua +1 -1
- package/src/Shared/SaveSlotUtils.lua +42 -0
- package/src/Shared/SaveSlotUtils.spec.lua +57 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.14.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.13.0...@quenty/saveslot@2.14.0) (2026-09-23)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- Save slot allows disselection ([927feab](https://github.com/Quenty/NevermoreEngine/commit/927feab348fd96ac575103ca46ba44dfb3b452bc))
|
|
11
|
+
|
|
6
12
|
# [2.13.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.12.1...@quenty/saveslot@2.13.0) (2026-09-21)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @quenty/saveslot
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/saveslot",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "PlayerDataStoreService wrapper for save slots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -31,17 +31,17 @@
|
|
|
31
31
|
"@quenty/adorneedata": "7.43.0",
|
|
32
32
|
"@quenty/attributeutils": "14.38.0",
|
|
33
33
|
"@quenty/baseobject": "10.16.0",
|
|
34
|
-
"@quenty/binder": "14.
|
|
34
|
+
"@quenty/binder": "14.47.0",
|
|
35
35
|
"@quenty/brio": "14.37.0",
|
|
36
|
-
"@quenty/cmdrservice": "13.
|
|
37
|
-
"@quenty/datastore": "13.
|
|
36
|
+
"@quenty/cmdrservice": "13.63.0",
|
|
37
|
+
"@quenty/datastore": "13.58.0",
|
|
38
38
|
"@quenty/instanceutils": "13.37.0",
|
|
39
39
|
"@quenty/jestutils": "1.1.0",
|
|
40
40
|
"@quenty/loader": "10.11.1",
|
|
41
41
|
"@quenty/maid": "3.12.0",
|
|
42
42
|
"@quenty/nevermore-test-runner": "1.6.0",
|
|
43
|
-
"@quenty/observablecollection": "12.
|
|
44
|
-
"@quenty/playerbinder": "14.
|
|
43
|
+
"@quenty/observablecollection": "12.53.0",
|
|
44
|
+
"@quenty/playerbinder": "14.51.0",
|
|
45
45
|
"@quenty/playermock": "1.10.0",
|
|
46
46
|
"@quenty/promise": "10.24.0",
|
|
47
47
|
"@quenty/propertyvalue": "7.37.0",
|
|
@@ -52,11 +52,12 @@
|
|
|
52
52
|
"@quenty/table": "3.9.2",
|
|
53
53
|
"@quenty/teleportserviceutils": "10.7.0",
|
|
54
54
|
"@quenty/tie": "10.51.0",
|
|
55
|
+
"@quenty/time": "2.6.0",
|
|
55
56
|
"@quenty/valueobject": "13.38.0",
|
|
56
57
|
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
57
58
|
},
|
|
58
59
|
"publishConfig": {
|
|
59
60
|
"access": "public"
|
|
60
61
|
},
|
|
61
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "31423d2314075bdd1f14ebbbc3eb637c5e0cb6ce"
|
|
62
63
|
}
|
|
@@ -120,6 +120,13 @@ function HasSaveSlotsClient.PromiseLastActiveSlotId(self: HasSaveSlotsClient): P
|
|
|
120
120
|
return self._remoting.PromiseLastActiveSlotId:PromiseInvokeServer()
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
+
--[=[
|
|
124
|
+
Clears the active slot selection, returning the player to a no-slot state
|
|
125
|
+
]=]
|
|
126
|
+
function HasSaveSlotsClient.PromiseDeselectSlot(self: HasSaveSlotsClient): Promise.Promise<()>
|
|
127
|
+
return self._remoting.PromiseDeselectSlot:PromiseInvokeServer()
|
|
128
|
+
end
|
|
129
|
+
|
|
123
130
|
--[=[
|
|
124
131
|
Returns the slot ID from the given index
|
|
125
132
|
]=]
|
|
@@ -725,6 +725,14 @@ function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
|
725
725
|
return (Promise :: any).rejected("Bad player")
|
|
726
726
|
end
|
|
727
727
|
end))
|
|
728
|
+
|
|
729
|
+
self._maid:GiveTask(self._remoting.PromiseDeselectSlot:Bind(function(remotePlayer: Player)
|
|
730
|
+
if remotePlayer == self._obj then
|
|
731
|
+
return self:PromiseDeselectSlot()
|
|
732
|
+
else
|
|
733
|
+
return (Promise :: any).rejected("Bad player")
|
|
734
|
+
end
|
|
735
|
+
end))
|
|
728
736
|
end
|
|
729
737
|
|
|
730
738
|
return PlayerBinder.new("HasSaveSlots", HasSaveSlots :: any) :: Binder.Binder<HasSaveSlots>
|
|
@@ -1237,6 +1237,28 @@ describe("HasSaveSlots playtime tracking", function()
|
|
|
1237
1237
|
context:Destroy()
|
|
1238
1238
|
end)
|
|
1239
1239
|
|
|
1240
|
+
it("zeroes LastSessionLength when a session begins, keeping the total minus it as the pre-session time", function()
|
|
1241
|
+
local context = setup()
|
|
1242
|
+
|
|
1243
|
+
local slotId = createAndSelect(context, 1)
|
|
1244
|
+
local tracker: any = context.hasSaveSlots:GetSlotsDataStore()
|
|
1245
|
+
tracker._playSessionStart = os.time() - 120
|
|
1246
|
+
tracker._playSessionLastFlush = os.time() - 120
|
|
1247
|
+
tracker:_flushPlaytime()
|
|
1248
|
+
|
|
1249
|
+
-- Switching away ends the session with its length recorded; coming back must not carry it over
|
|
1250
|
+
createAndSelect(context, 2)
|
|
1251
|
+
local reselectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
1252
|
+
expect(PromiseTestUtils.awaitSettled(reselectPromise, 10)).toEqual(true)
|
|
1253
|
+
reselectPromise:Yield()
|
|
1254
|
+
|
|
1255
|
+
local metadata = getMetadata(context, slotId)
|
|
1256
|
+
expect(metadata.TimePlayed ~= nil and metadata.TimePlayed >= 120).toEqual(true)
|
|
1257
|
+
expect(metadata.LastSessionLength).toEqual(0)
|
|
1258
|
+
|
|
1259
|
+
context:Destroy()
|
|
1260
|
+
end)
|
|
1261
|
+
|
|
1240
1262
|
it("does not accrue time before any slot is selected", function()
|
|
1241
1263
|
local context = setup()
|
|
1242
1264
|
|
|
@@ -41,6 +41,7 @@ local SaveSlotCodeUtils = require("SaveSlotCodeUtils")
|
|
|
41
41
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
42
42
|
local SaveSlotData = require("SaveSlotData")
|
|
43
43
|
local SaveSlotExportUtils = require("SaveSlotExportUtils")
|
|
44
|
+
local SaveSlotUtils = require("SaveSlotUtils")
|
|
44
45
|
local ValueObject = require("ValueObject")
|
|
45
46
|
|
|
46
47
|
-- The caller-supplied fields for a new slot. SlotId and SlotIndex are assigned by PromiseCreateSlot
|
|
@@ -485,7 +486,7 @@ function HasSaveSlotsDataStore.PromiseCreateSlot(
|
|
|
485
486
|
local data = {
|
|
486
487
|
SlotId = slotId,
|
|
487
488
|
SlotIndex = slotIndex,
|
|
488
|
-
SlotName = (metadata and metadata.SlotName) or
|
|
489
|
+
SlotName = (metadata and metadata.SlotName) or SaveSlotUtils.getDefaultSlotName(slotIndex),
|
|
489
490
|
CreatedTime = os.time(),
|
|
490
491
|
Summary = metadata and metadata.Summary,
|
|
491
492
|
TimePlayed = metadata and metadata.TimePlayed,
|
|
@@ -1573,7 +1574,8 @@ end
|
|
|
1573
1574
|
selecting a slot begins one (bumping PlayCount), and deselecting, switching, or unbinding ends
|
|
1574
1575
|
it. Elapsed wall time is folded into the slot's TimePlayed from a datastore saving callback, so
|
|
1575
1576
|
it persists on exactly the cadence the data is written -- always fresh at save time, with no
|
|
1576
|
-
separate timer -- and again at each session boundary.
|
|
1577
|
+
separate timer -- and again at each session boundary. Between flushes the active slot's total is
|
|
1578
|
+
stale on purpose; [SaveSlotUtils.getTimePlayed] re-derives it from the clock for display.
|
|
1577
1579
|
|
|
1578
1580
|
Skipped entirely when the owner opts out (`TrackPlaytime = false`), which is what offline admin
|
|
1579
1581
|
tooling wants: editing a slot from a console is not someone playing it, and no session is ever
|
|
@@ -1619,6 +1621,9 @@ function HasSaveSlotsDataStore._beginPlaySession(self: HasSaveSlotsDataStore, sl
|
|
|
1619
1621
|
local slot = self._slotMap[slotId]
|
|
1620
1622
|
if slot then
|
|
1621
1623
|
SaveSlotData.PlayCount:Set(slot, (SaveSlotData.PlayCount:Get(slot) or 0) + 1)
|
|
1624
|
+
-- Zeroed at the boundary so TimePlayed - LastSessionLength is the pre-session total for the
|
|
1625
|
+
-- whole session, whatever the flush cadence; see SaveSlotUtils.getTimePlayed.
|
|
1626
|
+
SaveSlotData.LastSessionLength:Set(slot, 0)
|
|
1622
1627
|
end
|
|
1623
1628
|
end
|
|
1624
1629
|
|
|
@@ -5,8 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
local require = require(script.Parent.loader).load(script)
|
|
7
7
|
|
|
8
|
+
local RelativeTimeUtils = require("RelativeTimeUtils")
|
|
8
9
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
9
10
|
local SaveSlotData = require("SaveSlotData")
|
|
11
|
+
local SaveSlotUtils = require("SaveSlotUtils")
|
|
12
|
+
local Time = require("Time")
|
|
13
|
+
local TimeDurationUtils = require("TimeDurationUtils")
|
|
10
14
|
|
|
11
15
|
local SaveSlotCmdrUtils = {}
|
|
12
16
|
|
|
@@ -14,6 +18,13 @@ local SaveSlotCmdrUtils = {}
|
|
|
14
18
|
-- JSON-encoded attribute, so they are shallow in practice; this only guards a pathological one.
|
|
15
19
|
local MAX_VALUE_DEPTH = 3
|
|
16
20
|
|
|
21
|
+
-- Unit suffixes for the compact "1h 23m" playtime a listing shows
|
|
22
|
+
local COMPACT_DURATION_STRINGS: TimeDurationUtils.DurationStringOverrides = {
|
|
23
|
+
hours = { one = "%dh", other = "%dh" },
|
|
24
|
+
minutes = { one = "%dm", other = "%dm" },
|
|
25
|
+
seconds = { one = "%ds", other = "%ds" },
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
function SaveSlotCmdrUtils.registerSlotIndexType(cmdr, saveSlotDataService)
|
|
18
29
|
local slotIndex = {
|
|
19
30
|
Transform = function(text: string, player: Player)
|
|
@@ -153,52 +164,29 @@ function SaveSlotCmdrUtils.formatValue(value: any, depth: number?): string
|
|
|
153
164
|
end
|
|
154
165
|
|
|
155
166
|
--[=[
|
|
156
|
-
Renders a duration in seconds as "1h 23m", "23m", or "45s".
|
|
157
|
-
|
|
158
|
-
@param seconds number
|
|
159
|
-
@return string
|
|
167
|
+
Renders a duration in seconds as its two largest units, e.g. "1h 23m", "23m 4s", or "45s".
|
|
160
168
|
]=]
|
|
161
169
|
function SaveSlotCmdrUtils.formatDuration(seconds: number): string
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return `{hours}h {minutes}m`
|
|
168
|
-
elseif minutes > 0 then
|
|
169
|
-
return `{minutes}m`
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
return `{total}s`
|
|
170
|
+
return TimeDurationUtils.format(math.max(0, seconds), "h __ m __ s __", {
|
|
171
|
+
largest = 2,
|
|
172
|
+
trunc = true,
|
|
173
|
+
strings = COMPACT_DURATION_STRINGS,
|
|
174
|
+
})
|
|
173
175
|
end
|
|
174
176
|
|
|
175
177
|
--[=[
|
|
176
|
-
Renders a unix timestamp as UTC plus how long ago it was, e.g. "2026-08-12 14:03 UTC (
|
|
177
|
-
The relative part is what an admin actually reads; the absolute one is what they quote back.
|
|
178
|
-
|
|
179
|
-
@param unixTime number
|
|
180
|
-
@param now number? -- defaults to os.time()
|
|
181
|
-
@return string
|
|
178
|
+
Renders a unix timestamp as UTC plus how long ago it was, e.g. "2026-08-12 14:03 UTC (3 hours ago)".
|
|
179
|
+
The relative part is what an admin actually reads; the absolute one is what they quote back. A
|
|
180
|
+
timestamp ahead of `now` (clock skew) prints the absolute part alone. `now` defaults to os.time().
|
|
182
181
|
]=]
|
|
183
182
|
function SaveSlotCmdrUtils.formatTimestamp(unixTime: number, now: number?): string
|
|
184
|
-
local absolute =
|
|
185
|
-
local
|
|
186
|
-
if
|
|
183
|
+
local absolute = Time.format("YYYY-MM-DD HH:mm [UTC]", unixTime)
|
|
184
|
+
local resolvedNow = now or os.time()
|
|
185
|
+
if unixTime > resolvedNow then
|
|
187
186
|
return absolute
|
|
188
187
|
end
|
|
189
188
|
|
|
190
|
-
|
|
191
|
-
if elapsed < 60 then
|
|
192
|
-
relative = "just now"
|
|
193
|
-
elseif elapsed < 3600 then
|
|
194
|
-
relative = `{math.floor(elapsed / 60)}m ago`
|
|
195
|
-
elseif elapsed < 86400 then
|
|
196
|
-
relative = `{math.floor(elapsed / 3600)}h ago`
|
|
197
|
-
else
|
|
198
|
-
relative = `{math.floor(elapsed / 86400)}d ago`
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
return `{absolute} ({relative})`
|
|
189
|
+
return `{absolute} ({RelativeTimeUtils.from(unixTime, resolvedNow)})`
|
|
202
190
|
end
|
|
203
191
|
|
|
204
192
|
--[=[
|
|
@@ -251,7 +239,7 @@ function SaveSlotCmdrUtils.formatSlotBlock(
|
|
|
251
239
|
status: string?,
|
|
252
240
|
now: number?
|
|
253
241
|
): string
|
|
254
|
-
local name = metadata.SlotName or
|
|
242
|
+
local name = metadata.SlotName or SaveSlotUtils.getDefaultSlotName(metadata.SlotIndex)
|
|
255
243
|
local lines = { `"{name}" ({metadata.SlotIndex}){if status then ` — {status}` else ""}` }
|
|
256
244
|
|
|
257
245
|
local played = {}
|
|
@@ -244,8 +244,8 @@ describe("SaveSlotCmdrUtils.formatSlotBlock", function()
|
|
|
244
244
|
|
|
245
245
|
expect(block).toBe(table.concat({
|
|
246
246
|
'"Alpha" (1) — Active',
|
|
247
|
-
" played 1h 23m, 4 session(s), last played 2025-07-31 20:13 UTC (
|
|
248
|
-
" created 2025-07-28 22:13 UTC (
|
|
247
|
+
" played 1h 23m, 4 session(s), last played 2025-07-31 20:13 UTC (2 hours ago)",
|
|
248
|
+
" created 2025-07-28 22:13 UTC (3 days ago)",
|
|
249
249
|
" progress: chapter = 3",
|
|
250
250
|
}, "\n"))
|
|
251
251
|
end)
|
|
@@ -27,7 +27,7 @@ export type SaveSlotMetadata = {
|
|
|
27
27
|
-- Accrued automatically by HasSaveSlots while the slot is the active slot; see _setupPlaytimeTracking.
|
|
28
28
|
TimePlayed: number?, -- total seconds the slot has been actively played, across every session
|
|
29
29
|
PlayCount: number?, -- number of sessions (incremented each time the slot is selected)
|
|
30
|
-
LastSessionLength: number?, -- seconds of the current/most-recent session
|
|
30
|
+
LastSessionLength: number?, -- seconds of the current/most-recent session, zeroed when a session begins
|
|
31
31
|
-- A session-only slot that is never persisted and is filtered out of the save-slot list. Set at
|
|
32
32
|
-- creation and never mutated; see HasSaveSlots.PromiseSelectEphemeralSlot.
|
|
33
33
|
IsEphemeral: boolean?,
|
|
@@ -20,6 +20,7 @@ return TieDefinition.new("HasSaveSlots", {
|
|
|
20
20
|
PromiseGetSlotMetadata = TieDefinition.Types.METHOD,
|
|
21
21
|
PromiseSlotIdFromIndex = TieDefinition.Types.METHOD,
|
|
22
22
|
PromiseLastActiveSlotId = TieDefinition.Types.METHOD,
|
|
23
|
+
PromiseDeselectSlot = TieDefinition.Types.METHOD,
|
|
23
24
|
|
|
24
25
|
-- Answered from the teleport data the player arrived with (see HasSaveSlotsBase); both realms
|
|
25
26
|
-- resolve the incoming slot id from their own [TeleportDataService].
|
|
@@ -32,7 +33,6 @@ return TieDefinition.new("HasSaveSlots", {
|
|
|
32
33
|
ObserveActiveSlotStoreBrio = TieDefinition.Types.METHOD,
|
|
33
34
|
PromiseActiveSlotStore = TieDefinition.Types.METHOD,
|
|
34
35
|
PromiseSlotsLoaded = TieDefinition.Types.METHOD,
|
|
35
|
-
PromiseDeselectSlot = TieDefinition.Types.METHOD,
|
|
36
36
|
PromiseSelectLastSaveSlot = TieDefinition.Types.METHOD,
|
|
37
37
|
PromiseSelectNewSaveSlot = TieDefinition.Types.METHOD,
|
|
38
38
|
PromiseSelectEphemeralSlot = TieDefinition.Types.METHOD,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[=[
|
|
3
|
+
@class SaveSlotUtils
|
|
4
|
+
]=]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local SaveSlotData = require("SaveSlotData")
|
|
9
|
+
|
|
10
|
+
local SaveSlotUtils = {}
|
|
11
|
+
|
|
12
|
+
--[=[
|
|
13
|
+
The name a slot gets when it is created without one, or when its name is cleared.
|
|
14
|
+
]=]
|
|
15
|
+
function SaveSlotUtils.getDefaultSlotName(slotIndex: number): string
|
|
16
|
+
assert(type(slotIndex) == "number", "Bad slotIndex")
|
|
17
|
+
|
|
18
|
+
return `Slot {slotIndex}`
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
--[=[
|
|
22
|
+
Seconds the slot has been played, current as of `now` (defaults to `os.time()`). `TimePlayed`
|
|
23
|
+
only lands on the slot when its data saves or its session ends, so for the active slot the
|
|
24
|
+
running session is re-derived: the total minus the part of it already credited to this session,
|
|
25
|
+
plus the wall time since the slot was selected. It never reads below the credited total, so a
|
|
26
|
+
client clock behind the server's cannot make it go backwards.
|
|
27
|
+
]=]
|
|
28
|
+
function SaveSlotUtils.getTimePlayed(metadata: SaveSlotData.SaveSlotMetadata, isActive: boolean, now: number?): number
|
|
29
|
+
assert(type(metadata) == "table", "Bad metadata")
|
|
30
|
+
assert(type(isActive) == "boolean", "Bad isActive")
|
|
31
|
+
|
|
32
|
+
local timePlayed = metadata.TimePlayed or 0
|
|
33
|
+
if not isActive or metadata.LastPlayedTime == nil then
|
|
34
|
+
return timePlayed
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
local beforeSession = timePlayed - (metadata.LastSessionLength or 0)
|
|
38
|
+
local sessionLength = (now or os.time()) - metadata.LastPlayedTime
|
|
39
|
+
return math.max(timePlayed, beforeSession + sessionLength)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
return SaveSlotUtils
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
local require = require(script.Parent.loader).load(script)
|
|
3
|
+
|
|
4
|
+
local Jest = require("Jest")
|
|
5
|
+
local SaveSlotUtils = require("SaveSlotUtils")
|
|
6
|
+
|
|
7
|
+
local describe = Jest.Globals.describe
|
|
8
|
+
local expect = Jest.Globals.expect
|
|
9
|
+
local it = Jest.Globals.it
|
|
10
|
+
|
|
11
|
+
local NOW = 1_754_000_000
|
|
12
|
+
|
|
13
|
+
local function metadata(fields: { [string]: any }): any
|
|
14
|
+
local result: { [string]: any } = { SlotId = "slot-1", SlotIndex = 1 }
|
|
15
|
+
for key, value in fields do
|
|
16
|
+
result[key] = value
|
|
17
|
+
end
|
|
18
|
+
return result
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe("SaveSlotUtils.getTimePlayed", function()
|
|
22
|
+
it("returns the credited total for an inactive slot", function()
|
|
23
|
+
local slot = metadata({ TimePlayed = 500, LastSessionLength = 120, LastPlayedTime = NOW - 3600 })
|
|
24
|
+
|
|
25
|
+
expect(SaveSlotUtils.getTimePlayed(slot, false, NOW)).toBe(500)
|
|
26
|
+
end)
|
|
27
|
+
|
|
28
|
+
it("returns zero for a slot that has never been played", function()
|
|
29
|
+
expect(SaveSlotUtils.getTimePlayed(metadata({}), false, NOW)).toBe(0)
|
|
30
|
+
expect(SaveSlotUtils.getTimePlayed(metadata({}), true, NOW)).toBe(0)
|
|
31
|
+
end)
|
|
32
|
+
|
|
33
|
+
it("counts the running session from the moment the active slot was selected", function()
|
|
34
|
+
local slot = metadata({ TimePlayed = 500, LastSessionLength = 0, LastPlayedTime = NOW - 90 })
|
|
35
|
+
|
|
36
|
+
expect(SaveSlotUtils.getTimePlayed(slot, true, NOW)).toBe(590)
|
|
37
|
+
end)
|
|
38
|
+
|
|
39
|
+
it("does not double count the part of the session a flush already credited", function()
|
|
40
|
+
-- 60s of a 90s session has been flushed into the total
|
|
41
|
+
local slot = metadata({ TimePlayed = 560, LastSessionLength = 60, LastPlayedTime = NOW - 90 })
|
|
42
|
+
|
|
43
|
+
expect(SaveSlotUtils.getTimePlayed(slot, true, NOW)).toBe(590)
|
|
44
|
+
end)
|
|
45
|
+
|
|
46
|
+
it("never reads below the credited total when the clock is behind the server", function()
|
|
47
|
+
local slot = metadata({ TimePlayed = 560, LastSessionLength = 60, LastPlayedTime = NOW - 90 })
|
|
48
|
+
|
|
49
|
+
expect(SaveSlotUtils.getTimePlayed(slot, true, NOW - 45)).toBe(560)
|
|
50
|
+
end)
|
|
51
|
+
|
|
52
|
+
it("starts a first session from zero", function()
|
|
53
|
+
local slot = metadata({ LastPlayedTime = NOW - 30 })
|
|
54
|
+
|
|
55
|
+
expect(SaveSlotUtils.getTimePlayed(slot, true, NOW)).toBe(30)
|
|
56
|
+
end)
|
|
57
|
+
end)
|