@quenty/adorneedata 7.5.0 → 7.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,18 @@
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.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/adorneedata@7.5.0...@quenty/adorneedata@7.6.0) (2024-09-12)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add AdorneeData:Unset(adornee) ([214b490](https://github.com/Quenty/NevermoreEngine/commit/214b490c3dbc64a6b511167534436376dfc05573))
12
+ * Add AdorneeDataEntry supporting optional attributes ([b840805](https://github.com/Quenty/NevermoreEngine/commit/b8408052efc0dd6f5039d7d9b73ae22b45b201d9))
13
+
14
+
15
+
16
+
17
+
6
18
  # [7.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/adorneedata@7.4.0...@quenty/adorneedata@7.5.0) (2024-08-09)
7
19
 
8
20
  **Note:** Version bump only for package @quenty/adorneedata
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/adorneedata",
3
- "version": "7.5.0",
3
+ "version": "7.6.0",
4
4
  "description": "Bridges attributes and serialization",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,17 +25,17 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/attributeutils": "^14.4.0",
28
+ "@quenty/attributeutils": "^14.5.0",
29
29
  "@quenty/defaultvalueutils": "^1.2.0",
30
- "@quenty/ducktype": "^5.3.0",
31
- "@quenty/loader": "^10.3.0",
32
- "@quenty/rx": "^13.4.0",
33
- "@quenty/rxsignal": "^7.4.0",
30
+ "@quenty/ducktype": "^5.4.0",
31
+ "@quenty/loader": "^10.4.0",
32
+ "@quenty/rx": "^13.5.0",
33
+ "@quenty/rxsignal": "^7.5.0",
34
34
  "@quenty/table": "^3.5.0",
35
35
  "@quentystudios/t": "^3.0.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "ba466bdbc05c42fb607cf5e228c16339201d21d7"
40
+ "gitHead": "fb172906f3ee725269ec1e5f4daf9dca227e729d"
41
41
  }
@@ -22,7 +22,7 @@
22
22
  You can then use the data to retrieve values
23
23
 
24
24
  ```lua
25
- local data = CombatConfiguration:CreateValue(workspace)
25
+ local data = CombatConfiguration:Create(workspace)
26
26
 
27
27
  -- Can ready any data
28
28
  print(data.EnableCombat.Value) --> true
@@ -62,7 +62,7 @@
62
62
  assert(CombatConfiguration:IsData(defaultCombatState))
63
63
 
64
64
  -- Or read attributes directly
65
- CombatConfiguration:GetAttributes(workspace))
65
+ CombatConfiguration:Get(workspace))
66
66
 
67
67
  -- Note that this is the same as an attribute
68
68
  print(workspace:GetAttribute("EnableCombat")) --> true
@@ -116,17 +116,17 @@ function AdorneeData:__index(index)
116
116
  return AdorneeData[index]
117
117
  elseif type(index) == "string" then
118
118
  local found = self._fullPrototype[index]
119
- if not found then
120
- error(string.format("[AdorneeData] - Bad index %q is not a known adornee", index))
119
+ if found == nil then
120
+ error(string.format("[AdorneeData] - Bad index %q is not a known attribute name", index))
121
121
  end
122
122
 
123
123
  if AdorneeDataEntry.isAdorneeDataEntry(found) then
124
124
  return found
125
125
  else
126
126
  -- TODO: Cache this construction
127
- return AdorneeDataEntry.new(index, function(adornee)
127
+ return AdorneeDataEntry.new(typeof(found), function(adornee)
128
128
  return AttributeValue.new(adornee, index, found)
129
- end)
129
+ end, found)
130
130
  end
131
131
  end
132
132
  end
@@ -197,17 +197,16 @@ end
197
197
  function AdorneeData:Observe(adornee)
198
198
  assert(typeof(adornee) == "Instance", "Bad adornee")
199
199
 
200
- return self:CreateAdorneeDataValue(adornee):Observe(adornee)
200
+ return self:Create(adornee):Observe(adornee)
201
201
  end
202
202
 
203
-
204
203
  --[=[
205
204
  Gets attribute table for the data
206
205
 
207
206
  @param adornee Instance
208
207
  @return AdorneeDataValue
209
208
  ]=]
210
- function AdorneeData:CreateValue(adornee)
209
+ function AdorneeData:Create(adornee)
211
210
  assert(typeof(adornee) == "Instance", "Bad adornee")
212
211
 
213
212
  local attributeTableValue = AdorneeDataValue.new(adornee, self._fullPrototype)
@@ -215,25 +214,13 @@ function AdorneeData:CreateValue(adornee)
215
214
  return attributeTableValue
216
215
  end
217
216
 
218
- --[=[
219
- Gets attribute table for the data
220
-
221
- @param adornee Instance
222
- @return AdorneeDataValue
223
- ]=]
224
- function AdorneeData:CreateAdorneeDataValue(adornee)
225
- assert(typeof(adornee) == "Instance", "Bad adornee")
226
-
227
- return self:CreateValue(adornee)
228
- end
229
-
230
217
  --[=[
231
218
  Gets the attributes for the adornee
232
219
 
233
220
  @param adornee Instance
234
221
  @return TStrict
235
222
  ]=]
236
- function AdorneeData:GetAttributes(adornee)
223
+ function AdorneeData:Get(adornee)
237
224
  assert(typeof(adornee) == "Instance", "Bad adornee")
238
225
 
239
226
  local data = {}
@@ -253,29 +240,45 @@ function AdorneeData:GetAttributes(adornee)
253
240
  return self:CreateStrictData(data)
254
241
  end
255
242
 
243
+
256
244
  --[=[
257
245
  Sets the attributes for the adornee
258
246
 
259
247
  @param adornee Instance
260
248
  @param data T
261
249
  ]=]
262
- function AdorneeData:SetAttributes(adornee, data)
250
+ function AdorneeData:Set(adornee, data)
263
251
  assert(typeof(adornee) == "Instance", "Bad adornee")
264
252
  assert(self:IsData(data))
265
253
 
266
- local attributeTable = self:CreateAdorneeDataValue(adornee)
254
+ local attributeTable = self:Create(adornee)
267
255
  for key, value in pairs(data) do
268
256
  attributeTable[key].Value = value
269
257
  end
270
258
  end
271
259
 
260
+ --[=[
261
+ Unsets the adornee's attributes (only for baseline attributes)
262
+
263
+ @param adornee Instance
264
+ ]=]
265
+ function AdorneeData:Unset(adornee)
266
+ assert(typeof(adornee) == "Instance", "Bad adornee")
267
+
268
+ for key, _ in pairs(self._attributePrototype) do
269
+ adornee:SetAttribute(key, nil)
270
+ end
271
+
272
+ -- TODO: Unset value object values
273
+ end
274
+
272
275
  --[=[
273
276
  Sets the attributes for the adornee
274
277
 
275
278
  @param adornee Instance
276
279
  @param data TStrict
277
280
  ]=]
278
- function AdorneeData:SetStrictAttributes(adornee, data)
281
+ function AdorneeData:SetStrict(adornee, data)
279
282
  assert(typeof(adornee) == "Instance", "Bad adornee")
280
283
  assert(self:IsStrictData(data))
281
284
 
@@ -321,6 +324,12 @@ function AdorneeData:InitAttributes(adornee, data)
321
324
  end
322
325
  end
323
326
 
327
+ AdorneeData.GetAttributes = AdorneeData.Get
328
+ AdorneeData.SetAttributes = AdorneeData.Set
329
+ AdorneeData.CreateAdorneeDataValue = AdorneeData.Create
330
+ AdorneeData.CreateValue = AdorneeData.CreateValue
331
+ AdorneeData.SetStrictAttributes = AdorneeData.SetStrict
332
+
324
333
  --[=[
325
334
  Gets a strict interface which will return true if the value is a partial interface and
326
335
  false otherwise.
@@ -9,6 +9,7 @@ local require = require(script.Parent.loader).load(script)
9
9
  local DuckTypeUtils = require("DuckTypeUtils")
10
10
  local t = require("t")
11
11
  local DefaultValueUtils = require("DefaultValueUtils")
12
+ local AttributeValue = require("AttributeValue")
12
13
 
13
14
  local AdorneeDataEntry = {}
14
15
  AdorneeDataEntry.ClassName = "AdorneeDataEntry"
@@ -17,29 +18,46 @@ AdorneeDataEntry.__index = AdorneeDataEntry
17
18
  --[=[
18
19
  Creates a new adornee data entry
19
20
 
20
- @param dataType string
21
+ @param interface string | (value: any) -> (boolean, string?)
21
22
  @param createValueObject (adornee: Instance) -> ValueObject<T>
23
+ @param defaultValue T?
22
24
  @return AdorneeDataEntry<T>
23
25
  ]=]
24
- function AdorneeDataEntry.new(dataType, createValueObject)
25
- assert(type(dataType) == "string", "Bad dataType")
26
+ function AdorneeDataEntry.new(interface, createValueObject, defaultValue)
27
+ assert(type(interface) == "string" or type(interface) == "function", "Bad interface")
26
28
  assert(type(createValueObject) == "function", "Bad createValueObject")
27
29
 
28
30
  local self = setmetatable({}, AdorneeDataEntry)
29
31
 
30
- self._dataType = dataType
31
32
  self._createValueObject = createValueObject
32
- self._strictInterface = t.typeof(self._dataType)
33
33
 
34
- if self._dataType == "Instance" then
35
- self._defaultValue = nil
34
+ if type(interface) == "string" then
35
+ self._interface = t.typeof(interface)
36
+ elseif type(interface) == "function" then
37
+ self._interface = interface
36
38
  else
37
- self._defaultValue = DefaultValueUtils.getDefaultValueForType(self._dataType)
39
+ error("Bad interface")
40
+ end
41
+
42
+ if defaultValue ~= nil then
43
+ self._defaultValue = defaultValue
44
+ elseif self._dataType == "Instance" then
45
+ self._defaultValue = nil
46
+ elseif type(interface) ~= "function" then
47
+ self._defaultValue = DefaultValueUtils.getDefaultValueForType(interface)
38
48
  end
39
49
 
40
50
  return self
41
51
  end
42
52
 
53
+ function AdorneeDataEntry.optionalAttribute(interface, name)
54
+ assert(type(interface) == "string" or type(interface) == "function", "Bad interface")
55
+
56
+ return AdorneeDataEntry.new(t.optional(interface), function(instance)
57
+ return AttributeValue.new(instance, name, nil)
58
+ end, nil)
59
+ end
60
+
43
61
  --[=[
44
62
  Returns true if the implementation is an AdorneeDataEntry
45
63
 
@@ -81,7 +99,7 @@ end
81
99
  @param adornee Instance
82
100
  @return T
83
101
  ]=]
84
- function AdorneeDataEntry:GetValue(adornee)
102
+ function AdorneeDataEntry:Get(adornee)
85
103
  assert(typeof(adornee) == "Instance", "Bad adornee")
86
104
 
87
105
  local valueObject = self:Create(adornee)
@@ -95,18 +113,18 @@ end
95
113
  @param adornee Instance
96
114
  @param value T
97
115
  ]=]
98
- function AdorneeDataEntry:SetValue(adornee, value)
116
+ function AdorneeDataEntry:Set(adornee, value)
99
117
  assert(typeof(adornee) == "Instance", "Bad adornee")
100
- assert(self._strictInterface(value))
118
+ assert(self._interface(value))
101
119
 
102
- local valueObject = self:CreateValueObject(adornee)
120
+ local valueObject = self:Create(adornee)
103
121
  valueObject.Value = value
104
122
  end
105
123
 
106
124
  --[=[
107
125
  Gets the default value
108
126
 
109
- @return T
127
+ @return T?
110
128
  ]=]
111
129
  function AdorneeDataEntry:GetDefaultValue()
112
130
  return self._defaultValue
@@ -118,7 +136,7 @@ end
118
136
  @return (value: any) -> (boolean, string)
119
137
  ]=]
120
138
  function AdorneeDataEntry:GetStrictInterface()
121
- return self._strictInterface
139
+ return self._interface
122
140
  end
123
141
 
124
142
  --[=[
@@ -128,7 +146,7 @@ end
128
146
  @return (boolean, string)
129
147
  ]=]
130
148
  function AdorneeDataEntry:IsValid(value)
131
- return self._strictInterface(value)
149
+ return self._interface(value)
132
150
  end
133
151
 
134
152
  return AdorneeDataEntry