@quenty/saveslot 2.7.0 → 2.8.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 +19 -0
- package/package.json +4 -4
- package/src/Client/SaveSlotServiceClient.lua +1 -0
- package/src/Server/Binders/HasSaveSlots.ExportImport.spec.lua +52 -0
- package/src/Server/Binders/HasSaveSlots.SharedStore.spec.lua +37 -0
- package/src/Server/Binders/HasSaveSlots.TransferableEphemeral.spec.lua +92 -12
- package/src/Server/Binders/HasSaveSlots.lua +169 -993
- package/src/Server/Binders/HasSaveSlots.spec.lua +56 -9
- package/src/Server/Cmdr/SaveSlotCmdrService.lua +565 -318
- package/src/Server/Cmdr/SaveSlotCmdrService.spec.lua +420 -0
- package/src/Server/HasSaveSlotsDataStore.lua +1658 -0
- package/src/Server/OfflineSaveSlots.lua +170 -0
- package/src/Server/OfflineSaveSlots.spec.lua +174 -0
- package/src/Server/SaveSlotService.lua +64 -2
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.lua +206 -2
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.spec.lua +68 -1
- package/src/Shared/SaveSlotExportUtils.lua +80 -3
- package/src/Shared/SaveSlotExportUtils.spec.lua +47 -1
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--[=[
|
|
3
|
+
Binds the save slot system to a live [Player].
|
|
4
|
+
|
|
5
|
+
The slot model itself -- the roster, per-slot stores, selection, create/delete/reset,
|
|
6
|
+
export/import, ephemeral slots and playtime -- lives in [HasSaveSlotsDataStore], built here over
|
|
7
|
+
the player's datastore. What stays behind is everything that only means something for a player in
|
|
8
|
+
this server: replicating the slot container under them, the client remotes, teleport data, and
|
|
9
|
+
summary providers (which are handed the [Player]).
|
|
10
|
+
|
|
11
|
+
Every slot method below is a straight delegation. Reach for [HasSaveSlotsDataStore] directly only
|
|
12
|
+
when there is no player to bind -- admin tooling acting on someone who is not in this server.
|
|
13
|
+
|
|
3
14
|
@class HasSaveSlots
|
|
4
15
|
]=]
|
|
5
16
|
|
|
6
17
|
local require = require(script.Parent.loader).load(script)
|
|
7
18
|
|
|
8
|
-
local HttpService = game:GetService("HttpService")
|
|
9
|
-
|
|
10
19
|
local Binder = require("Binder")
|
|
11
20
|
local Brio = require("Brio")
|
|
12
21
|
local DataStoreStage = require("DataStoreStage")
|
|
13
22
|
local HasSaveSlotsBase = require("HasSaveSlotsBase")
|
|
23
|
+
local HasSaveSlotsDataStore = require("HasSaveSlotsDataStore")
|
|
14
24
|
local HasSaveSlotsInterface = require("HasSaveSlotsInterface")
|
|
15
|
-
local InMemoryDataStore = require("InMemoryDataStore")
|
|
16
25
|
local Maid = require("Maid")
|
|
17
26
|
local Observable = require("Observable")
|
|
18
27
|
local ObservableMap = require("ObservableMap")
|
|
@@ -21,68 +30,70 @@ local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
|
21
30
|
local Promise = require("Promise")
|
|
22
31
|
local Remoting = require("Remoting")
|
|
23
32
|
local Rx = require("Rx")
|
|
24
|
-
local RxBrioUtils = require("RxBrioUtils")
|
|
25
33
|
local SaveSlotCodeUtils = require("SaveSlotCodeUtils")
|
|
26
34
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
27
35
|
local SaveSlotData = require("SaveSlotData")
|
|
28
36
|
local SaveSlotExportUtils = require("SaveSlotExportUtils")
|
|
29
37
|
local SaveSlotSharedDataStoreService = require("SaveSlotSharedDataStoreService")
|
|
30
38
|
local ServiceBag = require("ServiceBag")
|
|
39
|
+
local Signal = require("Signal")
|
|
31
40
|
local TeleportDataService = require("TeleportDataService")
|
|
41
|
+
local ValueObject = require("ValueObject")
|
|
32
42
|
|
|
33
43
|
-- A summary provider contributes one named piece of a slot's Summary. It is called with the player and
|
|
34
44
|
-- the slot's DataStoreStage and returns an Observable of a JSON-serializable value. Providers are
|
|
35
45
|
-- aggregated into a table keyed by their registered name; see RegisterSummaryProvider and _setupSummary.
|
|
36
46
|
export type SummaryProvider = (Player, DataStoreStage.DataStoreStage) -> Observable.Observable<any>
|
|
37
47
|
|
|
48
|
+
-- Re-exported so consumers keep naming this through HasSaveSlots; see HasSaveSlotsDataStore.
|
|
49
|
+
export type SaveSlotCreateMetadata = HasSaveSlotsDataStore.SaveSlotCreateMetadata
|
|
50
|
+
|
|
38
51
|
-- A provider that errors (when called, or mid-stream) contributes this sentinel rather than stalling or
|
|
39
52
|
-- failing the whole aggregate; _setupSummary strips it back out before writing the Summary. Compared by
|
|
40
53
|
-- identity, so it never collides with a real value (even an empty table) a provider might emit.
|
|
41
54
|
local NONE = {}
|
|
42
55
|
|
|
43
|
-
|
|
44
|
-
-- itself (from a fresh GUID and the slotIndex argument), so they are never taken from here.
|
|
45
|
-
export type SaveSlotCreateMetadata = {
|
|
46
|
-
SlotName: string?,
|
|
47
|
-
Summary: SaveSlotData.SaveSlotSummary?,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
local HasSaveSlots = setmetatable({}, HasSaveSlotsBase)
|
|
56
|
+
local HasSaveSlots = {}
|
|
51
57
|
HasSaveSlots.ClassName = "HasSaveSlots"
|
|
52
58
|
HasSaveSlots.__index = HasSaveSlots
|
|
59
|
+
-- Runtime inheritance only. Typing the metatable target as `any` keeps the old solver from chasing
|
|
60
|
+
-- the full HasSaveSlotsBase type here, which -- now that this class also names HasSaveSlotsDataStore
|
|
61
|
+
-- across every delegation -- overflows its complexity budget ("Code is too complex"). The inherited
|
|
62
|
+
-- surface is supplied structurally below.
|
|
63
|
+
setmetatable(HasSaveSlots :: any, HasSaveSlotsBase)
|
|
64
|
+
|
|
65
|
+
-- Minimal structural surface inherited from HasSaveSlotsBase, for this class and its consumers. See
|
|
66
|
+
-- the setmetatable note above for why we don't intersect HasSaveSlotsBase.HasSaveSlotsBase.
|
|
67
|
+
type HasSaveSlotsBaseLike = {
|
|
68
|
+
_obj: Player,
|
|
69
|
+
_maid: Maid.Maid,
|
|
70
|
+
|
|
71
|
+
ActiveSlotId: ValueObject.ValueObject<SaveSlotData.SlotId?>,
|
|
72
|
+
LastActiveSlotId: ValueObject.ValueObject<SaveSlotData.SlotId?>,
|
|
73
|
+
ActiveTransferableEphemeralKey: ValueObject.ValueObject<string?>,
|
|
74
|
+
MaxSlotCount: ValueObject.ValueObject<number>,
|
|
75
|
+
SlotChanged: Signal.Signal<SaveSlotData.SlotId>,
|
|
76
|
+
|
|
77
|
+
PromiseHasSaveSlotFromTeleport: (self: any) -> Promise.Promise<boolean>,
|
|
78
|
+
PromiseLoadSaveSlotFromTeleport: (self: any) -> Promise.Promise<SaveSlotData.SlotId?>,
|
|
79
|
+
Destroy: (self: any) -> (),
|
|
80
|
+
}
|
|
53
81
|
|
|
54
82
|
export type HasSaveSlots =
|
|
55
83
|
typeof(setmetatable(
|
|
56
84
|
{} :: {
|
|
57
|
-
_obj: Player,
|
|
58
85
|
_serviceBag: ServiceBag.ServiceBag,
|
|
59
86
|
_playerDataStoreService: any,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
-- The in-memory stores backing ephemeral (session-only) slots, keyed by slot id. A slot's
|
|
63
|
-
-- IsEphemeral property is the discriminator (see _isEphemeral); this holds the store objects a
|
|
64
|
-
-- property can't. See PromiseSelectEphemeralSlot.
|
|
65
|
-
_ephemeralStores: { [SaveSlotData.SlotId]: InMemoryDataStore.InMemoryDataStore },
|
|
66
|
-
-- The shared-store key each transferable ephemeral slot was loaded from, so a teleport can
|
|
67
|
-
-- re-save its live state under that key and carry it forward. See PromiseSelectTransferableEphemeralSlot.
|
|
68
|
-
_transferableEphemeralKeys: { [SaveSlotData.SlotId]: string },
|
|
69
|
-
_codeGenerator: SaveSlotCodeUtils.CodeGenerator,
|
|
70
|
-
_loadPromise: Promise.Promise<{}>,
|
|
87
|
+
-- A HasSaveSlotsDataStore. Untyped for the reason given on GetSlotsDataStore.
|
|
88
|
+
_slotsDataStore: any,
|
|
71
89
|
_remoting: any,
|
|
72
|
-
_dataStore: any,
|
|
73
|
-
_systemStore: any,
|
|
74
|
-
_metadataStore: any,
|
|
75
90
|
_summaryProviders: ObservableMap.ObservableMap<string, SummaryProvider>,
|
|
76
|
-
_lastActiveSlotId: SaveSlotData.SlotId?,
|
|
77
91
|
_teleportDataService: any,
|
|
78
92
|
_sharedSaveSlotDataStoreService: any,
|
|
79
|
-
_playSessionSlotId: SaveSlotData.SlotId?,
|
|
80
|
-
_playSessionStart: number?,
|
|
81
|
-
_playSessionLastFlush: number?,
|
|
82
93
|
},
|
|
83
94
|
{} :: typeof({ __index = HasSaveSlots })
|
|
84
95
|
))
|
|
85
|
-
&
|
|
96
|
+
& HasSaveSlotsBaseLike
|
|
86
97
|
|
|
87
98
|
function HasSaveSlots.new(player: Player, serviceBag: ServiceBag.ServiceBag): HasSaveSlots
|
|
88
99
|
local self: HasSaveSlots = setmetatable(HasSaveSlotsBase.new(player, serviceBag) :: any, HasSaveSlots)
|
|
@@ -92,24 +103,39 @@ function HasSaveSlots.new(player: Player, serviceBag: ServiceBag.ServiceBag): Ha
|
|
|
92
103
|
self._teleportDataService = self._serviceBag:GetService(TeleportDataService)
|
|
93
104
|
self._sharedSaveSlotDataStoreService = self._serviceBag:GetService(SaveSlotSharedDataStoreService)
|
|
94
105
|
|
|
95
|
-
self._slotContainer = self._maid:Add(Instance.new("Folder"))
|
|
96
|
-
self._slotContainer.Name = SaveSlotConstants.METADATA_CONTAINER_NAME
|
|
97
|
-
self._slotContainer.Archivable = false
|
|
98
|
-
self._slotContainer.Parent = self._obj
|
|
99
|
-
|
|
100
|
-
self._slotMap = {}
|
|
101
|
-
self._ephemeralStores = {}
|
|
102
|
-
self._transferableEphemeralKeys = {}
|
|
103
|
-
self._codeGenerator = SaveSlotCodeUtils.generateDefaultCode
|
|
104
|
-
|
|
105
106
|
self._summaryProviders = self._maid:Add(ObservableMap.new())
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
-- UserId is read defensively because it is not indexable on every stand-in a binder can be bound to.
|
|
109
|
+
local okUserId, userId = pcall(function()
|
|
110
|
+
return self._obj.UserId
|
|
111
|
+
end)
|
|
112
|
+
|
|
113
|
+
-- Annotated rather than inlined into the call: inferring this table against the class's
|
|
114
|
+
-- intersection type tips luau-lsp into "Code is too complex to typecheck".
|
|
115
|
+
local options: HasSaveSlotsDataStore.HasSaveSlotsDataStoreOptions = {
|
|
116
|
+
ActiveSlotId = self.ActiveSlotId,
|
|
117
|
+
LastActiveSlotId = self.LastActiveSlotId,
|
|
118
|
+
ActiveTransferableEphemeralKey = self.ActiveTransferableEphemeralKey,
|
|
119
|
+
MaxSlotCount = self.MaxSlotCount,
|
|
120
|
+
SharedDataStoreService = self._sharedSaveSlotDataStoreService,
|
|
121
|
+
PromisePreSelect = function(slotId: SaveSlotData.SlotId)
|
|
122
|
+
return self:_promisePreSelectFromSaveSlotService(slotId)
|
|
123
|
+
end,
|
|
124
|
+
UserId = if okUserId and type(userId) == "number" then userId else nil,
|
|
125
|
+
UserName = self._obj.Name,
|
|
126
|
+
TrackPlaytime = true,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
self._slotsDataStore =
|
|
130
|
+
self._maid:Add(HasSaveSlotsDataStore.new(self._playerDataStoreService:PromiseDataStore(self._obj), options))
|
|
131
|
+
|
|
132
|
+
-- Replicate the slot roster from the player, which is where the client reads it (see
|
|
133
|
+
-- SaveSlotDataService). The slot system itself has no idea a player is involved.
|
|
134
|
+
self._maid:GiveTask(self._slotsDataStore.SlotContainerParent:Mount(self._obj))
|
|
108
135
|
|
|
109
136
|
self._remoting = self._maid:Add(Remoting.Server.new(self._obj, "HasSaveSlots"))
|
|
110
137
|
|
|
111
138
|
self:_setupSummary()
|
|
112
|
-
self:_setupPlaytimeTracking()
|
|
113
139
|
self:_setupRemotes()
|
|
114
140
|
|
|
115
141
|
self._maid:GiveTask(HasSaveSlotsInterface.Server:Implement(self._obj, self))
|
|
@@ -117,53 +143,50 @@ function HasSaveSlots.new(player: Player, serviceBag: ServiceBag.ServiceBag): Ha
|
|
|
117
143
|
return self
|
|
118
144
|
end
|
|
119
145
|
|
|
146
|
+
--[=[
|
|
147
|
+
Returns the underlying player-independent slot system, a [HasSaveSlotsDataStore]. Prefer the
|
|
148
|
+
delegating methods on this class; this is for code that needs to hand the slot system to something
|
|
149
|
+
that does not know about players.
|
|
150
|
+
|
|
151
|
+
Typed `any` deliberately: naming `HasSaveSlotsDataStore.HasSaveSlotsDataStore` anywhere in this
|
|
152
|
+
file -- even once -- pushes the old solver over its complexity budget ("Code is too complex"). The
|
|
153
|
+
delegating methods below still carry their own precise return types, which is what callers read;
|
|
154
|
+
require the module directly for a typed handle.
|
|
155
|
+
|
|
156
|
+
@return HasSaveSlotsDataStore
|
|
157
|
+
]=]
|
|
158
|
+
function HasSaveSlots.GetSlotsDataStore(self: HasSaveSlots): any
|
|
159
|
+
return self._slotsDataStore
|
|
160
|
+
end
|
|
161
|
+
|
|
120
162
|
--[=[
|
|
121
163
|
Observes the [DataStoreStage] for the active slot as a [Brio]
|
|
122
164
|
]=]
|
|
123
165
|
function HasSaveSlots.ObserveActiveSlotStoreBrio(
|
|
124
166
|
self: HasSaveSlots
|
|
125
167
|
): Observable.Observable<Brio.Brio<DataStoreStage.DataStoreStage>>
|
|
126
|
-
return
|
|
127
|
-
Rx.switchMap(function()
|
|
128
|
-
return self.ActiveSlotId
|
|
129
|
-
:ObserveBrio(function(slotId: SaveSlotData.SlotId?)
|
|
130
|
-
return (slotId ~= nil)
|
|
131
|
-
end)
|
|
132
|
-
:Pipe({
|
|
133
|
-
RxBrioUtils.map(function(slotId: SaveSlotData.SlotId)
|
|
134
|
-
return self:_getSlotStore(slotId)
|
|
135
|
-
end) :: any,
|
|
136
|
-
}) :: any
|
|
137
|
-
end) :: any,
|
|
138
|
-
}) :: any
|
|
168
|
+
return self._slotsDataStore:ObserveActiveSlotStoreBrio()
|
|
139
169
|
end
|
|
140
170
|
|
|
141
171
|
--[=[
|
|
142
172
|
Returns the [DataStoreStage] for the active slot
|
|
143
173
|
]=]
|
|
144
174
|
function HasSaveSlots.PromiseActiveSlotStore(self: HasSaveSlots): Promise.Promise<DataStoreStage.DataStoreStage?>
|
|
145
|
-
return
|
|
146
|
-
if not self.ActiveSlotId.Value then
|
|
147
|
-
return (Promise :: any).resolved(nil)
|
|
148
|
-
end
|
|
149
|
-
return self:_getSlotStore(self.ActiveSlotId.Value)
|
|
150
|
-
end)
|
|
175
|
+
return self._slotsDataStore:PromiseActiveSlotStore()
|
|
151
176
|
end
|
|
152
177
|
|
|
153
178
|
--[=[
|
|
154
179
|
Promises that all slots have loaded
|
|
155
180
|
]=]
|
|
156
181
|
function HasSaveSlots.PromiseSlotsLoaded(self: HasSaveSlots): Promise.Promise<any>
|
|
157
|
-
return self.
|
|
182
|
+
return self._slotsDataStore:PromiseSlotsLoaded()
|
|
158
183
|
end
|
|
159
184
|
|
|
160
185
|
--[=[
|
|
161
186
|
Returns whether the slot with the given ID exists
|
|
162
187
|
]=]
|
|
163
188
|
function HasSaveSlots.PromiseHasSlot(self: HasSaveSlots, slotId: SaveSlotData.SlotId?): Promise.Promise<boolean>
|
|
164
|
-
return
|
|
165
|
-
return slotId and ((self._slotMap[slotId] :: Folder?) ~= nil)
|
|
166
|
-
end)
|
|
189
|
+
return self._slotsDataStore:PromiseHasSlot(slotId)
|
|
167
190
|
end
|
|
168
191
|
|
|
169
192
|
-- SaveSlotService owns the callbacks and runs them. Reached through the module instance rather than by
|
|
@@ -186,72 +209,16 @@ end
|
|
|
186
209
|
Selects the slot with the given ID
|
|
187
210
|
]=]
|
|
188
211
|
function HasSaveSlots.PromiseSelectSlot(self: HasSaveSlots, slotId: SaveSlotData.SlotId): Promise.Promise<any>
|
|
189
|
-
return
|
|
190
|
-
if slotId == self.ActiveSlotId.Value then
|
|
191
|
-
return -- Already set
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
local slot = self._slotMap[slotId]
|
|
195
|
-
if not slot then
|
|
196
|
-
return (Promise :: any).rejected(`Slot \{{slotId}\} not found`)
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
local function setSlot()
|
|
200
|
-
self.ActiveSlotId.Value = slotId
|
|
201
|
-
SaveSlotData.LastPlayedTime:Set(slot, os.time())
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
local function promiseSetSlot()
|
|
205
|
-
return self._maid
|
|
206
|
-
:GivePromise(self:_promisePreSelectFromSaveSlotService(slotId))
|
|
207
|
-
:Then(function(allowed: boolean)
|
|
208
|
-
if not allowed then
|
|
209
|
-
return (Promise :: any).rejected(`Slot \{{slotId}\} refused by a pre-select callback`)
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
return setSlot()
|
|
213
|
-
end)
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
-- Initialize or save and switch
|
|
217
|
-
if self.ActiveSlotId.Value == nil then
|
|
218
|
-
return promiseSetSlot()
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
-- Leaving an ephemeral slot has nothing to persist, so switch without a datastore flush (the flush
|
|
222
|
-
-- exists to save the outgoing slot's progress, and an ephemeral slot has none).
|
|
223
|
-
if self:_isEphemeral(self.ActiveSlotId.Value) then
|
|
224
|
-
return promiseSetSlot()
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
return self._maid:GivePromise(self._dataStore:Save()):Then(promiseSetSlot)
|
|
228
|
-
end)
|
|
212
|
+
return self._slotsDataStore:PromiseSelectSlot(slotId)
|
|
229
213
|
end
|
|
230
214
|
|
|
231
215
|
--[=[
|
|
232
216
|
Clears the active slot selection, returning the player to a no-slot state --
|
|
233
217
|
the counterpart to [HasSaveSlots.PromiseSelectSlot], backing a "back to menu"
|
|
234
|
-
affordance.
|
|
235
|
-
PromiseSelectSlot runs when switching away), and the last-active slot is
|
|
236
|
-
remembered, so [HasSaveSlots.PromiseSelectLastSaveSlot] can resume it later.
|
|
237
|
-
A no-op when no slot is active.
|
|
218
|
+
affordance. See [HasSaveSlotsDataStore.PromiseDeselectSlot].
|
|
238
219
|
]=]
|
|
239
220
|
function HasSaveSlots.PromiseDeselectSlot(self: HasSaveSlots): Promise.Promise<()>
|
|
240
|
-
return
|
|
241
|
-
if self.ActiveSlotId.Value == nil then
|
|
242
|
-
return -- Already deselected
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
-- An ephemeral slot has nothing to flush, so clear it without a datastore save.
|
|
246
|
-
if self:_isEphemeral(self.ActiveSlotId.Value) then
|
|
247
|
-
self.ActiveSlotId.Value = nil
|
|
248
|
-
return
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
return self._dataStore:Save():Then(function()
|
|
252
|
-
self.ActiveSlotId.Value = nil
|
|
253
|
-
end)
|
|
254
|
-
end)
|
|
221
|
+
return self._slotsDataStore:PromiseDeselectSlot()
|
|
255
222
|
end
|
|
256
223
|
|
|
257
224
|
--[=[
|
|
@@ -262,45 +229,12 @@ function HasSaveSlots.PromiseCreateSlot(
|
|
|
262
229
|
slotIndex: number,
|
|
263
230
|
metadata: SaveSlotCreateMetadata?
|
|
264
231
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
265
|
-
return
|
|
266
|
-
if (slotIndex < 1) or (slotIndex > self.MaxSlotCount.Value) then
|
|
267
|
-
return (Promise :: any).rejected(`Index must be in range [1, {self.MaxSlotCount.Value}]`)
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
for existingSlotId, slot in self._slotMap do
|
|
271
|
-
if self:_isEphemeral(existingSlotId) then
|
|
272
|
-
continue -- ephemeral slots carry no meaningful index; never let one block a real index
|
|
273
|
-
end
|
|
274
|
-
if slotIndex == SaveSlotData.SlotIndex:Get(slot) then
|
|
275
|
-
return (Promise :: any).rejected(`Slot {slotIndex} already exists`)
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
local slotId = HttpService:GenerateGUID(false)
|
|
280
|
-
local data = {
|
|
281
|
-
SlotId = slotId,
|
|
282
|
-
SlotIndex = slotIndex,
|
|
283
|
-
SlotName = (metadata and metadata.SlotName) or `Slot {slotIndex}`,
|
|
284
|
-
CreatedTime = os.time(),
|
|
285
|
-
Summary = metadata and metadata.Summary,
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
self:_buildSlot(slotId, data, true)
|
|
289
|
-
return slotId
|
|
290
|
-
end)
|
|
232
|
+
return self._slotsDataStore:PromiseCreateSlot(slotIndex, metadata)
|
|
291
233
|
end
|
|
292
234
|
|
|
293
235
|
--[=[
|
|
294
|
-
Exports a slot's saved data into a plain, serializable [SaveSlotExportUtils.SaveSlotExport].
|
|
295
|
-
|
|
296
|
-
exporting it would leak the SaveSlots system data and universe-scoped global data living
|
|
297
|
-
alongside it. Only isolated non-main slot substores are exportable.
|
|
298
|
-
|
|
299
|
-
`allowMainSlot` opts out of that refusal for trusted admin tooling (see [SaveSlotCmdrService]).
|
|
300
|
-
The SaveSlots system data is always stripped from the result, so the export never carries the
|
|
301
|
-
slot roster or the other slots' saved data. Universe-scoped global data sharing the root store
|
|
302
|
-
is indistinguishable from the main slot's own data and is still carried, which is why this is
|
|
303
|
-
not exposed through [SaveSlotService].
|
|
236
|
+
Exports a slot's saved data into a plain, serializable [SaveSlotExportUtils.SaveSlotExport]. Refuses
|
|
237
|
+
the main slot unless `allowMainSlot` is set -- see [HasSaveSlotsDataStore.PromiseExportSlot].
|
|
304
238
|
|
|
305
239
|
@param slotId SlotId
|
|
306
240
|
@param allowMainSlot boolean? -- defaults to false
|
|
@@ -311,91 +245,32 @@ function HasSaveSlots.PromiseExportSlot(
|
|
|
311
245
|
slotId: SaveSlotData.SlotId,
|
|
312
246
|
allowMainSlot: boolean?
|
|
313
247
|
): Promise.Promise<SaveSlotExportUtils.SaveSlotExport>
|
|
314
|
-
return
|
|
315
|
-
local slot = self._slotMap[slotId]
|
|
316
|
-
if not slot then
|
|
317
|
-
return (Promise :: any).rejected(`Slot \{{slotId}\} not found`)
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
local isMainSlot = SaveSlotExportUtils.isMainSlotIndex(SaveSlotData.SlotIndex:Get(slot))
|
|
321
|
-
if isMainSlot and not allowMainSlot then
|
|
322
|
-
return (Promise :: any).rejected("Cannot export the main slot")
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
local metadata = SaveSlotData:Get(slot)
|
|
326
|
-
return self:_getSlotStore(slotId):LoadAll({}):Then(function(sourceData)
|
|
327
|
-
local data = if type(sourceData) == "table" then table.clone(sourceData) else {}
|
|
328
|
-
|
|
329
|
-
if isMainSlot then
|
|
330
|
-
-- The main slot's store is the player's shared root, so LoadAll pulls the SaveSlots system
|
|
331
|
-
-- data with it -- the slot roster and every non-main slot's saved data. Drop it so the
|
|
332
|
-
-- export is only this slot, and so importing it can't nest a whole roster inside a slot
|
|
333
|
-
-- (mirrors PromiseDuplicateSlot, which strips the same key for the same reason).
|
|
334
|
-
data[SaveSlotConstants.SYSTEM_STORE_KEY] = nil
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
return SaveSlotExportUtils.create(data, metadata.SlotName, metadata.Summary)
|
|
338
|
-
end)
|
|
339
|
-
end)
|
|
248
|
+
return self._slotsDataStore:PromiseExportSlot(slotId, allowMainSlot)
|
|
340
249
|
end
|
|
341
250
|
|
|
342
251
|
--[=[
|
|
343
|
-
Imports an exported slot into a fresh slot at the lowest free non-main index
|
|
344
|
-
|
|
345
|
-
shared root store would wipe the player's global data. Resolves to the new slot's id. Rejects a
|
|
346
|
-
malformed export, or when no non-main index is free.
|
|
252
|
+
Imports an exported slot into a fresh slot, at the lowest free non-main index by default. See
|
|
253
|
+
[HasSaveSlotsDataStore.PromiseImportSlot].
|
|
347
254
|
|
|
348
255
|
@param export SaveSlotExportUtils.SaveSlotExport
|
|
256
|
+
@param targetSlotIndex number? -- defaults to the lowest free non-main index
|
|
349
257
|
@return Promise<SlotId>
|
|
350
258
|
]=]
|
|
351
259
|
function HasSaveSlots.PromiseImportSlot(
|
|
352
260
|
self: HasSaveSlots,
|
|
353
|
-
export: SaveSlotExportUtils.SaveSlotExport
|
|
261
|
+
export: SaveSlotExportUtils.SaveSlotExport,
|
|
262
|
+
targetSlotIndex: number?
|
|
354
263
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
355
|
-
return
|
|
356
|
-
if not SaveSlotExportUtils.isSaveSlotExport(export) then
|
|
357
|
-
return (Promise :: any).rejected("Bad save slot export")
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
-- Lowest free index strictly above the main slot: an imported slot must never occupy the
|
|
361
|
-
-- default index, whose store is the shared root datastore.
|
|
362
|
-
local usedIndices = {}
|
|
363
|
-
for existingSlotId, slot in self._slotMap do
|
|
364
|
-
if not self:_isEphemeral(existingSlotId) then
|
|
365
|
-
usedIndices[SaveSlotData.SlotIndex:Get(slot)] = true
|
|
366
|
-
end
|
|
367
|
-
end
|
|
368
|
-
local freeIndex = SaveSlotConstants.DEFAULT_SLOT_INDEX + 1
|
|
369
|
-
while usedIndices[freeIndex] do
|
|
370
|
-
freeIndex += 1
|
|
371
|
-
end
|
|
372
|
-
if freeIndex > self.MaxSlotCount.Value then
|
|
373
|
-
return (Promise :: any).rejected("No free non-main slot index available")
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
return self:PromiseCreateSlot(freeIndex, {
|
|
377
|
-
SlotName = export.slotName,
|
|
378
|
-
Summary = export.summary,
|
|
379
|
-
}):Then(function(newSlotId: SaveSlotData.SlotId)
|
|
380
|
-
-- freeIndex is always > DEFAULT_SLOT_INDEX, so this store is an isolated substore
|
|
381
|
-
-- (never the shared root); a plain Overwrite cannot touch system or global data.
|
|
382
|
-
self:_getSlotStore(newSlotId):Overwrite(export.data)
|
|
383
|
-
|
|
384
|
-
-- Flush so the imported slot survives a crash before the next autosave.
|
|
385
|
-
return self._dataStore:Save():Then(function()
|
|
386
|
-
return newSlotId
|
|
387
|
-
end)
|
|
388
|
-
end)
|
|
389
|
-
end)
|
|
264
|
+
return self._slotsDataStore:PromiseImportSlot(export, targetSlotIndex)
|
|
390
265
|
end
|
|
391
266
|
|
|
392
267
|
--[=[
|
|
393
|
-
Exports a non-main slot
|
|
394
|
-
|
|
268
|
+
Exports a non-main slot and writes it to the shared save slot store under the given key. See
|
|
269
|
+
[HasSaveSlotsDataStore.PromiseSaveSlotToSharedDataStore].
|
|
395
270
|
|
|
396
271
|
@param slotId SlotId
|
|
397
272
|
@param key string
|
|
398
|
-
@param allowMainSlot boolean? -- defaults to false
|
|
273
|
+
@param allowMainSlot boolean? -- defaults to false
|
|
399
274
|
@return Promise<boolean>
|
|
400
275
|
]=]
|
|
401
276
|
function HasSaveSlots.PromiseSaveSlotToSharedDataStore(
|
|
@@ -404,14 +279,12 @@ function HasSaveSlots.PromiseSaveSlotToSharedDataStore(
|
|
|
404
279
|
key: string,
|
|
405
280
|
allowMainSlot: boolean?
|
|
406
281
|
): Promise.Promise<boolean>
|
|
407
|
-
return self:
|
|
408
|
-
return self._sharedSaveSlotDataStoreService:PromiseWrite(key, export)
|
|
409
|
-
end)
|
|
282
|
+
return self._slotsDataStore:PromiseSaveSlotToSharedDataStore(slotId, key, allowMainSlot)
|
|
410
283
|
end
|
|
411
284
|
|
|
412
285
|
--[=[
|
|
413
|
-
Reads an export from the shared save slot store and imports it into a fresh non-main slot
|
|
414
|
-
[
|
|
286
|
+
Reads an export from the shared save slot store and imports it into a fresh non-main slot. See
|
|
287
|
+
[HasSaveSlotsDataStore.PromiseImportSlotFromSharedDataStore].
|
|
415
288
|
|
|
416
289
|
@param key string
|
|
417
290
|
@return Promise<SlotId>
|
|
@@ -420,25 +293,14 @@ function HasSaveSlots.PromiseImportSlotFromSharedDataStore(
|
|
|
420
293
|
self: HasSaveSlots,
|
|
421
294
|
key: string
|
|
422
295
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
423
|
-
|
|
424
|
-
-- nothing upstream rejects it when the player leaves mid-read.
|
|
425
|
-
return self._maid:GivePromise(self._sharedSaveSlotDataStoreService:PromiseRead(key)):Then(function(export)
|
|
426
|
-
if not self.Destroy then
|
|
427
|
-
return (Promise :: any).rejected() -- Destroyed. Empty, so it stays out of the logs
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
if export == nil then
|
|
431
|
-
return (Promise :: any).rejected(`No save slot stored under \{{key}\}`)
|
|
432
|
-
end
|
|
433
|
-
return self:PromiseImportSlot(export)
|
|
434
|
-
end)
|
|
296
|
+
return self._slotsDataStore:PromiseImportSlotFromSharedDataStore(key)
|
|
435
297
|
end
|
|
436
298
|
|
|
437
299
|
--[=[
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
300
|
+
Resumes a transfer from the given shared-store key into a fresh ephemeral slot and selects it. Only
|
|
301
|
+
entries written as transfers are accepted; a share code is redeemed through
|
|
302
|
+
[HasSaveSlots.PromiseImportEphemeralSaveSlotFromCode]. See
|
|
303
|
+
[HasSaveSlotsDataStore.PromiseSelectTransferableEphemeralSlot].
|
|
442
304
|
|
|
443
305
|
@param key string
|
|
444
306
|
@return Promise<SlotId>
|
|
@@ -447,75 +309,17 @@ function HasSaveSlots.PromiseSelectTransferableEphemeralSlot(
|
|
|
447
309
|
self: HasSaveSlots,
|
|
448
310
|
key: string
|
|
449
311
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
450
|
-
return
|
|
451
|
-
-- Maid-owned for the same reason as _promiseLoadSlots: this read runs on the join path (a teleport
|
|
452
|
-
-- arriving with an ephemeral key) and outlives a leave, and its continuation builds a slot.
|
|
453
|
-
return self._maid:GivePromise(self._sharedSaveSlotDataStoreService:PromiseRead(key)):Then(function(export)
|
|
454
|
-
if not self.Destroy then
|
|
455
|
-
-- Destroyed. Rejecting keeps the Promise<SlotId> contract honest -- a nil fulfilment reads as
|
|
456
|
-
-- "imported, no slot" to a caller like SaveSlotCmdrService. Empty, so it stays out of the logs.
|
|
457
|
-
return (Promise :: any).rejected()
|
|
458
|
-
end
|
|
459
|
-
|
|
460
|
-
if export == nil then
|
|
461
|
-
return (Promise :: any).rejected(`No save slot stored under \{{key}\}`)
|
|
462
|
-
end
|
|
463
|
-
if not SaveSlotExportUtils.isSaveSlotExport(export) then
|
|
464
|
-
return (Promise :: any).rejected("Bad save slot export in shared store")
|
|
465
|
-
end
|
|
466
|
-
|
|
467
|
-
local slotId = HttpService:GenerateGUID(false)
|
|
468
|
-
self:_buildSlot(slotId, {
|
|
469
|
-
SlotId = slotId,
|
|
470
|
-
SlotIndex = SaveSlotConstants.EPHEMERAL_SLOT_INDEX,
|
|
471
|
-
SlotName = export.slotName or "Transfer",
|
|
472
|
-
CreatedTime = os.time(),
|
|
473
|
-
Summary = export.summary,
|
|
474
|
-
}, true, true)
|
|
475
|
-
|
|
476
|
-
-- Seed the in-memory store before selecting so a consumer of ObserveActiveSlotStoreBrio never
|
|
477
|
-
-- observes an empty active slot; then remember the key this slot transfers under.
|
|
478
|
-
self:_getSlotStore(slotId):Overwrite(export.data)
|
|
479
|
-
self._transferableEphemeralKeys[slotId] = key
|
|
480
|
-
|
|
481
|
-
return self:PromiseSelectSlot(slotId):Then(function()
|
|
482
|
-
return slotId
|
|
483
|
-
end)
|
|
484
|
-
end)
|
|
485
|
-
end)
|
|
312
|
+
return self._slotsDataStore:PromiseSelectTransferableEphemeralSlot(key)
|
|
486
313
|
end
|
|
487
314
|
|
|
488
315
|
--[=[
|
|
489
|
-
Builds this player's teleport slice for a transferable ephemeral slot
|
|
490
|
-
|
|
491
|
-
nil when the active slot is not a transferable ephemeral slot. A failed re-save degrades to nil so a
|
|
492
|
-
teleport is never blocked (the destination then re-loads the last saved state). Asynchronous -- it is
|
|
493
|
-
consumed through [TeleportDataService.PromiseBuildTeleportData].
|
|
316
|
+
Builds this player's teleport slice for a transferable ephemeral slot. See
|
|
317
|
+
[HasSaveSlotsDataStore.PromiseBuildEphemeralTransferSlice].
|
|
494
318
|
|
|
495
319
|
@return Promise<{ [string]: any }?>
|
|
496
320
|
]=]
|
|
497
321
|
function HasSaveSlots.PromiseBuildEphemeralTransferSlice(self: HasSaveSlots): Promise.Promise<{ [string]: any }?>
|
|
498
|
-
return
|
|
499
|
-
local slotId = self.ActiveSlotId.Value
|
|
500
|
-
if not slotId then
|
|
501
|
-
return nil
|
|
502
|
-
end
|
|
503
|
-
local storeKey = self._transferableEphemeralKeys[slotId]
|
|
504
|
-
if not storeKey then
|
|
505
|
-
return nil
|
|
506
|
-
end
|
|
507
|
-
|
|
508
|
-
return self:PromiseExportSlot(slotId)
|
|
509
|
-
:Then(function(export)
|
|
510
|
-
return self._sharedSaveSlotDataStoreService:PromiseWrite(storeKey, export)
|
|
511
|
-
end)
|
|
512
|
-
:Then(function()
|
|
513
|
-
return { [SaveSlotConstants.TELEPORT_DATA_EPHEMERAL_KEY] = storeKey }
|
|
514
|
-
end)
|
|
515
|
-
:Catch(function()
|
|
516
|
-
return nil
|
|
517
|
-
end)
|
|
518
|
-
end)
|
|
322
|
+
return self._slotsDataStore:PromiseBuildEphemeralTransferSlice()
|
|
519
323
|
end
|
|
520
324
|
|
|
521
325
|
--[=[
|
|
@@ -524,10 +328,12 @@ end
|
|
|
524
328
|
the common case, e.g. a menu resume hop -- carries it too; a server-initiated teleport still works via
|
|
525
329
|
the trusted band. Resolves to the slot id, or nil when none arrived.
|
|
526
330
|
|
|
527
|
-
Because the client band is honored, a client can present any key it knows
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
331
|
+
Because the client band is honored, a client can present any key it knows -- which is why the entry
|
|
332
|
+
behind it must have been written as a transfer (see [SaveSlotExportUtils.Kind]). A share code, the one
|
|
333
|
+
key players deliberately pass around, is refused here, so redeeming one stays a decision the server
|
|
334
|
+
makes in [HasSaveSlots.PromiseImportEphemeralSaveSlotFromCode] rather than something a teleport can do.
|
|
335
|
+
A transfer key is itself replicated (see `ActiveTransferableEphemeralKey`) and only ever seeds a
|
|
336
|
+
throwaway, never-persisted slot, so what it exposes is read-only visibility of that snapshot.
|
|
531
337
|
|
|
532
338
|
@return Promise<SlotId?>
|
|
533
339
|
]=]
|
|
@@ -552,36 +358,15 @@ end
|
|
|
552
358
|
@param generator CodeGenerator
|
|
553
359
|
]=]
|
|
554
360
|
function HasSaveSlots.SetCodeGenerator(self: HasSaveSlots, generator: SaveSlotCodeUtils.CodeGenerator): ()
|
|
555
|
-
|
|
556
|
-
self._codeGenerator = generator
|
|
557
|
-
end
|
|
558
|
-
|
|
559
|
-
-- Builds a code for a slot from the configured generator, resolving the owner's identity defensively
|
|
560
|
-
-- (player.UserId is not indexable on every stand-in) and the slot's name/index from its metadata.
|
|
561
|
-
function HasSaveSlots._generateCode(self: HasSaveSlots, slotId: SaveSlotData.SlotId): string
|
|
562
|
-
local slot = self._slotMap[slotId]
|
|
563
|
-
local metadata = if slot then SaveSlotData:Get(slot) else nil
|
|
564
|
-
local okUserId, userId = pcall(function()
|
|
565
|
-
return self._obj.UserId
|
|
566
|
-
end)
|
|
567
|
-
|
|
568
|
-
return self._codeGenerator({
|
|
569
|
-
userId = if okUserId and type(userId) == "number" then userId else nil,
|
|
570
|
-
userName = self._obj.Name,
|
|
571
|
-
slotName = metadata and metadata.SlotName,
|
|
572
|
-
slotIndex = metadata and metadata.SlotIndex,
|
|
573
|
-
})
|
|
361
|
+
self._slotsDataStore:SetCodeGenerator(generator)
|
|
574
362
|
end
|
|
575
363
|
|
|
576
364
|
--[=[
|
|
577
|
-
Exports a slot to the shared store under a fresh generated code and resolves to that code.
|
|
578
|
-
|
|
579
|
-
Defaults to the active slot. Refuses the main slot unless `allowMainSlot` is set (see
|
|
580
|
-
[HasSaveSlots.PromiseExportSlot]). The code format comes from the configured generator (see
|
|
581
|
-
[HasSaveSlots.SetCodeGenerator]).
|
|
365
|
+
Exports a slot to the shared store under a fresh generated code and resolves to that code. See
|
|
366
|
+
[HasSaveSlotsDataStore.PromiseExportSaveSlotToCode].
|
|
582
367
|
|
|
583
368
|
@param slotId SlotId? -- defaults to the active slot
|
|
584
|
-
@param allowMainSlot boolean? -- defaults to false
|
|
369
|
+
@param allowMainSlot boolean? -- defaults to false
|
|
585
370
|
@return Promise<string>
|
|
586
371
|
]=]
|
|
587
372
|
function HasSaveSlots.PromiseExportSaveSlotToCode(
|
|
@@ -589,22 +374,13 @@ function HasSaveSlots.PromiseExportSaveSlotToCode(
|
|
|
589
374
|
slotId: SaveSlotData.SlotId?,
|
|
590
375
|
allowMainSlot: boolean?
|
|
591
376
|
): Promise.Promise<string>
|
|
592
|
-
return
|
|
593
|
-
local targetSlotId = slotId or self.ActiveSlotId.Value
|
|
594
|
-
if not targetSlotId then
|
|
595
|
-
return (Promise :: any).rejected("No slot to export")
|
|
596
|
-
end
|
|
597
|
-
|
|
598
|
-
local code = self:_generateCode(targetSlotId)
|
|
599
|
-
return self:PromiseSaveSlotToSharedDataStore(targetSlotId, code, allowMainSlot):Then(function()
|
|
600
|
-
return code
|
|
601
|
-
end)
|
|
602
|
-
end)
|
|
377
|
+
return self._slotsDataStore:PromiseExportSaveSlotToCode(slotId, allowMainSlot)
|
|
603
378
|
end
|
|
604
379
|
|
|
605
380
|
--[=[
|
|
606
|
-
|
|
607
|
-
|
|
381
|
+
Redeems a share code into a fresh transferable ephemeral slot and selects it. The slot transfers
|
|
382
|
+
onward under a freshly minted key, never the code itself. See
|
|
383
|
+
[HasSaveSlotsDataStore.PromiseImportEphemeralSaveSlotFromCode].
|
|
608
384
|
|
|
609
385
|
@param code string
|
|
610
386
|
@return Promise<SlotId>
|
|
@@ -613,16 +389,15 @@ function HasSaveSlots.PromiseImportEphemeralSaveSlotFromCode(
|
|
|
613
389
|
self: HasSaveSlots,
|
|
614
390
|
code: string
|
|
615
391
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
616
|
-
return self:
|
|
392
|
+
return self._slotsDataStore:PromiseImportEphemeralSaveSlotFromCode(code)
|
|
617
393
|
end
|
|
618
394
|
|
|
619
395
|
--[=[
|
|
620
|
-
Exports a slot as a raw JSON string (no shared store)
|
|
621
|
-
|
|
622
|
-
[HasSaveSlots.PromiseExportSlot]).
|
|
396
|
+
Exports a slot as a raw JSON string (no shared store). See
|
|
397
|
+
[HasSaveSlotsDataStore.PromiseExportSaveSlotToJson].
|
|
623
398
|
|
|
624
399
|
@param slotId SlotId? -- defaults to the active slot
|
|
625
|
-
@param allowMainSlot boolean? -- defaults to false
|
|
400
|
+
@param allowMainSlot boolean? -- defaults to false
|
|
626
401
|
@return Promise<string>
|
|
627
402
|
]=]
|
|
628
403
|
function HasSaveSlots.PromiseExportSaveSlotToJson(
|
|
@@ -630,103 +405,23 @@ function HasSaveSlots.PromiseExportSaveSlotToJson(
|
|
|
630
405
|
slotId: SaveSlotData.SlotId?,
|
|
631
406
|
allowMainSlot: boolean?
|
|
632
407
|
): Promise.Promise<string>
|
|
633
|
-
return
|
|
634
|
-
local targetSlotId = slotId or self.ActiveSlotId.Value
|
|
635
|
-
if not targetSlotId then
|
|
636
|
-
return (Promise :: any).rejected("No slot to export")
|
|
637
|
-
end
|
|
638
|
-
|
|
639
|
-
return self:PromiseExportSlot(targetSlotId, allowMainSlot):Then(function(export)
|
|
640
|
-
return HttpService:JSONEncode(export)
|
|
641
|
-
end)
|
|
642
|
-
end)
|
|
408
|
+
return self._slotsDataStore:PromiseExportSaveSlotToJson(slotId, allowMainSlot)
|
|
643
409
|
end
|
|
644
410
|
|
|
645
411
|
--[=[
|
|
646
|
-
Duplicates the slot with the given ID into a new slot at the lowest free index,
|
|
647
|
-
|
|
648
|
-
its metadata (playtime, timestamps) starts fresh, and its name is suffixed with
|
|
649
|
-
" (Copy)". Rejects when the source slot is missing or every index is in use.
|
|
650
|
-
|
|
651
|
-
An ephemeral slot may be duplicated: the copy is a real, persisted slot seeded with the ephemeral
|
|
652
|
-
slot's live in-memory data, which is how a throwaway session is turned into a save. It keeps the
|
|
653
|
-
source's name unsuffixed (the copy is the first real slot for that session, not a second copy of an
|
|
654
|
-
existing save) and, like any duplicate, is not selected -- see
|
|
655
|
-
[HasSaveSlots.PromisePersistEphemeralSlot] for the version that continues play on the new slot.
|
|
412
|
+
Duplicates the slot with the given ID into a new slot at the lowest free index, copying its saved
|
|
413
|
+
data and accrued playtime. See [HasSaveSlotsDataStore.PromiseDuplicateSlot].
|
|
656
414
|
]=]
|
|
657
415
|
function HasSaveSlots.PromiseDuplicateSlot(
|
|
658
416
|
self: HasSaveSlots,
|
|
659
417
|
slotId: SaveSlotData.SlotId
|
|
660
418
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
661
|
-
return
|
|
662
|
-
local sourceSlot = self._slotMap[slotId]
|
|
663
|
-
if not sourceSlot then
|
|
664
|
-
return (Promise :: any).rejected(`Slot \{{slotId}\} not found`)
|
|
665
|
-
end
|
|
666
|
-
|
|
667
|
-
local sourceIsEphemeral = self:_isEphemeral(slotId)
|
|
668
|
-
|
|
669
|
-
-- Lowest free positive index, filling gaps left by deletions (mirrors PromiseSelectNewSaveSlot).
|
|
670
|
-
local usedIndices = {}
|
|
671
|
-
for existingSlotId, slot in self._slotMap do
|
|
672
|
-
if not self:_isEphemeral(existingSlotId) then
|
|
673
|
-
usedIndices[SaveSlotData.SlotIndex:Get(slot)] = true
|
|
674
|
-
end
|
|
675
|
-
end
|
|
676
|
-
local freeIndex = 1
|
|
677
|
-
while usedIndices[freeIndex] do
|
|
678
|
-
freeIndex += 1
|
|
679
|
-
end
|
|
680
|
-
if freeIndex > self.MaxSlotCount.Value then
|
|
681
|
-
return (Promise :: any).rejected("All slots are already in use")
|
|
682
|
-
end
|
|
683
|
-
|
|
684
|
-
local sourceMetadata = SaveSlotData:Get(sourceSlot)
|
|
685
|
-
|
|
686
|
-
-- Read the source's saved data before creating the copy so a read failure leaves no orphan slot.
|
|
687
|
-
return self:_getSlotStore(slotId):LoadAll({}):Then(function(sourceData)
|
|
688
|
-
-- The default slot shares the player's root store with the SaveSlots system data. Never carry
|
|
689
|
-
-- that system key across into the copy's saved data.
|
|
690
|
-
local slotData = if type(sourceData) == "table" then table.clone(sourceData) else {}
|
|
691
|
-
slotData[SaveSlotConstants.SYSTEM_STORE_KEY] = nil
|
|
692
|
-
|
|
693
|
-
return self
|
|
694
|
-
:PromiseCreateSlot(freeIndex, {
|
|
695
|
-
SlotName = if sourceIsEphemeral
|
|
696
|
-
then sourceMetadata.SlotName
|
|
697
|
-
else `{sourceMetadata.SlotName} (Copy)`,
|
|
698
|
-
Summary = sourceMetadata.Summary,
|
|
699
|
-
})
|
|
700
|
-
:Then(function(newSlotId: SaveSlotData.SlotId)
|
|
701
|
-
local destStore = self:_getSlotStore(newSlotId)
|
|
702
|
-
|
|
703
|
-
if destStore == self._dataStore then
|
|
704
|
-
-- The copy is the default slot, whose store is the shared root. Merge so the SaveSlots
|
|
705
|
-
-- system store living alongside it survives (a plain Overwrite would wipe it).
|
|
706
|
-
destStore:OverwriteMerge(slotData)
|
|
707
|
-
else
|
|
708
|
-
destStore:Overwrite(slotData)
|
|
709
|
-
end
|
|
710
|
-
|
|
711
|
-
-- Flush so the duplicated data survives a crash before the next autosave.
|
|
712
|
-
return self._dataStore:Save():Then(function()
|
|
713
|
-
return newSlotId
|
|
714
|
-
end)
|
|
715
|
-
end)
|
|
716
|
-
end)
|
|
717
|
-
end)
|
|
419
|
+
return self._slotsDataStore:PromiseDuplicateSlot(slotId)
|
|
718
420
|
end
|
|
719
421
|
|
|
720
422
|
--[=[
|
|
721
|
-
Turns an ephemeral slot into a real save
|
|
722
|
-
|
|
723
|
-
is now being written. Defaults to the active slot, which in practice is the only ephemeral slot there
|
|
724
|
-
is -- one stops existing the moment it stops being active. Resolves to the new slot's id.
|
|
725
|
-
|
|
726
|
-
The copy is taken from the ephemeral slot's live in-memory data at the moment this runs, and selecting
|
|
727
|
-
the new slot retires the ephemeral one, so anything written to the old store between the copy and the
|
|
728
|
-
selection is dropped. Rejects when no slot is active, the slot is missing, the slot is not ephemeral,
|
|
729
|
-
or every index is in use.
|
|
423
|
+
Turns an ephemeral slot into a real save and selects it. See
|
|
424
|
+
[HasSaveSlotsDataStore.PromisePersistEphemeralSlot].
|
|
730
425
|
|
|
731
426
|
@param slotId SlotId? -- defaults to the active slot
|
|
732
427
|
@return Promise<SlotId>
|
|
@@ -735,88 +430,14 @@ function HasSaveSlots.PromisePersistEphemeralSlot(
|
|
|
735
430
|
self: HasSaveSlots,
|
|
736
431
|
slotId: SaveSlotData.SlotId?
|
|
737
432
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
738
|
-
return
|
|
739
|
-
local targetSlotId = slotId or self.ActiveSlotId.Value
|
|
740
|
-
if not targetSlotId then
|
|
741
|
-
return (Promise :: any).rejected("No slot to persist")
|
|
742
|
-
end
|
|
743
|
-
|
|
744
|
-
if not self._slotMap[targetSlotId] then
|
|
745
|
-
return (Promise :: any).rejected(`Slot \{{targetSlotId}\} not found`)
|
|
746
|
-
end
|
|
747
|
-
|
|
748
|
-
if not self:_isEphemeral(targetSlotId) then
|
|
749
|
-
return (Promise :: any).rejected(`Slot \{{targetSlotId}\} is already persisted`)
|
|
750
|
-
end
|
|
751
|
-
|
|
752
|
-
return self:PromiseDuplicateSlot(targetSlotId):Then(function(newSlotId: SaveSlotData.SlotId)
|
|
753
|
-
return self:PromiseSelectSlot(newSlotId):Then(function()
|
|
754
|
-
return newSlotId
|
|
755
|
-
end)
|
|
756
|
-
end)
|
|
757
|
-
end)
|
|
433
|
+
return self._slotsDataStore:PromisePersistEphemeralSlot(slotId)
|
|
758
434
|
end
|
|
759
435
|
|
|
760
436
|
--[=[
|
|
761
|
-
Deletes the slot with the given ID.
|
|
762
|
-
and retired along with its in-memory store -- rather than being refused for being the active slot.
|
|
437
|
+
Deletes the slot with the given ID. See [HasSaveSlotsDataStore.PromiseDeleteSlot].
|
|
763
438
|
]=]
|
|
764
439
|
function HasSaveSlots.PromiseDeleteSlot(self: HasSaveSlots, slotId: SaveSlotData.SlotId): Promise.Promise<any>
|
|
765
|
-
return
|
|
766
|
-
-- An ephemeral slot only exists while it is active, so deleting one is retiring it. Nothing was
|
|
767
|
-
-- ever persisted, so there is no stored data to wipe afterwards -- hence the early return.
|
|
768
|
-
if self:_isEphemeral(slotId) then
|
|
769
|
-
if slotId == self.ActiveSlotId.Value then
|
|
770
|
-
return self:PromiseDeselectSlot()
|
|
771
|
-
end
|
|
772
|
-
self:_destroyEphemeralSlot(slotId)
|
|
773
|
-
return (Promise :: any).resolved()
|
|
774
|
-
end
|
|
775
|
-
|
|
776
|
-
if slotId == self.ActiveSlotId.Value then
|
|
777
|
-
return (Promise :: any).rejected("Cannot delete active slot")
|
|
778
|
-
end
|
|
779
|
-
|
|
780
|
-
local slot = self._slotMap[slotId]
|
|
781
|
-
if not slot then
|
|
782
|
-
return (Promise :: any).rejected(`Slot \{{slotId}\} not found`)
|
|
783
|
-
end
|
|
784
|
-
|
|
785
|
-
self._maid[slotId] = nil
|
|
786
|
-
|
|
787
|
-
-- The continue pointer must not outlive its slot. When the deleted slot is the one the player
|
|
788
|
-
-- would resume on (e.g. the just-deselected active slot, or a never-reselected last-active),
|
|
789
|
-
-- clear the last-active memory so "Continue" stops offering a slot that no longer exists.
|
|
790
|
-
if slotId == self._lastActiveSlotId then
|
|
791
|
-
self._lastActiveSlotId = nil
|
|
792
|
-
self.LastActiveSlotId.Value = nil
|
|
793
|
-
end
|
|
794
|
-
|
|
795
|
-
-- Wipe default slot
|
|
796
|
-
local slotIndex = SaveSlotData.SlotIndex:Get(slot)
|
|
797
|
-
local deletePromise = nil
|
|
798
|
-
|
|
799
|
-
if slotIndex == SaveSlotConstants.DEFAULT_SLOT_INDEX then
|
|
800
|
-
deletePromise = self._dataStore:PromiseKeyList():Then(function(keys)
|
|
801
|
-
for _, key in keys do
|
|
802
|
-
if key ~= SaveSlotConstants.SYSTEM_STORE_KEY then
|
|
803
|
-
self._dataStore:Delete(key)
|
|
804
|
-
end
|
|
805
|
-
end
|
|
806
|
-
self._metadataStore:Delete(slotId)
|
|
807
|
-
end)
|
|
808
|
-
else
|
|
809
|
-
-- Or delete slot from substore
|
|
810
|
-
self._systemStore:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY):Delete(slotId)
|
|
811
|
-
self._metadataStore:Delete(slotId)
|
|
812
|
-
deletePromise = (Promise :: any).resolved()
|
|
813
|
-
end
|
|
814
|
-
|
|
815
|
-
-- Flush the deletion to prevent stale reads
|
|
816
|
-
return deletePromise:Then(function()
|
|
817
|
-
return self._dataStore:Save()
|
|
818
|
-
end)
|
|
819
|
-
end)
|
|
440
|
+
return self._slotsDataStore:PromiseDeleteSlot(slotId)
|
|
820
441
|
end
|
|
821
442
|
|
|
822
443
|
--[=[
|
|
@@ -825,104 +446,25 @@ end
|
|
|
825
446
|
are gone.
|
|
826
447
|
]=]
|
|
827
448
|
function HasSaveSlots.PromiseDeleteAllSlots(self: HasSaveSlots): Promise.Promise<any>
|
|
828
|
-
return
|
|
829
|
-
-- Clear the selection first so the previously active slot is deletable
|
|
830
|
-
self.ActiveSlotId.Value = nil
|
|
831
|
-
self._lastActiveSlotId = nil
|
|
832
|
-
self.LastActiveSlotId.Value = nil
|
|
833
|
-
|
|
834
|
-
local slotIds = {}
|
|
835
|
-
for slotId in self._slotMap do
|
|
836
|
-
table.insert(slotIds, slotId)
|
|
837
|
-
end
|
|
838
|
-
|
|
839
|
-
-- Delete sequentially to avoid concurrent datastore saves
|
|
840
|
-
local promise = (Promise :: any).resolved()
|
|
841
|
-
for _, slotId in slotIds do
|
|
842
|
-
promise = promise:Then(function()
|
|
843
|
-
return self:PromiseDeleteSlot(slotId)
|
|
844
|
-
end)
|
|
845
|
-
end
|
|
846
|
-
return promise
|
|
847
|
-
end)
|
|
449
|
+
return self._slotsDataStore:PromiseDeleteAllSlots()
|
|
848
450
|
end
|
|
849
451
|
|
|
850
452
|
--[=[
|
|
851
|
-
Resets the slot with the given id to a fresh empty one
|
|
852
|
-
and creating a new one at the same index. The slot keeps its index and name; its saved data
|
|
853
|
-
and metadata (timestamps) start fresh. Resolves to the new slot id.
|
|
854
|
-
|
|
855
|
-
When the reset slot is the active slot, the selection clears and then reselects the fresh
|
|
856
|
-
slot: everything bound to [HasSaveSlots.ObserveActiveSlotStoreBrio] tears down as the
|
|
857
|
-
selection clears and rebuilds against the empty store on reselect, so consumers reset
|
|
858
|
-
reactively without wiping their own state. A non-active slot is left unselected, and its
|
|
859
|
-
"Continue" pointer (when it was the last-active slot) is carried across to the fresh id so
|
|
860
|
-
the reset slot stays resumable. Rejects when the slot is missing.
|
|
453
|
+
Resets the slot with the given id to a fresh empty one. See [HasSaveSlotsDataStore.PromiseResetSlot].
|
|
861
454
|
]=]
|
|
862
455
|
function HasSaveSlots.PromiseResetSlot(
|
|
863
456
|
self: HasSaveSlots,
|
|
864
457
|
slotId: SaveSlotData.SlotId
|
|
865
458
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
866
|
-
return
|
|
867
|
-
local slot = self._slotMap[slotId]
|
|
868
|
-
if not slot then
|
|
869
|
-
return (Promise :: any).rejected(`Slot \{{slotId}\} not found`)
|
|
870
|
-
end
|
|
871
|
-
|
|
872
|
-
if self:_isEphemeral(slotId) then
|
|
873
|
-
return (Promise :: any).rejected("Cannot reset an ephemeral slot")
|
|
874
|
-
end
|
|
875
|
-
|
|
876
|
-
local metadata = SaveSlotData:Get(slot)
|
|
877
|
-
local wasActive = (slotId == self.ActiveSlotId.Value)
|
|
878
|
-
-- PromiseDeleteSlot clears the continue pointer when it targets the last-active slot; capture it
|
|
879
|
-
-- now so the non-active path can move it onto the fresh slot id below.
|
|
880
|
-
local wasLastActive = (slotId == self._lastActiveSlotId)
|
|
881
|
-
|
|
882
|
-
if wasActive then
|
|
883
|
-
-- Clear the selection so the slot is deletable, skipping the deselect flush that would
|
|
884
|
-
-- persist progress we are about to delete.
|
|
885
|
-
self.ActiveSlotId.Value = nil
|
|
886
|
-
end
|
|
887
|
-
|
|
888
|
-
return self:PromiseDeleteSlot(slotId)
|
|
889
|
-
:Then(function()
|
|
890
|
-
return self:PromiseCreateSlot(metadata.SlotIndex, { SlotName = metadata.SlotName })
|
|
891
|
-
end)
|
|
892
|
-
:Then(function(newSlotId: SaveSlotData.SlotId)
|
|
893
|
-
if wasActive then
|
|
894
|
-
-- Reselecting restores the continue pointer via the ActiveSlotId hook.
|
|
895
|
-
return self:PromiseSelectSlot(newSlotId):Then(function()
|
|
896
|
-
return newSlotId
|
|
897
|
-
end)
|
|
898
|
-
end
|
|
899
|
-
|
|
900
|
-
-- Non-active reset never reselects, so carry the resume pointer onto the fresh id
|
|
901
|
-
-- ourselves when this slot was the one "Continue" would resume.
|
|
902
|
-
if wasLastActive then
|
|
903
|
-
self._lastActiveSlotId = newSlotId
|
|
904
|
-
self.LastActiveSlotId.Value = newSlotId
|
|
905
|
-
end
|
|
906
|
-
|
|
907
|
-
return newSlotId
|
|
908
|
-
end)
|
|
909
|
-
end)
|
|
459
|
+
return self._slotsDataStore:PromiseResetSlot(slotId)
|
|
910
460
|
end
|
|
911
461
|
|
|
912
462
|
--[=[
|
|
913
|
-
Resets the active slot to a fresh empty one -- see [HasSaveSlots.PromiseResetSlot].
|
|
914
|
-
|
|
915
|
-
slot stays selected. Resolves to the new slot id, or nil when no slot is active.
|
|
463
|
+
Resets the active slot to a fresh empty one -- see [HasSaveSlots.PromiseResetSlot]. Resolves to the
|
|
464
|
+
new slot id, or nil when no slot is active.
|
|
916
465
|
]=]
|
|
917
466
|
function HasSaveSlots.PromiseResetActiveSlot(self: HasSaveSlots): Promise.Promise<SaveSlotData.SlotId?>
|
|
918
|
-
return
|
|
919
|
-
local slotId = self.ActiveSlotId.Value
|
|
920
|
-
if not slotId then
|
|
921
|
-
return nil -- Nothing selected to reset
|
|
922
|
-
end
|
|
923
|
-
|
|
924
|
-
return self:PromiseResetSlot(slotId)
|
|
925
|
-
end)
|
|
467
|
+
return self._slotsDataStore:PromiseResetActiveSlot()
|
|
926
468
|
end
|
|
927
469
|
|
|
928
470
|
--[=[
|
|
@@ -933,20 +475,7 @@ function HasSaveSlots.PromiseSetSlotMetadata(
|
|
|
933
475
|
slotId: SaveSlotData.SlotId,
|
|
934
476
|
data: SaveSlotData.SaveSlotMetadata
|
|
935
477
|
): Promise.Promise<any>
|
|
936
|
-
|
|
937
|
-
return (Promise :: any).rejected("SlotId is locked")
|
|
938
|
-
end
|
|
939
|
-
|
|
940
|
-
return (self._loadPromise :: any):Then(function()
|
|
941
|
-
local slot = self._slotMap[slotId]
|
|
942
|
-
|
|
943
|
-
-- Routing depends on immutable indices to distinguish the default slot
|
|
944
|
-
if data.SlotIndex and (data.SlotIndex ~= SaveSlotData.SlotIndex:Get(slot)) then
|
|
945
|
-
return (Promise :: any).rejected("SlotIndex is locked")
|
|
946
|
-
end
|
|
947
|
-
|
|
948
|
-
SaveSlotData:Set(slot, data)
|
|
949
|
-
end)
|
|
478
|
+
return self._slotsDataStore:PromiseSetSlotMetadata(slotId, data)
|
|
950
479
|
end
|
|
951
480
|
|
|
952
481
|
--[=[
|
|
@@ -956,10 +485,7 @@ function HasSaveSlots.PromiseGetSlotMetadata(
|
|
|
956
485
|
self: HasSaveSlots,
|
|
957
486
|
slotId: SaveSlotData.SlotId
|
|
958
487
|
): Promise.Promise<SaveSlotData.SaveSlotMetadata?>
|
|
959
|
-
return
|
|
960
|
-
local slot = self._slotMap[slotId]
|
|
961
|
-
return (Promise :: any).resolved(slot and SaveSlotData:Get(slot))
|
|
962
|
-
end)
|
|
488
|
+
return self._slotsDataStore:PromiseGetSlotMetadata(slotId)
|
|
963
489
|
end
|
|
964
490
|
|
|
965
491
|
--[=[
|
|
@@ -969,26 +495,14 @@ function HasSaveSlots.PromiseSlotIdFromIndex(
|
|
|
969
495
|
self: HasSaveSlots,
|
|
970
496
|
slotIndex: number
|
|
971
497
|
): Promise.Promise<SaveSlotData.SlotId?>
|
|
972
|
-
return
|
|
973
|
-
for slotId, slot in self._slotMap do
|
|
974
|
-
if self:_isEphemeral(slotId) then
|
|
975
|
-
continue -- ephemeral slots are never addressable by index
|
|
976
|
-
end
|
|
977
|
-
if slotIndex == SaveSlotData.SlotIndex:Get(slot) then
|
|
978
|
-
return (Promise :: any).resolved(slotId)
|
|
979
|
-
end
|
|
980
|
-
end
|
|
981
|
-
return (Promise :: any).resolved(nil)
|
|
982
|
-
end)
|
|
498
|
+
return self._slotsDataStore:PromiseSlotIdFromIndex(slotIndex)
|
|
983
499
|
end
|
|
984
500
|
|
|
985
501
|
--[=[
|
|
986
502
|
Gets the last active slot ID
|
|
987
503
|
]=]
|
|
988
504
|
function HasSaveSlots.PromiseLastActiveSlotId(self: HasSaveSlots): Promise.Promise<SaveSlotData.SlotId?>
|
|
989
|
-
return
|
|
990
|
-
return self.ActiveSlotId.Value or self._lastActiveSlotId
|
|
991
|
-
end)
|
|
505
|
+
return self._slotsDataStore:PromiseLastActiveSlotId()
|
|
992
506
|
end
|
|
993
507
|
|
|
994
508
|
--[=[
|
|
@@ -997,21 +511,7 @@ end
|
|
|
997
511
|
"Continue" affordance that every save-slot consumer tends to need.
|
|
998
512
|
]=]
|
|
999
513
|
function HasSaveSlots.PromiseSelectLastSaveSlot(self: HasSaveSlots): Promise.Promise<SaveSlotData.SlotId?>
|
|
1000
|
-
return self:
|
|
1001
|
-
if not lastActiveSlotId then
|
|
1002
|
-
return nil
|
|
1003
|
-
end
|
|
1004
|
-
|
|
1005
|
-
return self:PromiseHasSlot(lastActiveSlotId):Then(function(hasLastSlot: boolean)
|
|
1006
|
-
if not hasLastSlot then
|
|
1007
|
-
return nil
|
|
1008
|
-
end
|
|
1009
|
-
|
|
1010
|
-
return self:PromiseSelectSlot(lastActiveSlotId):Then(function()
|
|
1011
|
-
return lastActiveSlotId
|
|
1012
|
-
end)
|
|
1013
|
-
end)
|
|
1014
|
-
end)
|
|
514
|
+
return self._slotsDataStore:PromiseSelectLastSaveSlot()
|
|
1015
515
|
end
|
|
1016
516
|
|
|
1017
517
|
--[=[
|
|
@@ -1020,45 +520,12 @@ end
|
|
|
1020
520
|
affordance.
|
|
1021
521
|
]=]
|
|
1022
522
|
function HasSaveSlots.PromiseSelectNewSaveSlot(self: HasSaveSlots): Promise.Promise<SaveSlotData.SlotId?>
|
|
1023
|
-
return
|
|
1024
|
-
local usedIndices = {}
|
|
1025
|
-
for existingSlotId, slot in self._slotMap do
|
|
1026
|
-
if not self:_isEphemeral(existingSlotId) then
|
|
1027
|
-
usedIndices[SaveSlotData.SlotIndex:Get(slot)] = true
|
|
1028
|
-
end
|
|
1029
|
-
end
|
|
1030
|
-
|
|
1031
|
-
-- Lowest free positive index. Fills gaps left by deletions (delete slot 2 of
|
|
1032
|
-
-- [1,2,3] and the next new slot reuses index 2). With a finite MaxSlotCount this
|
|
1033
|
-
-- returns nil once [1, MaxSlotCount] is full; with an unbounded count (math.huge)
|
|
1034
|
-
-- there is always a next integer, so it never returns nil.
|
|
1035
|
-
local freeIndex = 1
|
|
1036
|
-
while usedIndices[freeIndex] do
|
|
1037
|
-
freeIndex += 1
|
|
1038
|
-
end
|
|
1039
|
-
|
|
1040
|
-
if freeIndex > self.MaxSlotCount.Value then
|
|
1041
|
-
return nil
|
|
1042
|
-
end
|
|
1043
|
-
|
|
1044
|
-
return self:PromiseCreateSlot(freeIndex):Then(function(slotId: SaveSlotData.SlotId)
|
|
1045
|
-
return self:PromiseSelectSlot(slotId):Then(function()
|
|
1046
|
-
return slotId
|
|
1047
|
-
end)
|
|
1048
|
-
end)
|
|
1049
|
-
end)
|
|
523
|
+
return self._slotsDataStore:PromiseSelectNewSaveSlot()
|
|
1050
524
|
end
|
|
1051
525
|
|
|
1052
526
|
--[=[
|
|
1053
|
-
Creates a fresh ephemeral slot and selects it, resolving to its id.
|
|
1054
|
-
|
|
1055
|
-
playtime the same way, and its metadata replicates to the client like any other slot's, so UI can render
|
|
1056
|
-
the active session's name and summary -- but it is never persisted: no metadata is written, its data store
|
|
1057
|
-
is in-memory, and it is torn down the moment it stops being the active slot. It is also excluded from the
|
|
1058
|
-
save list ([SaveSlotDataService.GetSlotList] / [SaveSlotDataService.ObserveSlotList]), so it never shows up
|
|
1059
|
-
as something the player can return to. Selecting it never disturbs the persisted active-slot pointer or the
|
|
1060
|
-
"Continue" target, so the real slot the player came from resumes untouched afterward. Backs a throwaway
|
|
1061
|
-
session (e.g. exploring a lobby) that must leave no trace on save data.
|
|
527
|
+
Creates a fresh ephemeral slot and selects it, resolving to its id. See
|
|
528
|
+
[HasSaveSlotsDataStore.PromiseSelectEphemeralSlot].
|
|
1062
529
|
|
|
1063
530
|
@param metadata SaveSlotCreateMetadata? -- optional SlotName/Summary for the in-memory slot
|
|
1064
531
|
@return Promise<SlotId>
|
|
@@ -1067,22 +534,7 @@ function HasSaveSlots.PromiseSelectEphemeralSlot(
|
|
|
1067
534
|
self: HasSaveSlots,
|
|
1068
535
|
metadata: SaveSlotCreateMetadata?
|
|
1069
536
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
1070
|
-
return
|
|
1071
|
-
local slotId = HttpService:GenerateGUID(false)
|
|
1072
|
-
local data = {
|
|
1073
|
-
SlotId = slotId,
|
|
1074
|
-
SlotIndex = SaveSlotConstants.EPHEMERAL_SLOT_INDEX,
|
|
1075
|
-
SlotName = (metadata and metadata.SlotName) or "Ephemeral",
|
|
1076
|
-
CreatedTime = os.time(),
|
|
1077
|
-
Summary = metadata and metadata.Summary,
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
self:_buildSlot(slotId, data, true, true)
|
|
1081
|
-
|
|
1082
|
-
return self:PromiseSelectSlot(slotId):Then(function()
|
|
1083
|
-
return slotId
|
|
1084
|
-
end)
|
|
1085
|
-
end)
|
|
537
|
+
return self._slotsDataStore:PromiseSelectEphemeralSlot(metadata)
|
|
1086
538
|
end
|
|
1087
539
|
|
|
1088
540
|
--[=[
|
|
@@ -1118,198 +570,6 @@ function HasSaveSlots.PromiseIncomingSlotId(self: HasSaveSlots): Promise.Promise
|
|
|
1118
570
|
end)
|
|
1119
571
|
end
|
|
1120
572
|
|
|
1121
|
-
-- Maid-owning every hop is what makes this safe, for the same reason as the selection chain in
|
|
1122
|
-
-- SaveSlotService: a session-locked or retrying read settles long after the player left, and Promise has no
|
|
1123
|
-
-- cancellation, so owning only the outermost promise detaches nothing upstream. Calling into this destroyed
|
|
1124
|
-
-- (metatable-stripped) object -- or into its destroyed stores -- throws, and because a datastore load
|
|
1125
|
-
-- resolves inside its UpdateAsync transform, that throw surfaces as a "Transform function error" and takes
|
|
1126
|
-
-- the transform's write down with it. The liveness checks cover a settle that lands mid-teardown, before
|
|
1127
|
-
-- this promise's own maid task was reached. See SaveSlotLateSettle.spec.
|
|
1128
|
-
function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
|
|
1129
|
-
return self._maid:GivePromise(self._playerDataStoreService:PromiseDataStore(self._obj)):Then(function(dataStore)
|
|
1130
|
-
if not self.Destroy then
|
|
1131
|
-
return nil -- Destroyed
|
|
1132
|
-
end
|
|
1133
|
-
|
|
1134
|
-
self._dataStore = dataStore
|
|
1135
|
-
self._systemStore = dataStore:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
1136
|
-
self._metadataStore = self._systemStore:GetSubStore(SaveSlotConstants.METADATA_STORE_KEY)
|
|
1137
|
-
|
|
1138
|
-
return self._maid:GivePromise(self._metadataStore:LoadAll({})):Then(function(metadata)
|
|
1139
|
-
if not self.Destroy then
|
|
1140
|
-
return nil -- Destroyed
|
|
1141
|
-
end
|
|
1142
|
-
|
|
1143
|
-
for slotId, data in metadata do
|
|
1144
|
-
self:_buildSlot(slotId, data)
|
|
1145
|
-
end
|
|
1146
|
-
|
|
1147
|
-
return self._maid
|
|
1148
|
-
:GivePromise(self._systemStore:Load("activeSlotId"))
|
|
1149
|
-
:Then(function(activeId: SaveSlotData.SlotId?)
|
|
1150
|
-
if not self.Destroy then
|
|
1151
|
-
return nil -- Destroyed
|
|
1152
|
-
end
|
|
1153
|
-
|
|
1154
|
-
self._lastActiveSlotId = activeId
|
|
1155
|
-
self.LastActiveSlotId.Value = activeId
|
|
1156
|
-
|
|
1157
|
-
-- The persisted active-slot pointer and the replicated "Continue" target only ever track real
|
|
1158
|
-
-- slots. This replaces StoreOnValueChange so an ephemeral selection is invisible to both:
|
|
1159
|
-
-- entering one leaves them pinned to the real slot, and the ephemeral slot is torn down the
|
|
1160
|
-
-- moment it stops being active. We track the id we are leaving to know which of those to do.
|
|
1161
|
-
local previousActiveSlotId: SaveSlotData.SlotId? = activeId
|
|
1162
|
-
|
|
1163
|
-
self._maid:GiveTask(self.ActiveSlotId.Changed:Connect(function()
|
|
1164
|
-
local active = self.ActiveSlotId.Value
|
|
1165
|
-
|
|
1166
|
-
-- Replicate the active transferable-ephemeral slot's shared-store key (nil otherwise) so a
|
|
1167
|
-
-- client-initiated teleport can carry it forward (SaveSlotServiceClient's provider reads this).
|
|
1168
|
-
self.ActiveTransferableEphemeralKey.Value = if active
|
|
1169
|
-
then self._transferableEphemeralKeys[active]
|
|
1170
|
-
else nil
|
|
1171
|
-
|
|
1172
|
-
local leftSlotId = previousActiveSlotId
|
|
1173
|
-
-- Read before the retire below, while the outgoing slot is still in the map.
|
|
1174
|
-
local leavingEphemeral = self:_isEphemeral(leftSlotId)
|
|
1175
|
-
previousActiveSlotId = active
|
|
1176
|
-
|
|
1177
|
-
-- Persist the pointer + remember the Continue target only for real-slot transitions
|
|
1178
|
-
-- (real -> real, real -> nil deselect, nil -> real). Skip both ephemeral cases: entering an
|
|
1179
|
-
-- ephemeral slot must stay invisible to persistence, and leaving one back to no slot must
|
|
1180
|
-
-- leave the real pointer pinned where it was.
|
|
1181
|
-
local enteringEphemeral = self:_isEphemeral(active)
|
|
1182
|
-
local leavingEphemeralToMenu = leavingEphemeral and active == nil
|
|
1183
|
-
if not (enteringEphemeral or leavingEphemeralToMenu) then
|
|
1184
|
-
self._systemStore:Store("activeSlotId", active)
|
|
1185
|
-
if active ~= nil then
|
|
1186
|
-
self._lastActiveSlotId = active
|
|
1187
|
-
self.LastActiveSlotId.Value = active
|
|
1188
|
-
end
|
|
1189
|
-
end
|
|
1190
|
-
|
|
1191
|
-
-- An ephemeral slot exists only while it is the active slot; retire the one we just left.
|
|
1192
|
-
if leavingEphemeral and leftSlotId ~= active then
|
|
1193
|
-
self:_destroyEphemeralSlot(leftSlotId :: SaveSlotData.SlotId)
|
|
1194
|
-
end
|
|
1195
|
-
end))
|
|
1196
|
-
|
|
1197
|
-
-- Matches the liveness-guard returns above, which make this callback's inferred return
|
|
1198
|
-
-- type nil; falling off the end instead returns no values at all.
|
|
1199
|
-
return nil
|
|
1200
|
-
end)
|
|
1201
|
-
end)
|
|
1202
|
-
end)
|
|
1203
|
-
end
|
|
1204
|
-
|
|
1205
|
-
function HasSaveSlots._getSlotStore(self: HasSaveSlots, slotId: SaveSlotData.SlotId): DataStoreStage.DataStoreStage
|
|
1206
|
-
local ephemeralStore = self._ephemeralStores[slotId]
|
|
1207
|
-
if ephemeralStore then
|
|
1208
|
-
return ephemeralStore
|
|
1209
|
-
end
|
|
1210
|
-
|
|
1211
|
-
local slot = self._slotMap[slotId]
|
|
1212
|
-
if slot and (SaveSlotData.SlotIndex:Get(slot) == SaveSlotConstants.DEFAULT_SLOT_INDEX) then
|
|
1213
|
-
return self._dataStore
|
|
1214
|
-
end
|
|
1215
|
-
return self._systemStore:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY):GetSubStore(slotId)
|
|
1216
|
-
end
|
|
1217
|
-
|
|
1218
|
-
local MUTABLE_METADATA_KEYS =
|
|
1219
|
-
{ "SlotName", "CreatedTime", "LastPlayedTime", "Summary", "TimePlayed", "PlayCount", "LastSessionLength" }
|
|
1220
|
-
|
|
1221
|
-
function HasSaveSlots._buildSlot(
|
|
1222
|
-
self: HasSaveSlots,
|
|
1223
|
-
slotId: SaveSlotData.SlotId,
|
|
1224
|
-
data: SaveSlotData.SaveSlotMetadata,
|
|
1225
|
-
isNew: boolean?,
|
|
1226
|
-
isEphemeral: boolean?
|
|
1227
|
-
): ()
|
|
1228
|
-
local maid = Maid.new()
|
|
1229
|
-
self._maid[slotId] = maid
|
|
1230
|
-
|
|
1231
|
-
local slot = maid:Add(Instance.new("Folder"))
|
|
1232
|
-
slot.Name = slotId
|
|
1233
|
-
slot.Archivable = false
|
|
1234
|
-
|
|
1235
|
-
local attributes = SaveSlotData:Create(slot)
|
|
1236
|
-
attributes.SlotId.Value = slotId
|
|
1237
|
-
attributes.SlotIndex.Value = data.SlotIndex
|
|
1238
|
-
|
|
1239
|
-
if isEphemeral then
|
|
1240
|
-
-- Ephemeral: seed the metadata in memory with no write-back wiring, and back the slot with an in-memory
|
|
1241
|
-
-- store. The folder still joins the replicated container so the client can read the active slot's
|
|
1242
|
-
-- metadata (name, summary, playtime) the same way it reads a real slot's -- what makes the slot
|
|
1243
|
-
-- ephemeral is that nothing is persisted, not that it is invisible. The IsEphemeral attribute is what
|
|
1244
|
-
-- keeps it out of the save list; SaveSlotDataService's list reads filter on it.
|
|
1245
|
-
--
|
|
1246
|
-
-- The in-memory store's lifetime is owned by this slot's maid (which is in turn owned by self._maid),
|
|
1247
|
-
-- so it is Destroyed -- and becomes GC-eligible -- the instant the slot is retired (_destroyEphemeralSlot)
|
|
1248
|
-
-- or the player unbinds. Nothing outside this object holds a lasting reference: while the slot is active
|
|
1249
|
-
-- ObserveActiveSlotStoreBrio hands it out inside a Brio that dies when the slot deselects, releasing it.
|
|
1250
|
-
attributes.IsEphemeral.Value = true
|
|
1251
|
-
self._ephemeralStores[slotId] = maid:Add(InMemoryDataStore.new(slotId))
|
|
1252
|
-
|
|
1253
|
-
for _, key in MUTABLE_METADATA_KEYS do
|
|
1254
|
-
attributes[key].Value = data[key]
|
|
1255
|
-
end
|
|
1256
|
-
|
|
1257
|
-
-- Parent last, so the folder replicates carrying IsEphemeral -- a client that saw it land without the
|
|
1258
|
-
-- flag would briefly list a throwaway slot as a save.
|
|
1259
|
-
slot.Parent = self._slotContainer
|
|
1260
|
-
|
|
1261
|
-
self._slotMap[slotId] = slot
|
|
1262
|
-
maid:GiveTask(function()
|
|
1263
|
-
self._slotMap[slotId] = nil
|
|
1264
|
-
self._ephemeralStores[slotId] = nil
|
|
1265
|
-
self._transferableEphemeralKeys[slotId] = nil
|
|
1266
|
-
end)
|
|
1267
|
-
return
|
|
1268
|
-
end
|
|
1269
|
-
|
|
1270
|
-
local metadataStore = self._metadataStore:GetSubStore(slotId)
|
|
1271
|
-
|
|
1272
|
-
-- Store immutable SlotIndex once on creation
|
|
1273
|
-
if isNew then
|
|
1274
|
-
metadataStore:Store("SlotIndex", data.SlotIndex)
|
|
1275
|
-
end
|
|
1276
|
-
|
|
1277
|
-
-- Store mutable metadata on change
|
|
1278
|
-
for _, key in MUTABLE_METADATA_KEYS do
|
|
1279
|
-
attributes[key].Value = data[key]
|
|
1280
|
-
maid:GiveTask(metadataStore:StoreOnValueChange(key, attributes[key]))
|
|
1281
|
-
|
|
1282
|
-
if isNew then
|
|
1283
|
-
metadataStore:Store(key, attributes[key].Value)
|
|
1284
|
-
end
|
|
1285
|
-
end
|
|
1286
|
-
|
|
1287
|
-
slot.Parent = self._slotContainer
|
|
1288
|
-
|
|
1289
|
-
self._slotMap[slotId] = slot
|
|
1290
|
-
|
|
1291
|
-
maid:GiveTask(function()
|
|
1292
|
-
self._slotMap[slotId] = nil
|
|
1293
|
-
end)
|
|
1294
|
-
end
|
|
1295
|
-
|
|
1296
|
-
-- Whether the slot is an ephemeral (session-only, never-persisted) slot. The slot's own IsEphemeral property
|
|
1297
|
-
-- is the single source of truth (set once at creation in _buildSlot); nil-safe so callers can pass a possibly
|
|
1298
|
-
-- nil active-slot id directly.
|
|
1299
|
-
function HasSaveSlots._isEphemeral(self: HasSaveSlots, slotId: SaveSlotData.SlotId?): boolean
|
|
1300
|
-
if slotId == nil then
|
|
1301
|
-
return false
|
|
1302
|
-
end
|
|
1303
|
-
local slot = self._slotMap[slotId] :: Folder?
|
|
1304
|
-
return slot ~= nil and SaveSlotData.IsEphemeral:Get(slot) == true
|
|
1305
|
-
end
|
|
1306
|
-
|
|
1307
|
-
-- Tears down the ephemeral slot's maid (folder, in-memory store, and every map entry via the teardown task
|
|
1308
|
-
-- registered in _buildSlot). Idempotent -- clearing an already-cleared maid key is a no-op.
|
|
1309
|
-
function HasSaveSlots._destroyEphemeralSlot(self: HasSaveSlots, slotId: SaveSlotData.SlotId): ()
|
|
1310
|
-
self._maid[slotId] = nil
|
|
1311
|
-
end
|
|
1312
|
-
|
|
1313
573
|
function HasSaveSlots._setupSummary(self: HasSaveSlots): ()
|
|
1314
574
|
self._maid:GiveTask(
|
|
1315
575
|
self:ObserveActiveSlotStoreBrio():Subscribe(function(brio: Brio.Brio<DataStoreStage.DataStoreStage>)
|
|
@@ -1317,8 +577,7 @@ function HasSaveSlots._setupSummary(self: HasSaveSlots): ()
|
|
|
1317
577
|
return
|
|
1318
578
|
end
|
|
1319
579
|
|
|
1320
|
-
local
|
|
1321
|
-
local activeSlot = activeSlotId and self._slotMap[activeSlotId]
|
|
580
|
+
local activeSlot = self._slotsDataStore:GetSlotFolder(self.ActiveSlotId.Value)
|
|
1322
581
|
if not activeSlot then
|
|
1323
582
|
return
|
|
1324
583
|
end
|
|
@@ -1402,91 +661,8 @@ function HasSaveSlots._observeProviderValue(
|
|
|
1402
661
|
}) :: any
|
|
1403
662
|
end
|
|
1404
663
|
|
|
1405
|
-
--[=[
|
|
1406
|
-
Accrues per-slot playtime automatically. A "session" spans the time a slot is the active slot:
|
|
1407
|
-
selecting a slot begins one (bumping PlayCount), and deselecting, switching, or unbinding ends
|
|
1408
|
-
it. Elapsed wall time is folded into the slot's TimePlayed from a datastore saving callback, so
|
|
1409
|
-
it persists on exactly the cadence the data is written -- always fresh at save time, with no
|
|
1410
|
-
separate timer -- and again at each session boundary.
|
|
1411
|
-
]=]
|
|
1412
|
-
function HasSaveSlots._setupPlaytimeTracking(self: HasSaveSlots): ()
|
|
1413
|
-
self._playSessionSlotId = nil
|
|
1414
|
-
self._playSessionStart = nil
|
|
1415
|
-
self._playSessionLastFlush = nil
|
|
1416
|
-
|
|
1417
|
-
-- The active slot bounds the session: end the previous one (if any) and begin the new one.
|
|
1418
|
-
self._maid:GiveTask(self.ActiveSlotId.Changed:Connect(function()
|
|
1419
|
-
self:_endPlaySession()
|
|
1420
|
-
|
|
1421
|
-
local activeSlotId = self.ActiveSlotId.Value
|
|
1422
|
-
if activeSlotId ~= nil then
|
|
1423
|
-
self:_beginPlaySession(activeSlotId)
|
|
1424
|
-
end
|
|
1425
|
-
end))
|
|
1426
|
-
|
|
1427
|
-
-- Fold accrued time into TimePlayed just before every save so the written value is current. The
|
|
1428
|
-
-- callback runs before the save serializes staged data (see DataStore._syncData), so the flush is
|
|
1429
|
-
-- captured by that same save -- including the final save-on-leave.
|
|
1430
|
-
self._maid:GivePromise(self._loadPromise):Then(function()
|
|
1431
|
-
self._maid:GiveTask(self._dataStore:AddSavingCallback(function()
|
|
1432
|
-
self:_flushPlaytime()
|
|
1433
|
-
end))
|
|
1434
|
-
end)
|
|
1435
|
-
|
|
1436
|
-
-- Best-effort flush on unbind for the case where the binder tears down before that final save.
|
|
1437
|
-
self._maid:GiveTask(function()
|
|
1438
|
-
self:_endPlaySession()
|
|
1439
|
-
end)
|
|
1440
|
-
end
|
|
1441
|
-
|
|
1442
|
-
function HasSaveSlots._beginPlaySession(self: HasSaveSlots, slotId: SaveSlotData.SlotId): ()
|
|
1443
|
-
local now = os.time()
|
|
1444
|
-
self._playSessionSlotId = slotId
|
|
1445
|
-
self._playSessionStart = now
|
|
1446
|
-
self._playSessionLastFlush = now
|
|
1447
|
-
|
|
1448
|
-
local slot = self._slotMap[slotId]
|
|
1449
|
-
if slot then
|
|
1450
|
-
SaveSlotData.PlayCount:Set(slot, (SaveSlotData.PlayCount:Get(slot) or 0) + 1)
|
|
1451
|
-
end
|
|
1452
|
-
end
|
|
1453
|
-
|
|
1454
|
-
function HasSaveSlots._flushPlaytime(self: HasSaveSlots): ()
|
|
1455
|
-
local slotId = self._playSessionSlotId
|
|
1456
|
-
if slotId == nil then
|
|
1457
|
-
return
|
|
1458
|
-
end
|
|
1459
|
-
|
|
1460
|
-
local slot = self._slotMap[slotId]
|
|
1461
|
-
if not slot then
|
|
1462
|
-
return
|
|
1463
|
-
end
|
|
1464
|
-
|
|
1465
|
-
local now = os.time()
|
|
1466
|
-
|
|
1467
|
-
-- Add only the time since the last flush so repeated flushes within a session never double count.
|
|
1468
|
-
local sinceFlush = now - (self._playSessionLastFlush or now)
|
|
1469
|
-
if sinceFlush > 0 then
|
|
1470
|
-
SaveSlotData.TimePlayed:Set(slot, (SaveSlotData.TimePlayed:Get(slot) or 0) + sinceFlush)
|
|
1471
|
-
self._playSessionLastFlush = now
|
|
1472
|
-
end
|
|
1473
|
-
|
|
1474
|
-
SaveSlotData.LastSessionLength:Set(slot, now - (self._playSessionStart or now))
|
|
1475
|
-
end
|
|
1476
|
-
|
|
1477
|
-
function HasSaveSlots._endPlaySession(self: HasSaveSlots): ()
|
|
1478
|
-
if self._playSessionSlotId == nil then
|
|
1479
|
-
return
|
|
1480
|
-
end
|
|
1481
|
-
|
|
1482
|
-
self:_flushPlaytime()
|
|
1483
|
-
self._playSessionSlotId = nil
|
|
1484
|
-
self._playSessionStart = nil
|
|
1485
|
-
self._playSessionLastFlush = nil
|
|
1486
|
-
end
|
|
1487
|
-
|
|
1488
664
|
function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
1489
|
-
self._maid:GiveTask(self._remoting.PromiseHasSlot:Bind(function(remotePlayer, ...)
|
|
665
|
+
self._maid:GiveTask(self._remoting.PromiseHasSlot:Bind(function(remotePlayer: Player, ...)
|
|
1490
666
|
if remotePlayer == self._obj then
|
|
1491
667
|
return self:PromiseHasSlot(...)
|
|
1492
668
|
else
|
|
@@ -1494,7 +670,7 @@ function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
|
1494
670
|
end
|
|
1495
671
|
end))
|
|
1496
672
|
|
|
1497
|
-
self._maid:GiveTask(self._remoting.PromiseSelectSlot:Bind(function(remotePlayer, ...)
|
|
673
|
+
self._maid:GiveTask(self._remoting.PromiseSelectSlot:Bind(function(remotePlayer: Player, ...)
|
|
1498
674
|
if remotePlayer == self._obj then
|
|
1499
675
|
return self:PromiseSelectSlot(...)
|
|
1500
676
|
else
|
|
@@ -1502,7 +678,7 @@ function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
|
1502
678
|
end
|
|
1503
679
|
end))
|
|
1504
680
|
|
|
1505
|
-
self._maid:GiveTask(self._remoting.PromiseCreateSlot:Bind(function(remotePlayer, ...)
|
|
681
|
+
self._maid:GiveTask(self._remoting.PromiseCreateSlot:Bind(function(remotePlayer: Player, ...)
|
|
1506
682
|
if remotePlayer == self._obj then
|
|
1507
683
|
return self:PromiseCreateSlot(...)
|
|
1508
684
|
else
|
|
@@ -1510,7 +686,7 @@ function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
|
1510
686
|
end
|
|
1511
687
|
end))
|
|
1512
688
|
|
|
1513
|
-
self._maid:GiveTask(self._remoting.PromiseDeleteSlot:Bind(function(remotePlayer, ...)
|
|
689
|
+
self._maid:GiveTask(self._remoting.PromiseDeleteSlot:Bind(function(remotePlayer: Player, ...)
|
|
1514
690
|
if remotePlayer == self._obj then
|
|
1515
691
|
return self:PromiseDeleteSlot(...)
|
|
1516
692
|
else
|
|
@@ -1518,7 +694,7 @@ function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
|
1518
694
|
end
|
|
1519
695
|
end))
|
|
1520
696
|
|
|
1521
|
-
self._maid:GiveTask(self._remoting.PromiseSetSlotMetadata:Bind(function(remotePlayer, ...)
|
|
697
|
+
self._maid:GiveTask(self._remoting.PromiseSetSlotMetadata:Bind(function(remotePlayer: Player, ...)
|
|
1522
698
|
if remotePlayer == self._obj then
|
|
1523
699
|
return self:PromiseSetSlotMetadata(...)
|
|
1524
700
|
else
|
|
@@ -1526,7 +702,7 @@ function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
|
1526
702
|
end
|
|
1527
703
|
end))
|
|
1528
704
|
|
|
1529
|
-
self._maid:GiveTask(self._remoting.PromiseGetSlotMetadata:Bind(function(remotePlayer, ...)
|
|
705
|
+
self._maid:GiveTask(self._remoting.PromiseGetSlotMetadata:Bind(function(remotePlayer: Player, ...)
|
|
1530
706
|
if remotePlayer == self._obj then
|
|
1531
707
|
return self:PromiseGetSlotMetadata(...)
|
|
1532
708
|
else
|
|
@@ -1534,7 +710,7 @@ function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
|
1534
710
|
end
|
|
1535
711
|
end))
|
|
1536
712
|
|
|
1537
|
-
self._maid:GiveTask(self._remoting.PromiseSlotIdFromIndex:Bind(function(remotePlayer, ...)
|
|
713
|
+
self._maid:GiveTask(self._remoting.PromiseSlotIdFromIndex:Bind(function(remotePlayer: Player, ...)
|
|
1538
714
|
if remotePlayer == self._obj then
|
|
1539
715
|
return self:PromiseSlotIdFromIndex(...)
|
|
1540
716
|
else
|
|
@@ -1542,7 +718,7 @@ function HasSaveSlots._setupRemotes(self: HasSaveSlots): ()
|
|
|
1542
718
|
end
|
|
1543
719
|
end))
|
|
1544
720
|
|
|
1545
|
-
self._maid:GiveTask(self._remoting.PromiseLastActiveSlotId:Bind(function(remotePlayer)
|
|
721
|
+
self._maid:GiveTask(self._remoting.PromiseLastActiveSlotId:Bind(function(remotePlayer: Player)
|
|
1546
722
|
if remotePlayer == self._obj then
|
|
1547
723
|
return self:PromiseLastActiveSlotId()
|
|
1548
724
|
else
|