@quenty/saveslot 2.0.0 → 2.2.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,20 @@
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.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.1.0...@quenty/saveslot@2.2.0) (2026-07-25)
7
+
8
+ ### Bug Fixes
9
+
10
+ - Ephemeral save slots replicate to the client ([457f3e9](https://github.com/Quenty/NevermoreEngine/commit/457f3e95e1c9f6714e027c0e96754f646ee7f6a5))
11
+
12
+ ### Features
13
+
14
+ - Export other people's save slots for debugging ([d5600ae](https://github.com/Quenty/NevermoreEngine/commit/d5600ae650d0af21dbd0c26d24f7cf7e292489b9))
15
+
16
+ # [2.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.0.0...@quenty/saveslot@2.1.0) (2026-07-24)
17
+
18
+ **Note:** Version bump only for package @quenty/saveslot
19
+
6
20
  # [2.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.15.0...@quenty/saveslot@2.0.0) (2026-07-24)
7
21
 
8
22
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/saveslot",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "PlayerDataStoreService wrapper for save slots",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,34 +28,34 @@
28
28
  "Quenty"
29
29
  ],
30
30
  "dependencies": {
31
- "@quenty/adorneedata": "7.39.0",
32
- "@quenty/attributeutils": "14.34.0",
31
+ "@quenty/adorneedata": "7.40.0",
32
+ "@quenty/attributeutils": "14.35.0",
33
33
  "@quenty/baseobject": "10.15.0",
34
- "@quenty/binder": "14.42.0",
35
- "@quenty/brio": "14.34.0",
36
- "@quenty/cmdrservice": "13.53.0",
37
- "@quenty/datastore": "13.48.0",
38
- "@quenty/instanceutils": "13.34.0",
34
+ "@quenty/binder": "14.43.0",
35
+ "@quenty/brio": "14.35.0",
36
+ "@quenty/cmdrservice": "13.55.0",
37
+ "@quenty/datastore": "13.50.0",
38
+ "@quenty/instanceutils": "13.35.0",
39
39
  "@quenty/loader": "10.11.0",
40
40
  "@quenty/maid": "3.11.0",
41
41
  "@quenty/nevermore-test-runner": "1.5.0",
42
- "@quenty/observablecollection": "12.44.0",
43
- "@quenty/playerbinder": "14.43.0",
44
- "@quenty/playermock": "1.3.0",
45
- "@quenty/promise": "10.22.0",
46
- "@quenty/propertyvalue": "7.34.0",
47
- "@quenty/remoting": "12.38.0",
48
- "@quenty/rx": "13.32.0",
42
+ "@quenty/observablecollection": "12.46.0",
43
+ "@quenty/playerbinder": "14.45.0",
44
+ "@quenty/playermock": "1.5.0",
45
+ "@quenty/promise": "10.23.0",
46
+ "@quenty/propertyvalue": "7.35.0",
47
+ "@quenty/remoting": "12.40.0",
48
+ "@quenty/rx": "13.33.0",
49
49
  "@quenty/servicebag": "11.20.0",
50
50
  "@quenty/signal": "7.13.1",
51
51
  "@quenty/table": "3.9.2",
52
- "@quenty/teleportserviceutils": "10.0.0",
53
- "@quenty/tie": "10.45.0",
54
- "@quenty/valueobject": "13.35.0",
52
+ "@quenty/teleportserviceutils": "10.2.0",
53
+ "@quenty/tie": "10.46.0",
54
+ "@quenty/valueobject": "13.36.0",
55
55
  "@quentystudios/jest-lua": "3.10.0-quenty.2"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"
59
59
  },
60
- "gitHead": "e5b734b961479a14dd903dfccc38a14b2fc1a684"
60
+ "gitHead": "8677b70e89a1ef1585f8492b0638ec4a29aba8a3"
61
61
  }
@@ -109,3 +109,353 @@ describe("HasSaveSlotsClient active-slot observation", function()
109
109
  expect(observed).toEqual("slot-b")
110
110
  end)
111
111
  end)
