@quenty/gameconfig 12.24.0 → 12.24.2-canary.547.11ae689.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.
@@ -1,50 +1,67 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class GameConfigAssetBase
3
4
  ]=]
4
5
 
5
6
  local require = require(script.Parent.loader).load(script)
6
7
 
8
+ local AttributeValue = require("AttributeValue")
7
9
  local BaseObject = require("BaseObject")
8
- local Rx = require("Rx")
9
- local RxAttributeUtils = require("RxAttributeUtils")
10
- local RxInstanceUtils = require("RxInstanceUtils")
11
10
  local GameConfigAssetConstants = require("GameConfigAssetConstants")
12
- local Promise = require("Promise")
13
11
  local GameConfigAssetUtils = require("GameConfigAssetUtils")
14
- local AttributeValue = require("AttributeValue")
15
12
  local GameConfigTranslator = require("GameConfigTranslator")
13
+ local Promise = require("Promise")
14
+ local Rx = require("Rx")
15
+ local RxAttributeUtils = require("RxAttributeUtils")
16
+ local RxInstanceUtils = require("RxInstanceUtils")
17
+ local _CancelToken = require("CancelToken")
18
+ local _JSONTranslator = require("JSONTranslator")
19
+ local _Observable = require("Observable")
20
+ local _ServiceBag = require("ServiceBag")
21
+ local _GameConfigAssetTypes = require("GameConfigAssetTypes")
16
22
 
17
23
  local GameConfigAssetBase = setmetatable({}, BaseObject)
18
24
  GameConfigAssetBase.ClassName = "GameConfigAssetBase"
19
25
  GameConfigAssetBase.__index = GameConfigAssetBase
20
26
 
27
+ export type GameConfigAssetBase = typeof(setmetatable(
28
+ {} :: {
29
+ _obj: Folder,
30
+ _serviceBag: _ServiceBag.ServiceBag,
31
+ _nameTranslationKey: AttributeValue.AttributeValue<string>,
32
+ _descriptionTranslationKey: AttributeValue.AttributeValue<string>,
33
+ _configTranslator: _JSONTranslator.JSONTranslator,
34
+ },
35
+ { __index = GameConfigAssetBase}
36
+ ))
37
+
21
38
  --[=[
22
39
  Constructs a new GameConfigAssetBase. Should be done via binder. This is a base class.
23
40
  @param obj Folder
24
41
  @param serviceBag ServiceBag
25
42
  @return GameConfigAssetBase
26
43
  ]=]
27
- function GameConfigAssetBase.new(obj, serviceBag)
28
- local self = setmetatable(BaseObject.new(obj), GameConfigAssetBase)
44
+ function GameConfigAssetBase.new(obj: Folder, serviceBag: _ServiceBag.ServiceBag): GameConfigAssetBase
45
+ local self: GameConfigAssetBase = setmetatable(BaseObject.new(obj) :: any, GameConfigAssetBase)
29
46
 
30
47
  self._serviceBag = assert(serviceBag, "No serviceBag")
31
48
  self._nameTranslationKey = AttributeValue.new(self._obj, "NameTranslationKey", "assets.name.unknown")
32
- self._descriptionTranslationKey = AttributeValue.new(self._obj, "DescriptionTranslationKey", "assets.description.unknown")
49
+ self._descriptionTranslationKey =
50
+ AttributeValue.new(self._obj, "DescriptionTranslationKey", "assets.description.unknown")
33
51
  self._configTranslator = self._serviceBag:GetService(GameConfigTranslator)
34
52
 
35
53
  return self
36
54
  end
37
55
 
38
-
39
56
  --[=[
40
57
  Observes the translated name
41
58
  @return Observable<string>
42
59
  ]=]
43
- function GameConfigAssetBase:ObserveTranslatedName()
60
+ function GameConfigAssetBase:ObserveTranslatedName(): _Observable.Observable<string>
44
61
  return self:ObserveNameTranslationKey():Pipe({
45
62
  Rx.switchMap(function(key)
46
63
  return self._configTranslator:ObserveFormatByKey(key)
47
- end)
64
+ end),
48
65
  })
49
66
  end
50
67
 
@@ -52,22 +69,33 @@ end
52
69
  Observes the translated description
53
70
  @return Observable<string>
54
71
  ]=]
