@quenty/datastore 7.3.0 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [7.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.3.0...@quenty/datastore@7.4.0) (2022-11-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/datastore
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [7.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.2.1...@quenty/datastore@7.3.0) (2022-11-08)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @quenty/datastore
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/datastore",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "Quenty's Datastore implementation for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "24d3b85c01f0ce732d4290b62af8cc1b5c47f07a"
|
|
42
42
|
}
|
package/src/Server/DataStore.lua
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Wraps the datastore object to provide async cached loading and saving. See [DataStoreStage] for more API.
|
|
3
3
|
|
|
4
4
|
Has the following features
|
|
5
|
-
* Automatic
|
|
6
|
-
* Jitter
|
|
5
|
+
* Automatic saving every 5 minutes
|
|
6
|
+
* Jitter (doesn't save all at the same time)
|
|
7
7
|
* De-duplication (only updates data it needs)
|
|
8
|
+
* Battle tested across multiple top games.
|
|
8
9
|
|
|
9
10
|
```lua
|
|
10
11
|
local playerMoneyValue = Instance.new("IntValue")
|
|
@@ -17,7 +18,45 @@
|
|
|
17
18
|
end):Catch(function()
|
|
18
19
|
-- TODO: Notify player
|
|
19
20
|
end)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To use a datastore for a player, it's recommended you use the [PlayerDataStoreService]. This looks
|
|
24
|
+
something like this. See [ServiceBag] for more information on service initialization.
|
|
25
|
+
|
|
26
|
+
```lua
|
|
27
|
+
local serviceBag = ServiceBag.new()
|
|
28
|
+
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
29
|
+
|
|
30
|
+
serviceBag:Init()
|
|
31
|
+
serviceBag:Start()
|
|
32
|
+
|
|
33
|
+
local topMaid = Maid.new()
|
|
34
|
+
|
|
35
|
+
local function handlePlayer(player)
|
|
36
|
+
local maid = Maid.new()
|
|
37
|
+
|
|
38
|
+
local playerMoneyValue = Instance.new("IntValue")
|
|
39
|
+
playerMoneyValue.Name = "Money"
|
|
40
|
+
playerMoneyValue.Value = 0
|
|
41
|
+
playerMoneyValue.Parent = player
|
|
20
42
|
|
|
43
|
+
maid:GivePromise(playerDataStoreService:PromiseDataStore(Players)):Then(function(dataStore)
|
|
44
|
+
maid:GivePromise(dataStore:Load("money", 0))
|
|
45
|
+
:Then(function(money)
|
|
46
|
+
playerMoneyValue.Value = money
|
|
47
|
+
maid:GiveTask(dataStore:StoreOnValueChange("money", playerMoneyValue))
|
|
48
|
+
end)
|
|
49
|
+
end)
|
|
50
|
+
|
|
51
|
+
topMaid[player] = maid
|
|
52
|
+
end
|
|
53
|
+
Players.PlayerAdded:Connect(handlePlayer)
|
|
54
|
+
Players.PlayerRemoving:Connect(function(player)
|
|
55
|
+
topMaid[player] = nil
|
|
56
|
+
end)
|
|
57
|
+
for _, player in pairs(Players:GetPlayers()) do
|
|
58
|
+
task.spawn(handlePlayer, player)
|
|
59
|
+
end
|
|
21
60
|
```
|
|
22
61
|
|
|
23
62
|
@server
|
|
@@ -48,6 +87,7 @@ DataStore.__index = DataStore
|
|
|
48
87
|
Constructs a new DataStore. See [DataStoreStage] for more API.
|
|
49
88
|
@param robloxDataStore DataStore
|
|
50
89
|
@param key string
|
|
90
|
+
@return DataStore
|
|
51
91
|
]=]
|
|
52
92
|
function DataStore.new(robloxDataStore, key)
|
|
53
93
|
local self = setmetatable(DataStoreStage.new(), DataStore)
|
|
@@ -125,6 +165,11 @@ function DataStore:DidLoadFail()
|
|
|
125
165
|
return false
|
|
126
166
|
end
|
|
127
167
|
|
|
168
|
+
--[=[
|
|
169
|
+
Returns whether the datastore has loaded successfully.\
|
|
170
|
+
|
|
171
|
+
@return Promise<boolean>
|
|
172
|
+
]=]
|
|
128
173
|
function DataStore:PromiseLoadSuccessful()
|
|
129
174
|
return self._maid:GivePromise(self:_promiseLoad()):Then(function()
|
|
130
175
|
return true
|
|
@@ -1,10 +1,49 @@
|
|
|
1
1
|
--[=[
|
|
2
|
-
DataStore manager for player that automatically saves on player leave and game close.
|
|
3
|
-
|
|
2
|
+
DataStore manager for player that automatically saves on player leave and game close.
|
|
3
|
+
|
|
4
|
+
:::tip
|
|
5
|
+
Consider using [PlayerDataStoreService] instead, which wraps one PlayerDataStoreManager.
|
|
6
|
+
:::
|
|
4
7
|
|
|
5
8
|
This will ensure that the datastores are reused between different services and other things integrating
|
|
6
9
|
with Nevermore.
|
|
7
10
|
|
|
11
|
+
```lua
|
|
12
|
+
local serviceBag = ServiceBag.new()
|
|
13
|
+
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
14
|
+
|
|
15
|
+
serviceBag:Init()
|
|
16
|
+
serviceBag:Start()
|
|
17
|
+
|
|
18
|
+
local topMaid = Maid.new()
|
|
19
|
+
|
|
20
|
+
local function handlePlayer(player)
|
|
21
|
+
local maid = Maid.new()
|
|
22
|
+
|
|
23
|
+
local playerMoneyValue = Instance.new("IntValue")
|
|
24
|
+
playerMoneyValue.Name = "Money"
|
|
25
|
+
playerMoneyValue.Value = 0
|
|
26
|
+
playerMoneyValue.Parent = player
|
|
27
|
+
|
|
28
|
+
maid:GivePromise(playerDataStoreService:PromiseDataStore(Players)):Then(function(dataStore)
|
|
29
|
+
maid:GivePromise(dataStore:Load("money", 0))
|
|
30
|
+
:Then(function(money)
|
|
31
|
+
playerMoneyValue.Value = money
|
|
32
|
+
maid:GiveTask(dataStore:StoreOnValueChange("money", playerMoneyValue))
|
|
33
|
+
end)
|
|
34
|
+
end)
|
|
35
|
+
|
|
36
|
+
topMaid[player] = maid
|
|
37
|
+
end
|
|
38
|
+
Players.PlayerAdded:Connect(handlePlayer)
|
|
39
|
+
Players.PlayerRemoving:Connect(function(player)
|
|
40
|
+
topMaid[player] = nil
|
|
41
|
+
end)
|
|
42
|
+
for _, player in pairs(Players:GetPlayers()) do
|
|
43
|
+
task.spawn(handlePlayer, player)
|
|
44
|
+
end
|
|
45
|
+
```
|
|
46
|
+
|
|
8
47
|
@server
|
|
9
48
|
@class PlayerDataStoreManager
|
|
10
49
|
]=]
|