@quenty/saveslot 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.2.3...@quenty/saveslot@2.3.0) (2026-07-27)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **saveslot:** save slot commands take a players argument ([#756](https://github.com/Quenty/NevermoreEngine/issues/756)) ([724b9b4](https://github.com/Quenty/NevermoreEngine/commit/724b9b40e4acdb4700d841e514e578332c60e155))
|
|
11
|
+
|
|
12
|
+
## [2.2.3](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.2.2...@quenty/saveslot@2.2.3) (2026-07-27)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @quenty/saveslot
|
|
15
|
+
|
|
6
16
|
## [2.2.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.2.1...@quenty/saveslot@2.2.2) (2026-07-26)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @quenty/saveslot
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/saveslot",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "PlayerDataStoreService wrapper for save slots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -33,23 +33,23 @@
|
|
|
33
33
|
"@quenty/baseobject": "10.15.0",
|
|
34
34
|
"@quenty/binder": "14.43.1",
|
|
35
35
|
"@quenty/brio": "14.35.1",
|
|
36
|
-
"@quenty/cmdrservice": "13.55.
|
|
37
|
-
"@quenty/datastore": "13.50.
|
|
36
|
+
"@quenty/cmdrservice": "13.55.2",
|
|
37
|
+
"@quenty/datastore": "13.50.2",
|
|
38
38
|
"@quenty/instanceutils": "13.35.1",
|
|
39
39
|
"@quenty/loader": "10.11.0",
|
|
40
40
|
"@quenty/maid": "3.11.0",
|
|
41
41
|
"@quenty/nevermore-test-runner": "1.5.0",
|
|
42
|
-
"@quenty/observablecollection": "12.46.
|
|
43
|
-
"@quenty/playerbinder": "14.45.
|
|
44
|
-
"@quenty/playermock": "1.5.
|
|
42
|
+
"@quenty/observablecollection": "12.46.2",
|
|
43
|
+
"@quenty/playerbinder": "14.45.2",
|
|
44
|
+
"@quenty/playermock": "1.5.2",
|
|
45
45
|
"@quenty/promise": "10.23.0",
|
|
46
46
|
"@quenty/propertyvalue": "7.35.1",
|
|
47
|
-
"@quenty/remoting": "12.40.
|
|
47
|
+
"@quenty/remoting": "12.40.2",
|
|
48
48
|
"@quenty/rx": "13.33.0",
|
|
49
49
|
"@quenty/servicebag": "11.20.0",
|
|
50
50
|
"@quenty/signal": "7.13.1",
|
|
51
51
|
"@quenty/table": "3.9.2",
|
|
52
|
-
"@quenty/teleportserviceutils": "10.2.
|
|
52
|
+
"@quenty/teleportserviceutils": "10.2.3",
|
|
53
53
|
"@quenty/tie": "10.46.1",
|
|
54
54
|
"@quenty/valueobject": "13.36.1",
|
|
55
55
|
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "da2c11ce06d21a5e9b4f92c69fb82beb821d89ea"
|
|
61
61
|
}
|
|
@@ -158,6 +158,39 @@ describe("HasSaveSlots.PromiseExportSlot / PromiseImportSlot", function()
|
|
|
158
158
|
end)
|
|
159
159
|
end)
|
|
160
160
|
|
|
161
|
+
it("exports the main slot when allowMainSlot is set", function()
|
|
162
|
+
runWithContext(function(context)
|
|
163
|
+
local hasSaveSlots = context.hasSaveSlots
|
|
164
|
+
|
|
165
|
+
local mainSlotId = createSelectAndWrite(hasSaveSlots, SaveSlotConstants.DEFAULT_SLOT_INDEX)
|
|
166
|
+
|
|
167
|
+
local export = awaitValueOf(hasSaveSlots:PromiseExportSlot(mainSlotId, true))
|
|
168
|
+
expect(export.data.Coins).toEqual(7)
|
|
169
|
+
expect(export.data.World_2.Eggs).toEqual(3)
|
|
170
|
+
end)
|
|
171
|
+
end)
|
|
172
|
+
|
|
173
|
+
it("strips the SaveSlots system data from a main slot export", function()
|
|
174
|
+
runWithContext(function(context)
|
|
175
|
+
local hasSaveSlots = context.hasSaveSlots
|
|
176
|
+
|
|
177
|
+
local mainSlotId = createSelectAndWrite(hasSaveSlots, SaveSlotConstants.DEFAULT_SLOT_INDEX)
|
|
178
|
+
createSelectAndWrite(hasSaveSlots, 2)
|
|
179
|
+
|
|
180
|
+
local export = awaitValueOf(hasSaveSlots:PromiseExportSlot(mainSlotId, true))
|
|
181
|
+
expect(export.data[SaveSlotConstants.SYSTEM_STORE_KEY]).toBeNil()
|
|
182
|
+
end)
|
|
183
|
+
end)
|
|
184
|
+
|
|
185
|
+
it("still refuses the main slot when allowMainSlot is false", function()
|
|
186
|
+
runWithContext(function(context)
|
|
187
|
+
local hasSaveSlots = context.hasSaveSlots
|
|
188
|
+
|
|
189
|
+
local mainSlotId = awaitValueOf(hasSaveSlots:PromiseCreateSlot(SaveSlotConstants.DEFAULT_SLOT_INDEX))
|
|
190
|
+
expect(awaitResolved(hasSaveSlots:PromiseExportSlot(mainSlotId, false))).toEqual(false)
|
|
191
|
+
end)
|
|
192
|
+
end)
|
|
193
|
+
|
|
161
194
|
it("refuses to export a missing slot", function()
|
|
162
195
|
runWithContext(function(context)
|
|
163
196
|
local hasSaveSlots = context.hasSaveSlots
|
|
@@ -273,16 +273,24 @@ end
|
|
|
273
273
|
|
|
274
274
|
--[=[
|
|
275
275
|
Exports a slot's saved data into a plain, serializable [SaveSlotExportUtils.SaveSlotExport].
|
|
276
|
-
Rejects the main/default slot: its store is the player's shared root datastore, so
|
|
277
|
-
would leak the SaveSlots system data and universe-scoped global data living
|
|
278
|
-
isolated non-main slot substores are exportable.
|
|
276
|
+
Rejects the main/default slot by default: its store is the player's shared root datastore, so
|
|
277
|
+
exporting it would leak the SaveSlots system data and universe-scoped global data living
|
|
278
|
+
alongside it. Only isolated non-main slot substores are exportable.
|
|
279
|
+
|
|
280
|
+
`allowMainSlot` opts out of that refusal for trusted admin tooling (see [SaveSlotCmdrService]).
|
|
281
|
+
The SaveSlots system data is always stripped from the result, so the export never carries the
|
|
282
|
+
slot roster or the other slots' saved data. Universe-scoped global data sharing the root store
|
|
283
|
+
is indistinguishable from the main slot's own data and is still carried, which is why this is
|
|
284
|
+
not exposed through [SaveSlotService].
|
|
279
285
|
|
|
280
286
|
@param slotId SlotId
|
|
287
|
+
@param allowMainSlot boolean? -- defaults to false
|
|
281
288
|
@return Promise<SaveSlotExportUtils.SaveSlotExport>
|
|
282
289
|
]=]
|
|
283
290
|
function HasSaveSlots.PromiseExportSlot(
|
|
284
291
|
self: HasSaveSlots,
|
|
285
|
-
slotId: SaveSlotData.SlotId
|
|
292
|
+
slotId: SaveSlotData.SlotId,
|
|
293
|
+
allowMainSlot: boolean?
|
|
286
294
|
): Promise.Promise<SaveSlotExportUtils.SaveSlotExport>
|
|
287
295
|
return (self._loadPromise :: any):Then(function()
|
|
288
296
|
local slot = self._slotMap[slotId]
|
|
@@ -290,13 +298,23 @@ function HasSaveSlots.PromiseExportSlot(
|
|
|
290
298
|
return (Promise :: any).rejected(`Slot \{{slotId}\} not found`)
|
|
291
299
|
end
|
|
292
300
|
|
|
293
|
-
|
|
301
|
+
local isMainSlot = SaveSlotExportUtils.isMainSlotIndex(SaveSlotData.SlotIndex:Get(slot))
|
|
302
|
+
if isMainSlot and not allowMainSlot then
|
|
294
303
|
return (Promise :: any).rejected("Cannot export the main slot")
|
|
295
304
|
end
|
|
296
305
|
|
|
297
306
|
local metadata = SaveSlotData:Get(slot)
|
|
298
307
|
return self:_getSlotStore(slotId):LoadAll({}):Then(function(sourceData)
|
|
299
308
|
local data = if type(sourceData) == "table" then table.clone(sourceData) else {}
|
|
309
|
+
|
|
310
|
+
if isMainSlot then
|
|
311
|
+
-- The main slot's store is the player's shared root, so LoadAll pulls the SaveSlots system
|
|
312
|
+
-- data with it -- the slot roster and every non-main slot's saved data. Drop it so the
|
|
313
|
+
-- export is only this slot, and so importing it can't nest a whole roster inside a slot
|
|
314
|
+
-- (mirrors PromiseDuplicateSlot, which strips the same key for the same reason).
|
|
315
|
+
data[SaveSlotConstants.SYSTEM_STORE_KEY] = nil
|
|
316
|
+
end
|
|
317
|
+
|
|
300
318
|
return SaveSlotExportUtils.create(data, metadata.SlotName, metadata.Summary)
|
|
301
319
|
end)
|
|
302
320
|
end)
|
|
@@ -358,14 +376,16 @@ end
|
|
|
358
376
|
|
|
359
377
|
@param slotId SlotId
|
|
360
378
|
@param key string
|
|
379
|
+
@param allowMainSlot boolean? -- defaults to false, see [HasSaveSlots.PromiseExportSlot]
|
|
361
380
|
@return Promise<boolean>
|
|
362
381
|
]=]
|
|
363
382
|
function HasSaveSlots.PromiseSaveSlotToSharedDataStore(
|
|
364
383
|
self: HasSaveSlots,
|
|
365
384
|
slotId: SaveSlotData.SlotId,
|
|
366
|
-
key: string
|
|
385
|
+
key: string,
|
|
386
|
+
allowMainSlot: boolean?
|
|
367
387
|
): Promise.Promise<boolean>
|
|
368
|
-
return self:PromiseExportSlot(slotId):Then(function(export)
|
|
388
|
+
return self:PromiseExportSlot(slotId, allowMainSlot):Then(function(export)
|
|
369
389
|
return self._sharedSaveSlotDataStoreService:PromiseWrite(key, export)
|
|
370
390
|
end)
|
|
371
391
|
end
|
|
@@ -523,15 +543,18 @@ end
|
|
|
523
543
|
--[=[
|
|
524
544
|
Exports a slot to the shared store under a fresh generated code and resolves to that code. The code
|
|
525
545
|
is a shareable handle other sessions load with [HasSaveSlots.PromiseImportEphemeralSaveSlotFromCode].
|
|
526
|
-
Defaults to the active slot. Refuses the main slot
|
|
527
|
-
format comes from the configured generator (see
|
|
546
|
+
Defaults to the active slot. Refuses the main slot unless `allowMainSlot` is set (see
|
|
547
|
+
[HasSaveSlots.PromiseExportSlot]). The code format comes from the configured generator (see
|
|
548
|
+
[HasSaveSlots.SetCodeGenerator]).
|
|
528
549
|
|
|
529
550
|
@param slotId SlotId? -- defaults to the active slot
|
|
551
|
+
@param allowMainSlot boolean? -- defaults to false, see [HasSaveSlots.PromiseExportSlot]
|
|
530
552
|
@return Promise<string>
|
|
531
553
|
]=]
|
|
532
554
|
function HasSaveSlots.PromiseExportSaveSlotToCode(
|
|
533
555
|
self: HasSaveSlots,
|
|
534
|
-
slotId: SaveSlotData.SlotId
|
|
556
|
+
slotId: SaveSlotData.SlotId?,
|
|
557
|
+
allowMainSlot: boolean?
|
|
535
558
|
): Promise.Promise<string>
|
|
536
559
|
return (self._loadPromise :: any):Then(function()
|
|
537
560
|
local targetSlotId = slotId or self.ActiveSlotId.Value
|
|
@@ -540,7 +563,7 @@ function HasSaveSlots.PromiseExportSaveSlotToCode(
|
|
|
540
563
|
end
|
|
541
564
|
|
|
542
565
|
local code = self:_generateCode(targetSlotId)
|
|
543
|
-
return self:PromiseSaveSlotToSharedDataStore(targetSlotId, code):Then(function()
|
|
566
|
+
return self:PromiseSaveSlotToSharedDataStore(targetSlotId, code, allowMainSlot):Then(function()
|
|
544
567
|
return code
|
|
545
568
|
end)
|
|
546
569
|
end)
|
|
@@ -562,14 +585,17 @@ end
|
|
|
562
585
|
|
|
563
586
|
--[=[
|
|
564
587
|
Exports a slot as a raw JSON string (no shared store), for direct inspection or attaching to a bug
|
|
565
|
-
report. Defaults to the active slot. Refuses the main slot (see
|
|
588
|
+
report. Defaults to the active slot. Refuses the main slot unless `allowMainSlot` is set (see
|
|
589
|
+
[HasSaveSlots.PromiseExportSlot]).
|
|
566
590
|
|
|
567
591
|
@param slotId SlotId? -- defaults to the active slot
|
|
592
|
+
@param allowMainSlot boolean? -- defaults to false, see [HasSaveSlots.PromiseExportSlot]
|
|
568
593
|
@return Promise<string>
|
|
569
594
|
]=]
|
|
570
595
|
function HasSaveSlots.PromiseExportSaveSlotToJson(
|
|
571
596
|
self: HasSaveSlots,
|
|
572
|
-
slotId: SaveSlotData.SlotId
|
|
597
|
+
slotId: SaveSlotData.SlotId?,
|
|
598
|
+
allowMainSlot: boolean?
|
|
573
599
|
): Promise.Promise<string>
|
|
574
600
|
return (self._loadPromise :: any):Then(function()
|
|
575
601
|
local targetSlotId = slotId or self.ActiveSlotId.Value
|
|
@@ -577,7 +603,7 @@ function HasSaveSlots.PromiseExportSaveSlotToJson(
|
|
|
577
603
|
return (Promise :: any).rejected("No slot to export")
|
|
578
604
|
end
|
|
579
605
|
|
|
580
|
-
return self:PromiseExportSlot(targetSlotId):Then(function(export)
|
|
606
|
+
return self:PromiseExportSlot(targetSlotId, allowMainSlot):Then(function(export)
|
|
581
607
|
return HttpService:JSONEncode(export)
|
|
582
608
|
end)
|
|
583
609
|
end)
|
|
@@ -55,15 +55,29 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
55
55
|
Name = "list-save-slots",
|
|
56
56
|
Description = "Lists all save slots.",
|
|
57
57
|
Group = "SaveSlots",
|
|
58
|
-
Args = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
Args = {
|
|
59
|
+
{
|
|
60
|
+
Name = "Players",
|
|
61
|
+
Type = "players",
|
|
62
|
+
Description = "Players to list slots for (e.g. . for yourself, or * for everyone).",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
}, function(_context, players: { Player })
|
|
62
66
|
local listString = ""
|
|
63
67
|
|
|
64
|
-
for _,
|
|
65
|
-
local
|
|
66
|
-
|
|
68
|
+
for _, player in players do
|
|
69
|
+
local activeSlotId = self._saveSlotDataService:GetActiveSlotId(player)
|
|
70
|
+
local slotList = self._saveSlotDataService:GetSlotList(player)
|
|
71
|
+
|
|
72
|
+
listString ..= `\n{player.Name}:\n`
|
|
73
|
+
if #slotList == 0 then
|
|
74
|
+
listString ..= "No slots.\n"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
for _, slot in slotList do
|
|
78
|
+
local isActive = (slot.SlotId == activeSlotId)
|
|
79
|
+
listString ..= `\n"{slot.SlotName}" ({slot.SlotIndex}){isActive and " — Active" or ""}\n{slot.Summary}\n`
|
|
80
|
+
end
|
|
67
81
|
end
|
|
68
82
|
|
|
69
83
|
return listString
|
|
@@ -73,16 +87,27 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
73
87
|
Name = "get-active-save-slot",
|
|
74
88
|
Description = "Returns the active save slot.",
|
|
75
89
|
Group = "SaveSlots",
|
|
76
|
-
Args = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
Args = {
|
|
91
|
+
{
|
|
92
|
+
Name = "Players",
|
|
93
|
+
Type = "players",
|
|
94
|
+
Description = "Players to query (e.g. . for yourself, or * for everyone).",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
}, function(_context, players: { Player })
|
|
98
|
+
local lines = {}
|
|
99
|
+
|
|
100
|
+
for _, player in players do
|
|
101
|
+
local activeSlotId = self._saveSlotDataService:GetActiveSlotId(player)
|
|
102
|
+
if activeSlotId then
|
|
103
|
+
local slotData = self._saveSlotDataService:GetSlotMetadata(player, activeSlotId)
|
|
104
|
+
table.insert(lines, `{player.Name} is using slot {slotData.SlotIndex} ("{slotData.SlotName}").`)
|
|
105
|
+
else
|
|
106
|
+
table.insert(lines, `{player.Name} has no active slot.`)
|
|
107
|
+
end
|
|
81
108
|
end
|
|
82
109
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return `Currently using slot {slotData.SlotIndex} ("{slotData.SlotName}").`
|
|
110
|
+
return table.concat(lines, "\n")
|
|
86
111
|
end)
|
|
87
112
|
|
|
88
113
|
self._cmdrService:RegisterCommand({
|
|
@@ -90,50 +115,59 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
90
115
|
Description = "Switches to the given save slot.",
|
|
91
116
|
Group = "SaveSlots",
|
|
92
117
|
Args = {
|
|
118
|
+
{
|
|
119
|
+
Name = "Players",
|
|
120
|
+
Type = "players",
|
|
121
|
+
Description = "Players to switch (e.g. . for yourself, or * for everyone).",
|
|
122
|
+
},
|
|
93
123
|
{
|
|
94
124
|
Name = "Slot",
|
|
95
125
|
Type = "slotIndex",
|
|
96
126
|
Description = "Slot index to switch to, or . for your current slot.",
|
|
97
127
|
},
|
|
98
128
|
},
|
|
99
|
-
}, function(
|
|
100
|
-
local
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
}, function(_context, players: { Player }, slotIndex: number)
|
|
130
|
+
local lines = self:_promisePlayerLines(players, function(hasSaveSlots, player)
|
|
131
|
+
local slotId = self._saveSlotDataService:GetSlotIdFromIndex(player, slotIndex)
|
|
132
|
+
if not slotId then
|
|
133
|
+
return `{player.Name} has no slot with index {slotIndex}.`
|
|
134
|
+
end
|
|
104
135
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
136
|
+
if slotId == self._saveSlotDataService:GetActiveSlotId(player) then
|
|
137
|
+
return `{player.Name} already has slot {slotIndex} active.`
|
|
138
|
+
end
|
|
108
139
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
:Then(function(hasSaveSlots)
|
|
112
|
-
return hasSaveSlots:PromiseSelectSlot(slotId)
|
|
140
|
+
return hasSaveSlots:PromiseSelectSlot(slotId):Then(function()
|
|
141
|
+
return `{player.Name} switched to slot {slotIndex}.`
|
|
113
142
|
end)
|
|
114
|
-
|
|
143
|
+
end):Wait()
|
|
115
144
|
|
|
116
|
-
return
|
|
145
|
+
return table.concat(lines, "\n")
|
|
117
146
|
end)
|
|
118
147
|
|
|
119
148
|
self._cmdrService:RegisterCommand({
|
|
120
149
|
Name = "deselect-save-slot",
|
|
121
150
|
Description = "Clears the active save slot, returning to a no-slot state.",
|
|
122
151
|
Group = "SaveSlots",
|
|
123
|
-
Args = {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
152
|
+
Args = {
|
|
153
|
+
{
|
|
154
|
+
Name = "Players",
|
|
155
|
+
Type = "players",
|
|
156
|
+
Description = "Players to deselect (e.g. . for yourself, or * for everyone).",
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
}, function(_context, players: { Player })
|
|
160
|
+
local lines = self:_promisePlayerLines(players, function(hasSaveSlots, player)
|
|
161
|
+
if not self._saveSlotDataService:GetActiveSlotId(player) then
|
|
162
|
+
return `{player.Name} has no active slot.`
|
|
163
|
+
end
|
|
128
164
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
:Then(function(hasSaveSlots)
|
|
132
|
-
return hasSaveSlots:PromiseDeselectSlot()
|
|
165
|
+
return hasSaveSlots:PromiseDeselectSlot():Then(function()
|
|
166
|
+
return `{player.Name} deselected active slot.`
|
|
133
167
|
end)
|
|
134
|
-
|
|
168
|
+
end):Wait()
|
|
135
169
|
|
|
136
|
-
return
|
|
170
|
+
return table.concat(lines, "\n")
|
|
137
171
|
end)
|
|
138
172
|
|
|
139
173
|
self._cmdrService:RegisterCommand({
|
|
@@ -141,6 +175,11 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
141
175
|
Description = "Creates save slots. Defaults to the lowest free index when none is given.",
|
|
142
176
|
Group = "SaveSlots",
|
|
143
177
|
Args = {
|
|
178
|
+
{
|
|
179
|
+
Name = "Players",
|
|
180
|
+
Type = "players",
|
|
181
|
+
Description = "Players to create slots for (e.g. . for yourself, or * for everyone).",
|
|
182
|
+
},
|
|
144
183
|
{
|
|
145
184
|
Name = "Slots",
|
|
146
185
|
Type = "numbers",
|
|
@@ -148,60 +187,63 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
148
187
|
Optional = true,
|
|
149
188
|
},
|
|
150
189
|
},
|
|
151
|
-
}, function(
|
|
152
|
-
local
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
-- Default to the lowest free index, filling gaps left by deletions.
|
|
163
|
-
local freeIndex = 1
|
|
164
|
-
while used[freeIndex] do
|
|
165
|
-
freeIndex += 1
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
if freeIndex > maxSlotCount then
|
|
169
|
-
return "All slots are already in use."
|
|
190
|
+
}, function(_context, players: { Player }, slotIndices: { number }?)
|
|
191
|
+
local lines = self:_promisePlayerLines(players, function(hasSaveSlots, player)
|
|
192
|
+
-- The cap is per-player, so it has to come off each target rather than the executor, whose
|
|
193
|
+
-- cap may be larger. Read from the binder rather than the mirrored attribute, since that is
|
|
194
|
+
-- what PromiseCreateSlot itself validates against.
|
|
195
|
+
local maxSlotCount = hasSaveSlots.MaxSlotCount.Value
|
|
196
|
+
|
|
197
|
+
-- Track indices already taken so a batch fills gaps and never collides within itself.
|
|
198
|
+
local used = {}
|
|
199
|
+
for _, metadata in self._saveSlotDataService:GetSlotList(player) do
|
|
200
|
+
used[metadata.SlotIndex] = true
|
|
170
201
|
end
|
|
171
202
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return `Index must be in range [1, {maxSlotCount}].`
|
|
203
|
+
local toCreate = {}
|
|
204
|
+
if slotIndices == nil then
|
|
205
|
+
-- Default to the lowest free index, filling gaps left by deletions.
|
|
206
|
+
local freeIndex = 1
|
|
207
|
+
while used[freeIndex] do
|
|
208
|
+
freeIndex += 1
|
|
179
209
|
end
|
|
180
|
-
|
|
181
|
-
|
|
210
|
+
|
|
211
|
+
if freeIndex > maxSlotCount then
|
|
212
|
+
return `{player.Name}: all slots are already in use.`
|
|
182
213
|
end
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
214
|
+
|
|
215
|
+
table.insert(toCreate, freeIndex)
|
|
216
|
+
else
|
|
217
|
+
-- Validate the whole batch up front so nothing is created when any index is bad.
|
|
218
|
+
local seen = {}
|
|
219
|
+
for _, slotIndex in slotIndices do
|
|
220
|
+
if (slotIndex < 1) or (slotIndex > maxSlotCount) then
|
|
221
|
+
return `{player.Name}: index must be in range [1, {maxSlotCount}].`
|
|
222
|
+
end
|
|
223
|
+
if used[slotIndex] then
|
|
224
|
+
return `{player.Name}: slot {slotIndex} already exists.`
|
|
225
|
+
end
|
|
226
|
+
if not seen[slotIndex] then
|
|
227
|
+
seen[slotIndex] = true
|
|
228
|
+
table.insert(toCreate, slotIndex)
|
|
229
|
+
end
|
|
186
230
|
end
|
|
187
231
|
end
|
|
188
|
-
end
|
|
189
232
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return promise
|
|
233
|
+
-- Create sequentially to avoid concurrent datastore saves.
|
|
234
|
+
local promise = Promise.resolved()
|
|
235
|
+
for _, slotIndex in toCreate do
|
|
236
|
+
promise = promise:Then(function()
|
|
237
|
+
return hasSaveSlots:PromiseCreateSlot(slotIndex)
|
|
238
|
+
end)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
return promise:Then(function()
|
|
242
|
+
return `{player.Name} created slot(s) {table.concat(toCreate, ", ")}.`
|
|
201
243
|
end)
|
|
202
|
-
|
|
244
|
+
end):Wait()
|
|
203
245
|
|
|
204
|
-
return
|
|
246
|
+
return table.concat(lines, "\n")
|
|
205
247
|
end)
|
|
206
248
|
|
|
207
249
|
self._cmdrService:RegisterCommand({
|
|
@@ -209,57 +251,41 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
209
251
|
Description = "Deletes the given save slots.",
|
|
210
252
|
Group = "SaveSlots",
|
|
211
253
|
Args = {
|
|
254
|
+
{
|
|
255
|
+
Name = "Players",
|
|
256
|
+
Type = "players",
|
|
257
|
+
Description = "Players to delete slots for (e.g. . for yourself, or * for everyone).",
|
|
258
|
+
},
|
|
212
259
|
{
|
|
213
260
|
Name = "Slots",
|
|
214
261
|
Type = "slotIndices",
|
|
215
262
|
Description = "Slot indices to delete (e.g. 1,2, . for your current slot, or * for all).",
|
|
216
263
|
},
|
|
217
264
|
},
|
|
218
|
-
}, function(
|
|
219
|
-
local
|
|
220
|
-
|
|
221
|
-
-- Resolve indices to ids up front; `*` can include the active slot and duplicates.
|
|
222
|
-
local seen = {}
|
|
223
|
-
local toDelete = {}
|
|
224
|
-
for _, slotIndex in slotIndices do
|
|
225
|
-
local slotId = self._saveSlotDataService:GetSlotIdFromIndex(context.Executor, slotIndex)
|
|
226
|
-
if slotId and not seen[slotId] then
|
|
227
|
-
seen[slotId] = true
|
|
228
|
-
table.insert(toDelete, { slotIndex = slotIndex, slotId = slotId })
|
|
229
|
-
end
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
if #toDelete == 0 then
|
|
265
|
+
}, function(_context, players: { Player }, slotIndices: { number })
|
|
266
|
+
local targets = self:_resolveTargets(players, slotIndices)
|
|
267
|
+
if #targets == 0 then
|
|
233
268
|
return "No matching slots to delete."
|
|
234
269
|
end
|
|
235
270
|
|
|
236
|
-
self
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
end
|
|
253
|
-
return promise
|
|
254
|
-
end)
|
|
255
|
-
:Wait()
|
|
256
|
-
|
|
257
|
-
local deletedIndices = {}
|
|
258
|
-
for _, entry in toDelete do
|
|
259
|
-
table.insert(deletedIndices, entry.slotIndex)
|
|
260
|
-
end
|
|
271
|
+
local lines = self:_promiseSlotLines(targets, function(hasSaveSlots, entry, player)
|
|
272
|
+
-- The active slot can't be deleted while selected, so deselect it first (flushing its
|
|
273
|
+
-- progress) when reached. Read live rather than up front, since an earlier deletion in
|
|
274
|
+
-- this batch may have already deselected it.
|
|
275
|
+
local deselect = if entry.slotId == self._saveSlotDataService:GetActiveSlotId(player)
|
|
276
|
+
then hasSaveSlots:PromiseDeselectSlot()
|
|
277
|
+
else Promise.resolved()
|
|
278
|
+
|
|
279
|
+
return deselect
|
|
280
|
+
:Then(function()
|
|
281
|
+
return hasSaveSlots:PromiseDeleteSlot(entry.slotId)
|
|
282
|
+
end)
|
|
283
|
+
:Then(function()
|
|
284
|
+
return `{player.Name} deleted slot {entry.slotIndex}.`
|
|
285
|
+
end)
|
|
286
|
+
end):Wait()
|
|
261
287
|
|
|
262
|
-
return `Deleted
|
|
288
|
+
return `Deleted:\n{table.concat(lines, "\n")}`
|
|
263
289
|
end)
|
|
264
290
|
|
|
265
291
|
self._cmdrService:RegisterCommand({
|
|
@@ -267,54 +293,29 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
267
293
|
Description = "Duplicates save slots into new slots at the lowest free indices.",
|
|
268
294
|
Group = "SaveSlots",
|
|
269
295
|
Args = {
|
|
296
|
+
{
|
|
297
|
+
Name = "Players",
|
|
298
|
+
Type = "players",
|
|
299
|
+
Description = "Players to duplicate slots for (e.g. . for yourself, or * for everyone).",
|
|
300
|
+
},
|
|
270
301
|
{
|
|
271
302
|
Name = "Slots",
|
|
272
303
|
Type = "slotIndices",
|
|
273
304
|
Description = "Slot indices to duplicate (e.g. 1,2, . for your current slot, or * for all).",
|
|
274
305
|
},
|
|
275
306
|
},
|
|
276
|
-
}, function(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
local toDuplicate = {}
|
|
280
|
-
for _, slotIndex in slotIndices do
|
|
281
|
-
local slotId = self._saveSlotDataService:GetSlotIdFromIndex(context.Executor, slotIndex)
|
|
282
|
-
if slotId and not seen[slotId] then
|
|
283
|
-
seen[slotId] = true
|
|
284
|
-
table.insert(toDuplicate, { slotIndex = slotIndex, slotId = slotId })
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
if #toDuplicate == 0 then
|
|
307
|
+
}, function(_context, players: { Player }, slotIndices: { number })
|
|
308
|
+
local targets = self:_resolveTargets(players, slotIndices)
|
|
309
|
+
if #targets == 0 then
|
|
289
310
|
return "No matching slots to duplicate."
|
|
290
311
|
end
|
|
291
312
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
:
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
local results = {}
|
|
299
|
-
for _, entry in toDuplicate do
|
|
300
|
-
promise = promise:Then(function()
|
|
301
|
-
return hasSaveSlots
|
|
302
|
-
:PromiseDuplicateSlot(entry.slotId)
|
|
303
|
-
:Then(function(newSlotId)
|
|
304
|
-
local newMetadata =
|
|
305
|
-
self._saveSlotDataService:GetSlotMetadata(context.Executor, newSlotId)
|
|
306
|
-
table.insert(
|
|
307
|
-
results,
|
|
308
|
-
`slot {entry.slotIndex} → slot {newMetadata.SlotIndex} ("{newMetadata.SlotName}")`
|
|
309
|
-
)
|
|
310
|
-
end)
|
|
311
|
-
:Catch(function(err)
|
|
312
|
-
table.insert(results, `slot {entry.slotIndex}: {tostring(err)}`)
|
|
313
|
-
end)
|
|
314
|
-
end)
|
|
315
|
-
end
|
|
316
|
-
return promise:Then(function()
|
|
317
|
-
return results
|
|
313
|
+
-- Each copy consumes a free index the next one must see, which the sequential walk guarantees.
|
|
314
|
+
local lines = self
|
|
315
|
+
:_promiseSlotLines(targets, function(hasSaveSlots, entry, player)
|
|
316
|
+
return hasSaveSlots:PromiseDuplicateSlot(entry.slotId):Then(function(newSlotId)
|
|
317
|
+
local newMetadata = self._saveSlotDataService:GetSlotMetadata(player, newSlotId)
|
|
318
|
+
return `{player.Name} slot {entry.slotIndex} → slot {newMetadata.SlotIndex} ("{newMetadata.SlotName}")`
|
|
318
319
|
end)
|
|
319
320
|
end)
|
|
320
321
|
:Wait()
|
|
@@ -328,60 +329,32 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
328
329
|
Group = "SaveSlots",
|
|
329
330
|
Args = {
|
|
330
331
|
{
|
|
332
|
+
Name = "Players",
|
|
333
|
+
Type = "players",
|
|
334
|
+
Description = "Players to reset slots for (e.g. . for yourself, or * for everyone).",
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
-- Required rather than defaulting to the active slot: with Players ahead of it, an
|
|
338
|
+
-- optional Slots would leave `reset-save-slot *` as valid syntax that wipes the active
|
|
339
|
+
-- slot of every player in the server.
|
|
331
340
|
Name = "Slots",
|
|
332
341
|
Type = "slotIndices",
|
|
333
|
-
Description = "Slot indices to reset (e.g. 1,2, . for your current slot, or * for all).
|
|
334
|
-
Optional = true,
|
|
342
|
+
Description = "Slot indices to reset (e.g. 1,2, . for your current slot, or * for all).",
|
|
335
343
|
},
|
|
336
344
|
},
|
|
337
|
-
}, function(
|
|
338
|
-
local
|
|
339
|
-
if
|
|
340
|
-
|
|
341
|
-
local activeSlotId = self._saveSlotDataService:GetActiveSlotId(context.Executor)
|
|
342
|
-
if not activeSlotId then
|
|
343
|
-
return "No active slot."
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
local metadata = self._saveSlotDataService:GetSlotMetadata(context.Executor, activeSlotId)
|
|
347
|
-
table.insert(toReset, { slotIndex = metadata.SlotIndex, slotId = activeSlotId })
|
|
348
|
-
else
|
|
349
|
-
-- Resolve indices to ids up front; `*`/`.` can include duplicates.
|
|
350
|
-
local seen = {}
|
|
351
|
-
for _, slotIndex in slotIndices do
|
|
352
|
-
local slotId = self._saveSlotDataService:GetSlotIdFromIndex(context.Executor, slotIndex)
|
|
353
|
-
if slotId and not seen[slotId] then
|
|
354
|
-
seen[slotId] = true
|
|
355
|
-
table.insert(toReset, { slotIndex = slotIndex, slotId = slotId })
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
if #toReset == 0 then
|
|
360
|
-
return "No matching slots to reset."
|
|
361
|
-
end
|
|
345
|
+
}, function(_context, players: { Player }, slotIndices: { number })
|
|
346
|
+
local targets = self:_resolveTargets(players, slotIndices)
|
|
347
|
+
if #targets == 0 then
|
|
348
|
+
return "No matching slots to reset."
|
|
362
349
|
end
|
|
363
350
|
|
|
364
|
-
local
|
|
365
|
-
:
|
|
366
|
-
|
|
367
|
-
-- Reset sequentially to avoid concurrent datastore saves.
|
|
368
|
-
local promise = Promise.resolved()
|
|
369
|
-
local done = {}
|
|
370
|
-
for _, entry in toReset do
|
|
371
|
-
promise = promise:Then(function()
|
|
372
|
-
return hasSaveSlots:PromiseResetSlot(entry.slotId):Then(function()
|
|
373
|
-
table.insert(done, entry.slotIndex)
|
|
374
|
-
end)
|
|
375
|
-
end)
|
|
376
|
-
end
|
|
377
|
-
return promise:Then(function()
|
|
378
|
-
return done
|
|
379
|
-
end)
|
|
351
|
+
local lines = self:_promiseSlotLines(targets, function(hasSaveSlots, entry, player)
|
|
352
|
+
return hasSaveSlots:PromiseResetSlot(entry.slotId):Then(function()
|
|
353
|
+
return `{player.Name} reset slot {entry.slotIndex}.`
|
|
380
354
|
end)
|
|
381
|
-
|
|
355
|
+
end):Wait()
|
|
382
356
|
|
|
383
|
-
table.
|
|
384
|
-
return `Reset slot(s) {table.concat(resetIndices, ", ")}.`
|
|
357
|
+
return `Reset:\n{table.concat(lines, "\n")}`
|
|
385
358
|
end)
|
|
386
359
|
|
|
387
360
|
self._cmdrService:RegisterCommand({
|
|
@@ -402,13 +375,15 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
402
375
|
},
|
|
403
376
|
},
|
|
404
377
|
}, function(_context, players: { Player }, slotIndices: { number }?)
|
|
405
|
-
local targets = self:
|
|
378
|
+
local targets = self:_resolveTargets(players, slotIndices)
|
|
406
379
|
if #targets == 0 then
|
|
407
380
|
return "No matching slots to export."
|
|
408
381
|
end
|
|
409
382
|
|
|
410
|
-
|
|
411
|
-
|
|
383
|
+
-- Admin tooling exports the main slot too, which the normal path refuses. See
|
|
384
|
+
-- HasSaveSlots.PromiseExportSlot for what that carries.
|
|
385
|
+
local lines = self:_promiseSlotLines(targets, function(hasSaveSlots, entry, player)
|
|
386
|
+
return hasSaveSlots:PromiseExportSaveSlotToCode(entry.slotId, true):Then(function(code)
|
|
412
387
|
return `{player.Name} slot {entry.slotIndex} → {code}`
|
|
413
388
|
end)
|
|
414
389
|
end):Wait()
|
|
@@ -434,13 +409,15 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
434
409
|
},
|
|
435
410
|
},
|
|
436
411
|
}, function(_context, players: { Player }, slotIndices: { number }?)
|
|
437
|
-
local targets = self:
|
|
412
|
+
local targets = self:_resolveTargets(players, slotIndices)
|
|
438
413
|
if #targets == 0 then
|
|
439
414
|
return "No matching slots to export."
|
|
440
415
|
end
|
|
441
416
|
|
|
442
|
-
|
|
443
|
-
|
|
417
|
+
-- Admin tooling exports the main slot too, which the normal path refuses. See
|
|
418
|
+
-- HasSaveSlots.PromiseExportSlot for what that carries.
|
|
419
|
+
local blocks = self:_promiseSlotLines(targets, function(hasSaveSlots, entry, player)
|
|
420
|
+
return hasSaveSlots:PromiseExportSaveSlotToJson(entry.slotId, true):Then(function(json)
|
|
444
421
|
return `-- {player.Name} slot {entry.slotIndex}\n{json}`
|
|
445
422
|
end)
|
|
446
423
|
end):Wait()
|
|
@@ -453,21 +430,26 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
453
430
|
Description = "Imports a save slot code into a new persisted (non-main) slot.",
|
|
454
431
|
Group = "SaveSlots",
|
|
455
432
|
Args = {
|
|
433
|
+
{
|
|
434
|
+
Name = "Player",
|
|
435
|
+
Type = "player",
|
|
436
|
+
Description = "Player to import into (e.g. . for yourself).",
|
|
437
|
+
},
|
|
456
438
|
{
|
|
457
439
|
Name = "Code",
|
|
458
440
|
Type = "string",
|
|
459
441
|
Description = "The code to import.",
|
|
460
442
|
},
|
|
461
443
|
},
|
|
462
|
-
}, function(
|
|
444
|
+
}, function(_context, player: Player, code: string)
|
|
463
445
|
return self._maid
|
|
464
|
-
:GivePromise(self._hasSaveSlotsBinder:Promise(
|
|
446
|
+
:GivePromise(self._hasSaveSlotsBinder:Promise(player))
|
|
465
447
|
:Then(function(hasSaveSlots)
|
|
466
448
|
return hasSaveSlots:PromiseImportSlotFromSharedDataStore(code)
|
|
467
449
|
end)
|
|
468
450
|
:Then(function(newSlotId)
|
|
469
|
-
local metadata = self._saveSlotDataService:GetSlotMetadata(
|
|
470
|
-
return `Imported save slot from code into slot {metadata.SlotIndex} ("{metadata.SlotName}").`
|
|
451
|
+
local metadata = self._saveSlotDataService:GetSlotMetadata(player, newSlotId)
|
|
452
|
+
return `Imported save slot from code into {player.Name} slot {metadata.SlotIndex} ("{metadata.SlotName}").`
|
|
471
453
|
end)
|
|
472
454
|
:Catch(function(err)
|
|
473
455
|
return `Import failed: {tostring(err)}`
|
|
@@ -480,20 +462,25 @@ function SaveSlotCmdrService._registerCommands(self: SaveSlotCmdrService): ()
|
|
|
480
462
|
Description = "Imports a save slot code into a throwaway ephemeral slot and selects it.",
|
|
481
463
|
Group = "SaveSlots",
|
|
482
464
|
Args = {
|
|
465
|
+
{
|
|
466
|
+
Name = "Player",
|
|
467
|
+
Type = "player",
|
|
468
|
+
Description = "Player to import into (e.g. . for yourself).",
|
|
469
|
+
},
|
|
483
470
|
{
|
|
484
471
|
Name = "Code",
|
|
485
472
|
Type = "string",
|
|
486
473
|
Description = "The code to load.",
|
|
487
474
|
},
|
|
488
475
|
},
|
|
489
|
-
}, function(
|
|
476
|
+
}, function(_context, player: Player, code: string)
|
|
490
477
|
return self._maid
|
|
491
|
-
:GivePromise(self._hasSaveSlotsBinder:Promise(
|
|
478
|
+
:GivePromise(self._hasSaveSlotsBinder:Promise(player))
|
|
492
479
|
:Then(function(hasSaveSlots)
|
|
493
480
|
return hasSaveSlots:PromiseImportEphemeralSaveSlotFromCode(code)
|
|
494
481
|
end)
|
|
495
482
|
:Then(function()
|
|
496
|
-
return `Imported ephemeral save slot from code: {code}`
|
|
483
|
+
return `Imported ephemeral save slot into {player.Name} from code: {code}`
|
|
497
484
|
end)
|
|
498
485
|
:Catch(function(err)
|
|
499
486
|
return `Load failed: {tostring(err)}`
|
|
@@ -530,10 +517,10 @@ function SaveSlotCmdrService._resolveSlotEntries(
|
|
|
530
517
|
return entries
|
|
531
518
|
end
|
|
532
519
|
|
|
533
|
-
-- Pairs each player with their resolved slots, dropping players with nothing to
|
|
520
|
+
-- Pairs each player with their resolved slots, dropping players with nothing to act on. Note that
|
|
534
521
|
-- Cmdr resolves the "." and "*" slot operators against the executor's slot list, since types only
|
|
535
522
|
-- see the executor, so indices given that way come from the executor's slots.
|
|
536
|
-
function SaveSlotCmdrService.
|
|
523
|
+
function SaveSlotCmdrService._resolveTargets(
|
|
537
524
|
self: SaveSlotCmdrService,
|
|
538
525
|
players: { Player },
|
|
539
526
|
slotIndices: { number }?
|
|
@@ -548,13 +535,45 @@ function SaveSlotCmdrService._resolveExportTargets(
|
|
|
548
535
|
return targets
|
|
549
536
|
end
|
|
550
537
|
|
|
551
|
-
--
|
|
552
|
-
--
|
|
553
|
-
--
|
|
554
|
-
function SaveSlotCmdrService.
|
|
538
|
+
-- Runs handlePlayer once per player, sequentially, to avoid concurrent datastore writes. For the
|
|
539
|
+
-- commands that act on a player as a whole rather than on a resolved slot list. handlePlayer may
|
|
540
|
+
-- return a line directly to report without doing any work.
|
|
541
|
+
function SaveSlotCmdrService._promisePlayerLines(
|
|
542
|
+
self: SaveSlotCmdrService,
|
|
543
|
+
players: { Player },
|
|
544
|
+
handlePlayer: (any, Player) -> any
|
|
545
|
+
): any
|
|
546
|
+
local promise = Promise.resolved()
|
|
547
|
+
local results: { string } = {}
|
|
548
|
+
|
|
549
|
+
for _, player in players do
|
|
550
|
+
promise = promise:Then(function()
|
|
551
|
+
return self._maid
|
|
552
|
+
:GivePromise(self._hasSaveSlotsBinder:Promise(player))
|
|
553
|
+
:Then(function(hasSaveSlots)
|
|
554
|
+
return handlePlayer(hasSaveSlots, player)
|
|
555
|
+
end)
|
|
556
|
+
:Then(function(line)
|
|
557
|
+
table.insert(results, line)
|
|
558
|
+
end)
|
|
559
|
+
:Catch(function(err)
|
|
560
|
+
table.insert(results, `{player.Name}: {tostring(err)}`)
|
|
561
|
+
end)
|
|
562
|
+
end)
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
return promise:Then(function()
|
|
566
|
+
return results
|
|
567
|
+
end)
|
|
568
|
+
end
|
|
569
|
+
|
|
570
|
+
-- Runs handleSlot over every resolved slot of every target, sequentially, to avoid concurrent
|
|
571
|
+
-- datastore writes. Reports per-slot so a mid-batch failure (e.g. one player's slot failing to
|
|
572
|
+
-- load) still surfaces the successes.
|
|
573
|
+
function SaveSlotCmdrService._promiseSlotLines(
|
|
555
574
|
self: SaveSlotCmdrService,
|
|
556
575
|
targets: { { player: Player, entries: SlotEntries } },
|
|
557
|
-
|
|
576
|
+
handleSlot: (any, SlotEntry, Player) -> any
|
|
558
577
|
): any
|
|
559
578
|
local promise = Promise.resolved()
|
|
560
579
|
local results: { string } = {}
|
|
@@ -565,7 +584,7 @@ function SaveSlotCmdrService._promiseExportLines(
|
|
|
565
584
|
local slotPromise = Promise.resolved()
|
|
566
585
|
for _, entry in target.entries do
|
|
567
586
|
slotPromise = slotPromise:Then(function()
|
|
568
|
-
return
|
|
587
|
+
return handleSlot(hasSaveSlots, entry, target.player)
|
|
569
588
|
:Then(function(line)
|
|
570
589
|
table.insert(results, line)
|
|
571
590
|
end)
|