55
- function GameConfigAssetBase:ObserveTranslatedDescription()
72
+ function GameConfigAssetBase:ObserveTranslatedDescription(): _Observable.Observable<string>
56
73
  return self:ObserveDescriptionTranslationKey():Pipe({
57
74
  Rx.switchMap(function(key)
58
75
  return self._configTranslator:ObserveFormatByKey(key)
59
- end)
76
+ end),
60
77
  })
61
78
  end
62
79
 
63
- function GameConfigAssetBase:SetNameTranslationKey(nameTranslationKey)
80
+ --[=[
81
+ Sets the name translation key
82
+ @param nameTranslationKey string?
83
+ ]=]
84
+ function GameConfigAssetBase:SetNameTranslationKey(nameTranslationKey: string?)
64
85
  assert(type(nameTranslationKey) == "string" or nameTranslationKey == nil, "Bad nameTranslationKey")
65
86
 
66
87
  self._nameTranslationKey.Value = nameTranslationKey or "assets.name.unknown"
67
88
  end
68
89
 
69
- function GameConfigAssetBase:SetDescriptionTranslationKey(descriptionTranslationKey)
70
- assert(type(descriptionTranslationKey) == "string" or descriptionTranslationKey == nil, "Bad descriptionTranslationKey")
90
+ --[=[
91
+ Sets the description translation key
92
+ @param descriptionTranslationKey string?
93
+ ]=]
94
+ function GameConfigAssetBase:SetDescriptionTranslationKey(descriptionTranslationKey: string?)
95
+ assert(
96
+ type(descriptionTranslationKey) == "string" or descriptionTranslationKey == nil,
97
+ "Bad descriptionTranslationKey"
98
+ )
71
99
 
72
100
  self._descriptionTranslationKey.Value = descriptionTranslationKey or "assets.description.unknown"
73
101
  end
@@ -76,7 +104,7 @@ end
76
104
  Gets the asset id
77
105
  @return number
78
106
  ]=]
79
- function GameConfigAssetBase:GetAssetId()
107
+ function GameConfigAssetBase:GetAssetId(): number
80
108
  return self._obj:GetAttribute(GameConfigAssetConstants.ASSET_ID_ATTRIBUTE)
81
109
  end
82
110
 
@@ -84,7 +112,7 @@ end
84
112
  Observes the assetId
85
113
  @return Observable<number>
86
114
  ]=]
87
- function GameConfigAssetBase:ObserveAssetId()
115
+ function GameConfigAssetBase:ObserveAssetId(): _Observable.Observable<number>
88
116
  return RxAttributeUtils.observeAttribute(self._obj, GameConfigAssetConstants.ASSET_ID_ATTRIBUTE, nil)
89
117
  end
90
118
 
@@ -92,7 +120,7 @@ end
92
120
  Gets the asset type
93
121
  @return string?
94
122
  ]=]
95
- function GameConfigAssetBase:GetAssetType()
123
+ function GameConfigAssetBase:GetAssetType(): string?
96
124
  return self._obj:GetAttribute(GameConfigAssetConstants.ASSET_TYPE_ATTRIBUTE)
97
125
  end
98
126
 
@@ -100,7 +128,7 @@ end
100
128
  Observes the asset type
101
129
  @return Observable<string?>
102
130
  ]=]
103
- function GameConfigAssetBase:ObserveAssetType()
131
+ function GameConfigAssetBase:ObserveAssetType(): _Observable.Observable<string?>
104
132
  return RxAttributeUtils.observeAttribute(self._obj, GameConfigAssetConstants.ASSET_TYPE_ATTRIBUTE, nil)
105
133
  end
106
134
 
@@ -108,7 +136,7 @@ end
108
136
  Observes the asset key
109
137
  @return Observable<string>
110
138
  ]=]
111
- function GameConfigAssetBase:ObserveAssetKey()
139
+ function GameConfigAssetBase:ObserveAssetKey(): _Observable.Observable<string>
112
140
  return RxInstanceUtils.observeProperty(self._obj, "Name")
113
141
  end
114
142
 
@@ -116,28 +144,34 @@ end
116
144
  Gets the asset key
117
145
  @return string
118
146
  ]=]
119
- function GameConfigAssetBase:GetAssetKey()
147
+ function GameConfigAssetBase:GetAssetKey(): string
120
148
  return self._obj.Name
121
149
  end
122
150
 
151
+ export type GameConfigAssetState = {
152
+ assetId: number,
153
+ assetKey: string,
154
+ assetType: _GameConfigAssetTypes.GameConfigAssetType,
155
+ }
156
+
123
157
  --[=[
124
158
  Observes the asset state
125
159
  @return any
126
160
  ]=]
