@quenty/datastore 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
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
|
+
# [5.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@5.2.0...@quenty/datastore@5.3.0) (2022-07-31)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add DataStore SetCacheTime (not implemented yet) ([906e723](https://github.com/Quenty/NevermoreEngine/commit/906e72397075200e8cb8b98bc8b7b7f96d992907))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* Add GameDataStoreService service for global game data ([5f6d52c](https://github.com/Quenty/NevermoreEngine/commit/5f6d52ca9f2be811c426714cd6d94d9794f366b5))
|
|
17
|
+
* Support StoreOnValueChange with non ValueBase instances. ([ab45498](https://github.com/Quenty/NevermoreEngine/commit/ab4549833f41f2b3d8b43202965fd3202b649770))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
6
23
|
# [5.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@5.1.0...@quenty/datastore@5.2.0) (2022-07-02)
|
|
7
24
|
|
|
8
25
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/datastore",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Quenty's Datastore implementation for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/baseobject": "^5.
|
|
29
|
+
"@quenty/baseobject": "^5.1.0",
|
|
30
30
|
"@quenty/loader": "^5.0.0",
|
|
31
|
-
"@quenty/maid": "^2.
|
|
32
|
-
"@quenty/promise": "^5.
|
|
31
|
+
"@quenty/maid": "^2.4.0",
|
|
32
|
+
"@quenty/promise": "^5.1.0",
|
|
33
33
|
"@quenty/signal": "^2.2.0",
|
|
34
34
|
"@quenty/symbol": "^2.1.0",
|
|
35
35
|
"@quenty/table": "^3.1.0"
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e31b3a35aa475bb5699a24898a8639e107165b36"
|
|
41
41
|
}
|
package/src/Server/DataStore.lua
CHANGED
|
@@ -38,6 +38,7 @@ local DEBUG_WRITING = false
|
|
|
38
38
|
local AUTO_SAVE_TIME = 60*5
|
|
39
39
|
local CHECK_DIVISION = 15
|
|
40
40
|
local JITTER = 20 -- Randomly assign jitter so if a ton of players join at once we don't hit the datastore at once
|
|
41
|
+
local DEFAULT_CACHE_TIME_SECONDS = math.huge
|
|
41
42
|
|
|
42
43
|
local DataStore = setmetatable({}, DataStoreStage)
|
|
43
44
|
DataStore.ClassName = "DataStore"
|
|
@@ -53,6 +54,7 @@ function DataStore.new(robloxDataStore, key)
|
|
|
53
54
|
|
|
54
55
|
self._key = key or error("No key")
|
|
55
56
|
self._robloxDataStore = robloxDataStore or error("No robloxDataStore")
|
|
57
|
+
self._cacheTimeSeconds = DEFAULT_CACHE_TIME_SECONDS
|
|
56
58
|
|
|
57
59
|
--[=[
|
|
58
60
|
Prop that fires when saving. Promise will resolve once saving is complete.
|
|
@@ -89,6 +91,16 @@ function DataStore.new(robloxDataStore, key)
|
|
|
89
91
|
return self
|
|
90
92
|
end
|
|
91
93
|
|
|
94
|
+
--[=[
|
|
95
|
+
Sets how long the datastore will cache for
|
|
96
|
+
@param cacheTimeSeconds number?
|
|
97
|
+
]=]
|
|
98
|
+
function DataStore:SetCacheTime(cacheTimeSeconds)
|
|
99
|
+
assert(type(cacheTimeSeconds) == "number" or cacheTimeSeconds == nil, "Bad cacheTimeSeconds")
|
|
100
|
+
|
|
101
|
+
self._cacheTimeSeconds = cacheTimeSeconds or DEFAULT_CACHE_TIME_SECONDS
|
|
102
|
+
end
|
|
103
|
+
|
|
92
104
|
--[=[
|
|
93
105
|
Returns the full path for the datastore
|
|
94
106
|
@return string
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
Service which manages central access to datastore. This datastore will refresh pretty frequently and
|
|
3
|
+
can be used for configuration and other components, such as Twitter codes or global settings.
|
|
4
|
+
|
|
5
|
+
@class GameDataStoreService
|
|
6
|
+
]=]
|
|
7
|
+
|
|
8
|
+
local require = require(script.Parent.loader).load(script)
|
|
9
|
+
|
|
10
|
+
local RunService = game:GetService("RunService")
|
|
11
|
+
|
|
12
|
+
local DataStore = require("DataStore")
|
|
13
|
+
local DataStorePromises = require("DataStorePromises")
|
|
14
|
+
local Maid = require("Maid")
|
|
15
|
+
|
|
16
|
+
local GameDataStoreService = {}
|
|
17
|
+
|
|
18
|
+
function GameDataStoreService:Init(serviceBag)
|
|
19
|
+
assert(not self._serviceBag, "Already initialized")
|
|
20
|
+
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
21
|
+
|
|
22
|
+
self._maid = Maid.new()
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
--[=[
|
|
26
|
+
For if you want to disable saving in studio for faster close time!
|
|
27
|
+
]=]
|
|
28
|
+
function GameDataStoreService:DisableSaveOnCloseStudio()
|
|
29
|
+
assert(RunService:IsStudio())
|
|
30
|
+
|
|
31
|
+
self._disableSavingInStudio = true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
function GameDataStoreService:Start()
|
|
35
|
+
game:BindToClose(function()
|
|
36
|
+
if self._disableSavingInStudio then
|
|
37
|
+
return
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
return self:PromiseDataStore()
|
|
41
|
+
:Then(function(dataStore)
|
|
42
|
+
return dataStore:Save()
|
|
43
|
+
end)
|
|
44
|
+
:Wait()
|
|
45
|
+
end)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
function GameDataStoreService:PromiseDataStore()
|
|
49
|
+
if self._dataStorePromise then
|
|
50
|
+
return self._dataStorePromise
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
self._dataStorePromise = self:_promiseRobloxDataStore()
|
|
54
|
+
:Then(function(robloxDataStore)
|
|
55
|
+
local dataStore = DataStore.new(robloxDataStore, self:_getKey())
|
|
56
|
+
self._maid._datastore = dataStore
|
|
57
|
+
|
|
58
|
+
return dataStore
|
|
59
|
+
end)
|
|
60
|
+
|
|
61
|
+
return self._dataStorePromise
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
function GameDataStoreService:_promiseRobloxDataStore()
|
|
65
|
+
if self._robloxDataStorePromise then
|
|
66
|
+
return self._robloxDataStorePromise
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
self._robloxDataStorePromise = self._maid:GivePromise(DataStorePromises.promiseDataStore("GameDataStore", "Version1"))
|
|
70
|
+
|
|
71
|
+
return self._robloxDataStorePromise
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
function GameDataStoreService:_getKey()
|
|
75
|
+
return "version1"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
function GameDataStoreService:Destroy()
|
|
79
|
+
self._maid:DoCleaning()
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
return GameDataStoreService
|
|
@@ -245,7 +245,7 @@ end
|
|
|
245
245
|
]=]
|
|
246
246
|
function DataStoreStage:StoreOnValueChange(name, valueObj)
|
|
247
247
|
assert(type(name) == "string", "Bad name")
|
|
248
|
-
assert(typeof(valueObj) == "Instance", "Bad valueObj")
|
|
248
|
+
assert(typeof(valueObj) == "Instance" or (type(valueObj) == "table" and valueObj.Changed), "Bad valueObj")
|
|
249
249
|
|
|
250
250
|
if self._takenKeys[name] then
|
|
251
251
|
error(("[DataStoreStage] - Already have a writer for %q"):format(name))
|