112
+
113
+ local REAL_ID = "real-slot"
114
+ local EPHEMERAL_ID = "ephemeral-slot"
115
+
116
+ -- Unparented, so each test decides when the slot "replicates".
117
+ local function newSlot(slotId: string, slotIndex: number, slotName: string, isEphemeral: boolean?): Folder
118
+ local slot = Instance.new("Folder")
119
+ slot.Name = slotId
120
+ slot:SetAttribute("SlotIndex", slotIndex)
121
+ slot:SetAttribute("SlotName", slotName)
122
+ if isEphemeral then
123
+ slot:SetAttribute("IsEphemeral", true)
124
+ end
125
+ return slot
126
+ end
127
+
128
+ local function newSlotContainer(maid: Maid.Maid): Folder
129
+ local container = maid:Add(Instance.new("Folder"))
130
+ container.Name = "SaveSlots"
131
+ return container
132
+ end
133
+
134
+ type Record = { count: number, latest: any, values: { any } }
135
+
136
+ -- `values` collects only non-nil emissions (a Lua array cannot hold nils); streams that never emit nil
137
+ -- -- the boolean ones -- can assert their full sequence against it, everything else uses count/latest.
138
+ local function subscribeRecording(maid: Maid.Maid, observable: any): Record
139
+ local record: Record = { count = 0, latest = nil, values = {} }
140
+
141
+ maid:GiveTask(observable:Subscribe(function(value)
142
+ record.count += 1
143
+ record.latest = value
144
+ if value ~= nil then
145
+ table.insert(record.values, value)
146
+ end
147
+ end))
148
+
149
+ return record
150
+ end
151
+
152
+ local function awaitLatest(record: Record, predicate: (any) -> boolean): boolean
153
+ return PromiseTestUtils.awaitValue(function()
154
+ return predicate(record.latest)
155
+ end, 5)
156
+ end
157
+
158
+ local function listedIds(slotList: { any }?): { [string]: boolean }
159
+ local ids = {}
160
+ for _, metadata in (slotList or {}) :: { any } do
161
+ ids[metadata.SlotId] = true
162
+ end
163
+ return ids
164
+ end
165
+
166
+ describe("SaveSlotDataService active-slot metadata on the client", function()
167
+ it("emits nil immediately when nothing has replicated yet", function()
168
+ local maid, _, dataService = setup()
169
+ local playerMock = newPlayerMock(maid, true)
170
+
171
+ local record = subscribeRecording(maid, dataService:ObserveActiveSlotMetadata(playerMock))
172
+
173
+ expect(record.count).toEqual(1)
174
+ expect(record.latest).toBeNil()
175
+ end)
176
+
177
+ it("resolves the active ephemeral slot when its folder arrives after the active-slot id", function()
178
+ local maid, binder, dataService = setup()
179
+ local playerMock = newPlayerMock(maid, true)
180
+ binder:Bind(playerMock)
181
+ playerMock:SetAttribute("ActiveSlotId", EPHEMERAL_ID)
182
+
183
+ local record = subscribeRecording(maid, dataService:ObserveActiveSlotMetadata(playerMock))
184
+ expect(record.latest).toBeNil()
185
+
186
+ local container = newSlotContainer(maid)
187
+ newSlot(EPHEMERAL_ID, 0, "Lobby run", true).Parent = container
188
+ container.Parent = playerMock
189
+
190
+ expect(awaitLatest(record, function(metadata)
191
+ return metadata ~= nil and metadata.SlotName == "Lobby run"
192
+ end)).toEqual(true)
193
+ expect(record.latest.SlotId).toEqual(EPHEMERAL_ID)
194
+ expect(record.latest.IsEphemeral).toEqual(true)
195
+ end)
196
+
197
+ it("resolves the active ephemeral slot when the active-slot id arrives after its folder", function()
198
+ local maid, binder, dataService = setup()
199
+ local playerMock = newPlayerMock(maid, true)
200
+ binder:Bind(playerMock)
201
+
202
+ local container = newSlotContainer(maid)
203
+ newSlot(EPHEMERAL_ID, 0, "Lobby run", true).Parent = container
204
+ container.Parent = playerMock
205
+
206
+ local record = subscribeRecording(maid, dataService:ObserveActiveSlotMetadata(playerMock))
207
+ expect(record.latest).toBeNil()
208
+
209
+ playerMock:SetAttribute("ActiveSlotId", EPHEMERAL_ID)
210
+
211
+ expect(awaitLatest(record, function(metadata)
212
+ return metadata ~= nil and metadata.SlotId == EPHEMERAL_ID
213
+ end)).toEqual(true)
214
+ end)
215
+
216
+ it("emits nil again when the ephemeral slot's folder goes away under a still-set active-slot id", function()
217
+ local maid, binder, dataService = setup()
218
+ local playerMock = newPlayerMock(maid, true)
219
+ binder:Bind(playerMock)
220
+
221
+ local container = newSlotContainer(maid)
222
+ local ephemeralSlot = newSlot(EPHEMERAL_ID, 0, "Lobby run", true)
223
+ ephemeralSlot.Parent = container
224
+ container.Parent = playerMock
225
+ playerMock:SetAttribute("ActiveSlotId", EPHEMERAL_ID)
226
+
227
+ local record = subscribeRecording(maid, dataService:ObserveActiveSlotMetadata(playerMock))
228
+ expect(awaitLatest(record, function(metadata)
229
+ return metadata ~= nil
230
+ end)).toEqual(true)
231
+
232
+ -- A retire replicates as the folder disappearing; the id can still name it for a frame.
233
+ ephemeralSlot:Destroy()
234
+
235
+ expect(awaitLatest(record, function(metadata)
236
+ return metadata == nil
237
+ end)).toEqual(true)
238
+ end)
239
+
240
+ it("follows a switch from the ephemeral slot to a real one", function()
241
+ local maid, binder, dataService = setup()
242
+ local playerMock = newPlayerMock(maid, true)
243
+ binder:Bind(playerMock)
244
+
245
+ local container = newSlotContainer(maid)
246
+ local ephemeralSlot = newSlot(EPHEMERAL_ID, 0, "Lobby run", true)
247
+ ephemeralSlot.Parent = container
248
+ newSlot(REAL_ID, 1, "Slot 1").Parent = container
249
+ container.Parent = playerMock
250
+ playerMock:SetAttribute("ActiveSlotId", EPHEMERAL_ID)
251
+
252
+ local record = subscribeRecording(maid, dataService:ObserveActiveSlotMetadata(playerMock))
253
+ expect(awaitLatest(record, function(metadata)
254
+ return metadata ~= nil and metadata.SlotId == EPHEMERAL_ID
255
+ end)).toEqual(true)
256
+
257
+ playerMock:SetAttribute("ActiveSlotId", REAL_ID)
258
+ ephemeralSlot:Destroy()
259
+
260
+ expect(awaitLatest(record, function(metadata)
261
+ return metadata ~= nil and metadata.SlotId == REAL_ID
262
+ end)).toEqual(true)
263
+ expect(record.latest.IsEphemeral).toBeNil()
264
+ end)
265
+
266
+ it("reads the active ephemeral slot synchronously too", function()
267
+ local maid, binder, dataService = setup()
268
+ local playerMock = newPlayerMock(maid, true)
269
+ binder:Bind(playerMock)
270
+
271
+ local container = newSlotContainer(maid)
272
+ newSlot(EPHEMERAL_ID, 0, "Lobby run", true).Parent = container
273
+ container.Parent = playerMock
274
+ playerMock:SetAttribute("ActiveSlotId", EPHEMERAL_ID)
275
+
276
+ expect(PromiseTestUtils.awaitValue(function()
277
+ return dataService:GetActiveSlotMetadata(playerMock) ~= nil
278
+ end, 5)).toEqual(true)
279
+
280
+ local metadata = dataService:GetActiveSlotMetadata(playerMock)
281
+ expect(metadata.SlotId).toEqual(EPHEMERAL_ID)
282
+ expect(metadata.IsEphemeral).toEqual(true)
283
+ expect(dataService:IsActiveSlotEphemeral(playerMock)).toEqual(true)
284
+ end)
285
+ end)
286
+
287
+ describe("SaveSlotDataService ephemeral-state observation on the client", function()
288
+ it("stays false until the IsEphemeral attribute lands, then flips to true", function()
289
+ local maid, binder, dataService = setup()
290
+ local playerMock = newPlayerMock(maid, true)
291
+ binder:Bind(playerMock)
292
+
293
+ local container = newSlotContainer(maid)
294
+ local slot = newSlot(EPHEMERAL_ID, 0, "Lobby run")
295
+ slot.Parent = container
296
+ container.Parent = playerMock
297
+ playerMock:SetAttribute("ActiveSlotId", EPHEMERAL_ID)
298
+
299
+ local record = subscribeRecording(maid, dataService:ObserveIsActiveSlotEphemeral(playerMock))
300
+ expect(record.latest).toEqual(false)
301
+
302
+ slot:SetAttribute("IsEphemeral", true)
303
+
304
+ expect(awaitLatest(record, function(isEphemeral)
305
+ return isEphemeral == true
306
+ end)).toEqual(true)
307
+ expect(record.values).toEqual({ false, true })
308
+ end)
309
+
310
+ it("does not re-emit when unrelated metadata on the active slot changes", function()
311
+ local maid, binder, dataService = setup()
312
+ local playerMock = newPlayerMock(maid, true)
313
+ binder:Bind(playerMock)
314
+
315
+ local container = newSlotContainer(maid)
316
+ local slot = newSlot(EPHEMERAL_ID, 0, "Lobby run", true)
317
+ slot.Parent = container
318
+ container.Parent = playerMock
319
+ playerMock:SetAttribute("ActiveSlotId", EPHEMERAL_ID)
320
+
321
+ local record = subscribeRecording(maid, dataService:ObserveIsActiveSlotEphemeral(playerMock))
322
+ expect(awaitLatest(record, function(isEphemeral)
323
+ return isEphemeral == true
324
+ end)).toEqual(true)
325
+
326
+ local countAfterResolve = record.count
327
+ slot:SetAttribute("SlotName", "Lobby run 2")
328
+ slot:SetAttribute("TimePlayed", 90)
329
+
330
+ expect(PromiseTestUtils.awaitValue(function()
331
+ return record.count > countAfterResolve
332
+ end, 1)).toEqual(false)
333
+ expect(record.latest).toEqual(true)
334
+ end)
335
+
336
+ it("returns to false when the ephemeral slot is retired", function()
337
+ local maid, binder, dataService = setup()
338
+ local playerMock = newPlayerMock(maid, true)
339
+ binder:Bind(playerMock)
340
+
341
+ local container = newSlotContainer(maid)
342
+ local slot = newSlot(EPHEMERAL_ID, 0, "Lobby run", true)
343
+ slot.Parent = container
344
+ container.Parent = playerMock
345
+ playerMock:SetAttribute("ActiveSlotId", EPHEMERAL_ID)
346
+
347
+ local record = subscribeRecording(maid, dataService:ObserveIsActiveSlotEphemeral(playerMock))
348
+ expect(awaitLatest(record, function(isEphemeral)
349
+ return isEphemeral == true
350
+ end)).toEqual(true)
351
+
352
+ playerMock:SetAttribute("ActiveSlotId", nil)
353
+ slot:Destroy()
354
+
355
+ expect(awaitLatest(record, function(isEphemeral)
356
+ return isEphemeral == false
357
+ end)).toEqual(true)
358
+ expect(dataService:IsActiveSlotEphemeral(playerMock)).toEqual(false)
359
+ end)
360
+
361
+ it("reports false for a real active slot", function()
362
+ local maid, binder, dataService = setup()
363
+ local playerMock = newPlayerMock(maid, true)
364
+ binder:Bind(playerMock)
365
+
366
+ local container = newSlotContainer(maid)
367
+ newSlot(REAL_ID, 1, "Slot 1").Parent = container
368
+ container.Parent = playerMock
369
+ playerMock:SetAttribute("ActiveSlotId", REAL_ID)
370
+
371
+ local record = subscribeRecording(maid, dataService:ObserveIsActiveSlotEphemeral(playerMock))
372
+
373
+ expect(PromiseTestUtils.awaitValue(function()
374
+ return dataService:GetActiveSlotMetadata(playerMock) ~= nil
375
+ end, 5)).toEqual(true)
376
+ expect(record.values).toEqual({ false })
377
+ expect(dataService:IsActiveSlotEphemeral(playerMock)).toEqual(false)
378
+ end)
379
+ end)
380
+
381
+ describe("SaveSlotDataService slot list on the client", function()
382
+ it("emits nil rather than staying silent when the slot container has not replicated", function()
383
+ local maid, binder, dataService = setup()
384
+ local playerMock = newPlayerMock(maid, true)
385
+ binder:Bind(playerMock)
386
+
387
+ local record = subscribeRecording(maid, dataService:ObserveSlotList(playerMock))
388
+
389
+ expect(record.count).toEqual(1)
390
+ expect(record.latest).toBeNil()
391
+ end)
392
+
393
+ it("lists the real slot but not the ephemeral one", function()
394
+ local maid, binder, dataService = setup()
395
+ local playerMock = newPlayerMock(maid, true)
396
+ binder:Bind(playerMock)
397
+
398
+ local container = newSlotContainer(maid)
399
+ newSlot(REAL_ID, 1, "Slot 1").Parent = container
400
+ newSlot(EPHEMERAL_ID, 0, "Lobby run", true).Parent = container
401
+ container.Parent = playerMock
402
+
403
+ local synchronous = listedIds(dataService:GetSlotList(playerMock))
404
+ expect(synchronous[REAL_ID]).toEqual(true)
405
+ expect(synchronous[EPHEMERAL_ID]).toBeNil()
406
+
407
+ local record = subscribeRecording(maid, dataService:ObserveSlotList(playerMock))
408
+ expect(awaitLatest(record, function(slotList)
409
+ return listedIds(slotList)[REAL_ID] == true
410
+ end)).toEqual(true)
411
+ expect(listedIds(record.latest)[EPHEMERAL_ID]).toBeNil()
412
+ end)
413
+
414
+ it("replaces rather than appends a slot's entry when its metadata changes", function()
415
+ local maid, binder, dataService = setup()
416
+ local playerMock = newPlayerMock(maid, true)
417
+ binder:Bind(playerMock)
418
+
419
+ local container = newSlotContainer(maid)
420
+ local slot = newSlot(REAL_ID, 1, "Slot 1")
421
+ slot.Parent = container
422
+ container.Parent = playerMock
423
+
424
+ local record = subscribeRecording(maid, dataService:ObserveSlotList(playerMock))
425
+ expect(awaitLatest(record, function(slotList)
426
+ return listedIds(slotList)[REAL_ID] == true
427
+ end)).toEqual(true)
428
+
429
+ slot:SetAttribute("SlotName", "Renamed")
430
+
431
+ expect(awaitLatest(record, function(slotList)
432
+ return slotList ~= nil and slotList[1] ~= nil and slotList[1].SlotName == "Renamed"
433
+ end)).toEqual(true)
434
+ expect(#record.latest).toEqual(1)
435
+ end)
436
+
437
+ it("drops the slot from the list when its IsEphemeral attribute lands after the folder", function()
438
+ local maid, binder, dataService = setup()
439
+ local playerMock = newPlayerMock(maid, true)
440
+ binder:Bind(playerMock)
441
+
442
+ local container = newSlotContainer(maid)
443
+ newSlot(REAL_ID, 1, "Slot 1").Parent = container
444
+ local slot = newSlot(EPHEMERAL_ID, 0, "Lobby run")
445
+ slot.Parent = container
446
+ container.Parent = playerMock
447
+
448
+ local record = subscribeRecording(maid, dataService:ObserveSlotList(playerMock))
449
+ expect(awaitLatest(record, function(slotList)
450
+ return listedIds(slotList)[EPHEMERAL_ID] == true
451
+ end)).toEqual(true)
452
+
453
+ slot:SetAttribute("IsEphemeral", true)
454
+
455
+ expect(awaitLatest(record, function(slotList)
456
+ return listedIds(slotList)[EPHEMERAL_ID] == nil
457
+ end)).toEqual(true)
458
+ expect(listedIds(record.latest)[REAL_ID]).toEqual(true)
459
+ expect(listedIds(dataService:GetSlotList(playerMock))[EPHEMERAL_ID]).toBeNil()
460
+ end)
461
+ end)
@@ -934,11 +934,13 @@ end
934
934
  --[=[
935
935
  Creates a fresh ephemeral slot and selects it, resolving to its id. An ephemeral slot is selectable and
936
936
  active exactly like a real one -- it drives [HasSaveSlots.ObserveActiveSlotStoreBrio], summaries, and
937
- playtime the same way -- but it is never persisted: no metadata is written, its data store is in-memory,
938
- it is kept out of the replicated slot list, and it is torn down the moment it stops being the active slot.
939
- Selecting it also never disturbs the persisted active-slot pointer or the "Continue" target, so the real
940
- slot the player came from resumes untouched afterward. Backs a throwaway session (e.g. exploring a lobby)
941
- that must leave no trace on save data.
937
+ playtime the same way, and its metadata replicates to the client like any other slot's, so UI can render
938
+ the active session's name and summary -- but it is never persisted: no metadata is written, its data store
939
+ is in-memory, and it is torn down the moment it stops being the active slot. It is also excluded from the
940
+ save list ([SaveSlotDataService.GetSlotList] / [SaveSlotDataService.ObserveSlotList]), so it never shows up
941
+ as something the player can return to. Selecting it never disturbs the persisted active-slot pointer or the
942
+ "Continue" target, so the real slot the player came from resumes untouched afterward. Backs a throwaway
943
+ session (e.g. exploring a lobby) that must leave no trace on save data.
942
944
 
943
945
  @param metadata SaveSlotCreateMetadata? -- optional SlotName/Summary for the in-memory slot
944
946
  @return Promise<SlotId>
@@ -1092,9 +1094,11 @@ function HasSaveSlots._buildSlot(
1092
1094
  attributes.SlotIndex.Value = data.SlotIndex
1093
1095
 
1094
1096
  if isEphemeral then
1095
- -- Ephemeral: seed the metadata in memory with no write-back wiring, back the slot with an in-memory
1096
- -- store, and deliberately leave the folder unparented so it never joins the replicated slot container
1097
- -- (SaveSlotDataService lists that container's children -- an ephemeral slot must not surface as a save).
1097
+ -- Ephemeral: seed the metadata in memory with no write-back wiring, and back the slot with an in-memory
1098
+ -- store. The folder still joins the replicated container so the client can read the active slot's
1099
+ -- metadata (name, summary, playtime) the same way it reads a real slot's -- what makes the slot
1100
+ -- ephemeral is that nothing is persisted, not that it is invisible. The IsEphemeral attribute is what
1101
+ -- keeps it out of the save list; SaveSlotDataService's list reads filter on it.
1098
1102
  --
1099
1103
  -- The in-memory store's lifetime is owned by this slot's maid (which is in turn owned by self._maid),
1100
1104
  -- so it is Destroyed -- and becomes GC-eligible -- the instant the slot is retired (_destroyEphemeralSlot)
@@ -1107,6 +1111,10 @@ function HasSaveSlots._buildSlot(
1107
1111
  attributes[key].Value = data[key]
1108
1112
  end
1109
1113
 
1114
+ -- Parent last, so the folder replicates carrying IsEphemeral -- a client that saw it land without the
1115
+ -- flag would briefly list a throwaway slot as a save.
1116
+ slot.Parent = self._slotContainer
1117
+
1110
1118
  self._slotMap[slotId] = slot
1111
1119
  maid:GiveTask(function()
1112
1120
  self._slotMap[slotId] = nil
@@ -11,6 +11,7 @@ local require = require(script.Parent.loader).load(script)
11
11
 
12
12
  local DataStoreMock = require("DataStoreMock")
13
13
  local Jest = require("Jest")
14
+ local Maid = require("Maid")
14
15
  local Observable = require("Observable")
15
16
  local PlayerDataStoreService = require("PlayerDataStoreService")
16
17
  local PlayerMock = require("PlayerMock")
@@ -18,6 +19,7 @@ local PromiseTestUtils = require("PromiseTestUtils")
18
19
  local Rx = require("Rx")
19
20
  local SaveSlotDataService = require("SaveSlotDataService")
20
21
  local ServiceBag = require("ServiceBag")
22
+ local ValueObject = require("ValueObject")
21
23
 
22
24
  local HttpService = game:GetService("HttpService")
23
25
  local Workspace = game:GetService("Workspace")
@@ -1488,7 +1490,7 @@ describe("HasSaveSlots ephemeral slots", function()
1488
1490
  context.destroy()
1489
1491
  end)
1490
1492
 
1491
- it("keeps the ephemeral slot out of the replicated slot list", function()
1493
+ it("keeps the ephemeral slot out of the slot list while still replicating it", function()
1492
1494
  local context = setup()
1493
1495
 
1494
1496
  local realId = createAndSelectReal(context, 2)
@@ -1502,8 +1504,113 @@ describe("HasSaveSlots ephemeral slots", function()
1502
1504
  expect(listedIds[realId]).toEqual(true)
1503
1505
  expect(listedIds[ephemeralId]).toBeNil()
1504
1506
  expect(slotContainerHasChild(context, realId)).toEqual(true)
1505
- expect(slotContainerHasChild(context, ephemeralId)).toEqual(false)
1507
+ expect(slotContainerHasChild(context, ephemeralId)).toEqual(true)
1508
+
1509
+ context.destroy()
1510
+ end)
1511
+
1512
+ it("replicates the ephemeral slot's metadata so it is readable off the instance tree", function()
1513
+ local context = setup()
1514
+
1515
+ local ephemeralId = selectEphemeral(context, { SlotName = "Lobby run" })
1516
+
1517
+ local metadata = (SaveSlotDataService :: any):GetSlotMetadata(context.fakePlayer, ephemeralId)
1518
+ expect(metadata).never.toBeNil()
1519
+ expect(metadata.SlotId).toEqual(ephemeralId)
1520
+ expect(metadata.SlotName).toEqual("Lobby run")
1521
+ expect(metadata.IsEphemeral).toEqual(true)
1522
+
1523
+ context.destroy()
1524
+ end)
1525
+
1526
+ it("replicates the ephemeral slot's summary as its providers update it", function()
1527
+ local context = setup()
1528
+
1529
+ local coins = ValueObject.new(7)
1530
+ context.hasSaveSlots:RegisterSummaryProvider("coins", function()
1531
+ return coins:Observe()
1532
+ end)
1533
+
1534
+ local ephemeralId = selectEphemeral(context)
1535
+
1536
+ local function summaryCoins(): number?
1537
+ local metadata = (SaveSlotDataService :: any):GetSlotMetadata(context.fakePlayer, ephemeralId)
1538
+ return metadata and metadata.Summary and metadata.Summary.coins
1539
+ end
1540
+
1541
+ expect(PromiseTestUtils.awaitValue(function()
1542
+ return summaryCoins() == 7
1543
+ end, 10)).toEqual(true)
1544
+
1545
+ coins.Value = 9
1546
+ expect(PromiseTestUtils.awaitValue(function()
1547
+ return summaryCoins() == 9
1548
+ end, 10)).toEqual(true)
1549
+
1550
+ coins:Destroy()
1551
+ context.destroy()
1552
+ end)
1553
+
1554
+ it("emits the ephemeral slot through ObserveSlotMetadata, and nil once it is retired", function()
1555
+ local context = setup()
1556
+
1557
+ local ephemeralId = selectEphemeral(context, { SlotName = "Lobby run" })
1558
+
1559
+ local maid = Maid.new()
1560
+ local observed: any = nil
1561
+ maid:GiveTask(
1562
+ (SaveSlotDataService :: any)
1563
+ :ObserveSlotMetadata(context.fakePlayer, ephemeralId)
1564
+ :Subscribe(function(metadata)
1565
+ observed = metadata
1566
+ end)
1567
+ )
1568
+
1569
+ expect(PromiseTestUtils.awaitValue(function()
1570
+ return observed ~= nil and observed.SlotName == "Lobby run"
1571
+ end, 10)).toEqual(true)
1572
+
1573
+ resolve(context.hasSaveSlots:PromiseDeselectSlot())
1574
+
1575
+ expect(PromiseTestUtils.awaitValue(function()
1576
+ return observed == nil
1577
+ end, 10)).toEqual(true)
1578
+
1579
+ maid:DoCleaning()
1580
+ context.destroy()
1581
+ end)
1582
+
1583
+ it("excludes the ephemeral slot from ObserveSlotList without dropping the real slots", function()
1584
+ local context = setup()
1585
+
1586
+ local realId = createAndSelectReal(context, 2)
1587
+
1588
+ local maid = Maid.new()
1589
+ local observedIds: { [string]: boolean } = {}
1590
+ maid:GiveTask((SaveSlotDataService :: any):ObserveSlotList(context.fakePlayer):Subscribe(function(slotList: any)
1591
+ observedIds = {}
1592
+ for _, metadata in (slotList or {}) :: { any } do
1593
+ observedIds[metadata.SlotId] = true
1594
+ end
1595
+ end))
1596
+
1597
+ expect(PromiseTestUtils.awaitValue(function()
1598
+ return observedIds[realId] == true
1599
+ end, 10)).toEqual(true)
1600
+
1601
+ local ephemeralId = selectEphemeral(context)
1602
+
1603
+ -- Adding a real slot after the ephemeral one forces a re-emission that must have seen both, so the
1604
+ -- ephemeral slot's absence below is a filtered list rather than a list that never updated.
1605
+ local laterRealId = resolve(context.hasSaveSlots:PromiseCreateSlot(3))
1606
+ expect(PromiseTestUtils.awaitValue(function()
1607
+ return observedIds[laterRealId] == true
1608
+ end, 10)).toEqual(true)
1609
+
1610
+ expect(observedIds[ephemeralId]).toBeNil()
1611
+ expect(observedIds[realId]).toEqual(true)
1506
1612
 
1613
+ maid:DoCleaning()
1507
1614
  context.destroy()
1508
1615
  end)
1509
1616
 
@@ -16,6 +16,9 @@ local ServiceBag = require("ServiceBag")
16
16
  local SaveSlotCmdrService = {}
17
17
  SaveSlotCmdrService.ServiceName = "SaveSlotCmdrService"
18
18
 
19
+ type SlotEntry = { slotIndex: number, slotId: string }
20
+ type SlotEntries = { SlotEntry }
21
+
19
22
  export type SaveSlotCmdrService = typeof(setmetatable(
20
23
  {} :: {
21
24
  _serviceBag: ServiceBag.ServiceBag,
@@ -386,43 +389,29 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
386
389
  Description = "Exports save slots to the shared store and prints their codes.",
387
390
  Group = "SaveSlots",
388
391
  Args = {
392
+ {
393
+ Name = "Players",
394
+ Type = "players",
395
+ Description = "Players to export from (e.g. . for yourself, or * for everyone).",
396
+ },
389
397
  {
390
398
  Name = "Slots",
391
399
  Type = "slotIndices",
392
- Description = "Slot indices to export (e.g. 1,2, . for your current slot, or * for all). Omit for the active slot.",
400
+ Description = "Slot indices to export (e.g. 1,2, . for your current slot, or * for all). Omit for each player's active slot.",
393
401
  Optional = true,
394
402
  },
395
403
  },
396
- }, function(context, slotIndices: { number }?)
397
- local entries = self:_resolveSlotEntries(context, slotIndices)
398
- if #entries == 0 then
404
+ }, function(_context, players: { Player }, slotIndices: { number }?)
405
+ local targets = self:_resolveExportTargets(players, slotIndices)
406
+ if #targets == 0 then
399
407
  return "No matching slots to export."
400
408
  end
401
409
 
402
- local lines = self._maid
403
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
404
- :Then(function(hasSaveSlots)
405
- -- Export sequentially to avoid concurrent datastore writes; report per-slot so a
406
- -- mid-batch failure (e.g. the main slot, which export refuses) still surfaces the successes.
407
- local promise = Promise.resolved()
408
- local results = {}
409
- for _, entry in entries do
410
- promise = promise:Then(function()
411
- return hasSaveSlots
412
- :PromiseExportSaveSlotToCode(entry.slotId)
413
- :Then(function(code)
414
- table.insert(results, `slot {entry.slotIndex} → {code}`)
415
- end)
416
- :Catch(function(err)
417
- table.insert(results, `slot {entry.slotIndex}: {tostring(err)}`)
418
- end)
419
- end)
420
- end
421
- return promise:Then(function()
422
- return results
423
- end)
410
+ local lines = self:_promiseExportLines(targets, function(hasSaveSlots, entry, player)
411
+ return hasSaveSlots:PromiseExportSaveSlotToCode(entry.slotId):Then(function(code)
412
+ return `{player.Name} slot {entry.slotIndex} → {code}`
424
413
  end)
425
- :Wait()
414
+ end):Wait()
426
415
 
427
416
  return `Exported:\n{table.concat(lines, "\n")}`
428
417
  end)
@@ -432,41 +421,29 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
432
421
  Description = "Exports save slots as raw JSON (no shared store) and prints them.",
433
422
  Group = "SaveSlots",
434
423
  Args = {
424
+ {
425
+ Name = "Players",
426
+ Type = "players",
427
+ Description = "Players to export from (e.g. . for yourself, or * for everyone).",
428
+ },
435
429
  {
436
430
  Name = "Slots",
437
431
  Type = "slotIndices",
438
- Description = "Slot indices to export (e.g. 1,2, . for your current slot, or * for all). Omit for the active slot.",
432
+ Description = "Slot indices to export (e.g. 1,2, . for your current slot, or * for all). Omit for each player's active slot.",
439
433
  Optional = true,
440
434
  },
441
435
  },
442
- }, function(context, slotIndices: { number }?)
443
- local entries = self:_resolveSlotEntries(context, slotIndices)
444
- if #entries == 0 then
436
+ }, function(_context, players: { Player }, slotIndices: { number }?)
437
+ local targets = self:_resolveExportTargets(players, slotIndices)
438
+ if #targets == 0 then
445
439
  return "No matching slots to export."
446
440
  end
447
441
 
448
- local blocks = self._maid
449
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
450
- :Then(function(hasSaveSlots)
451
- local promise = Promise.resolved()
452
- local results = {}
453
- for _, entry in entries do
454
- promise = promise:Then(function()
455
- return hasSaveSlots
456
- :PromiseExportSaveSlotToJson(entry.slotId)
457
- :Then(function(json)
458
- table.insert(results, `-- slot {entry.slotIndex}\n{json}`)
459
- end)
460
- :Catch(function(err)
461
- table.insert(results, `slot {entry.slotIndex}: {tostring(err)}`)
462
- end)
463
- end)
464
- end
465
- return promise:Then(function()
466
- return results
467
- end)
442
+ local blocks = self:_promiseExportLines(targets, function(hasSaveSlots, entry, player)
443
+ return hasSaveSlots:PromiseExportSaveSlotToJson(entry.slotId):Then(function(json)
444
+ return `-- {player.Name} slot {entry.slotIndex}\n{json}`
468
445
  end)
469
- :Wait()
446
+ end):Wait()
470
447
 
471
448
  return table.concat(blocks, "\n\n")
472
449
  end)
@@ -526,24 +503,24 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
526
503
  end
527
504
 
528
505
  -- Resolves a slotIndices argument (or nil = the active slot) into de-duplicated { slotIndex, slotId }
529
- -- entries for the executor. An empty result means nothing matched, and the caller reports it.
506
+ -- entries for the player. An empty result means nothing matched, and the caller reports it.
530
507
  function SaveSlotCmdrService._resolveSlotEntries(
531
508
  self: SaveSlotCmdrService,
532
- context: any,
509
+ player: Player,
533
510
  slotIndices: { number }?
534
- ): { { slotIndex: number, slotId: string } }
511
+ ): SlotEntries
535
512
  local entries = {}
536
513
  if slotIndices == nil then
537
- local activeSlotId = self._saveSlotDataService:GetActiveSlotId(context.Executor)
514
+ local activeSlotId = self._saveSlotDataService:GetActiveSlotId(player)
538
515
  if not activeSlotId then
539
516
  return entries
540
517
  end
541
- local metadata = self._saveSlotDataService:GetSlotMetadata(context.Executor, activeSlotId)
518
+ local metadata = self._saveSlotDataService:GetSlotMetadata(player, activeSlotId)
542
519
  table.insert(entries, { slotIndex = metadata.SlotIndex, slotId = activeSlotId })
543
520
  else
544
521
  local seen = {}
545
522
  for _, slotIndex in slotIndices do
546
- local slotId = self._saveSlotDataService:GetSlotIdFromIndex(context.Executor, slotIndex)
523
+ local slotId = self._saveSlotDataService:GetSlotIdFromIndex(player, slotIndex)
547
524
  if slotId and not seen[slotId] then
548
525
  seen[slotId] = true
549
526
  table.insert(entries, { slotIndex = slotIndex, slotId = slotId })
@@ -553,6 +530,60 @@ function SaveSlotCmdrService._resolveSlotEntries(
553
530
  return entries
554
531
  end
555
532
 
533
+ -- Pairs each player with their resolved slots, dropping players with nothing to export. Note that
534
+ -- Cmdr resolves the "." and "*" slot operators against the executor's slot list, since types only
535
+ -- see the executor, so indices given that way come from the executor's slots.
536
+ function SaveSlotCmdrService._resolveExportTargets(
537
+ self: SaveSlotCmdrService,
538
+ players: { Player },
539
+ slotIndices: { number }?
540
+ ): { { player: Player, entries: SlotEntries } }
541
+ local targets = {}
542
+ for _, player in players do
543
+ local entries = self:_resolveSlotEntries(player, slotIndices)
544
+ if #entries > 0 then
545
+ table.insert(targets, { player = player, entries = entries })
546
+ end
547
+ end
548
+ return targets
549
+ end
550
+
551
+ -- Exports every resolved slot of every target, sequentially, to avoid concurrent datastore writes.
552
+ -- Reports per-slot so a mid-batch failure (e.g. the main slot, which export refuses) still surfaces
553
+ -- the successes.
554
+ function SaveSlotCmdrService._promiseExportLines(
555
+ self: SaveSlotCmdrService,
556
+ targets: { { player: Player, entries: SlotEntries } },
557
+ exportSlot: (any, SlotEntry, Player) -> any
558
+ ): any
559
+ local promise = Promise.resolved()
560
+ local results: { string } = {}
561
+
562
+ for _, target in targets do
563
+ promise = promise:Then(function()
564
+ return self._maid:GivePromise(self._hasSaveSlotsBinder:Promise(target.player)):Then(function(hasSaveSlots)
565
+ local slotPromise = Promise.resolved()
566
+ for _, entry in target.entries do
567
+ slotPromise = slotPromise:Then(function()
568
+ return exportSlot(hasSaveSlots, entry, target.player)
569
+ :Then(function(line)
570
+ table.insert(results, line)
571
+ end)
572
+ :Catch(function(err)
573
+ table.insert(results, `{target.player.Name} slot {entry.slotIndex}: {tostring(err)}`)
574
+ end)
575
+ end)
576
+ end
577
+ return slotPromise
578
+ end)
579
+ end)
580
+ end
581
+
582
+ return promise:Then(function()
583
+ return results
584
+ end)
585
+ end
586
+
556
587
  function SaveSlotCmdrService.Destroy(self: SaveSlotCmdrService): ()
557
588
  self._maid:Destroy()
558
589
  end
@@ -39,7 +39,8 @@ function SaveSlotDataService.Init(self: SaveSlotDataService, serviceBag: Service
39
39
  end
40
40
 
41
41
  --[=[
42
- Observes the player's active slot ID
42
+ Observes the player's active slot ID. Emits nil -- rather than staying silent -- while the
43
+ implementation has not replicated yet, so a subscriber always has a current answer.
43
44
  ]=]
44
45
  function SaveSlotDataService.ObserveActiveSlotId(
45
46
  self: SaveSlotDataService,
@@ -50,11 +51,13 @@ function SaveSlotDataService.ObserveActiveSlotId(
50
51
  return hasSaveSlots.ActiveSlotId:Observe()
51
52
  end),
52
53
  RxBrioUtils.emitOnDeath(nil),
54
+ Rx.defaultsToNil :: any,
53
55
  })
54
56
  end
55
57
 
56
58
  --[=[
57
- Observes the player's last active slot ID (the slot they can continue on)
59
+ Observes the player's last active slot ID (the slot they can continue on). Emits nil -- rather than
60
+ staying silent -- while the implementation has not replicated yet.
58
61
  ]=]
59
62
  function SaveSlotDataService.ObserveLastActiveSlotId(
60
63
  self: SaveSlotDataService,
@@ -65,6 +68,7 @@ function SaveSlotDataService.ObserveLastActiveSlotId(
65
68
  return hasSaveSlots.LastActiveSlotId:Observe()
66
69
  end),
67
70
  RxBrioUtils.emitOnDeath(nil),
71
+ Rx.defaultsToNil :: any,
68
72
  })
69
73
  end
70
74
 
@@ -90,8 +94,27 @@ function SaveSlotDataService.GetLastActiveSlotId(self: SaveSlotDataService, play
90
94
  return hasSaveSlots.ActiveSlotId.Value or hasSaveSlots.LastActiveSlotId.Value
91
95
  end
92
96
 
97
+ -- Ephemeral slots share the replicated container with real ones (so the client can resolve the active
98
+ -- slot's metadata), but they are throwaway sessions rather than saves -- every list read drops them.
99
+ -- This runs on the current metadata of each slot, so a slot whose IsEphemeral attribute lands after its
100
+ -- folder leaves the list as soon as the flag arrives, rather than sticking around as a phantom save.
101
+ local function withoutEphemeral(slotList: { SaveSlotData.SaveSlotMetadata }): { SaveSlotData.SaveSlotMetadata }
102
+ local filtered = {}
103
+ for _, metadata in slotList do
104
+ if not metadata.IsEphemeral then
105
+ table.insert(filtered, metadata)
106
+ end
107
+ end
108
+ return filtered
109
+ end
110
+
93
111
  --[=[
94
- Observes the player's active slot list
112
+ Observes the player's active slot list. Ephemeral slots (see
113
+ [HasSaveSlots.PromiseSelectEphemeralSlot]) are excluded -- observe the active slot's metadata
114
+ directly with [SaveSlotDataService.ObserveSlotMetadata] to see one.
115
+
116
+ Emits nil while the slot container has not replicated, then one entry per slot, re-emitting whenever
117
+ a slot is added or removed or any slot's own metadata changes.
95
118
  ]=]
96
119
  function SaveSlotDataService.ObserveSlotList(
97
120
  _self: SaveSlotDataService,
@@ -100,20 +123,49 @@ function SaveSlotDataService.ObserveSlotList(
100
123
  return (
101
124
  RxInstanceUtils.observeLastNamedChildBrio(player, "Folder", SaveSlotConstants.METADATA_CONTAINER_NAME) :: any
102
125
  ):Pipe({
126
+ -- Reduce to the live *folders* first and combineLatest their metadata, rather than flat-mapping
127
+ -- each folder straight to metadata: a flat map adds an entry per emission, so every attribute
128
+ -- change would append a second, stale entry for the same slot instead of replacing it.
103
129
  RxBrioUtils.switchMapBrio(function(slotContainer: Folder)
104
130
  return RxInstanceUtils.observeChildrenBrio(slotContainer):Pipe({
105
- RxBrioUtils.flatMapBrio(function(slotFolder)
106
- return SaveSlotData:Observe(slotFolder)
107
- end) :: any,
108
131
  RxBrioUtils.reduceToAliveList() :: any,
109
132
  })
110
133
  end),
111
134
  RxBrioUtils.emitOnDeath(nil),
135
+ Rx.switchMap(function(slotFolders: { Instance }?)
136
+ if not slotFolders then
137
+ return Rx.of(nil) :: any
138
+ end
139
+ if #slotFolders == 0 then
140
+ return Rx.of({}) :: any
141
+ end
142
+
143
+ local observables = {}
144
+ for index, slotFolder in slotFolders do
145
+ observables[index] = SaveSlotData:Observe(slotFolder)
146
+ end
147
+
148
+ return Rx.combineLatest(observables):Pipe({
149
+ Rx.map(function(metadataByIndex: { any }): { SaveSlotData.SaveSlotMetadata }
150
+ local slotList = {}
151
+ for index = 1, #slotFolders do
152
+ local metadata = metadataByIndex[index]
153
+ if metadata ~= nil then
154
+ table.insert(slotList, metadata)
155
+ end
156
+ end
157
+ return withoutEphemeral(slotList)
158
+ end) :: any,
159
+ }) :: any
160
+ end) :: any,
161
+ Rx.defaultsToNil :: any,
112
162
  })
113
163
  end
114
164
 
115
165
  --[=[
116
- Returns the player's slot list
166
+ Returns the player's slot list. Ephemeral slots (see
167
+ [HasSaveSlots.PromiseSelectEphemeralSlot]) are excluded -- read the active slot's metadata directly
168
+ with [SaveSlotDataService.GetSlotMetadata] to see one.
117
169
  ]=]
118
170
  function SaveSlotDataService.GetSlotList(_self: SaveSlotDataService, player: Player): { SaveSlotData.SaveSlotMetadata }
119
171
  local slotList = {}
@@ -125,11 +177,14 @@ function SaveSlotDataService.GetSlotList(_self: SaveSlotDataService, player: Pla
125
177
  end
126
178
  end
127
179
 
128
- return slotList
180
+ return withoutEphemeral(slotList)
129
181
  end
130
182
 
131
183
  --[=[
132
- Observes the slot metadata with the given ID for the player
184
+ Observes the slot metadata with the given ID for the player. Order-independent: the slot container,
185
+ the slot folder, and the slot's own attributes each replicate on their own schedule, so this emits
186
+ nil until the slot is actually there, the metadata once it is, again on every attribute that lands
187
+ afterwards, and nil again the moment the slot goes away (which is how an ephemeral slot ends).
133
188
  ]=]
134
189
  function SaveSlotDataService.ObserveSlotMetadata(
135
190
  _self: SaveSlotDataService,
@@ -144,8 +199,14 @@ function SaveSlotDataService.ObserveSlotMetadata(
144
199
  end),
145
200
  RxBrioUtils.emitOnDeath(nil),
146
201
  Rx.switchMap(function(slot: Folder?)
147
- return slot and SaveSlotData:Observe(slot) or Rx.EMPTY
202
+ -- Rx.of(nil), not Rx.EMPTY: an empty observable would swallow the slot's removal and leave
203
+ -- the subscriber holding metadata for a slot that no longer exists.
204
+ if not slot then
205
+ return Rx.of(nil) :: any
206
+ end
207
+ return SaveSlotData:Observe(slot) :: any
148
208
  end),
209
+ Rx.defaultsToNil :: any,
149
210
  })
150
211
  end
151
212
 
@@ -167,6 +228,78 @@ function SaveSlotDataService.GetSlotMetadata(
167
228
  end
168
229
  end
169
230
 
231
+ --[=[
232
+ Observes the metadata of whichever slot is currently active, following the selection as it changes
233
+ and emitting nil while no slot is active. This is the read a UI showing "what am I playing right
234
+ now" wants: composing [SaveSlotDataService.ObserveActiveSlotId] with
235
+ [SaveSlotDataService.ObserveSlotMetadata] by hand is easy to get wrong, because the active-slot id
236
+ and the slot folder it names replicate independently -- the id routinely arrives first.
237
+
238
+ An ephemeral slot is included here (it is genuinely the active slot); it is only the *list* reads
239
+ that exclude it.
240
+ ]=]
241
+ function SaveSlotDataService.ObserveActiveSlotMetadata(
242
+ self: SaveSlotDataService,
243
+ player: Player
244
+ ): Observable.Observable<SaveSlotData.SaveSlotMetadata?>
245
+ return self:ObserveActiveSlotId(player):Pipe({
246
+ Rx.switchMap(function(slotId: SaveSlotData.SlotId?)
247
+ if not slotId then
248
+ return Rx.of(nil) :: any
249
+ end
250
+ return self:ObserveSlotMetadata(player, slotId) :: any
251
+ end) :: any,
252
+ Rx.defaultsToNil :: any,
253
+ }) :: any
254
+ end
255
+
256
+ --[=[
257
+ Returns the metadata of whichever slot is currently active, or nil when no slot is active or its
258
+ metadata has not replicated yet. The synchronous counterpart to
259
+ [SaveSlotDataService.ObserveActiveSlotMetadata].
260
+ ]=]
261
+ function SaveSlotDataService.GetActiveSlotMetadata(
262
+ self: SaveSlotDataService,
263
+ player: Player
264
+ ): SaveSlotData.SaveSlotMetadata?
265
+ local slotId = self:GetActiveSlotId(player)
266
+ if not slotId then
267
+ return nil
268
+ end
269
+ return self:GetSlotMetadata(player, slotId)
270
+ end
271
+
272
+ --[=[
273
+ Observes whether the active slot is an ephemeral, never-persisted one (see
274
+ [HasSaveSlots.PromiseSelectEphemeralSlot]) -- what a UI checks before offering "save", "delete", or
275
+ anything else that only makes sense on a real save.
276
+
277
+ Emits false while the answer is not known yet (no slot active, or the slot's metadata still in
278
+ flight) and flips to true once the slot's IsEphemeral attribute lands, so a late attribute
279
+ downgrades the UI rather than the reverse. Deduplicated, so it only emits on genuine changes.
280
+ ]=]
281
+ function SaveSlotDataService.ObserveIsActiveSlotEphemeral(
282
+ self: SaveSlotDataService,
283
+ player: Player
284
+ ): Observable.Observable<boolean>
285
+ return self:ObserveActiveSlotMetadata(player):Pipe({
286
+ Rx.map(function(metadata: SaveSlotData.SaveSlotMetadata?): boolean
287
+ return metadata ~= nil and metadata.IsEphemeral == true
288
+ end) :: any,
289
+ Rx.distinct() :: any,
290
+ }) :: any
291
+ end
292
+
293
+ --[=[
294
+ Returns whether the active slot is an ephemeral, never-persisted one. False when no slot is active
295
+ or its metadata has not replicated yet. The synchronous counterpart to
296
+ [SaveSlotDataService.ObserveIsActiveSlotEphemeral].
297
+ ]=]
298
+ function SaveSlotDataService.IsActiveSlotEphemeral(self: SaveSlotDataService, player: Player): boolean
299
+ local metadata = self:GetActiveSlotMetadata(player)
300
+ return metadata ~= nil and metadata.IsEphemeral == true
301
+ end
302
+
170
303
  --[=[
171
304
  Returns the ID for the slot at the given index
172
305
  ]=]