127
- function GameConfigAssetBase:ObserveState()
161
+ function GameConfigAssetBase:ObserveState(): _Observable.Observable<GameConfigAssetState>
128
162
  return Rx.combineLatest({
129
- assetId = self:ObserveAssetId();
130
- assetKey = self:ObserveAssetKey();
131
- assetType = self:ObserveAssetType();
132
- })
163
+ assetId = self:ObserveAssetId(),
164
+ assetKey = self:ObserveAssetKey(),
165
+ assetType = self:ObserveAssetType(),
166
+ }) :: any
133
167
  end
134
168
 
135
169
  --[=[
136
170
  Promises the cloud price in Robux
137
171
  @param cancelToken CancelToken
138
- @return Promise<string?>
172
+ @return Promise<number?>
139
173
  ]=]
140
- function GameConfigAssetBase:PromiseCloudPriceInRobux(cancelToken)
174
+ function GameConfigAssetBase:PromiseCloudPriceInRobux(cancelToken: _CancelToken.CancelToken): Promise.Promise<number>
141
175
  return Rx.toPromise(self:ObserveCloudPriceInRobux(), cancelToken)
142
176
  end
143
177
 
@@ -146,7 +180,7 @@ end
146
180
  @param cancelToken CancelToken
147
181
  @return Promise<string?>
148
182
  ]=]
149
- function GameConfigAssetBase:PromiseCloudName(cancelToken)
183
+ function GameConfigAssetBase:PromiseCloudName(cancelToken: _CancelToken.CancelToken): Promise.Promise<string>
150
184
  return Rx.toPromise(self:ObserveCloudName(), cancelToken)
151
185
  end
152
186
  --[=[
@@ -154,7 +188,7 @@ end
154
188
  @param _cancelToken CancelToken
155
189
  @return Promise<Color3>
156
190
  ]=]
157
- function GameConfigAssetBase:PromiseColor(_cancelToken)
191
+ function GameConfigAssetBase:PromiseColor(_cancelToken: _CancelToken.CancelToken): Promise.Promise<Color3>
158
192
  return Promise.resolved(Color3.fromRGB(66, 158, 166))
159
193
  end
160
194
 
@@ -163,7 +197,7 @@ end
163
197
  @param cancelToken CancelToken
164
198
  @return Promise<string?>
165
199
  ]=]
166
- function GameConfigAssetBase:PromiseNameTranslationKey(cancelToken)
200
+ function GameConfigAssetBase:PromiseNameTranslationKey(cancelToken: _CancelToken.CancelToken): Promise.Promise<string>
167
201
  return Rx.toPromise(self:ObserveNameTranslationKey(), cancelToken)
168
202
  end
169
203
 
@@ -171,7 +205,7 @@ end
171
205
  Observes the name translation key.
172
206
  @return Observable<string?>
173
207
  ]=]
174
- function GameConfigAssetBase:ObserveNameTranslationKey()
208
+ function GameConfigAssetBase:ObserveNameTranslationKey(): _Observable.Observable<string?>
175
209
  return self._nameTranslationKey:Observe()
176
210
  end
177
211
 
@@ -179,7 +213,7 @@ end
179
213
  Observes the description translation key.
180
214
  @return Observable<string?>
181
215
  ]=]
182
- function GameConfigAssetBase:ObserveDescriptionTranslationKey()
216
+ function GameConfigAssetBase:ObserveDescriptionTranslationKey(): _Observable.Observable<string?>
183
217
  return self._descriptionTranslationKey:Observe()
184
218
  end
185
219
 
@@ -188,7 +222,7 @@ end
188
222
  translation keys.
189
223
  @return Observable<string?>
190
224
  ]=]
191
- function GameConfigAssetBase:ObserveCloudName()
225
+ function GameConfigAssetBase:ObserveCloudName(): _Observable.Observable<string?>
192
226
  return self:_observeCloudProperty({ "Name" }, "string")
193
227
  end
194
228
 
@@ -197,7 +231,7 @@ end
197
231
  translation keys.
198
232
  @return Observable<string?>
199
233
  ]=]
200
- function GameConfigAssetBase:ObserveCloudDescription()
234
+ function GameConfigAssetBase:ObserveCloudDescription(): _Observable.Observable<string?>
201
235
  return self:_observeCloudProperty({ "Description" }, "string")
202
236
  end
203
237
 
@@ -205,25 +239,28 @@ end
205
239
  Observes the cost in Robux.
