@quenty/saveslot 2.8.1 → 2.9.1

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 CHANGED
@@ -3,6 +3,17 @@
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.9.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.9.0...@quenty/saveslot@2.9.1) (2026-08-24)
7
+
8
+ **Note:** Version bump only for package @quenty/saveslot
9
+
10
+ # [2.9.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.8.1...@quenty/saveslot@2.9.0) (2026-08-24)
11
+
12
+ ### Bug Fixes
13
+
14
+ - Check if alive ([2c36dff](https://github.com/Quenty/NevermoreEngine/commit/2c36dff98a87749fc9f0598355751e5e52109b37))
15
+ - Store playtime synchronously ([502c4c9](https://github.com/Quenty/NevermoreEngine/commit/502c4c9b253980a64720780f7d7570c01fa85e77))
16
+
6
17
  ## [2.8.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.8.0...@quenty/saveslot@2.8.1) (2026-08-14)
7
18
 
8
19
  **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.8.1",
3
+ "version": "2.9.1",
4
4
  "description": "PlayerDataStoreService wrapper for save slots",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -33,13 +33,13 @@
33
33
  "@quenty/baseobject": "10.15.1",
34
34
  "@quenty/binder": "14.43.2",
35
35
  "@quenty/brio": "14.35.2",
36
- "@quenty/cmdrservice": "13.57.1",
37
- "@quenty/datastore": "13.52.1",
36
+ "@quenty/cmdrservice": "13.58.1",
37
+ "@quenty/datastore": "13.53.1",
38
38
  "@quenty/instanceutils": "13.35.2",
39
39
  "@quenty/loader": "10.11.1",
40
40
  "@quenty/maid": "3.11.1",
41
41
  "@quenty/nevermore-test-runner": "1.5.1",
42
- "@quenty/observablecollection": "12.47.1",
42
+ "@quenty/observablecollection": "12.48.1",
43
43
  "@quenty/playerbinder": "14.46.1",
44
44
  "@quenty/playermock": "1.6.1",
45
45
  "@quenty/promise": "10.23.1",
@@ -57,5 +57,5 @@
57
57
  "publishConfig": {
58
58
  "access": "public"
59
59
  },
60
- "gitHead": "f084360c3729ea424d49d9bc42f8f0d1c128fa82"
60
+ "gitHead": "1a2c0cc735d06b4adcd324f60302b950e12d68b0"
61
61
  }
@@ -1595,8 +1595,9 @@ function HasSaveSlotsDataStore._setupPlaytimeTracking(self: HasSaveSlotsDataStor
1595
1595
  end))
1596
1596
 
1597
1597
  -- Fold accrued time into TimePlayed just before every save so the written value is current. The
1598
- -- callback runs before the save serializes staged data (see DataStore._syncData), so the flush is
1599
- -- captured by that same save -- including the final save-on-leave.
1598
+ -- callback runs before the save serializes staged data (see DataStore._syncData), and the flush
1599
+ -- stages that data itself (see _stagePlaytime), so it is captured by that same save -- including
1600
+ -- the final save-on-leave.
1600
1601
  self._maid:GivePromise(self._loadPromise):Then(function()
1601
1602
  self._maid:GiveTask(self._dataStore:AddSavingCallback(function()
1602
1603
  self:_flushPlaytime()
@@ -1642,6 +1643,31 @@ function HasSaveSlotsDataStore._flushPlaytime(self: HasSaveSlotsDataStore): ()
1642
1643
  end
1643
1644
 
1644
1645
  SaveSlotData.LastSessionLength:Set(slot, now - (self._playSessionStart or now))
1646
+
1647
+ self:_stagePlaytime(slotId, slot)
1648
+ end
1649
+
1650
+ --[[
1651
+ Stages the just-written playtime attributes into the metadata store synchronously.
1652
+
1653
+ The usual StoreOnValueChange route is deferred, so it always lands after the save that asked for
1654
+ the flush took its snapshot (see DataStore._syncData): each save would persist the previous
1655
+ flush's value, and the final save-on-leave would drop the tail of the session. Storing here closes
1656
+ that window; the deferred listener then re-stores the same value as a no-op. Ephemeral slots
1657
+ persist nothing, so they keep the attribute-only behavior.
1658
+ ]]
1659
+ function HasSaveSlotsDataStore._stagePlaytime(
1660
+ self: HasSaveSlotsDataStore,
1661
+ slotId: SaveSlotData.SlotId,
1662
+ slot: Folder
1663
+ ): ()
1664
+ if self._metadataStore == nil or not self._metadataStore.Destroy or self:_isEphemeral(slotId) then
1665
+ return
1666
+ end
1667
+
1668
+ local metadataStore = self._metadataStore:GetSubStore(slotId)
1669
+ metadataStore:Store("TimePlayed", SaveSlotData.TimePlayed:Get(slot))
1670
+ metadataStore:Store("LastSessionLength", SaveSlotData.LastSessionLength:Get(slot))
1645
1671
  end
1646
1672
 
1647
1673
  function HasSaveSlotsDataStore._endPlaySession(self: HasSaveSlotsDataStore): ()
@@ -0,0 +1,122 @@
1
+ --!nonstrict
2
+ --[[
3
+ Playtime accrual persists on the save that asked for it. The flush runs from a saving callback,
4
+ so a value that only reached the store through the deferred attribute listener would land one
5
+ save late -- and the final save-on-leave would drop the tail of the session entirely.
6
+
7
+ @class SaveSlotPlaytime.spec.lua
8
+ ]]
9
+ local require = require(script.Parent.loader).load(script)
10
+
11
+ local DataStoreMock = require("DataStoreMock")
12
+ local DataStoreTestUtils = require("DataStoreTestUtils")
13
+ local HasSaveSlotsDataStore = require("HasSaveSlotsDataStore")
14
+ local Jest = require("Jest")
15
+ local Maid = require("Maid")
16
+ local PlayerDataStoreService = require("PlayerDataStoreService")
17
+ local Promise = require("Promise")
18
+ local PromiseTestUtils = require("PromiseTestUtils")
19
+ local SaveSlotConstants = require("SaveSlotConstants")
20
+ local SaveSlotSharedDataStoreService = require("SaveSlotSharedDataStoreService")
21
+ local ServiceBag = require("ServiceBag")
22
+ local ValueObject = require("ValueObject")
23
+
24
+ local describe = Jest.Globals.describe
25
+ local expect = Jest.Globals.expect
26
+ local it = Jest.Globals.it
27
+
28
+ local USER_ID = 4242
29
+ local SESSION_SECONDS = 120
30
+
31
+ local function setup()
32
+ local maid = Maid.new()
33
+ local serviceBag = maid:Add(ServiceBag.new())
34
+ local playerDataStoreService = serviceBag:GetService(PlayerDataStoreService)
35
+ local sharedDataStoreService = serviceBag:GetService(SaveSlotSharedDataStoreService)
36
+ serviceBag:Init()
37
+
38
+ local mock = DataStoreMock.new()
39
+ playerDataStoreService:SetRobloxDataStore(mock)
40
+ serviceBag:Start()
41
+
42
+ local function await(promise, label: string): any
43
+ if not PromiseTestUtils.awaitSettled(promise, 10) then
44
+ expect(`{label} hung`).toEqual(`{label} settled`)
45
+ return nil
46
+ end
47
+ local ok, value = promise:Yield()
48
+ if not ok then
49
+ expect(`{label} rejected: {tostring(value)}`).toEqual(`{label} fulfilled`)
50
+ return nil
51
+ end
52
+ return value
53
+ end
54
+
55
+ local dataStore = await(playerDataStoreService:PromiseDataStore(USER_ID), "data store")
56
+
57
+ local slotsDataStore = maid:Add(HasSaveSlotsDataStore.new(Promise.resolved(dataStore), {
58
+ ActiveSlotId = maid:Add(ValueObject.new(nil)),
59
+ LastActiveSlotId = maid:Add(ValueObject.new(nil)),
60
+ ActiveTransferableEphemeralKey = maid:Add(ValueObject.new(nil)),
61
+ MaxSlotCount = maid:Add(ValueObject.new(5)),
62
+ SharedDataStoreService = sharedDataStoreService,
63
+ UserId = USER_ID,
64
+ }))
65
+ await(slotsDataStore:PromiseSlotsLoaded(), "slots loaded")
66
+
67
+ return {
68
+ await = await,
69
+ mock = mock,
70
+ dataStore = dataStore,
71
+ slotsDataStore = slotsDataStore,
72
+ -- Selects a fresh slot and backdates the session so the next flush accrues real time without
73
+ -- the spec waiting it out.
74
+ beginBackdatedSession = function(): string
75
+ local slotId = await(slotsDataStore:PromiseCreateSlot(1), "create")
76
+ await(slotsDataStore:PromiseSelectSlot(slotId), "select")
77
+ slotsDataStore._playSessionStart -= SESSION_SECONDS
78
+ slotsDataStore._playSessionLastFlush -= SESSION_SECONDS
79
+ return slotId
80
+ end,
81
+ storedMetadata = function(slotId: string): any
82
+ local raw = mock:GetRaw(tostring(USER_ID))
83
+ local system = raw and raw[SaveSlotConstants.SYSTEM_STORE_KEY]
84
+ local metadata = system and system[SaveSlotConstants.METADATA_STORE_KEY]
85
+ return metadata and metadata[slotId]
86
+ end,
87
+ destroy = function()
88
+ DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
89
+ maid:DoCleaning()
90
+ end,
91
+ }
92
+ end
93
+
94
+ describe("save slot playtime", function()
95
+ it("persists accrued playtime on the save that triggered the flush", function()
96
+ local controller = setup()
97
+ local slotId = controller.beginBackdatedSession()
98
+
99
+ controller.await(controller.dataStore:Save(), "save")
100
+
101
+ local stored = controller.storedMetadata(slotId)
102
+ expect(stored).never.toBeNil()
103
+ -- At least the backdated span: the save's own latency can push os.time one second further.
104
+ expect(stored.TimePlayed).toBeGreaterThanOrEqual(SESSION_SECONDS)
105
+ expect(stored.LastSessionLength).toBeGreaterThanOrEqual(SESSION_SECONDS)
106
+
107
+ controller.destroy()
108
+ end)
109
+
110
+ it("keeps the replicated attribute and the stored value in step", function()
111
+ local controller = setup()
112
+ local slotId = controller.beginBackdatedSession()
113
+
114
+ controller.await(controller.dataStore:Save(), "save")
115
+
116
+ expect(controller.slotsDataStore:GetSlotMetadata(slotId).TimePlayed).toEqual(
117
+ controller.storedMetadata(slotId).TimePlayed
118
+ )
119
+
120
+ controller.destroy()
121
+ end)
122
+ end)