@quenty/saveslot 1.10.0 → 1.11.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 CHANGED
@@ -3,6 +3,16 @@
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
+ # [1.11.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.10.0...@quenty/saveslot@1.11.0) (2026-07-21)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **saveslot:** satisfy luau-lsp on ephemeral slot code ([12ac92b](https://github.com/Quenty/NevermoreEngine/commit/12ac92b5ecabc391b1cb716c16a3ee7113d7175f))
11
+
12
+ ### Features
13
+
14
+ - Add ephemeral save slots ([16bd91b](https://github.com/Quenty/NevermoreEngine/commit/16bd91b87943a65165245cba90d44274585903d6))
15
+
6
16
  # [1.10.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.9.0...@quenty/saveslot@1.10.0) (2026-07-21)
7
17
 
8
18
  **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": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "PlayerDataStoreService wrapper for save slots",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -34,7 +34,7 @@
34
34
  "@quenty/binder": "14.39.0",
35
35
  "@quenty/brio": "14.32.0",
36
36
  "@quenty/cmdrservice": "13.49.0",
37
- "@quenty/datastore": "13.44.0",
37
+ "@quenty/datastore": "13.45.0",
38
38
  "@quenty/instanceutils": "13.32.0",
39
39
  "@quenty/loader": "10.11.0",
40
40
  "@quenty/maid": "3.10.0",
@@ -56,5 +56,5 @@
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "8bd905a5c7e7f1fd4e178b54beeadef94a615d1d"
59
+ "gitHead": "f04837e2cf40c9cb66cb672f1f4d3f28ddb0088c"
60
60
  }
@@ -12,6 +12,7 @@ local Brio = require("Brio")
12
12
  local DataStoreStage = require("DataStoreStage")
13
13
  local HasSaveSlotsBase = require("HasSaveSlotsBase")
14
14
  local HasSaveSlotsInterface = require("HasSaveSlotsInterface")
15
+ local InMemoryDataStore = require("InMemoryDataStore")
15
16
  local Maid = require("Maid")
16
17
  local Observable = require("Observable")
17
18
  local ObservableMap = require("ObservableMap")
@@ -36,6 +37,13 @@ export type SummaryProvider = (Player, DataStoreStage.DataStoreStage) -> Observa
36
37
  -- identity, so it never collides with a real value (even an empty table) a provider might emit.
37
38
  local NONE = {}
38
39
 
40
+ -- An ephemeral slot carries no meaningful index -- a real slot's index positions it in the save list and
41
+ -- routes its store, neither of which applies to a throwaway slot. The authoritative "is ephemeral"
42
+ -- discriminator is the slot's own IsEphemeral property (see _isEphemeral), and every index-accounting path
43
+ -- skips ephemeral slots, so this value never routes anything and any number of ephemeral slots can coexist.
44
+ -- 0 is used because a real index is always >= 1 (DEFAULT_SLOT_INDEX is 1, PromiseCreateSlot rejects < 1).
45
+ local EPHEMERAL_SLOT_INDEX = 0
46
+
39
47
  -- The caller-supplied fields for a new slot. SlotId and SlotIndex are assigned by PromiseCreateSlot
40
48
  -- itself (from a fresh GUID and the slotIndex argument), so they are never taken from here.
41
49
  export type SaveSlotCreateMetadata = {
@@ -55,6 +63,10 @@ export type HasSaveSlots =
55
63
  _playerDataStoreService: any,
56
64
  _slotContainer: Folder,
57
65
  _slotMap: { [SaveSlotData.SlotId]: Folder },
66
+ -- The in-memory stores backing ephemeral (session-only) slots, keyed by slot id. A slot's
67
+ -- IsEphemeral property is the discriminator (see _isEphemeral); this holds the store objects a
68
+ -- property can't. See PromiseSelectEphemeralSlot.
69
+ _ephemeralStores: { [SaveSlotData.SlotId]: InMemoryDataStore.InMemoryDataStore },
58
70
  _loadPromise: Promise.Promise<{}>,
59
71
  _remoting: any,
60
72
  _dataStore: any,
@@ -84,6 +96,7 @@ function HasSaveSlots.new(player: Player, serviceBag: ServiceBag.ServiceBag): Ha
84
96
  self._slotContainer.Parent = self._obj
85
97
 
86
98
  self._slotMap = {}
99
+ self._ephemeralStores = {}
87
100
 
88
101
  self._summaryProviders = self._maid:Add(ObservableMap.new())
89
102
 
@@ -174,6 +187,13 @@ function HasSaveSlots.PromiseSelectSlot(self: HasSaveSlots, slotId: SaveSlotData
174
187
  return
175
188
  end
176
189
 
190
+ -- Leaving an ephemeral slot has nothing to persist, so switch without a datastore flush (the flush
191
+ -- exists to save the outgoing slot's progress, and an ephemeral slot has none).
192
+ if self:_isEphemeral(self.ActiveSlotId.Value) then
193
+ setSlot()
194
+ return
195
+ end
196
+
177
197
  return self._dataStore:Save():Then(setSlot)
178
198
  end)
179
199
  end
@@ -192,6 +212,12 @@ function HasSaveSlots.PromiseDeselectSlot(self: HasSaveSlots): Promise.Promise<(
192
212
  return -- Already deselected
193
213
  end
194
214
 
215
+ -- An ephemeral slot has nothing to flush, so clear it without a datastore save.
216
+ if self:_isEphemeral(self.ActiveSlotId.Value) then
217
+ self.ActiveSlotId.Value = nil
218
+ return
219
+ end
220
+
195
221
  return self._dataStore:Save():Then(function()
196
222
  self.ActiveSlotId.Value = nil
197
223
  end)
@@ -211,7 +237,10 @@ function HasSaveSlots.PromiseCreateSlot(
211
237
  return (Promise :: any).rejected(`Index must be in range [1, {self.MaxSlotCount.Value}]`)
212
238
  end
213
239
 
214
- for _, slot in self._slotMap do
240
+ for existingSlotId, slot in self._slotMap do
241
+ if self:_isEphemeral(existingSlotId) then
242
+ continue -- ephemeral slots carry no meaningful index; never let one block a real index
243
+ end
215
244
  if slotIndex == SaveSlotData.SlotIndex:Get(slot) then
216
245
  return (Promise :: any).rejected(`Slot {slotIndex} already exists`)
217
246
  end
@@ -247,10 +276,16 @@ function HasSaveSlots.PromiseDuplicateSlot(
247
276
  return (Promise :: any).rejected(`Slot \{{slotId}\} not found`)
248
277
  end
249
278
 
279
+ if self:_isEphemeral(slotId) then
280
+ return (Promise :: any).rejected("Cannot duplicate an ephemeral slot")
281
+ end
282
+
250
283
  -- Lowest free positive index, filling gaps left by deletions (mirrors PromiseSelectNewSaveSlot).
251
284
  local usedIndices = {}
252
- for _, slot in self._slotMap do
253
- usedIndices[SaveSlotData.SlotIndex:Get(slot)] = true
285
+ for existingSlotId, slot in self._slotMap do
286
+ if not self:_isEphemeral(existingSlotId) then
287
+ usedIndices[SaveSlotData.SlotIndex:Get(slot)] = true
288
+ end
254
289
  end
255
290
  local freeIndex = 1
256
291
  while usedIndices[freeIndex] do
@@ -393,6 +428,10 @@ function HasSaveSlots.PromiseResetSlot(
393
428
  return (Promise :: any).rejected(`Slot \{{slotId}\} not found`)
394
429
  end
395
430
 
431
+ if self:_isEphemeral(slotId) then
432
+ return (Promise :: any).rejected("Cannot reset an ephemeral slot")
433
+ end
434
+
396
435
  local metadata = SaveSlotData:Get(slot)
397
436
  local wasActive = (slotId == self.ActiveSlotId.Value)
398
437
  -- PromiseDeleteSlot clears the continue pointer when it targets the last-active slot; capture it
@@ -491,6 +530,9 @@ function HasSaveSlots.PromiseSlotIdFromIndex(
491
530
  ): Promise.Promise<SaveSlotData.SlotId?>
492
531
  return (self._loadPromise :: any):Then(function()
493
532
  for slotId, slot in self._slotMap do
533
+ if self:_isEphemeral(slotId) then
534
+ continue -- ephemeral slots are never addressable by index
535
+ end
494
536
  if slotIndex == SaveSlotData.SlotIndex:Get(slot) then
495
537
  return (Promise :: any).resolved(slotId)
496
538
  end
@@ -539,8 +581,10 @@ end
539
581
  function HasSaveSlots.PromiseSelectNewSaveSlot(self: HasSaveSlots): Promise.Promise<SaveSlotData.SlotId?>
540
582
  return (self._loadPromise :: any):Then(function(): any
541
583
  local usedIndices = {}
542
- for _, slot in self._slotMap do
543
- usedIndices[SaveSlotData.SlotIndex:Get(slot)] = true
584
+ for existingSlotId, slot in self._slotMap do
585
+ if not self:_isEphemeral(existingSlotId) then
586
+ usedIndices[SaveSlotData.SlotIndex:Get(slot)] = true
587
+ end
544
588
  end
545
589
 
546
590
  -- Lowest free positive index. Fills gaps left by deletions (delete slot 2 of
@@ -564,6 +608,40 @@ function HasSaveSlots.PromiseSelectNewSaveSlot(self: HasSaveSlots): Promise.Prom
564
608
  end)
565
609
  end
566
610
 
611
+ --[=[
612
+ Creates a fresh ephemeral slot and selects it, resolving to its id. An ephemeral slot is selectable and
613
+ active exactly like a real one -- it drives [HasSaveSlots.ObserveActiveSlotStoreBrio], summaries, and
614
+ playtime the same way -- but it is never persisted: no metadata is written, its data store is in-memory,
615
+ it is kept out of the replicated slot list, and it is torn down the moment it stops being the active slot.
616
+ Selecting it also never disturbs the persisted active-slot pointer or the "Continue" target, so the real
617
+ slot the player came from resumes untouched afterward. Backs a throwaway session (e.g. exploring a lobby)
618
+ that must leave no trace on save data.
619
+
620
+ @param metadata SaveSlotCreateMetadata? -- optional SlotName/Summary for the in-memory slot
621
+ @return Promise<SlotId>
622
+ ]=]
623
+ function HasSaveSlots.PromiseSelectEphemeralSlot(
624
+ self: HasSaveSlots,
625
+ metadata: SaveSlotCreateMetadata?
626
+ ): Promise.Promise<SaveSlotData.SlotId>
627
+ return (self._loadPromise :: any):Then(function()
628
+ local slotId = HttpService:GenerateGUID(false)
629
+ local data = {
630
+ SlotId = slotId,
631
+ SlotIndex = EPHEMERAL_SLOT_INDEX,
632
+ SlotName = (metadata and metadata.SlotName) or "Ephemeral",
633
+ CreatedTime = os.time(),
634
+ Summary = metadata and metadata.Summary,
635
+ }
636
+
637
+ self:_buildSlot(slotId, data, true, true)
638
+
639
+ return self:PromiseSelectSlot(slotId):Then(function()
640
+ return slotId
641
+ end)
642
+ end)
643
+ end
644
+
567
645
  --[=[
568
646
  Registers a named summary provider. Every registered provider's current value is aggregated into
569
647
  the active slot's Summary, keyed by `name` (see [HasSaveSlots.PromiseGetSlotMetadata]). Registering
@@ -611,14 +689,37 @@ function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
611
689
  return self._systemStore:Load("activeSlotId"):Then(function(activeId: SaveSlotData.SlotId?)
612
690
  self._lastActiveSlotId = activeId
613
691
  self.LastActiveSlotId.Value = activeId
614
- self._maid:GiveTask(self._systemStore:StoreOnValueChange("activeSlotId", self.ActiveSlotId))
615
692
 
616
- -- Keep the replicated last-active in sync as the player selects slots this session
693
+ -- The persisted active-slot pointer and the replicated "Continue" target only ever track real
694
+ -- slots. This replaces StoreOnValueChange so an ephemeral selection is invisible to both:
695
+ -- entering one leaves them pinned to the real slot, and the ephemeral slot is torn down the
696
+ -- moment it stops being active. We track the id we are leaving to know which of those to do.
697
+ local previousActiveSlotId: SaveSlotData.SlotId? = activeId
698
+
617
699
  self._maid:GiveTask(self.ActiveSlotId.Changed:Connect(function()
618
700
  local active = self.ActiveSlotId.Value
619
- if active ~= nil then
620
- self._lastActiveSlotId = active
621
- self.LastActiveSlotId.Value = active
701
+ local leftSlotId = previousActiveSlotId
702
+ -- Read before the retire below, while the outgoing slot is still in the map.
703
+ local leavingEphemeral = self:_isEphemeral(leftSlotId)
704
+ previousActiveSlotId = active
705
+
706
+ -- Persist the pointer + remember the Continue target only for real-slot transitions
707
+ -- (real -> real, real -> nil deselect, nil -> real). Skip both ephemeral cases: entering an
708
+ -- ephemeral slot must stay invisible to persistence, and leaving one back to no slot must
709
+ -- leave the real pointer pinned where it was.
710
+ local enteringEphemeral = self:_isEphemeral(active)
711
+ local leavingEphemeralToMenu = leavingEphemeral and active == nil
712
+ if not (enteringEphemeral or leavingEphemeralToMenu) then
713
+ self._systemStore:Store("activeSlotId", active)
714
+ if active ~= nil then
715
+ self._lastActiveSlotId = active
716
+ self.LastActiveSlotId.Value = active
717
+ end
718
+ end
719
+
720
+ -- An ephemeral slot exists only while it is the active slot; retire the one we just left.
721
+ if leavingEphemeral and leftSlotId ~= active then
722
+ self:_destroyEphemeralSlot(leftSlotId :: SaveSlotData.SlotId)
622
723
  end
623
724
  end))
624
725
  end)
@@ -627,6 +728,11 @@ function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
627
728
  end
628
729
 
629
730
  function HasSaveSlots._getSlotStore(self: HasSaveSlots, slotId: SaveSlotData.SlotId): DataStoreStage.DataStoreStage
731
+ local ephemeralStore = self._ephemeralStores[slotId]
732
+ if ephemeralStore then
733
+ return ephemeralStore
734
+ end
735
+
630
736
  local slot = self._slotMap[slotId]
631
737
  if slot and (SaveSlotData.SlotIndex:Get(slot) == SaveSlotConstants.DEFAULT_SLOT_INDEX) then
632
738
  return self._dataStore
@@ -634,11 +740,15 @@ function HasSaveSlots._getSlotStore(self: HasSaveSlots, slotId: SaveSlotData.Slo
634
740
  return self._systemStore:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY):GetSubStore(slotId)
635
741
  end
636
742
 
743
+ local MUTABLE_METADATA_KEYS =
744
+ { "SlotName", "CreatedTime", "LastPlayedTime", "Summary", "TimePlayed", "PlayCount", "LastSessionLength" }
745
+
637
746
  function HasSaveSlots._buildSlot(
638
747
  self: HasSaveSlots,
639
748
  slotId: SaveSlotData.SlotId,
640
749
  data: SaveSlotData.SaveSlotMetadata,
641
- isNew: boolean?
750
+ isNew: boolean?,
751
+ isEphemeral: boolean?
642
752
  ): ()
643
753
  local maid = Maid.new()
644
754
  self._maid[slotId] = maid
@@ -647,21 +757,43 @@ function HasSaveSlots._buildSlot(
647
757
  slot.Name = slotId
648
758
  slot.Archivable = false
649
759
 
650
- local metadataStore = self._metadataStore:GetSubStore(slotId)
651
-
652
760
  local attributes = SaveSlotData:Create(slot)
653
761
  attributes.SlotId.Value = slotId
654
762
  attributes.SlotIndex.Value = data.SlotIndex
655
763
 
764
+ if isEphemeral then
765
+ -- Ephemeral: seed the metadata in memory with no write-back wiring, back the slot with an in-memory
766
+ -- store, and deliberately leave the folder unparented so it never joins the replicated slot container
767
+ -- (SaveSlotDataService lists that container's children -- an ephemeral slot must not surface as a save).
768
+ --
769
+ -- The in-memory store's lifetime is owned by this slot's maid (which is in turn owned by self._maid),
770
+ -- so it is Destroyed -- and becomes GC-eligible -- the instant the slot is retired (_destroyEphemeralSlot)
771
+ -- or the player unbinds. Nothing outside this object holds a lasting reference: while the slot is active
772
+ -- ObserveActiveSlotStoreBrio hands it out inside a Brio that dies when the slot deselects, releasing it.
773
+ attributes.IsEphemeral.Value = true
774
+ self._ephemeralStores[slotId] = maid:Add(InMemoryDataStore.new(slotId))
775
+
776
+ for _, key in MUTABLE_METADATA_KEYS do
777
+ attributes[key].Value = data[key]
778
+ end
779
+
780
+ self._slotMap[slotId] = slot
781
+ maid:GiveTask(function()
782
+ self._slotMap[slotId] = nil
783
+ self._ephemeralStores[slotId] = nil
784
+ end)
785
+ return
786
+ end
787
+
788
+ local metadataStore = self._metadataStore:GetSubStore(slotId)
789
+
656
790
  -- Store immutable SlotIndex once on creation
657
791
  if isNew then
658
792
  metadataStore:Store("SlotIndex", data.SlotIndex)
659
793
  end
660
794
 
661
795
  -- Store mutable metadata on change
662
- for _, key in
663
- { "SlotName", "CreatedTime", "LastPlayedTime", "Summary", "TimePlayed", "PlayCount", "LastSessionLength" }
664
- do
796
+ for _, key in MUTABLE_METADATA_KEYS do
665
797
  attributes[key].Value = data[key]
666
798
  maid:GiveTask(metadataStore:StoreOnValueChange(key, attributes[key]))
667
799
 
@@ -679,6 +811,23 @@ function HasSaveSlots._buildSlot(
679
811
  end)
680
812
  end
681
813
 
814
+ -- Whether the slot is an ephemeral (session-only, never-persisted) slot. The slot's own IsEphemeral property
815
+ -- is the single source of truth (set once at creation in _buildSlot); nil-safe so callers can pass a possibly
816
+ -- nil active-slot id directly.
817
+ function HasSaveSlots._isEphemeral(self: HasSaveSlots, slotId: SaveSlotData.SlotId?): boolean
818
+ if slotId == nil then
819
+ return false
820
+ end
821
+ local slot = self._slotMap[slotId] :: Folder?
822
+ return slot ~= nil and SaveSlotData.IsEphemeral:Get(slot) == true
823
+ end
824
+
825
+ -- Tears down the ephemeral slot's maid (folder, in-memory store, and every map entry via the teardown task
826
+ -- registered in _buildSlot). Idempotent -- clearing an already-cleared maid key is a no-op.
827
+ function HasSaveSlots._destroyEphemeralSlot(self: HasSaveSlots, slotId: SaveSlotData.SlotId): ()
828
+ self._maid[slotId] = nil
829
+ end
830
+
682
831
  function HasSaveSlots._setupSummary(self: HasSaveSlots): ()
683
832
  self._maid:GiveTask(
684
833
  self:ObserveActiveSlotStoreBrio():Subscribe(function(brio: Brio.Brio<DataStoreStage.DataStoreStage>)
@@ -16,8 +16,10 @@ local PlayerDataStoreManager = require("PlayerDataStoreManager")
16
16
  local PlayerDataStoreService = require("PlayerDataStoreService")
17
17
  local PromiseTestUtils = require("PromiseTestUtils")
18
18
  local Rx = require("Rx")
19
+ local SaveSlotDataService = require("SaveSlotDataService")
19
20
  local ServiceBag = require("ServiceBag")
20
21
 
22
+ local HttpService = game:GetService("HttpService")
21
23
  local Workspace = game:GetService("Workspace")
22
24
 
23
25
  local describe = Jest.Globals.describe
@@ -1502,3 +1504,216 @@ describe("HasSaveSlots against a fake player (datastore down)", function()
1502
1504
  context.destroy()
1503
1505
  end)
1504
1506
  end)
1507
+
1508
+ describe("HasSaveSlots ephemeral slots", function()
1509
+ -- Settles a promise (failing the test on a hang) and returns its value.
1510
+ local function resolve(promise, timeout: number?)
1511
+ expect(PromiseTestUtils.awaitSettled(promise, timeout or 10)).toEqual(true)
1512
+ local ok, value = promise:Yield()
1513
+ expect(ok).toEqual(true)
1514
+ return value
1515
+ end
1516
+
1517
+ local function selectEphemeral(context: any, metadata: any?)
1518
+ return resolve(context.hasSaveSlots:PromiseSelectEphemeralSlot(metadata))
1519
+ end
1520
+
1521
+ local function createAndSelectReal(context: any, slotIndex: number)
1522
+ local slotId = resolve(context.hasSaveSlots:PromiseCreateSlot(slotIndex))
1523
+ resolve(context.hasSaveSlots:PromiseSelectSlot(slotId))
1524
+ return slotId
1525
+ end
1526
+
1527
+ -- The container SaveSlotDataService lists over; a real slot's folder lives here, an ephemeral one never does.
1528
+ local function slotContainerHasChild(context: any, slotId): boolean
1529
+ local container = context.fakePlayer:FindFirstChild("SaveSlots")
1530
+ return container ~= nil and container:FindFirstChild(slotId) ~= nil
1531
+ end
1532
+
1533
+ it("selects an ephemeral slot and reports it active", function()
1534
+ local context = setup()
1535
+
1536
+ local slotId = selectEphemeral(context)
1537
+ expect(type(slotId)).toEqual("string")
1538
+ expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(slotId)
1539
+ expect(resolve(context.hasSaveSlots:PromiseHasSlot(slotId))).toEqual(true)
1540
+
1541
+ context.destroy()
1542
+ end)
1543
+
1544
+ it("marks the slot with the IsEphemeral property, and real slots without it", function()
1545
+ local context = setup()
1546
+
1547
+ local realId = createAndSelectReal(context, 1)
1548
+ local ephemeralId = selectEphemeral(context)
1549
+
1550
+ local realMetadata = resolve(context.hasSaveSlots:PromiseGetSlotMetadata(realId))
1551
+ local ephemeralMetadata = resolve(context.hasSaveSlots:PromiseGetSlotMetadata(ephemeralId))
1552
+
1553
+ expect(ephemeralMetadata.IsEphemeral).toEqual(true)
1554
+ expect(realMetadata.IsEphemeral).never.toEqual(true)
1555
+
1556
+ context.destroy()
1557
+ end)
1558
+
1559
+ it("keeps the ephemeral slot out of the replicated slot list", function()
1560
+ local context = setup()
1561
+
1562
+ local realId = createAndSelectReal(context, 2)
1563
+ local ephemeralId = selectEphemeral(context)
1564
+
1565
+ local listedIds = {}
1566
+ for _, metadata in (SaveSlotDataService :: any):GetSlotList(context.fakePlayer) do
1567
+ listedIds[metadata.SlotId] = true
1568
+ end
1569
+
1570
+ expect(listedIds[realId]).toEqual(true)
1571
+ expect(listedIds[ephemeralId]).toBeNil()
1572
+ expect(slotContainerHasChild(context, realId)).toEqual(true)
1573
+ expect(slotContainerHasChild(context, ephemeralId)).toEqual(false)
1574
+
1575
+ context.destroy()
1576
+ end)
1577
+
1578
+ it("persists a real slot's data but never an ephemeral slot's", function()
1579
+ local context = setup()
1580
+
1581
+ -- A real slot whose data is flushed to the datastore -- selecting the ephemeral slot below saves the
1582
+ -- outgoing real slot -- giving a positive control alongside the ephemeral negative. Distinctive values
1583
+ -- so a substring search can't match them coincidentally elsewhere in the serialized blob.
1584
+ local realId = createAndSelectReal(context, 2)
1585
+ resolve(context.hasSaveSlots:PromiseActiveSlotStore()):Store("coins", 12321)
1586
+
1587
+ local ephemeralId = selectEphemeral(context)
1588
+ resolve(context.hasSaveSlots:PromiseActiveSlotStore()):Store("coins", 98789)
1589
+
1590
+ local raw = (context.mock :: any):GetRaw(tostring(FAKE_USER_ID))
1591
+ local encoded = if raw ~= nil then HttpService:JSONEncode(raw) else ""
1592
+
1593
+ -- string.find returns multiple values, so bind the first before asserting (expect takes one arg).
1594
+ local realIdFound = string.find(encoded, realId, 1, true) ~= nil
1595
+ local realValueFound = string.find(encoded, "12321", 1, true) ~= nil
1596
+ local ephemeralIdFound = string.find(encoded, ephemeralId, 1, true) ~= nil
1597
+ local ephemeralValueFound = string.find(encoded, "98789", 1, true) ~= nil
1598
+
1599
+ -- The real slot and its value reached the datastore...
1600
+ expect(realIdFound).toEqual(true)
1601
+ expect(realValueFound).toEqual(true)
1602
+ -- ...but nothing of the ephemeral slot did: not its id, not the value written through its store.
1603
+ expect(ephemeralIdFound).toEqual(false)
1604
+ expect(ephemeralValueFound).toEqual(false)
1605
+
1606
+ context.destroy()
1607
+ end)
1608
+
1609
+ it("destroys the ephemeral slot's in-memory store when it is retired", function()
1610
+ local context = setup()
1611
+
1612
+ selectEphemeral(context)
1613
+ local store = resolve(context.hasSaveSlots:PromiseActiveSlotStore())
1614
+ expect(getmetatable(store)).never.toBeNil()
1615
+
1616
+ resolve(context.hasSaveSlots:PromiseDeselectSlot())
1617
+
1618
+ -- BaseObject.Destroy clears the metatable, so a nil metatable means the store was torn down (and is
1619
+ -- now GC-eligible) when the slot was retired, rather than lingering.
1620
+ expect(getmetatable(store)).toBeNil()
1621
+
1622
+ context.destroy()
1623
+ end)
1624
+
1625
+ it("does not disturb the Continue pointer when an ephemeral slot is selected", function()
1626
+ local context = setup()
1627
+
1628
+ local realId = createAndSelectReal(context, 1)
1629
+ -- Selecting the ephemeral slot must leave the replicated last-active pinned to the real slot.
1630
+ selectEphemeral(context)
1631
+
1632
+ expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(realId)
1633
+
1634
+ context.destroy()
1635
+ end)
1636
+
1637
+ it("tears the ephemeral slot down once it stops being active", function()
1638
+ local context = setup()
1639
+
1640
+ local ephemeralId = selectEphemeral(context)
1641
+ expect(resolve(context.hasSaveSlots:PromiseHasSlot(ephemeralId))).toEqual(true)
1642
+
1643
+ resolve(context.hasSaveSlots:PromiseDeselectSlot())
1644
+
1645
+ expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(nil)
1646
+ expect(resolve(context.hasSaveSlots:PromiseHasSlot(ephemeralId))).toEqual(false)
1647
+ expect(slotContainerHasChild(context, ephemeralId)).toEqual(false)
1648
+
1649
+ context.destroy()
1650
+ end)
1651
+
1652
+ it("retires the ephemeral slot when switching to a real slot, keeping the real slots", function()
1653
+ local context = setup()
1654
+
1655
+ local slotA = createAndSelectReal(context, 1)
1656
+ local slotB = resolve(context.hasSaveSlots:PromiseCreateSlot(2))
1657
+ local ephemeralId = selectEphemeral(context)
1658
+
1659
+ resolve(context.hasSaveSlots:PromiseSelectSlot(slotB))
1660
+
1661
+ expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(slotB)
1662
+ expect(resolve(context.hasSaveSlots:PromiseHasSlot(ephemeralId))).toEqual(false)
1663
+ expect(resolve(context.hasSaveSlots:PromiseHasSlot(slotA))).toEqual(true)
1664
+ expect(resolve(context.hasSaveSlots:PromiseHasSlot(slotB))).toEqual(true)
1665
+
1666
+ context.destroy()
1667
+ end)
1668
+
1669
+ it("drives summaries through the ephemeral slot's in-memory store", function()
1670
+ local context = setup()
1671
+
1672
+ context.hasSaveSlots:RegisterSummaryProvider("coins", function()
1673
+ return Rx.of(42)
1674
+ end)
1675
+
1676
+ local ephemeralId = selectEphemeral(context)
1677
+
1678
+ local matched = PromiseTestUtils.awaitValue(function()
1679
+ local metadata = context.hasSaveSlots:PromiseGetSlotMetadata(ephemeralId):Wait()
1680
+ return metadata ~= nil and metadata.Summary ~= nil and metadata.Summary.coins == 42
1681
+ end, 10)
1682
+ expect(matched).toEqual(true)
1683
+
1684
+ context.destroy()
1685
+ end)
1686
+
1687
+ it("refuses to reset or duplicate an ephemeral slot", function()
1688
+ local context = setup()
1689
+
1690
+ local ephemeralId = selectEphemeral(context)
1691
+
1692
+ local resetPromise = context.hasSaveSlots:PromiseResetSlot(ephemeralId)
1693
+ expect(PromiseTestUtils.awaitSettled(resetPromise, 10)).toEqual(true)
1694
+ expect((resetPromise:Yield())).toEqual(false)
1695
+
1696
+ local duplicatePromise = context.hasSaveSlots:PromiseDuplicateSlot(ephemeralId)
1697
+ expect(PromiseTestUtils.awaitSettled(duplicatePromise, 10)).toEqual(true)
1698
+ expect((duplicatePromise:Yield())).toEqual(false)
1699
+
1700
+ context.destroy()
1701
+ end)
1702
+
1703
+ it("still resumes the real slot with Continue after an ephemeral session", function()
1704
+ local context = setup()
1705
+
1706
+ local realId = createAndSelectReal(context, 2)
1707
+ resolve(context.hasSaveSlots:PromiseDeselectSlot())
1708
+
1709
+ -- An ephemeral round trip in the middle must not steal the Continue slot.
1710
+ selectEphemeral(context)
1711
+ resolve(context.hasSaveSlots:PromiseDeselectSlot())
1712
+
1713
+ local continuedId = resolve(context.hasSaveSlots:PromiseSelectLastSaveSlot())
1714
+ expect(continuedId).toEqual(realId)
1715
+ expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(realId)
1716
+
1717
+ context.destroy()
1718
+ end)
1719
+ end)
@@ -28,6 +28,9 @@ export type SaveSlotMetadata = {
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
30
  LastSessionLength: number?, -- seconds of the current/most-recent session
31
+ -- A session-only slot that is never persisted and is filtered out of the save-slot list. Set at
32
+ -- creation and never mutated; see HasSaveSlots.PromiseSelectEphemeralSlot.
33
+ IsEphemeral: boolean?,
31
34
  }
32
35
 
33
36
  -- The Summary is a structured table JSON-encoded into one attribute. A string is also accepted so a
@@ -54,4 +57,5 @@ return AdorneeData.new({
54
57
  TimePlayed = AdorneeDataEntry.optionalAttribute("number", "TimePlayed"),
55
58
  PlayCount = AdorneeDataEntry.optionalAttribute("number", "PlayCount"),
56
59
  LastSessionLength = AdorneeDataEntry.optionalAttribute("number", "LastSessionLength"),
60
+ IsEphemeral = AdorneeDataEntry.optionalAttribute("boolean", "IsEphemeral"),
57
61
  })
@@ -35,6 +35,7 @@ return TieDefinition.new("HasSaveSlots", {
35
35
  PromiseDeselectSlot = TieDefinition.Types.METHOD,
36
36
  PromiseSelectLastSaveSlot = TieDefinition.Types.METHOD,
37
37
  PromiseSelectNewSaveSlot = TieDefinition.Types.METHOD,
38
+ PromiseSelectEphemeralSlot = TieDefinition.Types.METHOD,
38
39
  PromiseDeleteAllSlots = TieDefinition.Types.METHOD,
39
40
  },
40
41
  })