206
240
  @return Observable<number?>
207
241
  ]=]
208
- function GameConfigAssetBase:ObserveCloudPriceInRobux()
242
+ function GameConfigAssetBase:ObserveCloudPriceInRobux(): _Observable.Observable<number?>
209
243
  return self:_observeCloudProperty({ "PriceInRobux" }, "number")
210
244
  end
211
245
 
212
246
  --[=[
213
247
  @return Observable<number?>
214
248
  ]=]
215
- function GameConfigAssetBase:ObserveCloudIconImageAssetId()
249
+ function GameConfigAssetBase:ObserveCloudIconImageAssetId(): _Observable.Observable<number?>
216
250
  return self:_observeCloudProperty({ "IconImageAssetId", "IconImageId" }, "number")
217
251
  end
218
252
 
219
- function GameConfigAssetBase:_observeCloudProperty(propertyNameList, expectedType)
253
+ function GameConfigAssetBase:_observeCloudProperty(
254
+ propertyNameList: { string },
255
+ expectedType: string
256
+ ): _Observable.Observable<any?>
220
257
  assert(type(propertyNameList) == "table", "Bad propertyNameList")
221
258
  assert(type(expectedType) == "string", "Bad expectedType")
222
259
 
223
260
  return self:_observeCloudDataFromState():Pipe({
224
261
  Rx.map(function(data)
225
262
  if type(data) == "table" then
226
- for _, propertyName in pairs(propertyNameList) do
263
+ for _, propertyName in propertyNameList do
227
264
  local result = data[propertyName]
228
265
  if type(result) == expectedType then
229
266
  return result
@@ -234,31 +271,35 @@ function GameConfigAssetBase:_observeCloudProperty(propertyNameList, expectedTyp
234
271
  else
235
272
  return nil
236
273
  end
237
- end)
274
+ end),
238
275
  })
239
276
  end
240
277
 
241
- function GameConfigAssetBase:_observeCloudDataFromState()
278
+ function GameConfigAssetBase:_observeCloudDataFromState(): _Observable.Observable<any?>
242
279
  if self._cloudDataObservable then
243
280
  return self._cloudDataObservable
244
281
  end
245
282
 
246
283
  self._cloudDataObservable = self:ObserveState():Pipe({
247
- Rx.switchMap(function(state)
248
- if type(state.assetId) == "number" and type(state.assetType) == "string" and type(state.assetKey) == "string" then
284
+ Rx.switchMap(function(state): any
285
+ if
286
+ type(state.assetId) == "number"
287
+ and type(state.assetType) == "string"
288
+ and type(state.assetKey) == "string"
289
+ then
249
290
  return Rx.fromPromise(self:_promiseCloudDataForState(state))
250
291
  else
251
292
  return Rx.of(nil)
252
293
  end
253
- end);
254
- Rx.distinct();
255
- Rx.shareReplay(1);
294
+ end),
295
+ Rx.distinct() :: any,
296
+ Rx.shareReplay(1) :: any,
256
297
  })
257
298
 
258
299
  return self._cloudDataObservable
259
300
  end
260
301
 
261
- function GameConfigAssetBase:_promiseCloudDataForState(state)
302
+ function GameConfigAssetBase:_promiseCloudDataForState(state: GameConfigAssetState): Promise.Promise<any?>
262
303
  return GameConfigAssetUtils.promiseCloudDataForAssetType(self._serviceBag, state.assetType, state.assetId)
263
304
  end
264
305
 
@@ -10,6 +10,7 @@ local BadgeUtils = require("BadgeUtils")
10
10
  local GameConfigAssetTypes = require("GameConfigAssetTypes")
11
11
  local MarketplaceServiceCache = require("MarketplaceServiceCache")
12
12
  local Promise = require("Promise")
13
+ local _ServiceBag = require("ServiceBag")
13
14
 
14
15
  local GameConfigAssetUtils = {}
15
16
 
@@ -21,7 +22,12 @@ local GameConfigAssetUtils = {}
21
22
  @param assetId number
22
23
  @return Instance
23
24
  ]=]
24
- function GameConfigAssetUtils.create(binder, assetType, assetKey, assetId)
25
+ function GameConfigAssetUtils.create(
26
+ binder,
27
+ assetType: GameConfigAssetTypes.GameConfigAssetType,
28
+ assetKey: string,
29
+ assetId: number
30
+ ): Folder
25
31
  local asset = Instance.new("Folder")
