@quenty/saveslot 1.6.0 → 1.7.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 +13 -0
- package/package.json +3 -2
- package/src/Client/Binders/HasSaveSlotsClient.lua +14 -0
- package/src/Client/SaveSlotServiceClient.lua +17 -0
- package/src/Server/Binders/HasSaveSlots.lua +135 -0
- package/src/Server/Binders/HasSaveSlots.spec.lua +446 -8
- package/src/Server/Cmdr/SaveSlotCmdrService.lua +83 -16
- package/src/Server/SaveSlotService.lua +47 -12
- package/src/Server/SaveSlotService.spec.lua +109 -7
- package/src/Shared/Data/HasSaveSlotsData.lua +1 -0
- package/src/Shared/HasSaveSlotsBase.lua +54 -0
- package/src/Shared/HasSaveSlotsInterface.lua +11 -0
- package/src/Shared/SaveSlotDataService.lua +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
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.7.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.6.0...@quenty/saveslot@1.7.0) (2026-07-20)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- Strict typing on tests ([efbc458](https://github.com/Quenty/NevermoreEngine/commit/efbc45882fac95755ea4ff4e007c5f71bedebf6f))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- Integrate teleport data service directly into save slots for cross-game continuation ([ffa7496](https://github.com/Quenty/NevermoreEngine/commit/ffa7496047b80a82623440221c019fdfe09e31ea))
|
|
15
|
+
- **saveslot:** add last-active replication and continue/new-game/wipe APIs ([f5f4045](https://github.com/Quenty/NevermoreEngine/commit/f5f4045b5849482f95a780fce5ba298682afe173))
|
|
16
|
+
- Support deselecting the active save slot ([d7da61d](https://github.com/Quenty/NevermoreEngine/commit/d7da61d80742f56987e2cf69e7fb108e9b18fa2d))
|
|
17
|
+
- Support unbounded save slots via SetUnlimitedSlots ([ec34e9a](https://github.com/Quenty/NevermoreEngine/commit/ec34e9aa6c9fce0cab4dd4f6f88780581e3cd1e5))
|
|
18
|
+
|
|
6
19
|
# [1.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.5.0...@quenty/saveslot@1.6.0) (2026-07-18)
|
|
7
20
|
|
|
8
21
|
**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.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "PlayerDataStoreService wrapper for save slots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@quenty/servicebag": "11.19.0",
|
|
47
47
|
"@quenty/signal": "7.13.1",
|
|
48
48
|
"@quenty/table": "3.9.2",
|
|
49
|
+
"@quenty/teleportserviceutils": "9.34.0",
|
|
49
50
|
"@quenty/tie": "10.43.0",
|
|
50
51
|
"@quenty/valueobject": "13.33.0",
|
|
51
52
|
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
@@ -53,5 +54,5 @@
|
|
|
53
54
|
"publishConfig": {
|
|
54
55
|
"access": "public"
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "2c903e91ae2ea1702ae1ce94af20af83af81e4fe"
|
|
57
58
|
}
|
|
@@ -12,8 +12,10 @@ local HasSaveSlotsBase = require("HasSaveSlotsBase")
|
|
|
12
12
|
local HasSaveSlotsInterface = require("HasSaveSlotsInterface")
|
|
13
13
|
local Promise = require("Promise")
|
|
14
14
|
local Remoting = require("Remoting")
|
|
15
|
+
local SaveSlotConstants = require("SaveSlotConstants")
|
|
15
16
|
local SaveSlotData = require("SaveSlotData")
|
|
16
17
|
local ServiceBag = require("ServiceBag")
|
|
18
|
+
local TeleportDataServiceClient = require("TeleportDataServiceClient")
|
|
17
19
|
|
|
18
20
|
local HasSaveSlotsClient = setmetatable({}, HasSaveSlotsBase)
|
|
19
21
|
HasSaveSlotsClient.ClassName = "HasSaveSlotsClient"
|
|
@@ -25,6 +27,7 @@ export type HasSaveSlotsClient =
|
|
|
25
27
|
_obj: Player,
|
|
26
28
|
_serviceBag: ServiceBag.ServiceBag,
|
|
27
29
|
_remoting: any,
|
|
30
|
+
_teleportDataServiceClient: any,
|
|
28
31
|
},
|
|
29
32
|
{} :: typeof({ __index = HasSaveSlotsClient })
|
|
30
33
|
))
|
|
@@ -38,6 +41,7 @@ function HasSaveSlotsClient.new(player: Player, serviceBag: ServiceBag.ServiceBa
|
|
|
38
41
|
local self: HasSaveSlotsClient = setmetatable(HasSaveSlotsBase.new(player, serviceBag) :: any, HasSaveSlotsClient)
|
|
39
42
|
|
|
40
43
|
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
44
|
+
self._teleportDataServiceClient = self._serviceBag:GetService(TeleportDataServiceClient)
|
|
41
45
|
|
|
42
46
|
self._remoting = self._maid:Add(Remoting.Client.new(self._obj, "HasSaveSlots"))
|
|
43
47
|
|
|
@@ -125,4 +129,14 @@ function HasSaveSlotsClient.PromiseSlotIdFromIndex(
|
|
|
125
129
|
return self._remoting.PromiseSlotIdFromIndex:PromiseInvokeServer(slotIndex)
|
|
126
130
|
end
|
|
127
131
|
|
|
132
|
+
-- Client realm hook for HasSaveSlotsBase: the incoming slot id is whatever the local player
|
|
133
|
+
-- teleported in with, read from their local teleport data via TeleportDataServiceClient.
|
|
134
|
+
function HasSaveSlotsClient._getIncomingSlotId(self: HasSaveSlotsClient): SaveSlotData.SlotId?
|
|
135
|
+
local slotId = self._teleportDataServiceClient:GetArrivedValue(SaveSlotConstants.TELEPORT_DATA_SLOT_KEY)
|
|
136
|
+
if type(slotId) == "string" then
|
|
137
|
+
return slotId
|
|
138
|
+
end
|
|
139
|
+
return nil
|
|
140
|
+
end
|
|
141
|
+
|
|
128
142
|
return Binder.new("HasSaveSlots", HasSaveSlotsClient :: any) :: Binder.Binder<HasSaveSlotsClient>
|
|
@@ -9,7 +9,9 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
9
9
|
|
|
10
10
|
local Maid = require("Maid")
|
|
11
11
|
local Remoting = require("Remoting")
|
|
12
|
+
local SaveSlotConstants = require("SaveSlotConstants")
|
|
12
13
|
local ServiceBag = require("ServiceBag")
|
|
14
|
+
local TeleportDataServiceClient = require("TeleportDataServiceClient")
|
|
13
15
|
|
|
14
16
|
local SaveSlotServiceClient = {}
|
|
15
17
|
SaveSlotServiceClient.ServiceName = "SaveSlotServiceClient"
|
|
@@ -19,6 +21,7 @@ export type SaveSlotServiceClient = typeof(setmetatable(
|
|
|
19
21
|
_serviceBag: ServiceBag.ServiceBag,
|
|
20
22
|
_maid: Maid.Maid,
|
|
21
23
|
_remoting: any,
|
|
24
|
+
_teleportDataServiceClient: any,
|
|
22
25
|
},
|
|
23
26
|
{} :: typeof({ __index = SaveSlotServiceClient })
|
|
24
27
|
))
|
|
@@ -28,6 +31,9 @@ function SaveSlotServiceClient.Init(self: SaveSlotServiceClient, serviceBag: Ser
|
|
|
28
31
|
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
29
32
|
self._maid = Maid.new()
|
|
30
33
|
|
|
34
|
+
-- External
|
|
35
|
+
self._teleportDataServiceClient = self._serviceBag:GetService(TeleportDataServiceClient)
|
|
36
|
+
|
|
31
37
|
-- Internal
|
|
32
38
|
self._serviceBag:GetService(require("SaveSlotCmdrServiceClient"))
|
|
33
39
|
self._serviceBag:GetService(require("SaveSlotDataService"))
|
|
@@ -38,6 +44,17 @@ function SaveSlotServiceClient.Init(self: SaveSlotServiceClient, serviceBag: Ser
|
|
|
38
44
|
self._remoting = self._maid:Add(Remoting.Client.new(ReplicatedStorage, "SaveSlotService"))
|
|
39
45
|
end
|
|
40
46
|
|
|
47
|
+
--[=[
|
|
48
|
+
Returns whether the local player teleported in carrying a save-slot id -- i.e. arrived via an
|
|
49
|
+
internal slot teleport rather than a fresh join. Sync, presence-only (mirrors the server's
|
|
50
|
+
[SaveSlotService.IsInternalTeleport]).
|
|
51
|
+
|
|
52
|
+
@return boolean
|
|
53
|
+
]=]
|
|
54
|
+
function SaveSlotServiceClient.IsInternalTeleport(self: SaveSlotServiceClient): boolean
|
|
55
|
+
return self._teleportDataServiceClient:HasArrivedValue(SaveSlotConstants.TELEPORT_DATA_SLOT_KEY)
|
|
56
|
+
end
|
|
57
|
+
|
|
41
58
|
--[=[
|
|
42
59
|
Returns whether explicit slot selection is required
|
|
43
60
|
]=]
|
|
@@ -23,6 +23,7 @@ local RxBrioUtils = require("RxBrioUtils")
|
|
|
23
23
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
24
24
|
local SaveSlotData = require("SaveSlotData")
|
|
25
25
|
local ServiceBag = require("ServiceBag")
|
|
26
|
+
local TeleportDataService = require("TeleportDataService")
|
|
26
27
|
local ValueObject = require("ValueObject")
|
|
27
28
|
|
|
28
29
|
export type SaveSlotSummaryProvider = (Player, any) -> Observable.Observable<string>
|
|
@@ -46,6 +47,7 @@ export type HasSaveSlots =
|
|
|
46
47
|
_metadataStore: any,
|
|
47
48
|
_summaryProvider: ValueObject.ValueObject<SaveSlotSummaryProvider?>,
|
|
48
49
|
_lastActiveSlotId: SaveSlotData.SlotId?,
|
|
50
|
+
_teleportDataService: any,
|
|
49
51
|
},
|
|
50
52
|
{} :: typeof({ __index = HasSaveSlots })
|
|
51
53
|
))
|
|
@@ -56,6 +58,7 @@ function HasSaveSlots.new(player: Player, serviceBag: ServiceBag.ServiceBag): Ha
|
|
|
56
58
|
|
|
57
59
|
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
58
60
|
self._playerDataStoreService = self._serviceBag:GetService(PlayerDataStoreService)
|
|
61
|
+
self._teleportDataService = self._serviceBag:GetService(TeleportDataService)
|
|
59
62
|
|
|
60
63
|
self._slotContainer = self._maid:Add(Instance.new("Folder"))
|
|
61
64
|
self._slotContainer.Name = SaveSlotConstants.METADATA_CONTAINER_NAME
|
|
@@ -156,6 +159,26 @@ function HasSaveSlots.PromiseSelectSlot(self: HasSaveSlots, slotId: SaveSlotData
|
|
|
156
159
|
end)
|
|
157
160
|
end
|
|
158
161
|
|
|
162
|
+
--[=[
|
|
163
|
+
Clears the active slot selection, returning the player to a no-slot state --
|
|
164
|
+
the counterpart to [HasSaveSlots.PromiseSelectSlot], backing a "back to menu"
|
|
165
|
+
affordance. The active slot's progress is flushed first (mirroring the save
|
|
166
|
+
PromiseSelectSlot runs when switching away), and the last-active slot is
|
|
167
|
+
remembered, so [HasSaveSlots.PromiseSelectLastSaveSlot] can resume it later.
|
|
168
|
+
A no-op when no slot is active.
|
|
169
|
+
]=]
|
|
170
|
+
function HasSaveSlots.PromiseDeselectSlot(self: HasSaveSlots): Promise.Promise<()>
|
|
171
|
+
return (self._loadPromise :: any):Then(function()
|
|
172
|
+
if self.ActiveSlotId.Value == nil then
|
|
173
|
+
return -- Already deselected
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
return self._dataStore:Save():Then(function()
|
|
177
|
+
self.ActiveSlotId.Value = nil
|
|
178
|
+
end)
|
|
179
|
+
end)
|
|
180
|
+
end
|
|
181
|
+
|
|
159
182
|
--[=[
|
|
160
183
|
Creates a slot at the given index
|
|
161
184
|
]=]
|
|
@@ -205,6 +228,14 @@ function HasSaveSlots.PromiseDeleteSlot(self: HasSaveSlots, slotId: SaveSlotData
|
|
|
205
228
|
|
|
206
229
|
self._maid[slotId] = nil
|
|
207
230
|
|
|
231
|
+
-- The continue pointer must not outlive its slot. When the deleted slot is the one the player
|
|
232
|
+
-- would resume on (e.g. the just-deselected active slot, or a never-reselected last-active),
|
|
233
|
+
-- clear the last-active memory so "Continue" stops offering a slot that no longer exists.
|
|
234
|
+
if slotId == self._lastActiveSlotId then
|
|
235
|
+
self._lastActiveSlotId = nil
|
|
236
|
+
self.LastActiveSlotId.Value = nil
|
|
237
|
+
end
|
|
238
|
+
|
|
208
239
|
-- Wipe default slot
|
|
209
240
|
local slotIndex = SaveSlotData.SlotIndex:Get(slot)
|
|
210
241
|
local deletePromise = nil
|
|
@@ -232,6 +263,34 @@ function HasSaveSlots.PromiseDeleteSlot(self: HasSaveSlots, slotId: SaveSlotData
|
|
|
232
263
|
end)
|
|
233
264
|
end
|
|
234
265
|
|
|
266
|
+
--[=[
|
|
267
|
+
Deletes every slot for the player and clears the active/last-active
|
|
268
|
+
selection, resetting the player to a fresh state. Resolves once all slots
|
|
269
|
+
are gone.
|
|
270
|
+
]=]
|
|
271
|
+
function HasSaveSlots.PromiseDeleteAllSlots(self: HasSaveSlots): Promise.Promise<any>
|
|
272
|
+
return (self._loadPromise :: any):Then(function()
|
|
273
|
+
-- Clear the selection first so the previously active slot is deletable
|
|
274
|
+
self.ActiveSlotId.Value = nil
|
|
275
|
+
self._lastActiveSlotId = nil
|
|
276
|
+
self.LastActiveSlotId.Value = nil
|
|
277
|
+
|
|
278
|
+
local slotIds = {}
|
|
279
|
+
for slotId in self._slotMap do
|
|
280
|
+
table.insert(slotIds, slotId)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
-- Delete sequentially to avoid concurrent datastore saves
|
|
284
|
+
local promise = (Promise :: any).resolved()
|
|
285
|
+
for _, slotId in slotIds do
|
|
286
|
+
promise = promise:Then(function()
|
|
287
|
+
return self:PromiseDeleteSlot(slotId)
|
|
288
|
+
end)
|
|
289
|
+
end
|
|
290
|
+
return promise
|
|
291
|
+
end)
|
|
292
|
+
end
|
|
293
|
+
|
|
235
294
|
--[=[
|
|
236
295
|
Sets the metadata for the slot with the given ID
|
|
237
296
|
]=]
|
|
@@ -295,6 +354,62 @@ function HasSaveSlots.PromiseLastActiveSlotId(self: HasSaveSlots): Promise.Promi
|
|
|
295
354
|
end)
|
|
296
355
|
end
|
|
297
356
|
|
|
357
|
+
--[=[
|
|
358
|
+
Selects the player's last active slot if one still exists, resolving to the
|
|
359
|
+
selected slot id -- or nil when there is no slot to continue on. Backs a
|
|
360
|
+
"Continue" affordance that every save-slot consumer tends to need.
|
|
361
|
+
]=]
|
|
362
|
+
function HasSaveSlots.PromiseSelectLastSaveSlot(self: HasSaveSlots): Promise.Promise<SaveSlotData.SlotId?>
|
|
363
|
+
return self:PromiseLastActiveSlotId():Then(function(lastActiveSlotId: SaveSlotData.SlotId?)
|
|
364
|
+
if not lastActiveSlotId then
|
|
365
|
+
return nil
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
return self:PromiseHasSlot(lastActiveSlotId):Then(function(hasLastSlot: boolean)
|
|
369
|
+
if not hasLastSlot then
|
|
370
|
+
return nil
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
return self:PromiseSelectSlot(lastActiveSlotId):Then(function()
|
|
374
|
+
return lastActiveSlotId
|
|
375
|
+
end)
|
|
376
|
+
end)
|
|
377
|
+
end)
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
--[=[
|
|
381
|
+
Creates a new slot at the lowest free index and selects it, resolving to the
|
|
382
|
+
new slot id -- or nil when every slot is already in use. Backs a "New Game"
|
|
383
|
+
affordance.
|
|
384
|
+
]=]
|
|
385
|
+
function HasSaveSlots.PromiseSelectNewSaveSlot(self: HasSaveSlots): Promise.Promise<SaveSlotData.SlotId?>
|
|
386
|
+
return (self._loadPromise :: any):Then(function(): any
|
|
387
|
+
local usedIndices = {}
|
|
388
|
+
for _, slot in self._slotMap do
|
|
389
|
+
usedIndices[SaveSlotData.SlotIndex:Get(slot)] = true
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
-- Lowest free positive index. Fills gaps left by deletions (delete slot 2 of
|
|
393
|
+
-- [1,2,3] and the next new slot reuses index 2). With a finite MaxSlotCount this
|
|
394
|
+
-- returns nil once [1, MaxSlotCount] is full; with an unbounded count (math.huge)
|
|
395
|
+
-- there is always a next integer, so it never returns nil.
|
|
396
|
+
local freeIndex = 1
|
|
397
|
+
while usedIndices[freeIndex] do
|
|
398
|
+
freeIndex += 1
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
if freeIndex > self.MaxSlotCount.Value then
|
|
402
|
+
return nil
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
return self:PromiseCreateSlot(freeIndex):Then(function(slotId: SaveSlotData.SlotId)
|
|
406
|
+
return self:PromiseSelectSlot(slotId):Then(function()
|
|
407
|
+
return slotId
|
|
408
|
+
end)
|
|
409
|
+
end)
|
|
410
|
+
end)
|
|
411
|
+
end
|
|
412
|
+
|
|
298
413
|
--[=[
|
|
299
414
|
Sets the summary provider
|
|
300
415
|
]=]
|
|
@@ -302,6 +417,16 @@ function HasSaveSlots.SetSummaryProvider(self: HasSaveSlots, provider: SaveSlotS
|
|
|
302
417
|
self._summaryProvider.Value = provider
|
|
303
418
|
end
|
|
304
419
|
|
|
420
|
+
-- Server realm hook for HasSaveSlotsBase: the incoming slot id is whatever the player teleported in
|
|
421
|
+
-- with, read from their join data via TeleportDataService.
|
|
422
|
+
function HasSaveSlots._getIncomingSlotId(self: HasSaveSlots): SaveSlotData.SlotId?
|
|
423
|
+
local slotId = self._teleportDataService:GetArrivedValue(self._obj, SaveSlotConstants.TELEPORT_DATA_SLOT_KEY)
|
|
424
|
+
if type(slotId) == "string" then
|
|
425
|
+
return slotId
|
|
426
|
+
end
|
|
427
|
+
return nil
|
|
428
|
+
end
|
|
429
|
+
|
|
305
430
|
function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
|
|
306
431
|
return self._playerDataStoreService:PromiseDataStore(self._obj):Then(function(dataStore)
|
|
307
432
|
self._dataStore = dataStore
|
|
@@ -315,7 +440,17 @@ function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
|
|
|
315
440
|
|
|
316
441
|
return self._systemStore:Load("activeSlotId"):Then(function(activeId: SaveSlotData.SlotId?)
|
|
317
442
|
self._lastActiveSlotId = activeId
|
|
443
|
+
self.LastActiveSlotId.Value = activeId
|
|
318
444
|
self._maid:GiveTask(self._systemStore:StoreOnValueChange("activeSlotId", self.ActiveSlotId))
|
|
445
|
+
|
|
446
|
+
-- Keep the replicated last-active in sync as the player selects slots this session
|
|
447
|
+
self._maid:GiveTask(self.ActiveSlotId.Changed:Connect(function()
|
|
448
|
+
local active = self.ActiveSlotId.Value
|
|
449
|
+
if active ~= nil then
|
|
450
|
+
self._lastActiveSlotId = active
|
|
451
|
+
self.LastActiveSlotId.Value = active
|
|
452
|
+
end
|
|
453
|
+
end))
|
|
319
454
|
end)
|
|
320
455
|
end)
|
|
321
456
|
end)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
--!
|
|
1
|
+
--!strict
|
|
2
2
|
--[[
|
|
3
3
|
Integration coverage for the real HasSaveSlots binder, driven against a mocked datastore. Because
|
|
4
4
|
the load path only reads the player's UserId, a plain Folder stands in for a Player with
|
|
@@ -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 PlayerDataStoreManager = require("PlayerDataStoreManager")
|
|
15
|
+
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
15
16
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
16
17
|
local ServiceBag = require("ServiceBag")
|
|
17
18
|
|
|
@@ -35,17 +36,23 @@ afterEach(function()
|
|
|
35
36
|
PlayerDataStoreManager._toPlayerUserIdOrError = originalToUserId
|
|
36
37
|
end)
|
|
37
38
|
|
|
38
|
-
local function setup(mock)
|
|
39
|
+
local function setup(mock: DataStoreMock.DataStoreMock?)
|
|
39
40
|
mock = mock or DataStoreMock.new()
|
|
40
41
|
|
|
41
42
|
local serviceBag = ServiceBag.new()
|
|
42
|
-
|
|
43
|
+
serviceBag:GetService(require("TeleportDataService"))
|
|
44
|
+
-- GetService returns the required module's type; PlayerDataStoreService returns its class table, so
|
|
45
|
+
-- cast to the instance type before calling instance methods.
|
|
46
|
+
local playerDataStoreService = (
|
|
47
|
+
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
48
|
+
) :: PlayerDataStoreService.PlayerDataStoreService
|
|
43
49
|
local binder = serviceBag:GetService(require("HasSaveSlots"))
|
|
44
50
|
serviceBag:Init()
|
|
45
51
|
playerDataStoreService:SetRobloxDataStore(mock)
|
|
46
52
|
serviceBag:Start()
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
-- A Folder stands in for a Player; the load path only reads the UserId, intercepted below.
|
|
55
|
+
local fakePlayer = (Instance.new("Folder") :: any) :: Player
|
|
49
56
|
fakePlayer.Name = "FakePlayer"
|
|
50
57
|
fakePlayer.Parent = Workspace
|
|
51
58
|
|
|
@@ -57,10 +64,8 @@ local function setup(mock)
|
|
|
57
64
|
return originalToUserId(self, playerOrUserId)
|
|
58
65
|
end
|
|
59
66
|
|
|
60
|
-
local hasSaveSlots = binder:Bind(fakePlayer)
|
|
61
|
-
|
|
62
|
-
hasSaveSlots.MaxSlotCount.Value = 5
|
|
63
|
-
end
|
|
67
|
+
local hasSaveSlots = assert(binder:Bind(fakePlayer), "Failed to bind HasSaveSlots")
|
|
68
|
+
hasSaveSlots.MaxSlotCount.Value = 5
|
|
64
69
|
|
|
65
70
|
local function destroy()
|
|
66
71
|
fakePlayer:Destroy()
|
|
@@ -259,6 +264,439 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
259
264
|
|
|
260
265
|
context.destroy()
|
|
261
266
|
end)
|
|
267
|
+
|
|
268
|
+
it("should replicate the last active slot after selection", function()
|
|
269
|
+
local context = setup()
|
|
270
|
+
|
|
271
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
272
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
273
|
+
expect("create hung").toEqual("create settled")
|
|
274
|
+
context.destroy()
|
|
275
|
+
return
|
|
276
|
+
end
|
|
277
|
+
local _, slotId = createPromise:Yield()
|
|
278
|
+
|
|
279
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
280
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
281
|
+
expect("select hung").toEqual("select settled")
|
|
282
|
+
context.destroy()
|
|
283
|
+
return
|
|
284
|
+
end
|
|
285
|
+
selectPromise:Yield()
|
|
286
|
+
|
|
287
|
+
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(slotId)
|
|
288
|
+
|
|
289
|
+
context.destroy()
|
|
290
|
+
end)
|
|
291
|
+
|
|
292
|
+
it("PromiseDeselectSlot clears the active slot but remembers the last active", function()
|
|
293
|
+
local context = setup()
|
|
294
|
+
|
|
295
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
296
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
297
|
+
expect("create hung").toEqual("create settled")
|
|
298
|
+
context.destroy()
|
|
299
|
+
return
|
|
300
|
+
end
|
|
301
|
+
local _, slotId = createPromise:Yield()
|
|
302
|
+
|
|
303
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
304
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
305
|
+
expect("select hung").toEqual("select settled")
|
|
306
|
+
context.destroy()
|
|
307
|
+
return
|
|
308
|
+
end
|
|
309
|
+
selectPromise:Yield()
|
|
310
|
+
|
|
311
|
+
local deselectPromise = context.hasSaveSlots:PromiseDeselectSlot()
|
|
312
|
+
if not PromiseTestUtils.awaitSettled(deselectPromise, 10) then
|
|
313
|
+
expect("deselect hung").toEqual("deselect settled")
|
|
314
|
+
context.destroy()
|
|
315
|
+
return
|
|
316
|
+
end
|
|
317
|
+
expect((deselectPromise:Yield())).toEqual(true)
|
|
318
|
+
|
|
319
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toBeNil()
|
|
320
|
+
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(slotId)
|
|
321
|
+
|
|
322
|
+
-- The slot is deselected, not deleted: the last-active pointer still resolves it
|
|
323
|
+
local lastPromise = context.hasSaveSlots:PromiseLastActiveSlotId()
|
|
324
|
+
if not PromiseTestUtils.awaitSettled(lastPromise, 10) then
|
|
325
|
+
expect("lastActive hung").toEqual("lastActive settled")
|
|
326
|
+
context.destroy()
|
|
327
|
+
return
|
|
328
|
+
end
|
|
329
|
+
expect((lastPromise:Wait())).toEqual(slotId)
|
|
330
|
+
|
|
331
|
+
context.destroy()
|
|
332
|
+
end)
|
|
333
|
+
|
|
334
|
+
it("deleting the last-active slot clears the continue pointer", function()
|
|
335
|
+
-- Repro for the `delete-save-slot *` bug: deleting the (deselected) active slot left
|
|
336
|
+
-- LastActiveSlotId dangling, so the menu kept offering "Continue" for a slot that was gone.
|
|
337
|
+
local context = setup()
|
|
338
|
+
|
|
339
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
340
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
341
|
+
expect("create hung").toEqual("create settled")
|
|
342
|
+
context.destroy()
|
|
343
|
+
return
|
|
344
|
+
end
|
|
345
|
+
local _, slotId = createPromise:Yield()
|
|
346
|
+
|
|
347
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
348
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
349
|
+
expect("select hung").toEqual("select settled")
|
|
350
|
+
context.destroy()
|
|
351
|
+
return
|
|
352
|
+
end
|
|
353
|
+
selectPromise:Yield()
|
|
354
|
+
|
|
355
|
+
-- Deselect first, matching how the cmdr command frees the active slot before deleting it.
|
|
356
|
+
local deselectPromise = context.hasSaveSlots:PromiseDeselectSlot()
|
|
357
|
+
if not PromiseTestUtils.awaitSettled(deselectPromise, 10) then
|
|
358
|
+
expect("deselect hung").toEqual("deselect settled")
|
|
359
|
+
context.destroy()
|
|
360
|
+
return
|
|
361
|
+
end
|
|
362
|
+
deselectPromise:Yield()
|
|
363
|
+
|
|
364
|
+
-- Deselection deliberately keeps remembering the slot for "Continue"...
|
|
365
|
+
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(slotId)
|
|
366
|
+
|
|
367
|
+
local deletePromise = context.hasSaveSlots:PromiseDeleteSlot(slotId)
|
|
368
|
+
if not PromiseTestUtils.awaitSettled(deletePromise, 10) then
|
|
369
|
+
expect("delete hung").toEqual("delete settled")
|
|
370
|
+
context.destroy()
|
|
371
|
+
return
|
|
372
|
+
end
|
|
373
|
+
deletePromise:Yield()
|
|
374
|
+
|
|
375
|
+
-- ...but once that slot is deleted, there is nothing to continue on.
|
|
376
|
+
expect(context.hasSaveSlots.LastActiveSlotId.Value).toBeNil()
|
|
377
|
+
|
|
378
|
+
local lastPromise = context.hasSaveSlots:PromiseLastActiveSlotId()
|
|
379
|
+
if not PromiseTestUtils.awaitSettled(lastPromise, 10) then
|
|
380
|
+
expect("lastActive hung").toEqual("lastActive settled")
|
|
381
|
+
context.destroy()
|
|
382
|
+
return
|
|
383
|
+
end
|
|
384
|
+
expect((lastPromise:Wait())).toBeNil()
|
|
385
|
+
|
|
386
|
+
context.destroy()
|
|
387
|
+
end)
|
|
388
|
+
|
|
389
|
+
it("deleting a non-last-active slot leaves the continue pointer intact", function()
|
|
390
|
+
-- The clear must be scoped to the resumable slot: deleting some other slot must not wipe it.
|
|
391
|
+
local context = setup()
|
|
392
|
+
|
|
393
|
+
local firstPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
394
|
+
if not PromiseTestUtils.awaitSettled(firstPromise, 10) then
|
|
395
|
+
expect("first create hung").toEqual("first create settled")
|
|
396
|
+
context.destroy()
|
|
397
|
+
return
|
|
398
|
+
end
|
|
399
|
+
local _, firstSlotId = firstPromise:Yield()
|
|
400
|
+
|
|
401
|
+
local secondPromise = context.hasSaveSlots:PromiseCreateSlot(2)
|
|
402
|
+
if not PromiseTestUtils.awaitSettled(secondPromise, 10) then
|
|
403
|
+
expect("second create hung").toEqual("second create settled")
|
|
404
|
+
context.destroy()
|
|
405
|
+
return
|
|
406
|
+
end
|
|
407
|
+
local _, secondSlotId = secondPromise:Yield()
|
|
408
|
+
|
|
409
|
+
-- Slot 1 is the last-active; slot 2 is just another slot, and stays deletable while 1 is deselected.
|
|
410
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(firstSlotId)
|
|
411
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
412
|
+
expect("select hung").toEqual("select settled")
|
|
413
|
+
context.destroy()
|
|
414
|
+
return
|
|
415
|
+
end
|
|
416
|
+
selectPromise:Yield()
|
|
417
|
+
|
|
418
|
+
local deselectPromise = context.hasSaveSlots:PromiseDeselectSlot()
|
|
419
|
+
if not PromiseTestUtils.awaitSettled(deselectPromise, 10) then
|
|
420
|
+
expect("deselect hung").toEqual("deselect settled")
|
|
421
|
+
context.destroy()
|
|
422
|
+
return
|
|
423
|
+
end
|
|
424
|
+
deselectPromise:Yield()
|
|
425
|
+
|
|
426
|
+
local deletePromise = context.hasSaveSlots:PromiseDeleteSlot(secondSlotId)
|
|
427
|
+
if not PromiseTestUtils.awaitSettled(deletePromise, 10) then
|
|
428
|
+
expect("delete hung").toEqual("delete settled")
|
|
429
|
+
context.destroy()
|
|
430
|
+
return
|
|
431
|
+
end
|
|
432
|
+
deletePromise:Yield()
|
|
433
|
+
|
|
434
|
+
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(firstSlotId)
|
|
435
|
+
|
|
436
|
+
context.destroy()
|
|
437
|
+
end)
|
|
438
|
+
|
|
439
|
+
it("PromiseDeselectSlot is a no-op when no slot is active", function()
|
|
440
|
+
local context = setup()
|
|
441
|
+
|
|
442
|
+
local deselectPromise = context.hasSaveSlots:PromiseDeselectSlot()
|
|
443
|
+
if not PromiseTestUtils.awaitSettled(deselectPromise, 10) then
|
|
444
|
+
expect("deselect hung").toEqual("deselect settled")
|
|
445
|
+
context.destroy()
|
|
446
|
+
return
|
|
447
|
+
end
|
|
448
|
+
expect((deselectPromise:Yield())).toEqual(true)
|
|
449
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toBeNil()
|
|
450
|
+
|
|
451
|
+
context.destroy()
|
|
452
|
+
end)
|
|
453
|
+
|
|
454
|
+
it("PromiseDeselectSlot then PromiseSelectLastSaveSlot round-trips back into the slot", function()
|
|
455
|
+
local context = setup()
|
|
456
|
+
|
|
457
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
458
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
459
|
+
expect("create hung").toEqual("create settled")
|
|
460
|
+
context.destroy()
|
|
461
|
+
return
|
|
462
|
+
end
|
|
463
|
+
local _, slotId = createPromise:Yield()
|
|
464
|
+
|
|
465
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
466
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
467
|
+
expect("select hung").toEqual("select settled")
|
|
468
|
+
context.destroy()
|
|
469
|
+
return
|
|
470
|
+
end
|
|
471
|
+
selectPromise:Yield()
|
|
472
|
+
|
|
473
|
+
local deselectPromise = context.hasSaveSlots:PromiseDeselectSlot()
|
|
474
|
+
if not PromiseTestUtils.awaitSettled(deselectPromise, 10) then
|
|
475
|
+
expect("deselect hung").toEqual("deselect settled")
|
|
476
|
+
context.destroy()
|
|
477
|
+
return
|
|
478
|
+
end
|
|
479
|
+
deselectPromise:Yield()
|
|
480
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toBeNil()
|
|
481
|
+
|
|
482
|
+
local continuePromise = context.hasSaveSlots:PromiseSelectLastSaveSlot()
|
|
483
|
+
if not PromiseTestUtils.awaitSettled(continuePromise, 10) then
|
|
484
|
+
expect("continue hung").toEqual("continue settled")
|
|
485
|
+
context.destroy()
|
|
486
|
+
return
|
|
487
|
+
end
|
|
488
|
+
expect((continuePromise:Wait())).toEqual(slotId)
|
|
489
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(slotId)
|
|
490
|
+
|
|
491
|
+
context.destroy()
|
|
492
|
+
end)
|
|
493
|
+
|
|
494
|
+
it("PromiseSelectLastSaveSlot re-selects the last active slot after the active slot is cleared", function()
|
|
495
|
+
local context = setup()
|
|
496
|
+
|
|
497
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
498
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
499
|
+
expect("create hung").toEqual("create settled")
|
|
500
|
+
context.destroy()
|
|
501
|
+
return
|
|
502
|
+
end
|
|
503
|
+
local _, slotId = createPromise:Yield()
|
|
504
|
+
|
|
505
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
506
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
507
|
+
expect("select hung").toEqual("select settled")
|
|
508
|
+
context.destroy()
|
|
509
|
+
return
|
|
510
|
+
end
|
|
511
|
+
selectPromise:Yield()
|
|
512
|
+
|
|
513
|
+
-- Simulate returning to the menu: no active slot, but the last active is remembered
|
|
514
|
+
context.hasSaveSlots.ActiveSlotId.Value = nil
|
|
515
|
+
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(slotId)
|
|
516
|
+
|
|
517
|
+
local continuePromise = context.hasSaveSlots:PromiseSelectLastSaveSlot()
|
|
518
|
+
if not PromiseTestUtils.awaitSettled(continuePromise, 10) then
|
|
519
|
+
expect("continue hung").toEqual("continue settled")
|
|
520
|
+
context.destroy()
|
|
521
|
+
return
|
|
522
|
+
end
|
|
523
|
+
expect((continuePromise:Wait())).toEqual(slotId)
|
|
524
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(slotId)
|
|
525
|
+
|
|
526
|
+
context.destroy()
|
|
527
|
+
end)
|
|
528
|
+
|
|
529
|
+
it("PromiseSelectLastSaveSlot resolves nil when there is nothing to continue", function()
|
|
530
|
+
local context = setup()
|
|
531
|
+
|
|
532
|
+
local continuePromise = context.hasSaveSlots:PromiseSelectLastSaveSlot()
|
|
533
|
+
if not PromiseTestUtils.awaitSettled(continuePromise, 10) then
|
|
534
|
+
expect("continue hung").toEqual("continue settled")
|
|
535
|
+
context.destroy()
|
|
536
|
+
return
|
|
537
|
+
end
|
|
538
|
+
expect((continuePromise:Wait())).toBeNil()
|
|
539
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toBeNil()
|
|
540
|
+
|
|
541
|
+
context.destroy()
|
|
542
|
+
end)
|
|
543
|
+
|
|
544
|
+
it("PromiseSelectNewSaveSlot creates and selects a fresh slot each time", function()
|
|
545
|
+
local context = setup()
|
|
546
|
+
|
|
547
|
+
local firstPromise = context.hasSaveSlots:PromiseSelectNewSaveSlot()
|
|
548
|
+
if not PromiseTestUtils.awaitSettled(firstPromise, 10) then
|
|
549
|
+
expect("new game hung").toEqual("new game settled")
|
|
550
|
+
context.destroy()
|
|
551
|
+
return
|
|
552
|
+
end
|
|
553
|
+
local firstSlotId = firstPromise:Wait()
|
|
554
|
+
expect(type(firstSlotId)).toEqual("string")
|
|
555
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(firstSlotId)
|
|
556
|
+
|
|
557
|
+
local secondPromise = context.hasSaveSlots:PromiseSelectNewSaveSlot()
|
|
558
|
+
if not PromiseTestUtils.awaitSettled(secondPromise, 10) then
|
|
559
|
+
expect("second new game hung").toEqual("second new game settled")
|
|
560
|
+
context.destroy()
|
|
561
|
+
return
|
|
562
|
+
end
|
|
563
|
+
local secondSlotId = secondPromise:Wait()
|
|
564
|
+
expect(type(secondSlotId)).toEqual("string")
|
|
565
|
+
expect(secondSlotId ~= firstSlotId).toEqual(true)
|
|
566
|
+
|
|
567
|
+
context.destroy()
|
|
568
|
+
end)
|
|
569
|
+
|
|
570
|
+
it("PromiseDeleteAllSlots wipes every slot and clears the selection", function()
|
|
571
|
+
local context = setup()
|
|
572
|
+
|
|
573
|
+
local firstPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
574
|
+
if not PromiseTestUtils.awaitSettled(firstPromise, 10) then
|
|
575
|
+
expect("first create hung").toEqual("first create settled")
|
|
576
|
+
context.destroy()
|
|
577
|
+
return
|
|
578
|
+
end
|
|
579
|
+
local _, firstSlotId = firstPromise:Yield()
|
|
580
|
+
|
|
581
|
+
local secondPromise = context.hasSaveSlots:PromiseCreateSlot(2)
|
|
582
|
+
if not PromiseTestUtils.awaitSettled(secondPromise, 10) then
|
|
583
|
+
expect("second create hung").toEqual("second create settled")
|
|
584
|
+
context.destroy()
|
|
585
|
+
return
|
|
586
|
+
end
|
|
587
|
+
secondPromise:Yield()
|
|
588
|
+
|
|
589
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(firstSlotId)
|
|
590
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
591
|
+
expect("select hung").toEqual("select settled")
|
|
592
|
+
context.destroy()
|
|
593
|
+
return
|
|
594
|
+
end
|
|
595
|
+
selectPromise:Yield()
|
|
596
|
+
|
|
597
|
+
local wipePromise = context.hasSaveSlots:PromiseDeleteAllSlots()
|
|
598
|
+
if not PromiseTestUtils.awaitSettled(wipePromise, 10) then
|
|
599
|
+
expect("wipe hung").toEqual("wipe settled")
|
|
600
|
+
context.destroy()
|
|
601
|
+
return
|
|
602
|
+
end
|
|
603
|
+
wipePromise:Yield()
|
|
604
|
+
|
|
605
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toBeNil()
|
|
606
|
+
expect(context.hasSaveSlots.LastActiveSlotId.Value).toBeNil()
|
|
607
|
+
|
|
608
|
+
local hasPromise = context.hasSaveSlots:PromiseHasSlot(firstSlotId)
|
|
609
|
+
if not PromiseTestUtils.awaitSettled(hasPromise, 10) then
|
|
610
|
+
expect("hasSlot hung").toEqual("hasSlot settled")
|
|
611
|
+
context.destroy()
|
|
612
|
+
return
|
|
613
|
+
end
|
|
614
|
+
expect((hasPromise:Wait())).toEqual(false)
|
|
615
|
+
|
|
616
|
+
context.destroy()
|
|
617
|
+
end)
|
|
618
|
+
|
|
619
|
+
it("PromiseSelectNewSaveSlot reuses the lowest free index after a deletion", function()
|
|
620
|
+
local context = setup()
|
|
621
|
+
|
|
622
|
+
-- Fill indices 1, 2, 3 (nothing is selected, so all remain deletable)
|
|
623
|
+
local slotIdsByIndex = {}
|
|
624
|
+
for index = 1, 3 do
|
|
625
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(index)
|
|
626
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
627
|
+
expect("create hung").toEqual("create settled")
|
|
628
|
+
context.destroy()
|
|
629
|
+
return
|
|
630
|
+
end
|
|
631
|
+
local _, slotId = createPromise:Yield()
|
|
632
|
+
slotIdsByIndex[index] = slotId
|
|
633
|
+
end
|
|
634
|
+
|
|
635
|
+
-- Open a gap at index 2
|
|
636
|
+
local deletePromise = context.hasSaveSlots:PromiseDeleteSlot(slotIdsByIndex[2])
|
|
637
|
+
if not PromiseTestUtils.awaitSettled(deletePromise, 10) then
|
|
638
|
+
expect("delete hung").toEqual("delete settled")
|
|
639
|
+
context.destroy()
|
|
640
|
+
return
|
|
641
|
+
end
|
|
642
|
+
deletePromise:Yield()
|
|
643
|
+
|
|
644
|
+
-- The next new slot fills the gap at 2 rather than appending at 4
|
|
645
|
+
local newPromise = context.hasSaveSlots:PromiseSelectNewSaveSlot()
|
|
646
|
+
if not PromiseTestUtils.awaitSettled(newPromise, 10) then
|
|
647
|
+
expect("new game hung").toEqual("new game settled")
|
|
648
|
+
context.destroy()
|
|
649
|
+
return
|
|
650
|
+
end
|
|
651
|
+
local newSlotId = newPromise:Wait()
|
|
652
|
+
expect(type(newSlotId)).toEqual("string")
|
|
653
|
+
|
|
654
|
+
local metadataPromise = context.hasSaveSlots:PromiseGetSlotMetadata(newSlotId)
|
|
655
|
+
if not PromiseTestUtils.awaitSettled(metadataPromise, 10) then
|
|
656
|
+
expect("metadata hung").toEqual("metadata settled")
|
|
657
|
+
context.destroy()
|
|
658
|
+
return
|
|
659
|
+
end
|
|
660
|
+
expect((metadataPromise:Wait()).SlotIndex).toEqual(2)
|
|
661
|
+
|
|
662
|
+
context.destroy()
|
|
663
|
+
end)
|
|
664
|
+
|
|
665
|
+
it("allows creating a slot past a finite cap when the count is unbounded", function()
|
|
666
|
+
local context = setup()
|
|
667
|
+
context.hasSaveSlots.MaxSlotCount.Value = math.huge
|
|
668
|
+
|
|
669
|
+
-- Index 6 is beyond the setup's finite cap of 5; unbounded must accept it
|
|
670
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(6)
|
|
671
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
672
|
+
expect("create hung").toEqual("create settled")
|
|
673
|
+
context.destroy()
|
|
674
|
+
return
|
|
675
|
+
end
|
|
676
|
+
local ok, slotId = createPromise:Yield()
|
|
677
|
+
expect(ok).toEqual(true)
|
|
678
|
+
expect(type(slotId)).toEqual("string")
|
|
679
|
+
|
|
680
|
+
context.destroy()
|
|
681
|
+
end)
|
|
682
|
+
|
|
683
|
+
it("PromiseSelectNewSaveSlot never runs out of slots when unbounded", function()
|
|
684
|
+
local context = setup()
|
|
685
|
+
context.hasSaveSlots.MaxSlotCount.Value = math.huge
|
|
686
|
+
|
|
687
|
+
-- Allocate past the finite cap of 5; every call still yields a fresh slot
|
|
688
|
+
for _ = 1, 7 do
|
|
689
|
+
local newPromise = context.hasSaveSlots:PromiseSelectNewSaveSlot()
|
|
690
|
+
if not PromiseTestUtils.awaitSettled(newPromise, 10) then
|
|
691
|
+
expect("new game hung").toEqual("new game settled")
|
|
692
|
+
context.destroy()
|
|
693
|
+
return
|
|
694
|
+
end
|
|
695
|
+
expect(type(newPromise:Wait())).toEqual("string")
|
|
696
|
+
end
|
|
697
|
+
|
|
698
|
+
context.destroy()
|
|
699
|
+
end)
|
|
262
700
|
end)
|
|
263
701
|
|
|
264
702
|
describe("HasSaveSlots against a fake player (datastore down)", function()
|
|
@@ -8,6 +8,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
8
8
|
local CmdrService = require("CmdrService")
|
|
9
9
|
local HasSaveSlots = require("HasSaveSlots")
|
|
10
10
|
local Maid = require("Maid")
|
|
11
|
+
local Promise = require("Promise")
|
|
11
12
|
local SaveSlotCmdrUtils = require("SaveSlotCmdrUtils")
|
|
12
13
|
local SaveSlotDataService = require("SaveSlotDataService")
|
|
13
14
|
local ServiceBag = require("ServiceBag")
|
|
@@ -112,20 +113,59 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
112
113
|
return `Switched to slot {slotIndex}.`
|
|
113
114
|
end)
|
|
114
115
|
|
|
116
|
+
self._cmdrService:RegisterCommand({
|
|
117
|
+
Name = "deselect-save-slot",
|
|
118
|
+
Description = "Clears the active save slot, returning to a no-slot state.",
|
|
119
|
+
Group = "SaveSlots",
|
|
120
|
+
Args = {},
|
|
121
|
+
}, function(context)
|
|
122
|
+
if not self._saveSlotDataService:GetActiveSlotId(context.Executor) then
|
|
123
|
+
return "No active slot."
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
self._maid
|
|
127
|
+
:GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
|
|
128
|
+
:Then(function(hasSaveSlots)
|
|
129
|
+
return hasSaveSlots:PromiseDeselectSlot()
|
|
130
|
+
end)
|
|
131
|
+
:Wait()
|
|
132
|
+
|
|
133
|
+
return "Deselected active slot."
|
|
134
|
+
end)
|
|
135
|
+
|
|
115
136
|
self._cmdrService:RegisterCommand({
|
|
116
137
|
Name = "create-save-slot",
|
|
117
|
-
Description = "Creates a save slot
|
|
138
|
+
Description = "Creates a save slot. Defaults to the lowest free index when none is given.",
|
|
118
139
|
Group = "SaveSlots",
|
|
119
140
|
Args = {
|
|
120
141
|
{
|
|
121
142
|
Name = "Slot",
|
|
122
143
|
Type = "number",
|
|
123
|
-
Description = "Slot index to create.",
|
|
144
|
+
Description = "Slot index to create. Omit to use the lowest free index.",
|
|
145
|
+
Optional = true,
|
|
124
146
|
},
|
|
125
147
|
},
|
|
126
|
-
}, function(context, slotIndex: number)
|
|
148
|
+
}, function(context, slotIndex: number?)
|
|
127
149
|
local maxSlotCount = context.Executor:GetAttribute("MaxSlotCount")
|
|
128
|
-
|
|
150
|
+
|
|
151
|
+
if slotIndex == nil then
|
|
152
|
+
-- Default to the lowest free index, filling gaps left by deletions.
|
|
153
|
+
local used = {}
|
|
154
|
+
for _, metadata in self._saveSlotDataService:GetSlotList(context.Executor) do
|
|
155
|
+
used[metadata.SlotIndex] = true
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
local freeIndex = 1
|
|
159
|
+
while used[freeIndex] do
|
|
160
|
+
freeIndex += 1
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
if freeIndex > maxSlotCount then
|
|
164
|
+
return "All slots are already in use."
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
slotIndex = freeIndex
|
|
168
|
+
elseif (slotIndex < 1) or (slotIndex > maxSlotCount) then
|
|
129
169
|
return `Index must be in range [1, {maxSlotCount}].`
|
|
130
170
|
end
|
|
131
171
|
|
|
@@ -146,33 +186,60 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
146
186
|
|
|
147
187
|
self._cmdrService:RegisterCommand({
|
|
148
188
|
Name = "delete-save-slot",
|
|
149
|
-
Description = "Deletes the given save
|
|
189
|
+
Description = "Deletes the given save slots.",
|
|
150
190
|
Group = "SaveSlots",
|
|
151
191
|
Args = {
|
|
152
192
|
{
|
|
153
|
-
Name = "
|
|
154
|
-
Type = "
|
|
155
|
-
Description = "Slot
|
|
193
|
+
Name = "Slots",
|
|
194
|
+
Type = "slotIndices",
|
|
195
|
+
Description = "Slot indices to delete (e.g. 1,2 or * for all).",
|
|
156
196
|
},
|
|
157
197
|
},
|
|
158
|
-
}, function(context,
|
|
159
|
-
local
|
|
160
|
-
|
|
161
|
-
|
|
198
|
+
}, function(context, slotIndices: { number })
|
|
199
|
+
local activeSlotId = self._saveSlotDataService:GetActiveSlotId(context.Executor)
|
|
200
|
+
|
|
201
|
+
-- Resolve indices to ids up front; `*` can include the active slot and duplicates.
|
|
202
|
+
local seen = {}
|
|
203
|
+
local toDelete = {}
|
|
204
|
+
for _, slotIndex in slotIndices do
|
|
205
|
+
local slotId = self._saveSlotDataService:GetSlotIdFromIndex(context.Executor, slotIndex)
|
|
206
|
+
if slotId and not seen[slotId] then
|
|
207
|
+
seen[slotId] = true
|
|
208
|
+
table.insert(toDelete, { slotIndex = slotIndex, slotId = slotId })
|
|
209
|
+
end
|
|
162
210
|
end
|
|
163
211
|
|
|
164
|
-
if
|
|
165
|
-
return "
|
|
212
|
+
if #toDelete == 0 then
|
|
213
|
+
return "No matching slots to delete."
|
|
166
214
|
end
|
|
167
215
|
|
|
168
216
|
self._maid
|
|
169
217
|
:GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
|
|
170
218
|
:Then(function(hasSaveSlots)
|
|
171
|
-
|
|
219
|
+
-- Delete sequentially to avoid concurrent datastore saves. The active slot can't be
|
|
220
|
+
-- deleted while selected, so deselect it first (flushing its progress) when reached.
|
|
221
|
+
local promise = Promise.resolved()
|
|
222
|
+
for _, entry in toDelete do
|
|
223
|
+
promise = promise:Then(function()
|
|
224
|
+
if entry.slotId == activeSlotId then
|
|
225
|
+
return hasSaveSlots:PromiseDeselectSlot():Then(function()
|
|
226
|
+
return hasSaveSlots:PromiseDeleteSlot(entry.slotId)
|
|
227
|
+
end)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
return hasSaveSlots:PromiseDeleteSlot(entry.slotId)
|
|
231
|
+
end)
|
|
232
|
+
end
|
|
233
|
+
return promise
|
|
172
234
|
end)
|
|
173
235
|
:Wait()
|
|
174
236
|
|
|
175
|
-
|
|
237
|
+
local deletedIndices = {}
|
|
238
|
+
for _, entry in toDelete do
|
|
239
|
+
table.insert(deletedIndices, entry.slotIndex)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
return `Deleted slot(s) {table.concat(deletedIndices, ", ")}.`
|
|
176
243
|
end)
|
|
177
244
|
end
|
|
178
245
|
|
|
@@ -10,6 +10,7 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
10
10
|
local Brio = require("Brio")
|
|
11
11
|
local DataStoreStage = require("DataStoreStage")
|
|
12
12
|
local HasSaveSlots = require("HasSaveSlots")
|
|
13
|
+
local HasSaveSlotsData = require("HasSaveSlotsData")
|
|
13
14
|
local Maid = require("Maid")
|
|
14
15
|
local Observable = require("Observable")
|
|
15
16
|
local Promise = require("Promise")
|
|
@@ -18,6 +19,7 @@ local RxBrioUtils = require("RxBrioUtils")
|
|
|
18
19
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
19
20
|
local SaveSlotData = require("SaveSlotData")
|
|
20
21
|
local ServiceBag = require("ServiceBag")
|
|
22
|
+
local TeleportDataService = require("TeleportDataService")
|
|
21
23
|
|
|
22
24
|
local SaveSlotService = {}
|
|
23
25
|
SaveSlotService.ServiceName = "SaveSlotService"
|
|
@@ -31,6 +33,7 @@ export type SaveSlotService = typeof(setmetatable(
|
|
|
31
33
|
_maxSlotCount: number,
|
|
32
34
|
_defaultSummaryProvider: HasSaveSlots.SaveSlotSummaryProvider?,
|
|
33
35
|
_remoting: any,
|
|
36
|
+
_teleportDataService: any,
|
|
34
37
|
},
|
|
35
38
|
{} :: typeof({ __index = SaveSlotService })
|
|
36
39
|
))
|
|
@@ -42,6 +45,7 @@ function SaveSlotService.Init(self: SaveSlotService, serviceBag: ServiceBag.Serv
|
|
|
42
45
|
|
|
43
46
|
-- External
|
|
44
47
|
self._serviceBag:GetService(require("PlayerDataStoreService"))
|
|
48
|
+
self._teleportDataService = self._serviceBag:GetService(TeleportDataService)
|
|
45
49
|
|
|
46
50
|
-- Internal
|
|
47
51
|
self._serviceBag:GetService(require("SaveSlotCmdrService"))
|
|
@@ -61,6 +65,23 @@ function SaveSlotService.Init(self: SaveSlotService, serviceBag: ServiceBag.Serv
|
|
|
61
65
|
end
|
|
62
66
|
|
|
63
67
|
function SaveSlotService.Start(self: SaveSlotService)
|
|
68
|
+
-- Every teleport built through TeleportDataService for a single player carries that player's
|
|
69
|
+
-- active slot id, so cross-place teleports resume on the same slot without each teleport site
|
|
70
|
+
-- re-attaching it by hand.
|
|
71
|
+
self._maid:GiveTask(
|
|
72
|
+
self._teleportDataService:RegisterTeleportDataProvider(function(players: { Player }): { [string]: any }?
|
|
73
|
+
if #players ~= 1 then
|
|
74
|
+
return nil
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
local slotId = HasSaveSlotsData.ActiveSlotId:Get(players[1])
|
|
78
|
+
if type(slotId) == "string" then
|
|
79
|
+
return { [SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = slotId }
|
|
80
|
+
end
|
|
81
|
+
return nil
|
|
82
|
+
end)
|
|
83
|
+
)
|
|
84
|
+
|
|
64
85
|
self._maid:GiveTask(self._hasSaveSlotsBinder:ObserveAllBrio():Subscribe(function(brio)
|
|
65
86
|
if brio:IsDead() then
|
|
66
87
|
return
|
|
@@ -74,19 +95,11 @@ function SaveSlotService.Start(self: SaveSlotService)
|
|
|
74
95
|
hasSaveSlots:SetSummaryProvider(self._defaultSummaryProvider)
|
|
75
96
|
end
|
|
76
97
|
|
|
77
|
-
-- Select
|
|
98
|
+
-- Select the slot the player teleported in with, or proceed with the default flow
|
|
78
99
|
maid:GivePromise(hasSaveSlots:PromiseSlotsLoaded()):Then(function()
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if type(incomingSlotId) ~= "string" then
|
|
84
|
-
return self:_promiseSelectDefaultSlot(hasSaveSlots)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
return hasSaveSlots:PromiseHasSlot(incomingSlotId):Then(function(hasSlot: boolean)
|
|
88
|
-
if hasSlot then
|
|
89
|
-
return hasSaveSlots:PromiseSelectSlot(incomingSlotId)
|
|
100
|
+
return hasSaveSlots:PromiseLoadSaveSlotFromTeleport():Then(function(loadedSlotId)
|
|
101
|
+
if loadedSlotId then
|
|
102
|
+
return -- Teleported in with a valid slot; it is now selected
|
|
90
103
|
end
|
|
91
104
|
return self:_promiseSelectDefaultSlot(hasSaveSlots)
|
|
92
105
|
end)
|
|
@@ -141,6 +154,19 @@ function SaveSlotService.GetExplicitSelectionRequired(self: SaveSlotService): bo
|
|
|
141
154
|
return self._selectionRequired
|
|
142
155
|
end
|
|
143
156
|
|
|
157
|
+
--[=[
|
|
158
|
+
Returns whether the player teleported in carrying a save-slot id -- i.e. arrived via an internal
|
|
159
|
+
slot teleport rather than a fresh join. This is the sync, presence-only signal (it does not
|
|
160
|
+
validate the slot still exists); use [HasSaveSlots.PromiseHasSaveSlotFromTeleport] when existence
|
|
161
|
+
matters.
|
|
162
|
+
|
|
163
|
+
@param player Player
|
|
164
|
+
@return boolean
|
|
165
|
+
]=]
|
|
166
|
+
function SaveSlotService.IsInternalTeleport(self: SaveSlotService, player: Player): boolean
|
|
167
|
+
return self._teleportDataService:HasArrivedValue(player, SaveSlotConstants.TELEPORT_DATA_SLOT_KEY)
|
|
168
|
+
end
|
|
169
|
+
|
|
144
170
|
--[=[
|
|
145
171
|
Sets the max slot count
|
|
146
172
|
]=]
|
|
@@ -150,6 +176,15 @@ function SaveSlotService.SetMaxSlotCount(self: SaveSlotService, maxSlotCount: nu
|
|
|
150
176
|
self._maxSlotCount = maxSlotCount
|
|
151
177
|
end
|
|
152
178
|
|
|
179
|
+
--[=[
|
|
180
|
+
Removes the slot ceiling, so [HasSaveSlots.PromiseSelectNewSaveSlot] always
|
|
181
|
+
allocates the next free index. A thin alias over [SaveSlotService.SetMaxSlotCount]
|
|
182
|
+
with an unbounded count; same before-Start guard applies.
|
|
183
|
+
]=]
|
|
184
|
+
function SaveSlotService.SetUnlimitedSlots(self: SaveSlotService): ()
|
|
185
|
+
self:SetMaxSlotCount(math.huge)
|
|
186
|
+
end
|
|
187
|
+
|
|
153
188
|
--[=[
|
|
154
189
|
Sets the default slot summary provider
|
|
155
190
|
]=]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
--!
|
|
1
|
+
--!strict
|
|
2
2
|
--[[
|
|
3
3
|
Coverage for SaveSlotService's ServiceBag-driven configuration surface — the parts reachable
|
|
4
4
|
without a bound Player (a headless cloud test server has none). The player-driven slot
|
|
@@ -11,7 +11,11 @@ local require = require(script.Parent.loader).load(script)
|
|
|
11
11
|
|
|
12
12
|
local DataStoreMock = require("DataStoreMock")
|
|
13
13
|
local Jest = require("Jest")
|
|
14
|
+
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
15
|
+
local SaveSlotConstants = require("SaveSlotConstants")
|
|
16
|
+
local SaveSlotService = require("SaveSlotService")
|
|
14
17
|
local ServiceBag = require("ServiceBag")
|
|
18
|
+
local TeleportDataService = require("TeleportDataService")
|
|
15
19
|
|
|
16
20
|
local describe = Jest.Globals.describe
|
|
17
21
|
local expect = Jest.Globals.expect
|
|
@@ -21,11 +25,22 @@ local it = Jest.Globals.it
|
|
|
21
25
|
-- touches a real datastore. Returns the bag + service; the caller decides when to Start.
|
|
22
26
|
local function newServiceBag()
|
|
23
27
|
local serviceBag = ServiceBag.new()
|
|
24
|
-
local playerDataStoreService =
|
|
25
|
-
|
|
28
|
+
local playerDataStoreService = (
|
|
29
|
+
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
30
|
+
) :: PlayerDataStoreService.PlayerDataStoreService
|
|
31
|
+
local saveSlotService = (serviceBag:GetService(SaveSlotService) :: any) :: SaveSlotService.SaveSlotService
|
|
32
|
+
local teleportDataService = (
|
|
33
|
+
serviceBag:GetService(TeleportDataService) :: any
|
|
34
|
+
) :: TeleportDataService.TeleportDataService
|
|
26
35
|
serviceBag:Init()
|
|
27
36
|
playerDataStoreService:SetRobloxDataStore(DataStoreMock.new())
|
|
28
|
-
return serviceBag, saveSlotService
|
|
37
|
+
return serviceBag, saveSlotService, teleportDataService
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
-- A Folder is an Instance, so it satisfies the player guards and can carry the ActiveSlotId
|
|
41
|
+
-- attribute the provider reads, standing in for a Player without a real join.
|
|
42
|
+
local function fakePlayer(): Player
|
|
43
|
+
return (Instance.new("Folder") :: any) :: Player
|
|
29
44
|
end
|
|
30
45
|
|
|
31
46
|
describe("SaveSlotService initialization", function()
|
|
@@ -103,11 +118,33 @@ describe("SaveSlotService configuration guards", function()
|
|
|
103
118
|
serviceBag:Destroy()
|
|
104
119
|
end)
|
|
105
120
|
|
|
121
|
+
it("should accept SetUnlimitedSlots before Start", function()
|
|
122
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
123
|
+
|
|
124
|
+
expect(function()
|
|
125
|
+
saveSlotService:SetUnlimitedSlots()
|
|
126
|
+
end).never.toThrow()
|
|
127
|
+
|
|
128
|
+
serviceBag:Destroy()
|
|
129
|
+
end)
|
|
130
|
+
|
|
131
|
+
it("should reject SetUnlimitedSlots after Start", function()
|
|
132
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
133
|
+
serviceBag:Start()
|
|
134
|
+
|
|
135
|
+
-- Delegates to SetMaxSlotCount, so it surfaces the same before-Start guard
|
|
136
|
+
expect(function()
|
|
137
|
+
saveSlotService:SetUnlimitedSlots()
|
|
138
|
+
end).toThrow("SetMaxSlotCount must be called before Start")
|
|
139
|
+
|
|
140
|
+
serviceBag:Destroy()
|
|
141
|
+
end)
|
|
142
|
+
|
|
106
143
|
it("should reject a non-function summary provider", function()
|
|
107
144
|
local serviceBag, saveSlotService = newServiceBag()
|
|
108
145
|
|
|
109
146
|
expect(function()
|
|
110
|
-
saveSlotService:SetDefaultSummaryProvider("not a function")
|
|
147
|
+
saveSlotService:SetDefaultSummaryProvider("not a function" :: any)
|
|
111
148
|
end).toThrow("Bad provider")
|
|
112
149
|
|
|
113
150
|
serviceBag:Destroy()
|
|
@@ -117,11 +154,76 @@ describe("SaveSlotService configuration guards", function()
|
|
|
117
154
|
local serviceBag, saveSlotService = newServiceBag()
|
|
118
155
|
|
|
119
156
|
expect(function()
|
|
120
|
-
saveSlotService:SetDefaultSummaryProvider(function()
|
|
157
|
+
saveSlotService:SetDefaultSummaryProvider((function()
|
|
121
158
|
return nil
|
|
122
|
-
end)
|
|
159
|
+
end) :: any)
|
|
123
160
|
end).never.toThrow()
|
|
124
161
|
|
|
125
162
|
serviceBag:Destroy()
|
|
126
163
|
end)
|
|
127
164
|
end)
|
|
165
|
+
|
|
166
|
+
describe("SaveSlotService internal teleport", function()
|
|
167
|
+
it("should register a provider that carries a single player's active slot id", function()
|
|
168
|
+
local serviceBag, _saveSlotService, teleportDataService = newServiceBag()
|
|
169
|
+
serviceBag:Start()
|
|
170
|
+
|
|
171
|
+
local player = fakePlayer()
|
|
172
|
+
player:SetAttribute("ActiveSlotId", "slot-xyz")
|
|
173
|
+
|
|
174
|
+
local data = teleportDataService:BuildTeleportData({ player })
|
|
175
|
+
expect(data[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toEqual("slot-xyz")
|
|
176
|
+
|
|
177
|
+
player:Destroy()
|
|
178
|
+
serviceBag:Destroy()
|
|
179
|
+
end)
|
|
180
|
+
|
|
181
|
+
it("should not carry a slot id when the single player has no active slot", function()
|
|
182
|
+
local serviceBag, _saveSlotService, teleportDataService = newServiceBag()
|
|
183
|
+
serviceBag:Start()
|
|
184
|
+
|
|
185
|
+
local player = fakePlayer()
|
|
186
|
+
|
|
187
|
+
local data = teleportDataService:BuildTeleportData({ player })
|
|
188
|
+
expect(data[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toBeNil()
|
|
189
|
+
|
|
190
|
+
player:Destroy()
|
|
191
|
+
serviceBag:Destroy()
|
|
192
|
+
end)
|
|
193
|
+
|
|
194
|
+
it("should not carry a slot id for a multi-player teleport", function()
|
|
195
|
+
local serviceBag, _saveSlotService, teleportDataService = newServiceBag()
|
|
196
|
+
serviceBag:Start()
|
|
197
|
+
|
|
198
|
+
local playerA = fakePlayer()
|
|
199
|
+
local playerB = fakePlayer()
|
|
200
|
+
playerA:SetAttribute("ActiveSlotId", "slot-a")
|
|
201
|
+
playerB:SetAttribute("ActiveSlotId", "slot-b")
|
|
202
|
+
|
|
203
|
+
local data = teleportDataService:BuildTeleportData({ playerA, playerB })
|
|
204
|
+
expect(data[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toBeNil()
|
|
205
|
+
|
|
206
|
+
playerA:Destroy()
|
|
207
|
+
playerB:Destroy()
|
|
208
|
+
serviceBag:Destroy()
|
|
209
|
+
end)
|
|
210
|
+
|
|
211
|
+
it("should report IsInternalTeleport from the arrived teleport data", function()
|
|
212
|
+
local serviceBag, saveSlotService, teleportDataService = newServiceBag()
|
|
213
|
+
serviceBag:Start()
|
|
214
|
+
|
|
215
|
+
local arrived = fakePlayer()
|
|
216
|
+
teleportDataService:SetArrivedTeleportDataForTesting(arrived, {
|
|
217
|
+
[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = "slot-1",
|
|
218
|
+
})
|
|
219
|
+
expect(saveSlotService:IsInternalTeleport(arrived)).toEqual(true)
|
|
220
|
+
|
|
221
|
+
local fresh = fakePlayer()
|
|
222
|
+
teleportDataService:SetArrivedTeleportDataForTesting(fresh, {})
|
|
223
|
+
expect(saveSlotService:IsInternalTeleport(fresh)).toEqual(false)
|
|
224
|
+
|
|
225
|
+
arrived:Destroy()
|
|
226
|
+
fresh:Destroy()
|
|
227
|
+
serviceBag:Destroy()
|
|
228
|
+
end)
|
|
229
|
+
end)
|
|
@@ -10,5 +10,6 @@ local AdorneeDataEntry = require("AdorneeDataEntry")
|
|
|
10
10
|
|
|
11
11
|
return AdorneeData.new({
|
|
12
12
|
ActiveSlotId = AdorneeDataEntry.optionalAttribute("string", "ActiveSlotId"),
|
|
13
|
+
LastActiveSlotId = AdorneeDataEntry.optionalAttribute("string", "LastActiveSlotId"),
|
|
13
14
|
MaxSlotCount = math.huge,
|
|
14
15
|
})
|
|
@@ -7,6 +7,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
7
7
|
|
|
8
8
|
local BaseObject = require("BaseObject")
|
|
9
9
|
local HasSaveSlotsData = require("HasSaveSlotsData")
|
|
10
|
+
local Promise = require("Promise")
|
|
10
11
|
local SaveSlotData = require("SaveSlotData")
|
|
11
12
|
local ServiceBag = require("ServiceBag")
|
|
12
13
|
local Signal = require("Signal")
|
|
@@ -24,6 +25,7 @@ export type HasSaveSlotsBase =
|
|
|
24
25
|
_attributes: any,
|
|
25
26
|
|
|
26
27
|
ActiveSlotId: ValueObject.ValueObject<SaveSlotData.SlotId?>,
|
|
28
|
+
LastActiveSlotId: ValueObject.ValueObject<SaveSlotData.SlotId?>,
|
|
27
29
|
MaxSlotCount: ValueObject.ValueObject<number>,
|
|
28
30
|
|
|
29
31
|
SlotChanged: Signal.Signal<SaveSlotData.SlotId>,
|
|
@@ -40,6 +42,7 @@ function HasSaveSlotsBase.new(player: Player, serviceBag: ServiceBag.ServiceBag)
|
|
|
40
42
|
self._attributes = HasSaveSlotsData:Create(self._obj)
|
|
41
43
|
|
|
42
44
|
self.ActiveSlotId = self._attributes.ActiveSlotId
|
|
45
|
+
self.LastActiveSlotId = self._attributes.LastActiveSlotId
|
|
43
46
|
self.MaxSlotCount = self._attributes.MaxSlotCount
|
|
44
47
|
|
|
45
48
|
self.SlotChanged = self.ActiveSlotId.Changed
|
|
@@ -47,4 +50,55 @@ function HasSaveSlotsBase.new(player: Player, serviceBag: ServiceBag.ServiceBag)
|
|
|
47
50
|
return self
|
|
48
51
|
end
|
|
49
52
|
|
|
53
|
+
--[=[
|
|
54
|
+
Returns the save-slot id the player teleported in with, or nil. Realm hook: the server reads it
|
|
55
|
+
from the join data, the client from the local player's teleport data (both via
|
|
56
|
+
[TeleportDataService]). The base default returns nil so a realm that never sets one degrades to
|
|
57
|
+
"no incoming slot".
|
|
58
|
+
|
|
59
|
+
@return SaveSlotData.SlotId?
|
|
60
|
+
]=]
|
|
61
|
+
function HasSaveSlotsBase._getIncomingSlotId(_self: HasSaveSlotsBase): SaveSlotData.SlotId?
|
|
62
|
+
return nil
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
--[=[
|
|
66
|
+
Returns whether the player teleported in carrying a save-slot id that still exists for them.
|
|
67
|
+
This is the existence-validated form of "internal teleport".
|
|
68
|
+
|
|
69
|
+
@return Promise<boolean>
|
|
70
|
+
]=]
|
|
71
|
+
function HasSaveSlotsBase.PromiseHasSaveSlotFromTeleport(self: HasSaveSlotsBase): Promise.Promise<boolean>
|
|
72
|
+
local slotId = self:_getIncomingSlotId()
|
|
73
|
+
if type(slotId) ~= "string" then
|
|
74
|
+
return (Promise :: any).resolved(false)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
return (self :: any):PromiseHasSlot(slotId)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
--[=[
|
|
81
|
+
Selects the save slot the player teleported in with when it still exists, resolving to that slot
|
|
82
|
+
id -- or nil when there was no incoming slot or it no longer exists. Reuses the realm's own
|
|
83
|
+
`PromiseHasSlot`/`PromiseSelectSlot`, so it works identically on server and client.
|
|
84
|
+
|
|
85
|
+
@return Promise<SaveSlotData.SlotId?>
|
|
86
|
+
]=]
|
|
87
|
+
function HasSaveSlotsBase.PromiseLoadSaveSlotFromTeleport(self: HasSaveSlotsBase): Promise.Promise<SaveSlotData.SlotId?>
|
|
88
|
+
local slotId = self:_getIncomingSlotId()
|
|
89
|
+
if type(slotId) ~= "string" then
|
|
90
|
+
return (Promise :: any).resolved(nil)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
return (self :: any):PromiseHasSlot(slotId):Then(function(hasSlot: boolean)
|
|
94
|
+
if not hasSlot then
|
|
95
|
+
return nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
return (self :: any):PromiseSelectSlot(slotId):Then(function()
|
|
99
|
+
return slotId
|
|
100
|
+
end)
|
|
101
|
+
end)
|
|
102
|
+
end
|
|
103
|
+
|
|
50
104
|
return HasSaveSlotsBase
|
|
@@ -9,6 +9,7 @@ local TieDefinition = require("TieDefinition")
|
|
|
9
9
|
|
|
10
10
|
return TieDefinition.new("HasSaveSlots", {
|
|
11
11
|
ActiveSlotId = TieDefinition.Types.PROPERTY,
|
|
12
|
+
LastActiveSlotId = TieDefinition.Types.PROPERTY,
|
|
12
13
|
MaxSlotCount = TieDefinition.Types.PROPERTY,
|
|
13
14
|
|
|
14
15
|
PromiseHasSlot = TieDefinition.Types.METHOD,
|
|
@@ -20,10 +21,20 @@ return TieDefinition.new("HasSaveSlots", {
|
|
|
20
21
|
PromiseSlotIdFromIndex = TieDefinition.Types.METHOD,
|
|
21
22
|
PromiseLastActiveSlotId = TieDefinition.Types.METHOD,
|
|
22
23
|
|
|
24
|
+
-- Answered from the teleport data the player arrived with (see HasSaveSlotsBase); both realms
|
|
25
|
+
-- resolve the incoming slot id from their own [TeleportDataService].
|
|
26
|
+
PromiseHasSaveSlotFromTeleport = TieDefinition.Types.METHOD,
|
|
27
|
+
PromiseLoadSaveSlotFromTeleport = TieDefinition.Types.METHOD,
|
|
28
|
+
|
|
23
29
|
SlotChanged = TieDefinition.Types.SIGNAL,
|
|
24
30
|
|
|
25
31
|
[TieDefinition.Realms.SERVER] = {
|
|
26
32
|
ObserveActiveSlotStoreBrio = TieDefinition.Types.METHOD,
|
|
27
33
|
PromiseActiveSlotStore = TieDefinition.Types.METHOD,
|
|
34
|
+
PromiseSlotsLoaded = TieDefinition.Types.METHOD,
|
|
35
|
+
PromiseDeselectSlot = TieDefinition.Types.METHOD,
|
|
36
|
+
PromiseSelectLastSaveSlot = TieDefinition.Types.METHOD,
|
|
37
|
+
PromiseSelectNewSaveSlot = TieDefinition.Types.METHOD,
|
|
38
|
+
PromiseDeleteAllSlots = TieDefinition.Types.METHOD,
|
|
28
39
|
},
|
|
29
40
|
})
|
|
@@ -53,6 +53,21 @@ function SaveSlotDataService.ObserveActiveSlotId(
|
|
|
53
53
|
})
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
--[=[
|
|
57
|
+
Observes the player's last active slot ID (the slot they can continue on)
|
|
58
|
+
]=]
|
|
59
|
+
function SaveSlotDataService.ObserveLastActiveSlotId(
|
|
60
|
+
self: SaveSlotDataService,
|
|
61
|
+
player: Player
|
|
62
|
+
): Observable.Observable<SaveSlotData.SlotId?>
|
|
63
|
+
return (HasSaveSlotsInterface:ObserveBrio(player, self._realm) :: any):Pipe({
|
|
64
|
+
RxBrioUtils.switchMapBrio(function(hasSaveSlots)
|
|
65
|
+
return hasSaveSlots.LastActiveSlotId:Observe()
|
|
66
|
+
end),
|
|
67
|
+
RxBrioUtils.emitOnDeath(nil),
|
|
68
|
+
})
|
|
69
|
+
end
|
|
70
|
+
|
|
56
71
|
--[=[
|
|
57
72
|
Returns the player's active slot ID
|
|
58
73
|
]=]
|