@quenty/saveslot 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/package.json +6 -4
- package/src/Client/Binders/HasSaveSlotsClient.lua +12 -8
- package/src/Client/SaveSlotServiceClient.lua +25 -6
- package/src/Server/Binders/HasSaveSlots.lua +342 -39
- package/src/Server/Binders/HasSaveSlots.spec.lua +784 -0
- package/src/Server/Cmdr/SaveSlotCmdrService.lua +162 -23
- package/src/Server/SaveSlotOverflow.spec.lua +128 -0
- package/src/Server/SaveSlotService.lua +50 -25
- package/src/Server/SaveSlotService.spec.lua +96 -25
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.lua +15 -0
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.spec.lua +142 -0
- package/src/Shared/Data/SaveSlotData.lua +27 -2
- package/src/Shared/Data/SaveSlotData.spec.lua +68 -0
- package/src/Shared/HasSaveSlotsBase.lua +24 -21
- package/src/Shared/SaveSlotDataService.lua +14 -0
|
@@ -12,9 +12,11 @@ local require = require(script.Parent.loader).load(script)
|
|
|
12
12
|
local DataStoreMock = require("DataStoreMock")
|
|
13
13
|
local Jest = require("Jest")
|
|
14
14
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
15
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
15
16
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
16
17
|
local SaveSlotService = require("SaveSlotService")
|
|
17
18
|
local ServiceBag = require("ServiceBag")
|
|
19
|
+
local TeleportDataEnvelopeUtils = require("TeleportDataEnvelopeUtils")
|
|
18
20
|
local TeleportDataService = require("TeleportDataService")
|
|
19
21
|
|
|
20
22
|
local describe = Jest.Globals.describe
|
|
@@ -34,13 +36,24 @@ local function newServiceBag()
|
|
|
34
36
|
) :: TeleportDataService.TeleportDataService
|
|
35
37
|
serviceBag:Init()
|
|
36
38
|
playerDataStoreService:SetRobloxDataStore(DataStoreMock.new())
|
|
39
|
+
|
|
40
|
+
-- Fake players (Folders) have no real UserId; key envelope slices off a "UserId" attribute.
|
|
41
|
+
local anyTeleportDataService = teleportDataService :: any
|
|
42
|
+
anyTeleportDataService._getUserId = function(_self, player: Instance): any
|
|
43
|
+
return player:GetAttribute("UserId")
|
|
44
|
+
end
|
|
45
|
+
|
|
37
46
|
return serviceBag, saveSlotService, teleportDataService
|
|
38
47
|
end
|
|
39
48
|
|
|
40
|
-
-- A Folder is an Instance, so it satisfies the player guards and can carry the ActiveSlotId
|
|
41
|
-
--
|
|
42
|
-
local function fakePlayer(): Player
|
|
43
|
-
|
|
49
|
+
-- A Folder is an Instance, so it satisfies the player guards and can carry the ActiveSlotId and
|
|
50
|
+
-- UserId attributes the provider/envelope read, standing in for a Player without a real join.
|
|
51
|
+
local function fakePlayer(userId: number?): Player
|
|
52
|
+
local player = Instance.new("Folder")
|
|
53
|
+
if userId ~= nil then
|
|
54
|
+
player:SetAttribute("UserId", userId)
|
|
55
|
+
end
|
|
56
|
+
return (player :: any) :: Player
|
|
44
57
|
end
|
|
45
58
|
|
|
46
59
|
describe("SaveSlotService initialization", function()
|
|
@@ -140,23 +153,41 @@ describe("SaveSlotService configuration guards", function()
|
|
|
140
153
|
serviceBag:Destroy()
|
|
141
154
|
end)
|
|
142
155
|
|
|
143
|
-
it("should reject a non-function summary provider", function()
|
|
156
|
+
it("should reject a non-function default summary provider", function()
|
|
144
157
|
local serviceBag, saveSlotService = newServiceBag()
|
|
145
158
|
|
|
146
159
|
expect(function()
|
|
147
|
-
saveSlotService:
|
|
160
|
+
saveSlotService:RegisterDefaultSummaryProvider("progress", "not a function" :: any)
|
|
148
161
|
end).toThrow("Bad provider")
|
|
149
162
|
|
|
150
163
|
serviceBag:Destroy()
|
|
151
164
|
end)
|
|
152
165
|
|
|
153
|
-
it("should
|
|
166
|
+
it("should reject a non-string default summary provider name", function()
|
|
167
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
168
|
+
|
|
169
|
+
expect(function()
|
|
170
|
+
saveSlotService:RegisterDefaultSummaryProvider(nil :: any, function()
|
|
171
|
+
return nil :: any
|
|
172
|
+
end)
|
|
173
|
+
end).toThrow("Bad name")
|
|
174
|
+
|
|
175
|
+
serviceBag:Destroy()
|
|
176
|
+
end)
|
|
177
|
+
|
|
178
|
+
it("registers a default summary provider and returns an unregister function", function()
|
|
154
179
|
local serviceBag, saveSlotService = newServiceBag()
|
|
155
180
|
|
|
181
|
+
local unregister
|
|
182
|
+
expect(function()
|
|
183
|
+
unregister = saveSlotService:RegisterDefaultSummaryProvider("progress", function()
|
|
184
|
+
return nil :: any
|
|
185
|
+
end)
|
|
186
|
+
end).never.toThrow()
|
|
187
|
+
|
|
188
|
+
expect(type(unregister)).toEqual("function")
|
|
156
189
|
expect(function()
|
|
157
|
-
|
|
158
|
-
return nil
|
|
159
|
-
end) :: any)
|
|
190
|
+
unregister()
|
|
160
191
|
end).never.toThrow()
|
|
161
192
|
|
|
162
193
|
serviceBag:Destroy()
|
|
@@ -168,11 +199,12 @@ describe("SaveSlotService internal teleport", function()
|
|
|
168
199
|
local serviceBag, _saveSlotService, teleportDataService = newServiceBag()
|
|
169
200
|
serviceBag:Start()
|
|
170
201
|
|
|
171
|
-
local player = fakePlayer()
|
|
202
|
+
local player = fakePlayer(111)
|
|
172
203
|
player:SetAttribute("ActiveSlotId", "slot-xyz")
|
|
173
204
|
|
|
174
205
|
local data = teleportDataService:BuildTeleportData({ player })
|
|
175
|
-
|
|
206
|
+
local slice = TeleportDataEnvelopeUtils.readSlice(data, 111)
|
|
207
|
+
expect(slice and slice[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toEqual("slot-xyz")
|
|
176
208
|
|
|
177
209
|
player:Destroy()
|
|
178
210
|
serviceBag:Destroy()
|
|
@@ -182,47 +214,86 @@ describe("SaveSlotService internal teleport", function()
|
|
|
182
214
|
local serviceBag, _saveSlotService, teleportDataService = newServiceBag()
|
|
183
215
|
serviceBag:Start()
|
|
184
216
|
|
|
185
|
-
local player = fakePlayer()
|
|
217
|
+
local player = fakePlayer(111)
|
|
186
218
|
|
|
187
219
|
local data = teleportDataService:BuildTeleportData({ player })
|
|
188
|
-
|
|
220
|
+
local slice = TeleportDataEnvelopeUtils.readSlice(data, 111)
|
|
221
|
+
expect(slice and slice[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toBeNil()
|
|
189
222
|
|
|
190
223
|
player:Destroy()
|
|
191
224
|
serviceBag:Destroy()
|
|
192
225
|
end)
|
|
193
226
|
|
|
194
|
-
it("should
|
|
227
|
+
it("should carry each player's own active slot id for a multi-player teleport", function()
|
|
195
228
|
local serviceBag, _saveSlotService, teleportDataService = newServiceBag()
|
|
196
229
|
serviceBag:Start()
|
|
197
230
|
|
|
198
|
-
local playerA = fakePlayer()
|
|
199
|
-
local playerB = fakePlayer()
|
|
231
|
+
local playerA = fakePlayer(111)
|
|
232
|
+
local playerB = fakePlayer(222)
|
|
200
233
|
playerA:SetAttribute("ActiveSlotId", "slot-a")
|
|
201
234
|
playerB:SetAttribute("ActiveSlotId", "slot-b")
|
|
202
235
|
|
|
203
236
|
local data = teleportDataService:BuildTeleportData({ playerA, playerB })
|
|
204
|
-
|
|
237
|
+
local sliceA = TeleportDataEnvelopeUtils.readSlice(data, 111)
|
|
238
|
+
local sliceB = TeleportDataEnvelopeUtils.readSlice(data, 222)
|
|
239
|
+
expect(sliceA and sliceA[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toEqual("slot-a")
|
|
240
|
+
expect(sliceB and sliceB[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toEqual("slot-b")
|
|
205
241
|
|
|
206
242
|
playerA:Destroy()
|
|
207
243
|
playerB:Destroy()
|
|
208
244
|
serviceBag:Destroy()
|
|
209
245
|
end)
|
|
210
246
|
|
|
211
|
-
|
|
247
|
+
-- Awaits a boolean read promise and returns its fulfilled value.
|
|
248
|
+
local function awaitBool(promise: any): boolean
|
|
249
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
250
|
+
local ok, value = promise:Yield()
|
|
251
|
+
expect(ok).toEqual(true)
|
|
252
|
+
return value
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it("should report a client-initiated teleport (non-trusted band) as internal", function()
|
|
256
|
+
-- This is the fix: a slot the *client* attached only reaches the server via replication, and the
|
|
257
|
+
-- server must still see it.
|
|
212
258
|
local serviceBag, saveSlotService, teleportDataService = newServiceBag()
|
|
213
259
|
serviceBag:Start()
|
|
214
260
|
|
|
215
|
-
local arrived = fakePlayer()
|
|
216
|
-
teleportDataService:
|
|
261
|
+
local arrived = fakePlayer(111)
|
|
262
|
+
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, {
|
|
217
263
|
[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = "slot-1",
|
|
218
264
|
})
|
|
219
|
-
expect(saveSlotService:IsInternalTeleport(arrived)).toEqual(true)
|
|
220
265
|
|
|
221
|
-
|
|
222
|
-
teleportDataService:SetArrivedTeleportDataForTesting(fresh, {})
|
|
223
|
-
expect(saveSlotService:IsInternalTeleport(fresh)).toEqual(false)
|
|
266
|
+
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(true)
|
|
224
267
|
|
|
225
268
|
arrived:Destroy()
|
|
269
|
+
serviceBag:Destroy()
|
|
270
|
+
end)
|
|
271
|
+
|
|
272
|
+
it("should report a server-initiated teleport (trusted band) as internal", function()
|
|
273
|
+
local serviceBag, saveSlotService, teleportDataService = newServiceBag()
|
|
274
|
+
serviceBag:Start()
|
|
275
|
+
|
|
276
|
+
local arrived = fakePlayer(111)
|
|
277
|
+
teleportDataService:SetTrustedArrivedTeleportDataForTesting(arrived, {
|
|
278
|
+
[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = "slot-1",
|
|
279
|
+
})
|
|
280
|
+
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, nil) -- no client band; seals
|
|
281
|
+
|
|
282
|
+
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(true)
|
|
283
|
+
|
|
284
|
+
arrived:Destroy()
|
|
285
|
+
serviceBag:Destroy()
|
|
286
|
+
end)
|
|
287
|
+
|
|
288
|
+
it("should report a fresh join (no arrived data) as not internal", function()
|
|
289
|
+
local serviceBag, saveSlotService, teleportDataService = newServiceBag()
|
|
290
|
+
serviceBag:Start()
|
|
291
|
+
|
|
292
|
+
local fresh = fakePlayer(111)
|
|
293
|
+
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(fresh, nil) -- fresh-join sentinel; seals
|
|
294
|
+
|
|
295
|
+
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(fresh))).toEqual(false)
|
|
296
|
+
|
|
226
297
|
fresh:Destroy()
|
|
227
298
|
serviceBag:Destroy()
|
|
228
299
|
end)
|
|
@@ -24,6 +24,21 @@ function SaveSlotCmdrUtils.registerSlotIndexType(cmdr, saveSlotDataService)
|
|
|
24
24
|
Parse = function(keys)
|
|
25
25
|
return tonumber(keys[1])
|
|
26
26
|
end,
|
|
27
|
+
|
|
28
|
+
-- "." resolves to the player's current slot: the active slot when one is selected, otherwise the
|
|
29
|
+
-- slot they last played. Cmdr feeds this string back through Transform, so it fuzzy matches the
|
|
30
|
+
-- real slot. MakeListableType inherits Default, so "." works for delete-save-slot's list too.
|
|
31
|
+
Default = function(player: Player): string?
|
|
32
|
+
local slotId = saveSlotDataService:GetLastActiveSlotId(player)
|
|
33
|
+
if not slotId then
|
|
34
|
+
return nil
|
|
35
|
+
end
|
|
36
|
+
local metadata = saveSlotDataService:GetSlotMetadata(player, slotId)
|
|
37
|
+
if type(metadata) ~= "table" then
|
|
38
|
+
return nil
|
|
39
|
+
end
|
|
40
|
+
return tostring(metadata.SlotIndex)
|
|
41
|
+
end,
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
cmdr.Registry:RegisterType("slotIndex", slotIndex)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
Coverage for the "slotIndex"/"slotIndices" Cmdr types, focused on the "." shorthand (Cmdr's
|
|
4
|
+
Default callback) that resolves to the player's current slot -- the active slot, or the last one
|
|
5
|
+
they played. Cmdr itself is stubbed so the type's Default/Transform can be exercised directly.
|
|
6
|
+
|
|
7
|
+
@class SaveSlotCmdrUtils.spec.lua
|
|
8
|
+
]]
|
|
9
|
+
local require = require(script.Parent.loader).load(script)
|
|
10
|
+
|
|
11
|
+
local Jest = require("Jest")
|
|
12
|
+
local SaveSlotCmdrUtils = require("SaveSlotCmdrUtils")
|
|
13
|
+
|
|
14
|
+
local describe = Jest.Globals.describe
|
|
15
|
+
local expect = Jest.Globals.expect
|
|
16
|
+
local it = Jest.Globals.it
|
|
17
|
+
|
|
18
|
+
-- A stand-in player. The fake data service keys off nothing, so any sentinel works.
|
|
19
|
+
local FAKE_PLAYER = newproxy(false)
|
|
20
|
+
|
|
21
|
+
-- Minimal SaveSlotDataService driven by a mutable `state`. Mirrors the real methods the type uses.
|
|
22
|
+
local function newFakeDataService(state)
|
|
23
|
+
return {
|
|
24
|
+
GetSlotList = function(_self, _player)
|
|
25
|
+
return state.slots
|
|
26
|
+
end,
|
|
27
|
+
GetLastActiveSlotId = function(_self, _player)
|
|
28
|
+
return state.lastActiveSlotId
|
|
29
|
+
end,
|
|
30
|
+
GetSlotMetadata = function(_self, _player, slotId)
|
|
31
|
+
for _, slot in state.slots do
|
|
32
|
+
if slot.SlotId == slotId then
|
|
33
|
+
return slot
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
return nil
|
|
37
|
+
end,
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
-- Enough of Cmdr for registerSlotIndexType: a substring fuzzy finder, a listable wrapper that copies
|
|
42
|
+
-- fields the way the real Util.MakeListableType does (so Default propagation is exercised), and a
|
|
43
|
+
-- registry that captures the registered definitions.
|
|
44
|
+
local function newFakeCmdr()
|
|
45
|
+
local registered: { [string]: any } = {}
|
|
46
|
+
local cmdr = {
|
|
47
|
+
Util = {
|
|
48
|
+
MakeFuzzyFinder = function(entries)
|
|
49
|
+
return function(text)
|
|
50
|
+
local matches = {}
|
|
51
|
+
for _, entry in entries do
|
|
52
|
+
if text == "" or string.find(entry, text, 1, true) then
|
|
53
|
+
table.insert(matches, entry)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
return matches
|
|
57
|
+
end
|
|
58
|
+
end,
|
|
59
|
+
MakeListableType = function(singular)
|
|
60
|
+
return {
|
|
61
|
+
Listable = true,
|
|
62
|
+
Transform = singular.Transform,
|
|
63
|
+
Validate = singular.Validate,
|
|
64
|
+
Autocomplete = singular.Autocomplete,
|
|
65
|
+
Parse = singular.Parse,
|
|
66
|
+
Default = singular.Default,
|
|
67
|
+
}
|
|
68
|
+
end,
|
|
69
|
+
},
|
|
70
|
+
Registry = {
|
|
71
|
+
RegisterType = function(_self, name, definition)
|
|
72
|
+
registered[name] = definition
|
|
73
|
+
end,
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
return cmdr, registered
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
-- Registers the types against a fake data service backed by `state` and returns the registered types.
|
|
80
|
+
local function registerSlotIndex(state)
|
|
81
|
+
local cmdr, registered = newFakeCmdr()
|
|
82
|
+
SaveSlotCmdrUtils.registerSlotIndexType(cmdr :: any, newFakeDataService(state))
|
|
83
|
+
return registered.slotIndex, registered.slotIndices
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe("SaveSlotCmdrUtils.registerSlotIndexType", function()
|
|
87
|
+
it('resolves "." to the current slot\'s index via Default', function()
|
|
88
|
+
local slotIndex = registerSlotIndex({
|
|
89
|
+
lastActiveSlotId = "id-2",
|
|
90
|
+
slots = {
|
|
91
|
+
{ SlotId = "id-1", SlotIndex = 1 },
|
|
92
|
+
{ SlotId = "id-2", SlotIndex = 2 },
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
expect(slotIndex.Default(FAKE_PLAYER)).toBe("2")
|
|
97
|
+
end)
|
|
98
|
+
|
|
99
|
+
it("returns nil from Default when there is no current slot", function()
|
|
100
|
+
local slotIndex = registerSlotIndex({
|
|
101
|
+
lastActiveSlotId = nil,
|
|
102
|
+
slots = {},
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
expect(slotIndex.Default(FAKE_PLAYER)).toBeNil()
|
|
106
|
+
end)
|
|
107
|
+
|
|
108
|
+
it("returns nil from Default when the remembered slot no longer exists", function()
|
|
109
|
+
-- Last-active points at a deleted slot: GetSlotMetadata finds nothing, so "." resolves to nothing.
|
|
110
|
+
local slotIndex = registerSlotIndex({
|
|
111
|
+
lastActiveSlotId = "id-gone",
|
|
112
|
+
slots = {
|
|
113
|
+
{ SlotId = "id-1", SlotIndex = 1 },
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
expect(slotIndex.Default(FAKE_PLAYER)).toBeNil()
|
|
118
|
+
end)
|
|
119
|
+
|
|
120
|
+
it("still fuzzy-finds a literal index through Transform/Parse", function()
|
|
121
|
+
local slotIndex = registerSlotIndex({
|
|
122
|
+
lastActiveSlotId = "id-1",
|
|
123
|
+
slots = {
|
|
124
|
+
{ SlotId = "id-1", SlotIndex = 1 },
|
|
125
|
+
{ SlotId = "id-2", SlotIndex = 2 },
|
|
126
|
+
},
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
expect(slotIndex.Parse(slotIndex.Transform("2", FAKE_PLAYER))).toBe(2)
|
|
130
|
+
end)
|
|
131
|
+
|
|
132
|
+
it('exposes Default on the listable type too, so "." works for delete-save-slot', function()
|
|
133
|
+
local _slotIndex, slotIndices = registerSlotIndex({
|
|
134
|
+
lastActiveSlotId = "id-1",
|
|
135
|
+
slots = {
|
|
136
|
+
{ SlotId = "id-1", SlotIndex = 1 },
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
expect(slotIndices.Default(FAKE_PLAYER)).toBe("1")
|
|
141
|
+
end)
|
|
142
|
+
end)
|
|
@@ -7,19 +7,39 @@ local require = require(script.Parent.loader).load(script)
|
|
|
7
7
|
|
|
8
8
|
local AdorneeData = require("AdorneeData")
|
|
9
9
|
local AdorneeDataEntry = require("AdorneeDataEntry")
|
|
10
|
+
local JSONAttributeValue = require("JSONAttributeValue")
|
|
10
11
|
local PropertyValue = require("PropertyValue")
|
|
11
12
|
|
|
12
13
|
export type SlotId = string
|
|
13
14
|
|
|
15
|
+
-- A slot's Summary is the structured preview shown in a slot-selection UI, keyed by summary-provider
|
|
16
|
+
-- name (see HasSaveSlots.RegisterSummaryProvider). It is JSON-encoded into a single attribute, so the
|
|
17
|
+
-- values must be JSON-serializable.
|
|
18
|
+
export type SaveSlotSummary = { [string]: any }
|
|
19
|
+
|
|
14
20
|
export type SaveSlotMetadata = {
|
|
15
21
|
SlotId: SlotId,
|
|
16
22
|
SlotIndex: number,
|
|
17
23
|
SlotName: string?,
|
|
18
24
|
CreatedTime: number?,
|
|
19
25
|
LastPlayedTime: number?,
|
|
20
|
-
Summary:
|
|
26
|
+
Summary: SaveSlotSummary?,
|
|
27
|
+
-- Accrued automatically by HasSaveSlots while the slot is the active slot; see _setupPlaytimeTracking.
|
|
28
|
+
TimePlayed: number?, -- total seconds the slot has been actively played, across every session
|
|
29
|
+
PlayCount: number?, -- number of sessions (incremented each time the slot is selected)
|
|
30
|
+
LastSessionLength: number?, -- seconds of the current/most-recent session
|
|
21
31
|
}
|
|
22
32
|
|
|
33
|
+
-- The Summary is a structured table JSON-encoded into one attribute. A string is also accepted so a
|
|
34
|
+
-- legacy plain-string Summary (from before this was structured) loads without error -- it surfaces as
|
|
35
|
+
-- a string until the active slot's providers regenerate it as a table.
|
|
36
|
+
local function isSummaryValue(value: any): (boolean, string?)
|
|
37
|
+
if value == nil or type(value) == "table" or type(value) == "string" then
|
|
38
|
+
return true
|
|
39
|
+
end
|
|
40
|
+
return false, `Summary must be a table, string, or nil, got {typeof(value)}`
|
|
41
|
+
end
|
|
42
|
+
|
|
23
43
|
return AdorneeData.new({
|
|
24
44
|
SlotId = AdorneeDataEntry.new("string", function(folder: Folder)
|
|
25
45
|
return PropertyValue.new(folder, "Name")
|
|
@@ -28,5 +48,10 @@ return AdorneeData.new({
|
|
|
28
48
|
SlotName = AdorneeDataEntry.optionalAttribute("string", "SlotName"),
|
|
29
49
|
CreatedTime = AdorneeDataEntry.optionalAttribute("number", "CreatedTime"),
|
|
30
50
|
LastPlayedTime = AdorneeDataEntry.optionalAttribute("number", "LastPlayedTime"),
|
|
31
|
-
Summary = AdorneeDataEntry.
|
|
51
|
+
Summary = AdorneeDataEntry.new(isSummaryValue, function(folder: Folder)
|
|
52
|
+
return JSONAttributeValue.new(folder, "Summary", nil)
|
|
53
|
+
end),
|
|
54
|
+
TimePlayed = AdorneeDataEntry.optionalAttribute("number", "TimePlayed"),
|
|
55
|
+
PlayCount = AdorneeDataEntry.optionalAttribute("number", "PlayCount"),
|
|
56
|
+
LastSessionLength = AdorneeDataEntry.optionalAttribute("number", "LastSessionLength"),
|
|
32
57
|
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
--!nonstrict
|
|
2
|
+
--[[
|
|
3
|
+
Covers the Summary metadata field, which is JSON-encoded into a single attribute so a structured,
|
|
4
|
+
provider-keyed summary survives the attribute round-trip (attributes cannot hold tables directly).
|
|
5
|
+
|
|
6
|
+
@class SaveSlotData.spec.lua
|
|
7
|
+
]]
|
|
8
|
+
local require = require(script.Parent.loader).load(script)
|
|
9
|
+
|
|
10
|
+
local Jest = require("Jest")
|
|
11
|
+
local SaveSlotData = require("SaveSlotData")
|
|
12
|
+
|
|
13
|
+
local describe = Jest.Globals.describe
|
|
14
|
+
local expect = Jest.Globals.expect
|
|
15
|
+
local it = Jest.Globals.it
|
|
16
|
+
|
|
17
|
+
describe("SaveSlotData.Summary", function()
|
|
18
|
+
it("round-trips a structured Summary table through the attribute", function()
|
|
19
|
+
local folder = Instance.new("Folder")
|
|
20
|
+
|
|
21
|
+
SaveSlotData.Summary:Set(folder, { coins = 100, world = 3 })
|
|
22
|
+
local value = SaveSlotData.Summary:Get(folder)
|
|
23
|
+
|
|
24
|
+
expect(value.coins).toEqual(100)
|
|
25
|
+
expect(value.world).toEqual(3)
|
|
26
|
+
|
|
27
|
+
folder:Destroy()
|
|
28
|
+
end)
|
|
29
|
+
|
|
30
|
+
it("clears the Summary when set to nil", function()
|
|
31
|
+
local folder = Instance.new("Folder")
|
|
32
|
+
|
|
33
|
+
SaveSlotData.Summary:Set(folder, { coins = 1 })
|
|
34
|
+
SaveSlotData.Summary:Set(folder, nil)
|
|
35
|
+
|
|
36
|
+
expect(SaveSlotData.Summary:Get(folder)).toBeNil()
|
|
37
|
+
|
|
38
|
+
folder:Destroy()
|
|
39
|
+
end)
|
|
40
|
+
|
|
41
|
+
it("tolerates a legacy plain-string Summary without erroring", function()
|
|
42
|
+
-- Before the summary was structured it was a single string. A slot saved then still loads: the
|
|
43
|
+
-- value survives (as a string) until the active slot's providers regenerate it as a table.
|
|
44
|
+
local folder = Instance.new("Folder")
|
|
45
|
+
|
|
46
|
+
expect(function()
|
|
47
|
+
SaveSlotData.Summary:Set(folder, "Chapters: 1")
|
|
48
|
+
end).never.toThrow()
|
|
49
|
+
|
|
50
|
+
local value
|
|
51
|
+
expect(function()
|
|
52
|
+
value = SaveSlotData.Summary:Get(folder)
|
|
53
|
+
end).never.toThrow()
|
|
54
|
+
expect(value).toEqual("Chapters: 1")
|
|
55
|
+
|
|
56
|
+
folder:Destroy()
|
|
57
|
+
end)
|
|
58
|
+
|
|
59
|
+
it("rejects a non-serializable Summary value", function()
|
|
60
|
+
local folder = Instance.new("Folder")
|
|
61
|
+
|
|
62
|
+
expect(function()
|
|
63
|
+
SaveSlotData.Summary:Set(folder, 42 :: any)
|
|
64
|
+
end).toThrow()
|
|
65
|
+
|
|
66
|
+
folder:Destroy()
|
|
67
|
+
end)
|
|
68
|
+
end)
|
|
@@ -51,15 +51,16 @@ function HasSaveSlotsBase.new(player: Player, serviceBag: ServiceBag.ServiceBag)
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
--[=[
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
[TeleportDataService]
|
|
57
|
-
"no incoming
|
|
54
|
+
Resolves the save-slot id the player teleported in with, or nil. Realm hook: the server reads it from
|
|
55
|
+
the client-replicated teleport data, the client from the local player's teleport data (both via the
|
|
56
|
+
[TeleportDataService] unified read, which is a promise because the server must wait for the client to
|
|
57
|
+
replicate). The base default resolves nil so a realm that never sets one degrades to "no incoming
|
|
58
|
+
slot".
|
|
58
59
|
|
|
59
|
-
@return SaveSlotData.SlotId
|
|
60
|
+
@return Promise<SaveSlotData.SlotId?>
|
|
60
61
|
]=]
|
|
61
|
-
function HasSaveSlotsBase.
|
|
62
|
-
return nil
|
|
62
|
+
function HasSaveSlotsBase.PromiseIncomingSlotId(_self: HasSaveSlotsBase): Promise.Promise<SaveSlotData.SlotId?>
|
|
63
|
+
return (Promise :: any).resolved(nil)
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
--[=[
|
|
@@ -69,12 +70,13 @@ end
|
|
|
69
70
|
@return Promise<boolean>
|
|
70
71
|
]=]
|
|
71
72
|
function HasSaveSlotsBase.PromiseHasSaveSlotFromTeleport(self: HasSaveSlotsBase): Promise.Promise<boolean>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
return self:PromiseIncomingSlotId():Then(function(slotId: SaveSlotData.SlotId?)
|
|
74
|
+
if type(slotId) ~= "string" then
|
|
75
|
+
return false
|
|
76
|
+
end
|
|
76
77
|
|
|
77
|
-
|
|
78
|
+
return (self :: any):PromiseHasSlot(slotId)
|
|
79
|
+
end)
|
|
78
80
|
end
|
|
79
81
|
|
|
80
82
|
--[=[
|
|
@@ -85,18 +87,19 @@ end
|
|
|
85
87
|
@return Promise<SaveSlotData.SlotId?>
|
|
86
88
|
]=]
|
|
87
89
|
function HasSaveSlotsBase.PromiseLoadSaveSlotFromTeleport(self: HasSaveSlotsBase): Promise.Promise<SaveSlotData.SlotId?>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return (Promise :: any).resolved(nil)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
return (self :: any):PromiseHasSlot(slotId):Then(function(hasSlot: boolean)
|
|
94
|
-
if not hasSlot then
|
|
90
|
+
return self:PromiseIncomingSlotId():Then(function(slotId: SaveSlotData.SlotId?)
|
|
91
|
+
if type(slotId) ~= "string" then
|
|
95
92
|
return nil
|
|
96
93
|
end
|
|
97
94
|
|
|
98
|
-
return (self :: any):
|
|
99
|
-
|
|
95
|
+
return (self :: any):PromiseHasSlot(slotId):Then(function(hasSlot: boolean)
|
|
96
|
+
if not hasSlot then
|
|
97
|
+
return nil
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
return (self :: any):PromiseSelectSlot(slotId):Then(function()
|
|
101
|
+
return slotId
|
|
102
|
+
end)
|
|
100
103
|
end)
|
|
101
104
|
end)
|
|
102
105
|
end
|
|
@@ -76,6 +76,20 @@ function SaveSlotDataService.GetActiveSlotId(self: SaveSlotDataService, player:
|
|
|
76
76
|
return hasSaveSlots and hasSaveSlots.ActiveSlotId.Value
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
+
--[=[
|
|
80
|
+
Returns the player's last active slot ID -- the active slot when one is selected, otherwise the
|
|
81
|
+
slot they last played and can continue on. This is the slot the "." shorthand resolves to in the
|
|
82
|
+
save-slot Cmdr commands. The synchronous counterpart to
|
|
83
|
+
[SaveSlotDataService.ObserveLastActiveSlotId].
|
|
84
|
+
]=]
|
|
85
|
+
function SaveSlotDataService.GetLastActiveSlotId(self: SaveSlotDataService, player: Player): SaveSlotData.SlotId?
|
|
86
|
+
local hasSaveSlots = HasSaveSlotsInterface:Find(player, self._realm)
|
|
87
|
+
if not hasSaveSlots then
|
|
88
|
+
return nil
|
|
89
|
+
end
|
|
90
|
+
return hasSaveSlots.ActiveSlotId.Value or hasSaveSlots.LastActiveSlotId.Value
|
|
91
|
+
end
|
|
92
|
+
|
|
79
93
|
--[=[
|
|
80
94
|
Observes the player's active slot list
|
|
81
95
|
]=]
|