@quenty/saveslot 1.8.0 → 1.10.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 +16 -0
- package/package.json +6 -4
- package/src/Client/Binders/HasSaveSlotsClient.lua +12 -8
- package/src/Client/SaveSlotServiceClient.lua +25 -6
- package/src/Server/Binders/HasSaveSlots.lua +342 -39
- package/src/Server/Binders/HasSaveSlots.spec.lua +784 -0
- package/src/Server/Cmdr/SaveSlotCmdrService.lua +162 -23
- package/src/Server/SaveSlotOverflow.spec.lua +128 -0
- package/src/Server/SaveSlotService.lua +50 -25
- package/src/Server/SaveSlotService.spec.lua +96 -25
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.lua +15 -0
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.spec.lua +142 -0
- package/src/Shared/Data/SaveSlotData.lua +27 -2
- package/src/Shared/Data/SaveSlotData.spec.lua +68 -0
- package/src/Shared/HasSaveSlotsBase.lua +24 -21
- package/src/Shared/SaveSlotDataService.lua +14 -0
|
@@ -90,7 +90,7 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
90
90
|
{
|
|
91
91
|
Name = "Slot",
|
|
92
92
|
Type = "slotIndex",
|
|
93
|
-
Description = "Slot index to switch to.",
|
|
93
|
+
Description = "Slot index to switch to, or . for your current slot.",
|
|
94
94
|
},
|
|
95
95
|
},
|
|
96
96
|
}, function(context, slotIndex: number)
|
|
@@ -135,26 +135,28 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
135
135
|
|
|
136
136
|
self._cmdrService:RegisterCommand({
|
|
137
137
|
Name = "create-save-slot",
|
|
138
|
-
Description = "Creates
|
|
138
|
+
Description = "Creates save slots. Defaults to the lowest free index when none is given.",
|
|
139
139
|
Group = "SaveSlots",
|
|
140
140
|
Args = {
|
|
141
141
|
{
|
|
142
|
-
Name = "
|
|
143
|
-
Type = "
|
|
144
|
-
Description = "Slot
|
|
142
|
+
Name = "Slots",
|
|
143
|
+
Type = "numbers",
|
|
144
|
+
Description = "Slot indices to create (e.g. 1,2). Omit to use the lowest free index.",
|
|
145
145
|
Optional = true,
|
|
146
146
|
},
|
|
147
147
|
},
|
|
148
|
-
}, function(context,
|
|
148
|
+
}, function(context, slotIndices: { number }?)
|
|
149
149
|
local maxSlotCount = context.Executor:GetAttribute("MaxSlotCount")
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
end
|
|
151
|
+
-- Track indices already taken so a batch fills gaps and never collides within itself.
|
|
152
|
+
local used = {}
|
|
153
|
+
for _, metadata in self._saveSlotDataService:GetSlotList(context.Executor) do
|
|
154
|
+
used[metadata.SlotIndex] = true
|
|
155
|
+
end
|
|
157
156
|
|
|
157
|
+
local toCreate = {}
|
|
158
|
+
if slotIndices == nil then
|
|
159
|
+
-- Default to the lowest free index, filling gaps left by deletions.
|
|
158
160
|
local freeIndex = 1
|
|
159
161
|
while used[freeIndex] do
|
|
160
162
|
freeIndex += 1
|
|
@@ -164,24 +166,39 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
164
166
|
return "All slots are already in use."
|
|
165
167
|
end
|
|
166
168
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
169
|
+
table.insert(toCreate, freeIndex)
|
|
170
|
+
else
|
|
171
|
+
-- Validate the whole batch up front so nothing is created when any index is bad.
|
|
172
|
+
local seen = {}
|
|
173
|
+
for _, slotIndex in slotIndices do
|
|
174
|
+
if (slotIndex < 1) or (slotIndex > maxSlotCount) then
|
|
175
|
+
return `Index must be in range [1, {maxSlotCount}].`
|
|
176
|
+
end
|
|
177
|
+
if used[slotIndex] then
|
|
178
|
+
return `Slot {slotIndex} already exists.`
|
|
179
|
+
end
|
|
180
|
+
if not seen[slotIndex] then
|
|
181
|
+
seen[slotIndex] = true
|
|
182
|
+
table.insert(toCreate, slotIndex)
|
|
183
|
+
end
|
|
184
|
+
end
|
|
175
185
|
end
|
|
176
186
|
|
|
177
187
|
self._maid
|
|
178
188
|
:GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
|
|
179
189
|
:Then(function(hasSaveSlots)
|
|
180
|
-
|
|
190
|
+
-- Create sequentially to avoid concurrent datastore saves.
|
|
191
|
+
local promise = Promise.resolved()
|
|
192
|
+
for _, slotIndex in toCreate do
|
|
193
|
+
promise = promise:Then(function()
|
|
194
|
+
return hasSaveSlots:PromiseCreateSlot(slotIndex)
|
|
195
|
+
end)
|
|
196
|
+
end
|
|
197
|
+
return promise
|
|
181
198
|
end)
|
|
182
199
|
:Wait()
|
|
183
200
|
|
|
184
|
-
return `Created slot {
|
|
201
|
+
return `Created slot(s) {table.concat(toCreate, ", ")}.`
|
|
185
202
|
end)
|
|
186
203
|
|
|
187
204
|
self._cmdrService:RegisterCommand({
|
|
@@ -192,7 +209,7 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
192
209
|
{
|
|
193
210
|
Name = "Slots",
|
|
194
211
|
Type = "slotIndices",
|
|
195
|
-
Description = "Slot indices to delete (e.g. 1,2 or * for all).",
|
|
212
|
+
Description = "Slot indices to delete (e.g. 1,2, . for your current slot, or * for all).",
|
|
196
213
|
},
|
|
197
214
|
},
|
|
198
215
|
}, function(context, slotIndices: { number })
|
|
@@ -241,6 +258,128 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
241
258
|
|
|
242
259
|
return `Deleted slot(s) {table.concat(deletedIndices, ", ")}.`
|
|
243
260
|
end)
|
|
261
|
+
|
|
262
|
+
self._cmdrService:RegisterCommand({
|
|
263
|
+
Name = "duplicate-save-slot",
|
|
264
|
+
Description = "Duplicates save slots into new slots at the lowest free indices.",
|
|
265
|
+
Group = "SaveSlots",
|
|
266
|
+
Args = {
|
|
267
|
+
{
|
|
268
|
+
Name = "Slots",
|
|
269
|
+
Type = "slotIndices",
|
|
270
|
+
Description = "Slot indices to duplicate (e.g. 1,2, . for your current slot, or * for all).",
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
}, function(context, slotIndices: { number })
|
|
274
|
+
-- Resolve indices to ids up front; `*`/`.` can include duplicates.
|
|
275
|
+
local seen = {}
|
|
276
|
+
local toDuplicate = {}
|
|
277
|
+
for _, slotIndex in slotIndices do
|
|
278
|
+
local slotId = self._saveSlotDataService:GetSlotIdFromIndex(context.Executor, slotIndex)
|
|
279
|
+
if slotId and not seen[slotId] then
|
|
280
|
+
seen[slotId] = true
|
|
281
|
+
table.insert(toDuplicate, { slotIndex = slotIndex, slotId = slotId })
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
if #toDuplicate == 0 then
|
|
286
|
+
return "No matching slots to duplicate."
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
local lines = self._maid
|
|
290
|
+
:GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
|
|
291
|
+
:Then(function(hasSaveSlots)
|
|
292
|
+
-- Duplicate sequentially: each copy consumes a free index the next one must see. Report
|
|
293
|
+
-- per-slot so a mid-batch failure (e.g. the roster filling up) still surfaces the successes.
|
|
294
|
+
local promise = Promise.resolved()
|
|
295
|
+
local results = {}
|
|
296
|
+
for _, entry in toDuplicate do
|
|
297
|
+
promise = promise:Then(function()
|
|
298
|
+
return hasSaveSlots
|
|
299
|
+
:PromiseDuplicateSlot(entry.slotId)
|
|
300
|
+
:Then(function(newSlotId)
|
|
301
|
+
local newMetadata =
|
|
302
|
+
self._saveSlotDataService:GetSlotMetadata(context.Executor, newSlotId)
|
|
303
|
+
table.insert(
|
|
304
|
+
results,
|
|
305
|
+
`slot {entry.slotIndex} → slot {newMetadata.SlotIndex} ("{newMetadata.SlotName}")`
|
|
306
|
+
)
|
|
307
|
+
end)
|
|
308
|
+
:Catch(function(err)
|
|
309
|
+
table.insert(results, `slot {entry.slotIndex}: {tostring(err)}`)
|
|
310
|
+
end)
|
|
311
|
+
end)
|
|
312
|
+
end
|
|
313
|
+
return promise:Then(function()
|
|
314
|
+
return results
|
|
315
|
+
end)
|
|
316
|
+
end)
|
|
317
|
+
:Wait()
|
|
318
|
+
|
|
319
|
+
return `Duplicated:\n{table.concat(lines, "\n")}`
|
|
320
|
+
end)
|
|
321
|
+
|
|
322
|
+
self._cmdrService:RegisterCommand({
|
|
323
|
+
Name = "reset-save-slot",
|
|
324
|
+
Description = "Resets save slots to fresh empty ones, keeping their index and name.",
|
|
325
|
+
Group = "SaveSlots",
|
|
326
|
+
Args = {
|
|
327
|
+
{
|
|
328
|
+
Name = "Slots",
|
|
329
|
+
Type = "slotIndices",
|
|
330
|
+
Description = "Slot indices to reset (e.g. 1,2, . for your current slot, or * for all). Omit to reset the active slot.",
|
|
331
|
+
Optional = true,
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
}, function(context, slotIndices: { number }?)
|
|
335
|
+
local toReset = {}
|
|
336
|
+
if slotIndices == nil then
|
|
337
|
+
-- No indices given: reset the active slot.
|
|
338
|
+
local activeSlotId = self._saveSlotDataService:GetActiveSlotId(context.Executor)
|
|
339
|
+
if not activeSlotId then
|
|
340
|
+
return "No active slot."
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
local metadata = self._saveSlotDataService:GetSlotMetadata(context.Executor, activeSlotId)
|
|
344
|
+
table.insert(toReset, { slotIndex = metadata.SlotIndex, slotId = activeSlotId })
|
|
345
|
+
else
|
|
346
|
+
-- Resolve indices to ids up front; `*`/`.` can include duplicates.
|
|
347
|
+
local seen = {}
|
|
348
|
+
for _, slotIndex in slotIndices do
|
|
349
|
+
local slotId = self._saveSlotDataService:GetSlotIdFromIndex(context.Executor, slotIndex)
|
|
350
|
+
if slotId and not seen[slotId] then
|
|
351
|
+
seen[slotId] = true
|
|
352
|
+
table.insert(toReset, { slotIndex = slotIndex, slotId = slotId })
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
if #toReset == 0 then
|
|
357
|
+
return "No matching slots to reset."
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
local resetIndices = self._maid
|
|
362
|
+
:GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
|
|
363
|
+
:Then(function(hasSaveSlots)
|
|
364
|
+
-- Reset sequentially to avoid concurrent datastore saves.
|
|
365
|
+
local promise = Promise.resolved()
|
|
366
|
+
local done = {}
|
|
367
|
+
for _, entry in toReset do
|
|
368
|
+
promise = promise:Then(function()
|
|
369
|
+
return hasSaveSlots:PromiseResetSlot(entry.slotId):Then(function()
|
|
370
|
+
table.insert(done, entry.slotIndex)
|
|
371
|
+
end)
|
|
372
|
+
end)
|
|
373
|
+
end
|
|
374
|
+
return promise:Then(function()
|
|
375
|
+
return done
|
|
376
|
+
end)
|
|
377
|
+
end)
|
|
378
|
+
:Wait()
|
|
379
|
+
|
|
380
|
+
table.sort(resetIndices)
|
|
381
|
+
return `Reset slot(s) {table.concat(resetIndices, ", ")}.`
|
|
382
|
+
end)
|
|
244
383
|
end
|
|
245
384
|
|
|
246
385
|
function SaveSlotCmdrService.Destroy(self: SaveSlotCmdrService): ()
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
--!nonstrict
|
|
2
|
+
--[[
|
|
3
|
+
Characterizes how the save-slot system handles the overflow-save failure: when a slot accumulates
|
|
4
|
+
more data than Roblox can serialize under its per-key size ceiling, the save must fail loudly
|
|
5
|
+
instead of silently dropping data or corrupting the slot that was already stored. Driven through the
|
|
6
|
+
same mock-injected PlayerDataStoreService and SaveSlotConstants substore layout the load flow uses
|
|
7
|
+
(see SaveSlotLoadFlow.spec), with the DataStoreMock configured to a small
|
|
8
|
+
[DataStoreMock.SetMaxValueLength] so the overflow triggers without a multi-megabyte payload.
|
|
9
|
+
|
|
10
|
+
@class SaveSlotOverflow.spec.lua
|
|
11
|
+
]]
|
|
12
|
+
local require = require(script.Parent.loader).load(script)
|
|
13
|
+
|
|
14
|
+
local DataStoreMock = require("DataStoreMock")
|
|
15
|
+
local Jest = require("Jest")
|
|
16
|
+
local Maid = require("Maid")
|
|
17
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
18
|
+
local SaveSlotConstants = require("SaveSlotConstants")
|
|
19
|
+
local ServiceBag = require("ServiceBag")
|
|
20
|
+
|
|
21
|
+
local describe = Jest.Globals.describe
|
|
22
|
+
local expect = Jest.Globals.expect
|
|
23
|
+
local it = Jest.Globals.it
|
|
24
|
+
|
|
25
|
+
-- Builds a ServiceBag with a mock-injected PlayerDataStoreService, owned by a Maid so destroy() tears
|
|
26
|
+
-- down the service (and the session-locked stores its manager owns). Read controller.mock to seed,
|
|
27
|
+
-- fail, or size-limit the datastore.
|
|
28
|
+
local function setup(mock)
|
|
29
|
+
local maid = Maid.new()
|
|
30
|
+
mock = mock or DataStoreMock.new()
|
|
31
|
+
|
|
32
|
+
local serviceBag = maid:Add(ServiceBag.new())
|
|
33
|
+
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
34
|
+
serviceBag:Init()
|
|
35
|
+
playerDataStoreService:SetRobloxDataStore(mock)
|
|
36
|
+
serviceBag:Start()
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
playerDataStoreService = playerDataStoreService,
|
|
40
|
+
mock = mock,
|
|
41
|
+
destroy = function()
|
|
42
|
+
maid:DoCleaning()
|
|
43
|
+
end,
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
-- Resolves the session-locked datastore for a userId (bounded); returns nil on failure to settle.
|
|
48
|
+
local function resolveDataStore(playerDataStoreService, userId)
|
|
49
|
+
local promise = playerDataStoreService:PromiseDataStore(userId)
|
|
50
|
+
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
51
|
+
return nil
|
|
52
|
+
end
|
|
53
|
+
local ok, dataStore = promise:Yield()
|
|
54
|
+
if not ok then
|
|
55
|
+
return nil
|
|
56
|
+
end
|
|
57
|
+
return dataStore
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
-- Slot stores live at SaveSlots.slots.<slotId>, matching HasSaveSlots._getSlotStore.
|
|
61
|
+
local function getSlotStore(dataStore, slotId)
|
|
62
|
+
return dataStore
|
|
63
|
+
:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
64
|
+
:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY)
|
|
65
|
+
:GetSubStore(slotId)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe("save slot overflow save", function()
|
|
69
|
+
it("fails the save when a slot grows past the datastore size limit", function()
|
|
70
|
+
local controller = setup()
|
|
71
|
+
|
|
72
|
+
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
73
|
+
expect(dataStore).never.toBeNil()
|
|
74
|
+
|
|
75
|
+
local slotStore = getSlotStore(dataStore, "slot-abc")
|
|
76
|
+
|
|
77
|
+
-- A first, well-sized save acquires the session lock and writes the slot.
|
|
78
|
+
slotStore:Store("coins", 25)
|
|
79
|
+
local firstSave = dataStore:Save()
|
|
80
|
+
expect(PromiseTestUtils.awaitSettled(firstSave, 10)).toEqual(true)
|
|
81
|
+
expect((firstSave:Yield())).toEqual(true)
|
|
82
|
+
|
|
83
|
+
-- Now overflow the slot with more data than the key can serialize.
|
|
84
|
+
controller.mock:SetMaxValueLength(8192)
|
|
85
|
+
slotStore:Store("blob", string.rep("A", 32768))
|
|
86
|
+
|
|
87
|
+
local savePromise = dataStore:Save()
|
|
88
|
+
expect(PromiseTestUtils.awaitSettled(savePromise, 10)).toEqual(true)
|
|
89
|
+
expect((savePromise:Yield())).toEqual(false)
|
|
90
|
+
|
|
91
|
+
-- Lift the limit before teardown so the session lock's final unlock-save can flush and release
|
|
92
|
+
-- cleanly, rather than throwing during cleanup and leaking a retry into a later spec (these all
|
|
93
|
+
-- share one test place).
|
|
94
|
+
controller.mock:SetMaxValueLength(nil)
|
|
95
|
+
controller:destroy()
|
|
96
|
+
end)
|
|
97
|
+
|
|
98
|
+
it("preserves the already-saved slot data when an oversized save fails", function()
|
|
99
|
+
local controller = setup()
|
|
100
|
+
|
|
101
|
+
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
102
|
+
expect(dataStore).never.toBeNil()
|
|
103
|
+
|
|
104
|
+
local slotStore = getSlotStore(dataStore, "slot-abc")
|
|
105
|
+
|
|
106
|
+
slotStore:Store("coins", 25)
|
|
107
|
+
local firstSave = dataStore:Save()
|
|
108
|
+
expect(PromiseTestUtils.awaitSettled(firstSave, 10)).toEqual(true)
|
|
109
|
+
expect((firstSave:Yield())).toEqual(true)
|
|
110
|
+
|
|
111
|
+
controller.mock:SetMaxValueLength(8192)
|
|
112
|
+
slotStore:Store("blob", string.rep("A", 32768))
|
|
113
|
+
|
|
114
|
+
local savePromise = dataStore:Save()
|
|
115
|
+
expect(PromiseTestUtils.awaitSettled(savePromise, 10)).toEqual(true)
|
|
116
|
+
expect((savePromise:Yield())).toEqual(false)
|
|
117
|
+
|
|
118
|
+
-- The rejected write must not have corrupted the coins we already stored.
|
|
119
|
+
controller.mock:SetMaxValueLength(nil)
|
|
120
|
+
local loadPromise = slotStore:Load("coins")
|
|
121
|
+
expect(PromiseTestUtils.awaitSettled(loadPromise, 10)).toEqual(true)
|
|
122
|
+
local ok, value = loadPromise:Yield()
|
|
123
|
+
expect(ok).toEqual(true)
|
|
124
|
+
expect(value).toEqual(25)
|
|
125
|
+
|
|
126
|
+
controller:destroy()
|
|
127
|
+
end)
|
|
128
|
+
end)
|
|
@@ -13,6 +13,7 @@ local HasSaveSlots = require("HasSaveSlots")
|
|
|
13
13
|
local HasSaveSlotsData = require("HasSaveSlotsData")
|
|
14
14
|
local Maid = require("Maid")
|
|
15
15
|
local Observable = require("Observable")
|
|
16
|
+
local ObservableMap = require("ObservableMap")
|
|
16
17
|
local Promise = require("Promise")
|
|
17
18
|
local Remoting = require("Remoting")
|
|
18
19
|
local RxBrioUtils = require("RxBrioUtils")
|
|
@@ -31,7 +32,7 @@ export type SaveSlotService = typeof(setmetatable(
|
|
|
31
32
|
_hasSaveSlotsBinder: any,
|
|
32
33
|
_selectionRequired: boolean,
|
|
33
34
|
_maxSlotCount: number,
|
|
34
|
-
|
|
35
|
+
_defaultSummaryProviders: ObservableMap.ObservableMap<string, HasSaveSlots.SummaryProvider>,
|
|
35
36
|
_remoting: any,
|
|
36
37
|
_teleportDataService: any,
|
|
37
38
|
},
|
|
@@ -56,6 +57,7 @@ function SaveSlotService.Init(self: SaveSlotService, serviceBag: ServiceBag.Serv
|
|
|
56
57
|
|
|
57
58
|
self._selectionRequired = false
|
|
58
59
|
self._maxSlotCount = 1
|
|
60
|
+
self._defaultSummaryProviders = self._maid:Add(ObservableMap.new())
|
|
59
61
|
|
|
60
62
|
self._remoting = self._maid:Add(Remoting.Server.new(ReplicatedStorage, "SaveSlotService"))
|
|
61
63
|
|
|
@@ -65,16 +67,12 @@ function SaveSlotService.Init(self: SaveSlotService, serviceBag: ServiceBag.Serv
|
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
function SaveSlotService.Start(self: SaveSlotService)
|
|
68
|
-
-- Every teleport built through TeleportDataService
|
|
69
|
-
--
|
|
70
|
-
--
|
|
70
|
+
-- Every teleport built through TeleportDataService carries each player's own active slot id, so
|
|
71
|
+
-- cross-place teleports resume on the same slot without each teleport site re-attaching it by hand
|
|
72
|
+
-- (and a group teleport carries every member's slot, not just a single player's).
|
|
71
73
|
self._maid:GiveTask(
|
|
72
|
-
self._teleportDataService:
|
|
73
|
-
|
|
74
|
-
return nil
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
local slotId = HasSaveSlotsData.ActiveSlotId:Get(players[1])
|
|
74
|
+
self._teleportDataService:RegisterPerPlayerTeleportDataProvider(function(player: Player): { [string]: any }?
|
|
75
|
+
local slotId = HasSaveSlotsData.ActiveSlotId:Get(player)
|
|
78
76
|
if type(slotId) == "string" then
|
|
79
77
|
return { [SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = slotId }
|
|
80
78
|
end
|
|
@@ -91,9 +89,17 @@ function SaveSlotService.Start(self: SaveSlotService)
|
|
|
91
89
|
|
|
92
90
|
-- Pass consumer-specified configs
|
|
93
91
|
hasSaveSlots.MaxSlotCount.Value = self._maxSlotCount
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
|
|
93
|
+
-- Mirror every default summary provider onto this player, and keep it in sync: a provider
|
|
94
|
+
-- registered or unregistered later is added to or removed from every bound player reactively.
|
|
95
|
+
maid:GiveTask(self._defaultSummaryProviders:ObservePairsBrio():Subscribe(function(pairBrio)
|
|
96
|
+
if pairBrio:IsDead() then
|
|
97
|
+
return
|
|
98
|
+
end
|
|
99
|
+
local pairMaid = pairBrio:ToMaid()
|
|
100
|
+
local name, provider = pairBrio:GetValue()
|
|
101
|
+
pairMaid:GiveTask(hasSaveSlots:RegisterSummaryProvider(name, provider))
|
|
102
|
+
end))
|
|
97
103
|
|
|
98
104
|
-- Select the slot the player teleported in with, or proceed with the default flow
|
|
99
105
|
maid:GivePromise(hasSaveSlots:PromiseSlotsLoaded()):Then(function()
|
|
@@ -155,16 +161,16 @@ function SaveSlotService.GetExplicitSelectionRequired(self: SaveSlotService): bo
|
|
|
155
161
|
end
|
|
156
162
|
|
|
157
163
|
--[=[
|
|
158
|
-
|
|
159
|
-
slot teleport rather than a fresh join.
|
|
160
|
-
|
|
161
|
-
|
|
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.
|
|
162
168
|
|
|
163
169
|
@param player Player
|
|
164
|
-
@return boolean
|
|
170
|
+
@return Promise<boolean>
|
|
165
171
|
]=]
|
|
166
|
-
function SaveSlotService.
|
|
167
|
-
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)
|
|
168
174
|
end
|
|
169
175
|
|
|
170
176
|
--[=[
|
|
@@ -186,14 +192,24 @@ function SaveSlotService.SetUnlimitedSlots(self: SaveSlotService): ()
|
|
|
186
192
|
end
|
|
187
193
|
|
|
188
194
|
--[=[
|
|
189
|
-
|
|
195
|
+
Registers a named default summary provider, applied to every player's save slots. Each provider's
|
|
196
|
+
current value is aggregated into the active slot's Summary, keyed by `name`. Registering or
|
|
197
|
+
unregistering reflects on all bound players. Returns a function that unregisters the provider (also
|
|
198
|
+
give it to a [Maid]).
|
|
199
|
+
|
|
200
|
+
@param name string
|
|
201
|
+
@param provider HasSaveSlots.SummaryProvider
|
|
202
|
+
@return () -> ()
|
|
190
203
|
]=]
|
|
191
|
-
function SaveSlotService.
|
|
204
|
+
function SaveSlotService.RegisterDefaultSummaryProvider(
|
|
192
205
|
self: SaveSlotService,
|
|
193
|
-
|
|
194
|
-
|
|
206
|
+
name: string,
|
|
207
|
+
provider: HasSaveSlots.SummaryProvider
|
|
208
|
+
): () -> ()
|
|
209
|
+
assert(type(name) == "string", "Bad name")
|
|
195
210
|
assert(type(provider) == "function", "Bad provider")
|
|
196
|
-
|
|
211
|
+
|
|
212
|
+
return self._defaultSummaryProviders:Set(name, provider :: any)
|
|
197
213
|
end
|
|
198
214
|
|
|
199
215
|
--[=[
|
|
@@ -275,6 +291,15 @@ function SaveSlotService.PromiseDeleteSlot(
|
|
|
275
291
|
end)
|
|
276
292
|
end
|
|
277
293
|
|
|
294
|
+
--[=[
|
|
295
|
+
Resets the player's active slot to a fresh empty one
|
|
296
|
+
]=]
|
|
297
|
+
function SaveSlotService.PromiseResetActiveSlot(self: SaveSlotService, player: Player): Promise.Promise<any>
|
|
298
|
+
return self._hasSaveSlotsBinder:Promise(player):Then(function(hasSaveSlots)
|
|
299
|
+
return hasSaveSlots:PromiseResetActiveSlot()
|
|
300
|
+
end)
|
|
301
|
+
end
|
|
302
|
+
|
|
278
303
|
--[=[
|
|
279
304
|
Destroys the service
|
|
280
305
|
]=]
|