@quenty/datastore 3.5.0 → 3.6.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
+ # [3.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@3.5.1...@quenty/datastore@3.6.0) (2022-01-17)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add optional PlayerDataStoreService to centralize datastore usage across submodules. ([1c4349f](https://github.com/Quenty/NevermoreEngine/commit/1c4349fa3ed4ef59ed41117319057ca9e2bd6dfd))
12
+
13
+
14
+
15
+
16
+
17
+ ## [3.5.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@3.5.0...@quenty/datastore@3.5.1) (2022-01-16)
18
+
19
+ **Note:** Version bump only for package @quenty/datastore
20
+
21
+
22
+
23
+
24
+
6
25
  # [3.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@3.4.0...@quenty/datastore@3.5.0) (2022-01-07)
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": "3.5.0",
3
+ "version": "3.6.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": "^3.4.0",
30
- "@quenty/loader": "^3.3.0",
31
- "@quenty/maid": "^2.0.2",
32
- "@quenty/promise": "^3.5.0",
29
+ "@quenty/baseobject": "^3.5.0",
30
+ "@quenty/loader": "^3.4.0",
31
+ "@quenty/maid": "^2.1.0",
32
+ "@quenty/promise": "^3.6.0",
33
33
  "@quenty/signal": "^2.1.0",
34
34
  "@quenty/symbol": "^2.0.1",
35
35
  "@quenty/table": "^2.1.1"
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "5a3f3fb6c908fd3874f5ceacc70b404780275119"
40
+ "gitHead": "c094ba8f4e128cdff08919d89de226d3d65247ce"
41
41
  }
@@ -0,0 +1,124 @@
1
+ --[=[
2
+ Centralized service using serviceBag. This will let other packages work with a single player datastore service.
3
+
4
+ @server
5
+ @class PlayerDataStoreService
6
+ ]=]
7
+
8
+ local require = require(script.Parent.loader).load(script)
9
+
10
+ local PlayerDataStoreManager = require("PlayerDataStoreManager")
11
+ local DataStorePromises = require("DataStorePromises")
12
+ local Promise = require("Promise")
13
+ local Maid = require("Maid")
14
+
15
+ local PlayerDataStoreService = {}
16
+
17
+ --[=[
18
+ Initializes the PlayerDataStoreService. Should be done via [ServiceBag.Init].
19
+ @param serviceBag ServiceBag
20
+ ]=]
21
+ function PlayerDataStoreService:Init(serviceBag)
22
+ self._serviceBag = assert(serviceBag, "No serviceBag")
23
+
24
+ self._maid = Maid.new()
25
+ self._started = Promise.new()
26
+ self._maid:GiveTask(self._started)
27
+
28
+ self._dataStoreName = "PlayerData"
29
+ self._dataStoreScope = "SaveData"
30
+ end
31
+
32
+ --[=[
33
+ Initializes the datastore service for players. Should be done via [ServiceBag.Start].
34
+ ]=]
35
+ function PlayerDataStoreService:Start()
36
+ -- Give time for configuration
37
+ self._started:Resolve()
38
+ end
39
+
40
+ --[=[
41
+ Sets the name for the datastore to retrieve.
42
+
43
+ :::info
44
+ Must be done before start and after init.
45
+ :::
46
+
47
+ @param dataStoreName string
48
+ ]=]
49
+ function PlayerDataStoreService:SetDataStoreName(dataStoreName)
50
+ assert(type(dataStoreName) == "string", "Bad dataStoreName")
51
+ assert(self._started, "Not initialized")
52
+ assert(self._started:IsPending(), "Already started, cannot configure")
53
+
54
+ self._dataStoreName = dataStoreName
55
+ end
56
+
57
+ --[=[
58
+ Sets the scope for the datastore to retrieve.
59
+
60
+ :::info
61
+ Must be done before start and after init.
62
+ :::
63
+
64
+ @param dataStoreScope string
65
+ ]=]
66
+ function PlayerDataStoreService:SetDataStoreScope(dataStoreScope)
67
+ assert(type(dataStoreScope) == "string", "Bad dataStoreScope")
68
+ assert(self._started, "Not initialized")
69
+ assert(self._started:IsPending(), "Already started, cannot configure")
70
+
71
+ self._dataStoreScope = dataStoreScope
72
+ end
73
+
74
+ --[=[
75
+ Gets the datastore for the player.
76
+ @param player Player
77
+ @return Promise<DataStore>
78
+ ]=]
79
+ function PlayerDataStoreService:PromiseDataStore(player)
80
+ return self:PromiseManager()
81
+ :Then(function(manager)
82
+ return manager:GetDataStore(player)
83
+ end)
84
+ end
85
+
86
+ --[=[
87
+ Adds a removing callback to the manager.
88
+ @param callback function
89
+ @return Promise
90
+ ]=]
91
+ function PlayerDataStoreService:PromiseAddRemovingCallback(callback)
92
+ return self:PromiseManager()
93
+ :Then(function(manager)
94
+ manager:AddRemovingCallback(callback)
95
+ end)
96
+ end
97
+
98
+ --[=[
99
+ Retrieves the manager
100
+ @return PlayerDataStoreManager
101
+ ]=]
102
+ function PlayerDataStoreService:PromiseManager()
103
+ if self._dataStoreManagerPromise then
104
+ return self._dataStoreManagerPromise
105
+ end
106
+
107
+ self._dataStoreManagerPromise = self._started
108
+ :Then(function()
109
+ return DataStorePromises.promiseDataStore(self._dataStoreName, self._dataStoreScope)
110
+ end)
111
+ :Then(function(dataStore)
112
+ local manager = PlayerDataStoreManager.new(
113
+ dataStore,
114
+ function(player)
115
+ return tostring(player.UserId)
116
+ end)
117
+ self._maid:GiveTask(manager)
118
+ return manager
119
+ end)
120
+
121
+ return self._dataStoreManagerPromise
122
+ end
123
+
124
+ return PlayerDataStoreService