AdorneeData
Bridges attributes and serializable data table. It's typical to need to define data in 3 ways.
- Attributes on an instance for replication
- Tables for Lua configuration
- Within AttributeValues for writing regular code
Providing all 3
Usage
Here's how the usage works:
-- Store data somewhere central
return AdorneeData.new({
EnableCombat = true;
PunchDamage = 15;
})
You can then use the data to retrieve values
local data = CombatConfiguration:Create(workspace)
-- Can ready any data
print(data.EnableCombat.Value) --> true
print(data.PunchDamage.Value) --> 15
print(data.Value) --> { EnableCombat = true, PunchDamage = true }
-- Can write any data
data.EnableCombat.Value = false
data.PunchDamage.Value = 15
data.Value = {
EnableCombat = false;
PunchDamage = 150;
}
-- Can subscribe to the data
data.EnableCombat:Observe():Subscribe(print)
data.PunchDamage:Observe():Subscribe(print)
data:Observe():Subscribe(print)
-- Can also operate without creating a value (although creating value is cheap)
local punchDamage = CombatConfiguration.PunchDamage:Create(workspace)
punchDamage.Value = 20
punchDamage:Observe():Subscribe(print)
-- Or like this
CombatConfiguration.PunchDamage:SetValue(workspace, 25)
print(CombatConfiguration.PunchDamage:GetValue(workspace))
CombatConfiguration.PunchDamage:Observe(workspace):Subscribe(print)
-- You can also create validated data
local defaultCombatState = CombatConfiguration:CreateData({
EnableCombat = true;
PunchDamage = 15;
})
-- Or validate that the data you're getting is valid
assert(CombatConfiguration:IsData(defaultCombatState))
-- Or read attributes directly
CombatConfiguration:Get(workspace))
-- Note that this is the same as an attribute
print(workspace:GetAttribute("EnableCombat")) --> true
Functions
new
Attribute data specification
IsStrictData
AdorneeData:
IsStrictData
(
data:
any
) →
(
boolean
,
string
--
Error message
)
Returns true if the data is valid data, otherwise returns false and an error.
CreateStrictData
AdorneeData:
CreateStrictData
(
data:
TStrict
) →
TStrict
Validates and creates a new data table for the data that is readonly and frozen
CreateFullData
AdorneeData:
CreateFullData
(
data:
T
) →
T
Validates and creates a new data table that is readonly. This table will have all values or the defaults
CreateData
AdorneeData:
CreateData
(
data:
TPartial
) →
TPartial
Validates and creates a new data table that is readonly and frozen, but for partial data.
The data can just be part of the attributes.
Observe
Observes the attribute table for adornee
Create
Gets attribute table for the data
Get
Gets the attributes for the adornee
Set
Sets the attributes for the adornee
Unset
Unsets the adornee's attributes (only for baseline attributes)
SetStrict
Sets the attributes for the adornee
InitAttributes
Initializes the attributes for the adornee
GetStrictTInterface
AdorneeData:
GetStrictTInterface
(
) →
function
Gets a strict interface which will return true if the value is a partial interface and false otherwise.
GetTInterface
AdorneeData:
GetTInterface
(
) →
function
Gets a [t] interface which will return true if the value is a partial interface, and false otherwise.
IsData
AdorneeData:
IsData
(
data:
any
) →
(
boolean
,
string
--
Error message
)
Returns true if the data is valid partial data, otherwise returns false and an error.