@quenty/datastore 6.0.1 → 6.2.0-canary.4096cd9.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,25 @@
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
+ # [6.2.0-canary.4096cd9.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@6.1.0...@quenty/datastore@6.2.0-canary.4096cd9.0) (2022-09-08)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add BindToCloseService package and implement across places binding to close ([afdd829](https://github.com/Quenty/NevermoreEngine/commit/afdd829538c9d0ce2d6f51ad9fee9063f0f5bd24))
12
+
13
+
14
+
15
+
16
+
17
+ # [6.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@6.0.1...@quenty/datastore@6.1.0) (2022-08-22)
18
+
19
+ **Note:** Version bump only for package @quenty/datastore
20
+
21
+
22
+
23
+
24
+
6
25
  ## [6.0.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@6.0.0...@quenty/datastore@6.0.1) (2022-08-16)
7
26
 
8
27
  **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": "6.0.1",
3
+ "version": "6.2.0-canary.4096cd9.0",
4
4
  "description": "Quenty's Datastore implementation for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -26,16 +26,17 @@
26
26
  "Quenty"
27
27
  ],
28
28
  "dependencies": {
29
- "@quenty/baseobject": "^5.1.1",
30
- "@quenty/loader": "^5.0.1",
31
- "@quenty/maid": "^2.4.0",
32
- "@quenty/promise": "^5.1.1",
33
- "@quenty/signal": "^2.2.0",
34
- "@quenty/symbol": "^2.1.0",
35
- "@quenty/table": "^3.1.0"
29
+ "@quenty/baseobject": "5.1.1",
30
+ "@quenty/bindtocloseservice": "1.1.0-canary.4096cd9.0",
31
+ "@quenty/loader": "5.0.1",
32
+ "@quenty/maid": "2.4.0",
33
+ "@quenty/promise": "5.2.0-canary.4096cd9.0",
34
+ "@quenty/signal": "2.3.0",
35
+ "@quenty/symbol": "2.1.0",
36
+ "@quenty/table": "3.1.0"
36
37
  },
37
38
  "publishConfig": {
38
39
  "access": "public"
39
40
  },
40
- "gitHead": "340ac324c03fb3b844bbbe7ca57ee88874a724c9"
41
+ "gitHead": "4096cd94d2c38d382b7aafe8cb2fcb8bb340d051"
41
42
  }
@@ -7,8 +7,6 @@
7
7
 
8
8
  local require = require(script.Parent.loader).load(script)
9
9
 
10
- local RunService = game:GetService("RunService")
11
-
12
10
  local DataStore = require("DataStore")
13
11
  local DataStorePromises = require("DataStorePromises")
14
12
  local Maid = require("Maid")
@@ -20,30 +18,9 @@ function GameDataStoreService:Init(serviceBag)
20
18
  assert(not self._serviceBag, "Already initialized")
21
19
  self._serviceBag = assert(serviceBag, "No serviceBag")
22
20
 
23
- self._maid = Maid.new()
24
- end
21
+ self._bindToCloseService = self._serviceBag:GetService(require("BindToCloseService"))
25
22
 
26
- --[=[
27
- For if you want to disable saving in studio for faster close time!
28
- ]=]
29
- function GameDataStoreService:DisableSaveOnCloseStudio()
30
- assert(RunService:IsStudio())
31
-
32
- self._disableSavingInStudio = true
33
- end
34
-
35
- function GameDataStoreService:Start()
36
- game:BindToClose(function()
37
- if self._disableSavingInStudio then
38
- return
39
- end
40
-
41
- return self:PromiseDataStore()
42
- :Then(function(dataStore)
43
- return dataStore:Save()
44
- end)
45
- :Wait()
46
- end)
23
+ self._maid = Maid.new()
47
24
  end
48
25
 
49
26
  function GameDataStoreService:PromiseDataStore()
@@ -54,7 +31,11 @@ function GameDataStoreService:PromiseDataStore()
54
31
  self._dataStorePromise = self:_promiseRobloxDataStore()
55
32
  :Then(function(robloxDataStore)
56
33
  local dataStore = DataStore.new(robloxDataStore, self:_getKey())
57
- self._maid._datastore = dataStore
34
+ self._maid:GiveTask(dataStore)
35
+
36
+ self._maid:GiveTask(self._bindToCloseService:RegisterPromiseOnCloseCallback(function()
37
+ return dataStore:Save()
38
+ end))
58
39
 
59
40
  return dataStore
60
41
  end)
@@ -1,5 +1,6 @@
1
1
  --[=[
2
- DataStore manager for player that automatically saves on player leave and game close.
2
+ DataStore manager for player that automatically saves on player leave and game close. Consider using
3
+ [PlayerDataStoreService] instead.
3
4
 
4
5
  @server
5
6
  @class PlayerDataStoreManager
@@ -23,13 +24,17 @@ PlayerDataStoreManager.__index = PlayerDataStoreManager
23
24
 
24
25
  --[=[
25
26
  Constructs a new PlayerDataStoreManager.
27
+
26
28
  @param robloxDataStore DataStore
27
29
  @param keyGenerator (player) -> string -- Function that takes in a player, and outputs a key
30
+ @param skipBindingToClose boolean?
28
31
  @return PlayerDataStoreManager
29
32
  ]=]
30
- function PlayerDataStoreManager.new(robloxDataStore, keyGenerator)
33
+ function PlayerDataStoreManager.new(robloxDataStore, keyGenerator, skipBindingToClose)
31
34
  local self = setmetatable(BaseObject.new(), PlayerDataStoreManager)
32
35
 
36
+ assert(type(skipBindingToClose) == "boolean" or skipBindingToClose == nil, "Bad skipBindingToClose")
37
+
33
38
  self._robloxDataStore = robloxDataStore or error("No robloxDataStore")
34
39
  self._keyGenerator = keyGenerator or error("No keyGenerator")
35
40
 
@@ -48,13 +53,15 @@ function PlayerDataStoreManager.new(robloxDataStore, keyGenerator)
48
53
  self:_removePlayerDataStore(player)
49
54
  end))
50
55
 
51
- game:BindToClose(function()
52
- if self._disableSavingInStudio then
53
- return
54
- end
56
+ if skipBindingToClose ~= true then
57
+ game:BindToClose(function()
58
+ if self._disableSavingInStudio then
59
+ return
60
+ end
55
61
 
56
- self:PromiseAllSaves():Wait()
57
- end)
62
+ self:PromiseAllSaves():Wait()
63
+ end)
64
+ end
58
65
 
59
66
  return self
60
67
  end
@@ -24,6 +24,9 @@ function PlayerDataStoreService:Init(serviceBag)
24
24
 
25
25
  self._maid = Maid.new()
26
26
 
27
+ -- External
28
+ self._bindToCloseService = self._serviceBag:GetService(require("BindToCloseService"))
29
+
27
30
  self._started = Promise.new()
28
31
  self._maid:GiveTask(self._started)
29
32
 
@@ -115,7 +118,14 @@ function PlayerDataStoreService:PromiseManager()
115
118
  dataStore,
116
119
  function(player)
117
120
  return tostring(player.UserId)
118
- end)
121
+ end,
122
+ true)
123
+
124
+ -- A lot safer if we're hot reloading or need to monitor bind to close calls
125
+ self._maid:GiveTask(self._bindToCloseService:RegisterPromiseOnCloseCallback(function()
126
+ return manager:PromiseAllSaves()
127
+ end))
128
+
119
129
  self._maid:GiveTask(manager)
120
130
  return manager
121
131
  end)