@quenty/saveslot 1.9.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 +14 -0
- package/package.json +4 -4
- package/src/Client/Binders/HasSaveSlotsClient.lua +12 -8
- package/src/Client/SaveSlotServiceClient.lua +25 -6
- package/src/Server/Binders/HasSaveSlots.lua +178 -23
- package/src/Server/Binders/HasSaveSlots.spec.lua +215 -0
- package/src/Server/SaveSlotService.lua +7 -7
- package/src/Server/SaveSlotService.spec.lua +43 -7
- package/src/Shared/Data/SaveSlotData.lua +4 -0
- package/src/Shared/HasSaveSlotsBase.lua +24 -21
- package/src/Shared/HasSaveSlotsInterface.lua +1 -0
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
|
+
# [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
|
+
|
|
16
|
+
# [1.10.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.9.0...@quenty/saveslot@1.10.0) (2026-07-21)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @quenty/saveslot
|
|
19
|
+
|
|
6
20
|
# [1.9.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.8.0...@quenty/saveslot@1.9.0) (2026-07-21)
|
|
7
21
|
|
|
8
22
|
### Bug Fixes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/saveslot",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@quenty/servicebag": "11.19.0",
|
|
49
49
|
"@quenty/signal": "7.13.1",
|
|
50
50
|
"@quenty/table": "3.9.2",
|
|
51
|
-
"@quenty/teleportserviceutils": "9.
|
|
51
|
+
"@quenty/teleportserviceutils": "9.36.0",
|
|
52
52
|
"@quenty/tie": "10.43.0",
|
|
53
53
|
"@quenty/valueobject": "13.33.0",
|
|
54
54
|
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f04837e2cf40c9cb66cb672f1f4d3f28ddb0088c"
|
|
60
60
|
}
|
|
@@ -129,14 +129,18 @@ function HasSaveSlotsClient.PromiseSlotIdFromIndex(
|
|
|
129
129
|
return self._remoting.PromiseSlotIdFromIndex:PromiseInvokeServer(slotIndex)
|
|
130
130
|
end
|
|
131
131
|
|
|
132
|
-
-- Client realm hook for HasSaveSlotsBase: the incoming slot id is whatever the local player
|
|
133
|
-
--
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
132
|
+
-- Client realm hook for HasSaveSlotsBase: the incoming slot id is whatever the local player teleported
|
|
133
|
+
-- in with, read from the unified TeleportDataServiceClient view (a promise for symmetry with the
|
|
134
|
+
-- server; on the client it resolves immediately from local teleport data).
|
|
135
|
+
function HasSaveSlotsClient.PromiseIncomingSlotId(self: HasSaveSlotsClient): Promise.Promise<SaveSlotData.SlotId?>
|
|
136
|
+
return self._teleportDataServiceClient
|
|
137
|
+
:PromiseArrivedValue(SaveSlotConstants.TELEPORT_DATA_SLOT_KEY)
|
|
138
|
+
:Then(function(slotId): SaveSlotData.SlotId?
|
|
139
|
+
if type(slotId) == "string" then
|
|
140
|
+
return slotId
|
|
141
|
+
end
|
|
142
|
+
return nil
|
|
143
|
+
end)
|
|
140
144
|
end
|
|
141
145
|
|
|
142
146
|
return Binder.new("HasSaveSlots", HasSaveSlotsClient :: any) :: Binder.Binder<HasSaveSlotsClient>
|
|
@@ -7,6 +7,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
7
7
|
|
|
8
8
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
9
9
|
|
|
10
|
+
local HasSaveSlotsData = require("HasSaveSlotsData")
|
|
10
11
|
local Maid = require("Maid")
|
|
11
12
|
local Remoting = require("Remoting")
|
|
12
13
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
@@ -44,15 +45,33 @@ function SaveSlotServiceClient.Init(self: SaveSlotServiceClient, serviceBag: Ser
|
|
|
44
45
|
self._remoting = self._maid:Add(Remoting.Client.new(ReplicatedStorage, "SaveSlotService"))
|
|
45
46
|
end
|
|
46
47
|
|
|
48
|
+
function SaveSlotServiceClient.Start(self: SaveSlotServiceClient)
|
|
49
|
+
-- Symmetric mirror of the server's provider ([SaveSlotService.Start]): a teleport the client builds
|
|
50
|
+
-- carries the local player's active slot id, so a client-initiated teleport resumes on the same slot
|
|
51
|
+
-- without any menu re-attaching it by hand.
|
|
52
|
+
self._maid:GiveTask(
|
|
53
|
+
self._teleportDataServiceClient:RegisterPerPlayerTeleportDataProvider(
|
|
54
|
+
function(player: Player): { [string]: any }?
|
|
55
|
+
local slotId = HasSaveSlotsData.ActiveSlotId:Get(player)
|
|
56
|
+
if type(slotId) == "string" then
|
|
57
|
+
return { [SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = slotId }
|
|
58
|
+
end
|
|
59
|
+
return nil
|
|
60
|
+
end
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
47
65
|
--[=[
|
|
48
|
-
|
|
49
|
-
internal slot teleport rather than a fresh join.
|
|
50
|
-
[SaveSlotService.
|
|
66
|
+
Resolves whether the local player teleported in carrying a save-slot id -- i.e. arrived via an
|
|
67
|
+
internal slot teleport rather than a fresh join. Presence-only. A promise for symmetry with the
|
|
68
|
+
server's [SaveSlotService.PromiseIsInternalTeleport]; on the client it resolves immediately from
|
|
69
|
+
local teleport data.
|
|
51
70
|
|
|
52
|
-
@return boolean
|
|
71
|
+
@return Promise<boolean>
|
|
53
72
|
]=]
|
|
54
|
-
function SaveSlotServiceClient.
|
|
55
|
-
return self._teleportDataServiceClient:
|
|
73
|
+
function SaveSlotServiceClient.PromiseIsInternalTeleport(self: SaveSlotServiceClient): any
|
|
74
|
+
return self._teleportDataServiceClient:PromiseHasArrivedValue(SaveSlotConstants.TELEPORT_DATA_SLOT_KEY)
|
|
56
75
|
end
|
|
57
76
|
|
|
58
77
|
--[=[
|
|
@@ -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
|
|
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
|
|
253
|
-
|
|
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
|
|
543
|
-
|
|
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
|
|
@@ -582,13 +660,19 @@ function HasSaveSlots.RegisterSummaryProvider(self: HasSaveSlots, name: string,
|
|
|
582
660
|
end
|
|
583
661
|
|
|
584
662
|
-- Server realm hook for HasSaveSlotsBase: the incoming slot id is whatever the player teleported in
|
|
585
|
-
-- with, read from
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
663
|
+
-- with, read from the unified TeleportDataService view. It is a promise because a client-initiated
|
|
664
|
+
-- teleport only reaches the server once the client replicates its arrived data. The slot id is a
|
|
665
|
+
-- client *request* -- fine here, because PromiseLoadSaveSlotFromTeleport re-validates ownership via
|
|
666
|
+
-- PromiseHasSlot before selecting it.
|
|
667
|
+
function HasSaveSlots.PromiseIncomingSlotId(self: HasSaveSlots): Promise.Promise<SaveSlotData.SlotId?>
|
|
668
|
+
return self._teleportDataService
|
|
669
|
+
:PromiseArrivedValue(self._obj, SaveSlotConstants.TELEPORT_DATA_SLOT_KEY)
|
|
670
|
+
:Then(function(slotId): SaveSlotData.SlotId?
|
|
671
|
+
if type(slotId) == "string" then
|
|
672
|
+
return slotId
|
|
673
|
+
end
|
|
674
|
+
return nil
|
|
675
|
+
end)
|
|
592
676
|
end
|
|
593
677
|
|
|
594
678
|
function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
|
|
@@ -605,14 +689,37 @@ function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
|
|
|
605
689
|
return self._systemStore:Load("activeSlotId"):Then(function(activeId: SaveSlotData.SlotId?)
|
|
606
690
|
self._lastActiveSlotId = activeId
|
|
607
691
|
self.LastActiveSlotId.Value = activeId
|
|
608
|
-
self._maid:GiveTask(self._systemStore:StoreOnValueChange("activeSlotId", self.ActiveSlotId))
|
|
609
692
|
|
|
610
|
-
--
|
|
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
|
+
|
|
611
699
|
self._maid:GiveTask(self.ActiveSlotId.Changed:Connect(function()
|
|
612
700
|
local active = self.ActiveSlotId.Value
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
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)
|
|
616
723
|
end
|
|
617
724
|
end))
|
|
618
725
|
end)
|
|
@@ -621,6 +728,11 @@ function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
|
|
|
621
728
|
end
|
|
622
729
|
|
|
623
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
|
+
|
|
624
736
|
local slot = self._slotMap[slotId]
|
|
625
737
|
if slot and (SaveSlotData.SlotIndex:Get(slot) == SaveSlotConstants.DEFAULT_SLOT_INDEX) then
|
|
626
738
|
return self._dataStore
|
|
@@ -628,11 +740,15 @@ function HasSaveSlots._getSlotStore(self: HasSaveSlots, slotId: SaveSlotData.Slo
|
|
|
628
740
|
return self._systemStore:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY):GetSubStore(slotId)
|
|
629
741
|
end
|
|
630
742
|
|
|
743
|
+
local MUTABLE_METADATA_KEYS =
|
|
744
|
+
{ "SlotName", "CreatedTime", "LastPlayedTime", "Summary", "TimePlayed", "PlayCount", "LastSessionLength" }
|
|
745
|
+
|
|
631
746
|
function HasSaveSlots._buildSlot(
|
|
632
747
|
self: HasSaveSlots,
|
|
633
748
|
slotId: SaveSlotData.SlotId,
|
|
634
749
|
data: SaveSlotData.SaveSlotMetadata,
|
|
635
|
-
isNew: boolean
|
|
750
|
+
isNew: boolean?,
|
|
751
|
+
isEphemeral: boolean?
|
|
636
752
|
): ()
|
|
637
753
|
local maid = Maid.new()
|
|
638
754
|
self._maid[slotId] = maid
|
|
@@ -641,21 +757,43 @@ function HasSaveSlots._buildSlot(
|
|
|
641
757
|
slot.Name = slotId
|
|
642
758
|
slot.Archivable = false
|
|
643
759
|
|
|
644
|
-
local metadataStore = self._metadataStore:GetSubStore(slotId)
|
|
645
|
-
|
|
646
760
|
local attributes = SaveSlotData:Create(slot)
|
|
647
761
|
attributes.SlotId.Value = slotId
|
|
648
762
|
attributes.SlotIndex.Value = data.SlotIndex
|
|
649
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
|
+
|
|
650
790
|
-- Store immutable SlotIndex once on creation
|
|
651
791
|
if isNew then
|
|
652
792
|
metadataStore:Store("SlotIndex", data.SlotIndex)
|
|
653
793
|
end
|
|
654
794
|
|
|
655
795
|
-- Store mutable metadata on change
|
|
656
|
-
for _, key in
|
|
657
|
-
{ "SlotName", "CreatedTime", "LastPlayedTime", "Summary", "TimePlayed", "PlayCount", "LastSessionLength" }
|
|
658
|
-
do
|
|
796
|
+
for _, key in MUTABLE_METADATA_KEYS do
|
|
659
797
|
attributes[key].Value = data[key]
|
|
660
798
|
maid:GiveTask(metadataStore:StoreOnValueChange(key, attributes[key]))
|
|
661
799
|
|
|
@@ -673,6 +811,23 @@ function HasSaveSlots._buildSlot(
|
|
|
673
811
|
end)
|
|
674
812
|
end
|
|
675
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
|
+
|
|
676
831
|
function HasSaveSlots._setupSummary(self: HasSaveSlots): ()
|
|
677
832
|
self._maid:GiveTask(
|
|
678
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)
|
|
@@ -161,16 +161,16 @@ function SaveSlotService.GetExplicitSelectionRequired(self: SaveSlotService): bo
|
|
|
161
161
|
end
|
|
162
162
|
|
|
163
163
|
--[=[
|
|
164
|
-
|
|
165
|
-
slot teleport rather than a fresh join.
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
Resolves whether the player teleported in carrying a save-slot id -- i.e. arrived via an internal
|
|
165
|
+
slot teleport rather than a fresh join. Presence-only (it does not validate the slot still exists);
|
|
166
|
+
use [HasSaveSlots.PromiseHasSaveSlotFromTeleport] when existence matters. It is a promise because a
|
|
167
|
+
client-initiated teleport only reaches the server once the client replicates its arrived data.
|
|
168
168
|
|
|
169
169
|
@param player Player
|
|
170
|
-
@return boolean
|
|
170
|
+
@return Promise<boolean>
|
|
171
171
|
]=]
|
|
172
|
-
function SaveSlotService.
|
|
173
|
-
return self._teleportDataService:
|
|
172
|
+
function SaveSlotService.PromiseIsInternalTeleport(self: SaveSlotService, player: Player): Promise.Promise<boolean>
|
|
173
|
+
return self._teleportDataService:PromiseHasArrivedValue(player, SaveSlotConstants.TELEPORT_DATA_SLOT_KEY)
|
|
174
174
|
end
|
|
175
175
|
|
|
176
176
|
--[=[
|
|
@@ -12,6 +12,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
12
12
|
local DataStoreMock = require("DataStoreMock")
|
|
13
13
|
local Jest = require("Jest")
|
|
14
14
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
15
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
15
16
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
16
17
|
local SaveSlotService = require("SaveSlotService")
|
|
17
18
|
local ServiceBag = require("ServiceBag")
|
|
@@ -243,21 +244,56 @@ describe("SaveSlotService internal teleport", function()
|
|
|
243
244
|
serviceBag:Destroy()
|
|
244
245
|
end)
|
|
245
246
|
|
|
246
|
-
|
|
247
|
+
-- Awaits a boolean read promise and returns its fulfilled value.
|
|
248
|
+
local function awaitBool(promise: any): boolean
|
|
249
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
250
|
+
local ok, value = promise:Yield()
|
|
251
|
+
expect(ok).toEqual(true)
|
|
252
|
+
return value
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it("should report a client-initiated teleport (non-trusted band) as internal", function()
|
|
256
|
+
-- This is the fix: a slot the *client* attached only reaches the server via replication, and the
|
|
257
|
+
-- server must still see it.
|
|
247
258
|
local serviceBag, saveSlotService, teleportDataService = newServiceBag()
|
|
248
259
|
serviceBag:Start()
|
|
249
260
|
|
|
250
|
-
local arrived = fakePlayer()
|
|
251
|
-
teleportDataService:
|
|
261
|
+
local arrived = fakePlayer(111)
|
|
262
|
+
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, {
|
|
252
263
|
[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = "slot-1",
|
|
253
264
|
})
|
|
254
|
-
expect(saveSlotService:IsInternalTeleport(arrived)).toEqual(true)
|
|
255
265
|
|
|
256
|
-
|
|
257
|
-
teleportDataService:SetArrivedTeleportDataForTesting(fresh, {})
|
|
258
|
-
expect(saveSlotService:IsInternalTeleport(fresh)).toEqual(false)
|
|
266
|
+
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(true)
|
|
259
267
|
|
|
260
268
|
arrived:Destroy()
|
|
269
|
+
serviceBag:Destroy()
|
|
270
|
+
end)
|
|
271
|
+
|
|
272
|
+
it("should report a server-initiated teleport (trusted band) as internal", function()
|
|
273
|
+
local serviceBag, saveSlotService, teleportDataService = newServiceBag()
|
|
274
|
+
serviceBag:Start()
|
|
275
|
+
|
|
276
|
+
local arrived = fakePlayer(111)
|
|
277
|
+
teleportDataService:SetTrustedArrivedTeleportDataForTesting(arrived, {
|
|
278
|
+
[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = "slot-1",
|
|
279
|
+
})
|
|
280
|
+
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, nil) -- no client band; seals
|
|
281
|
+
|
|
282
|
+
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(true)
|
|
283
|
+
|
|
284
|
+
arrived:Destroy()
|
|
285
|
+
serviceBag:Destroy()
|
|
286
|
+
end)
|
|
287
|
+
|
|
288
|
+
it("should report a fresh join (no arrived data) as not internal", function()
|
|
289
|
+
local serviceBag, saveSlotService, teleportDataService = newServiceBag()
|
|
290
|
+
serviceBag:Start()
|
|
291
|
+
|
|
292
|
+
local fresh = fakePlayer(111)
|
|
293
|
+
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(fresh, nil) -- fresh-join sentinel; seals
|
|
294
|
+
|
|
295
|
+
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(fresh))).toEqual(false)
|
|
296
|
+
|
|
261
297
|
fresh:Destroy()
|
|
262
298
|
serviceBag:Destroy()
|
|
263
299
|
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
|
})
|
|
@@ -51,15 +51,16 @@ function HasSaveSlotsBase.new(player: Player, serviceBag: ServiceBag.ServiceBag)
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
--[=[
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
[TeleportDataService]
|
|
57
|
-
"no incoming
|
|
54
|
+
Resolves the save-slot id the player teleported in with, or nil. Realm hook: the server reads it from
|
|
55
|
+
the client-replicated teleport data, the client from the local player's teleport data (both via the
|
|
56
|
+
[TeleportDataService] unified read, which is a promise because the server must wait for the client to
|
|
57
|
+
replicate). The base default resolves nil so a realm that never sets one degrades to "no incoming
|
|
58
|
+
slot".
|
|
58
59
|
|
|
59
|
-
@return SaveSlotData.SlotId
|
|
60
|
+
@return Promise<SaveSlotData.SlotId?>
|
|
60
61
|
]=]
|
|
61
|
-
function HasSaveSlotsBase.
|
|
62
|
-
return nil
|
|
62
|
+
function HasSaveSlotsBase.PromiseIncomingSlotId(_self: HasSaveSlotsBase): Promise.Promise<SaveSlotData.SlotId?>
|
|
63
|
+
return (Promise :: any).resolved(nil)
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
--[=[
|
|
@@ -69,12 +70,13 @@ end
|
|
|
69
70
|
@return Promise<boolean>
|
|
70
71
|
]=]
|
|
71
72
|
function HasSaveSlotsBase.PromiseHasSaveSlotFromTeleport(self: HasSaveSlotsBase): Promise.Promise<boolean>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
return self:PromiseIncomingSlotId():Then(function(slotId: SaveSlotData.SlotId?)
|
|
74
|
+
if type(slotId) ~= "string" then
|
|
75
|
+
return false
|
|
76
|
+
end
|
|
76
77
|
|
|
77
|
-
|
|
78
|
+
return (self :: any):PromiseHasSlot(slotId)
|
|
79
|
+
end)
|
|
78
80
|
end
|
|
79
81
|
|
|
80
82
|
--[=[
|
|
@@ -85,18 +87,19 @@ end
|
|
|
85
87
|
@return Promise<SaveSlotData.SlotId?>
|
|
86
88
|
]=]
|
|
87
89
|
function HasSaveSlotsBase.PromiseLoadSaveSlotFromTeleport(self: HasSaveSlotsBase): Promise.Promise<SaveSlotData.SlotId?>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return (Promise :: any).resolved(nil)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
return (self :: any):PromiseHasSlot(slotId):Then(function(hasSlot: boolean)
|
|
94
|
-
if not hasSlot then
|
|
90
|
+
return self:PromiseIncomingSlotId():Then(function(slotId: SaveSlotData.SlotId?)
|
|
91
|
+
if type(slotId) ~= "string" then
|
|
95
92
|
return nil
|
|
96
93
|
end
|
|
97
94
|
|
|
98
|
-
return (self :: any):
|
|
99
|
-
|
|
95
|
+
return (self :: any):PromiseHasSlot(slotId):Then(function(hasSlot: boolean)
|
|
96
|
+
if not hasSlot then
|
|
97
|
+
return nil
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
return (self :: any):PromiseSelectSlot(slotId):Then(function()
|
|
101
|
+
return slotId
|
|
102
|
+
end)
|
|
100
103
|
end)
|
|
101
104
|
end)
|
|
102
105
|
end
|
|
@@ -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
|
})
|