@quenty/saveslot 2.2.3 → 2.4.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.
@@ -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
- }, function(context)
60
- local activeSlotId = self._saveSlotDataService:GetActiveSlotId(context.Executor)
61
- local slotList = self._saveSlotDataService:GetSlotList(context.Executor)
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 _, slot in slotList do
65
- local isActive = (slot.SlotId == activeSlotId)
66
- listString ..= `\n"{slot.SlotName}" ({slot.SlotIndex}){isActive and " — Active" or ""}\n{slot.Summary}\n`
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
- }, function(context)
78
- local activeSlotId = self._saveSlotDataService:GetActiveSlotId(context.Executor)
79
- if not activeSlotId then
80
- return "No active slot."
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
- local slotData = self._saveSlotDataService:GetSlotMetadata(context.Executor, activeSlotId)
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(context, slotIndex: number)
100
- local slotId = self._saveSlotDataService:GetSlotIdFromIndex(context.Executor, slotIndex)
101
- if not slotId then
102
- return `No slot with index {slotIndex}.`
103
- end
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
- if slotId == self._saveSlotDataService:GetActiveSlotId(context.Executor) then
106
- return "Slot is already active."
107
- end
136
+ if slotId == self._saveSlotDataService:GetActiveSlotId(player) then
137
+ return `{player.Name} already has slot {slotIndex} active.`
138
+ end
108
139
 
109
- self._maid
110
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
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
- :Wait()
143
+ end):Wait()
115
144
 
116
- return `Switched to slot {slotIndex}.`
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
- }, function(context)
125
- if not self._saveSlotDataService:GetActiveSlotId(context.Executor) then
126
- return "No active slot."
127
- end
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
- self._maid
130
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
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
- :Wait()
168
+ end):Wait()
135
169
 
136
- return "Deselected active slot."
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(context, slotIndices: { number }?)
152
- local maxSlotCount = context.Executor:GetAttribute("MaxSlotCount")
153
-
154
- -- Track indices already taken so a batch fills gaps and never collides within itself.
155
- local used = {}
156
- for _, metadata in self._saveSlotDataService:GetSlotList(context.Executor) do
157
- used[metadata.SlotIndex] = true
158
- end
159
-
160
- local toCreate = {}
161
- if slotIndices == nil then
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
- table.insert(toCreate, freeIndex)
173
- else
174
- -- Validate the whole batch up front so nothing is created when any index is bad.
175
- local seen = {}
176
- for _, slotIndex in slotIndices do
177
- if (slotIndex < 1) or (slotIndex > maxSlotCount) then
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
- if used[slotIndex] then
181
- return `Slot {slotIndex} already exists.`
210
+
211
+ if freeIndex > maxSlotCount then
212
+ return `{player.Name}: all slots are already in use.`
182
213
  end
183
- if not seen[slotIndex] then
184
- seen[slotIndex] = true
185
- table.insert(toCreate, slotIndex)
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
- self._maid
191
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
192
- :Then(function(hasSaveSlots)
193
- -- Create sequentially to avoid concurrent datastore saves.
194
- local promise = Promise.resolved()
195
- for _, slotIndex in toCreate do
196
- promise = promise:Then(function()
197
- return hasSaveSlots:PromiseCreateSlot(slotIndex)
198
- end)
199
- end
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
- :Wait()
244
+ end):Wait()
203
245
 
204
- return `Created slot(s) {table.concat(toCreate, ", ")}.`
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(context, slotIndices: { number })
219
- local activeSlotId = self._saveSlotDataService:GetActiveSlotId(context.Executor)
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._maid
237
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
238
- :Then(function(hasSaveSlots)
239
- -- Delete sequentially to avoid concurrent datastore saves. The active slot can't be
240
- -- deleted while selected, so deselect it first (flushing its progress) when reached.
241
- local promise = Promise.resolved()
242
- for _, entry in toDelete do
243
- promise = promise:Then(function()
244
- if entry.slotId == activeSlotId then
245
- return hasSaveSlots:PromiseDeselectSlot():Then(function()
246
- return hasSaveSlots:PromiseDeleteSlot(entry.slotId)
247
- end)
248
- end
249
-
250
- return hasSaveSlots:PromiseDeleteSlot(entry.slotId)
251
- end)
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 slot(s) {table.concat(deletedIndices, ", ")}.`
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(context, slotIndices: { number })
277
- -- Resolve indices to ids up front; `*`/`.` can include duplicates.
278
- local seen = {}
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
- local lines = self._maid
293
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
294
- :Then(function(hasSaveSlots)
295
- -- Duplicate sequentially: each copy consumes a free index the next one must see. Report
296
- -- per-slot so a mid-batch failure (e.g. the roster filling up) still surfaces the successes.
297
- local promise = Promise.resolved()
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). Omit to reset the active slot.",
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(context, slotIndices: { number }?)
338
- local toReset = {}
339
- if slotIndices == nil then
340
- -- No indices given: reset the active slot.
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 resetIndices = self._maid
365
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
366
- :Then(function(hasSaveSlots)
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
- :Wait()
355
+ end):Wait()
382
356
 
383
- table.sort(resetIndices)
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:_resolveExportTargets(players, slotIndices)
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
- local lines = self:_promiseExportLines(targets, function(hasSaveSlots, entry, player)
411
- return hasSaveSlots:PromiseExportSaveSlotToCode(entry.slotId):Then(function(code)
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:_resolveExportTargets(players, slotIndices)
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
- local blocks = self:_promiseExportLines(targets, function(hasSaveSlots, entry, player)
443
- return hasSaveSlots:PromiseExportSaveSlotToJson(entry.slotId):Then(function(json)
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(context, code: string)
444
+ }, function(_context, player: Player, code: string)
463
445
  return self._maid
464
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
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(context.Executor, newSlotId)
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(context, code: string)
476
+ }, function(_context, player: Player, code: string)
490
477
  return self._maid
491
- :GivePromise(self._hasSaveSlotsBinder:Promise(context.Executor))
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 export. Note that
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._resolveExportTargets(
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
- -- Exports every resolved slot of every target, sequentially, to avoid concurrent datastore writes.
552
- -- Reports per-slot so a mid-batch failure (e.g. the main slot, which export refuses) still surfaces
553
- -- the successes.
554
- function SaveSlotCmdrService._promiseExportLines(
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
- exportSlot: (any, SlotEntry, Player) -> any
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 exportSlot(hasSaveSlots, entry, target.player)
587
+ return handleSlot(hasSaveSlots, entry, target.player)
569
588
  :Then(function(line)
570
589
  table.insert(results, line)
571
590
  end)