26
32
  asset.Name = assetKey
27
33
 
@@ -41,7 +47,7 @@ end
41
47
  @param assetId number
42
48
  @return Promise<any>
43
49
  ]=]
44
- function GameConfigAssetUtils.promiseCloudDataForAssetType(serviceBag, assetType, assetId)
50
+ function GameConfigAssetUtils.promiseCloudDataForAssetType(serviceBag: _ServiceBag.ServiceBag, assetType: GameConfigAssetTypes.GameConfigAssetType, assetId: number): Promise.Promise<any>
45
51
  assert(type(assetType) == "string", "Bad assetType")
46
52
  assert(type(assetId) == "number", "Bad assetId")
47
53
 
@@ -19,7 +19,7 @@ local pluralMap = {
19
19
  [GameConfigAssetTypes.MEMBERSHIP] = "memberships";
20
20
  }
21
21
 
22
- for _, item in pairs(GameConfigAssetTypes) do
22
+ for _, item in GameConfigAssetTypes do
23
23
  assert(pluralMap[item], "Missing plural")
24
24
  end
25
25
 
@@ -6,63 +6,84 @@ local require = require(script.Parent.loader).load(script)
6
6
 
7
7
  local Table = require("Table")
8
8
 
9
+ export type GameConfigAssetType =
10
+ "badge"
11
+ | "product"
12
+ | "pass"
13
+ | "asset"
14
+ | "bundle"
15
+ | "place"
16
+ | "subscription"
17
+ | "membership"
18
+
19
+ export type GameConfigAssetTypes = {
20
+ BADGE: "badge",
21
+ PRODUCT: "product",
22
+ PASS: "pass",
23
+ ASSET: "asset",
24
+ BUNDLE: "bundle",
25
+ PLACE: "place",
26
+ SUBSCRIPTION: "subscription",
27
+ MEMBERSHIP: "membership",
28
+ }
29
+
9
30
  return Table.readonly({
10
- --[=[
31
+ --[=[
11
32
  Specifies the asset is of type badge
12
33
  @prop BADGE string
13
34
  @within GameConfigAssetTypes
14
35
  ]=]
15
- BADGE = "badge";
36
+ BADGE = "badge",
16
37
 
17
- --[=[
38
+ --[=[
18
39
  Specifies the asset is of type product
19
40
  @prop PRODUCT string
20
41
  @within GameConfigAssetTypes
21
42
  ]=]
22
- PRODUCT = "product";
43
+ PRODUCT = "product",
23
44
 
24
- --[=[
45
+ --[=[
25
46
  Specifies the asset is of type pass
26
47
  @prop PASS string
27
48
  @within GameConfigAssetTypes
28
49
  ]=]
29
- PASS = "pass";
50
+ PASS = "pass",
30
51
 
31
- --[=[
52
+ --[=[
32
53
  Specifies the asset is of type asset. This is basically anything in Roblox's asset id system.
33
54
  Think models, UGC, et cetera.
34
55
 
35
56
  @prop ASSET string
36
57
  @within GameConfigAssetTypes
37
58
  ]=]
38
- ASSET = "asset";
59
+ ASSET = "asset",
39
60
 
40
- --[=[
61
+ --[=[
41
62
  Bundle asset type
42
63
 
43
64
  @prop BUNDLE string
44
65
  @within GameConfigAssetTypes
45
66
  ]=]
46
- BUNDLE = "bundle";
67
+ BUNDLE = "bundle",
47
68
 
48
- --[=[
69
+ --[=[
49
70
  Specifies the asset is of type place
50
71
  @prop PLACE string
51
72
  @within GameConfigAssetTypes
52
73
  ]=]
53
- PLACE = "place";
74
+ PLACE = "place",
54
75
 
55
- --[=[
76
+ --[=[
56
77
  Specifies the asset is of type subscription
57
78
  @prop SUBSCRIPTION string
58
79
  @within GameConfigAssetTypes
59
80
  ]=]
60
- SUBSCRIPTION = "subscription";
81
+ SUBSCRIPTION = "subscription",
61
82
 
62
- --[=[
83
+ --[=[
63
84
  Specifies the asset is of type membership (Roblox Premium)
64
85
  @prop MEMBERSHIP string
65
86
  @within GameConfigAssetTypes
66
87
  ]=]
67
- MEMBERSHIP = "membership";
68
- })
88
+ MEMBERSHIP = "membership",
89
+ } :: GameConfigAssetTypes)