AdorneeConditionUtils
Utility library that defines a generalized interface for scriptable conditions. These conditions are rooted in Rx and can be scripted by a variety of systems. For example, we may have conditions on what ammo we can consume, or whether or not an action can be activated.
This library provides an interface for this to happen in. Conditions are marshalled through a BindableFunction and must be defined on both the client and server. However, these conditions can be reactive. It would be very simple to create a condition that also just links to a bool value if conditions should be only on the server.
local conditionFolder = AdorneeConditionUtils.createConditionContainer()
conditionFolder.Parent = workspace
local orGroup = AdorneeConditionUtils.createOrConditionGroup()
orGroup.Parent = conditionFolder
AdorneeConditionUtils.createRequiredProperty("Name", "Allowed").Parent = orGroup
local andGroup = AdorneeConditionUtils.createAndConditionGroup()
andGroup.Parent = orGroup
AdorneeConditionUtils.createRequiredProperty("Name", "Allow").Parent = andGroup
AdorneeConditionUtils.createRequiredAttribute("IsEnabled", true).Parent = andGroup
local testInst = Instance.new("Folder")
testInst.Name = "Deny"
testInst:SetAttribute("IsEnabled", false)
testInst.Parent = workspace
AdorneeConditionUtils.observeConditionsMet(conditionFolder, testInst):Subscribe(function(isAllowed)
print("Is allowed", isAllowed)
end) --> Is allowed false
task.delay(0.1, function()
testInst.Name = "Allowed" --> Is allowed true
end)
Functions
observeConditionsMet
Observes whether conditions are met or not.
AdorneeConditionUtils.observeConditionsMet(gun.AmmoAllowedConditions, ammo):Subscribe(function(allowed)
if allowed then
print("Can use this ammo to refill this gun")
end
end)
promiseQueryConditionsMet
Promises a query result of whether conditions are met or not. Unlike the observable, this will return a result once all combinations are met.
createConditionContainer
Creates a new condition container which conditions can be parented to. By default this is an "and" container, that is, all conditions underneath this container must be met for something to be allowed.
create
Creates a new adornee condition
createRequiredProperty
AdorneeConditionUtils.
createRequiredProperty
(
propertyName:
string
,
requiredValue:
any
) →
BindableFunction
Creates a new condition that a property is a set value.
createRequiredAttribute
AdorneeConditionUtils.
createRequiredAttribute
(
attributeName:
string
,
attributeValue:
any
) →
BindableFunction
Creates a new condition that an attribute must be set to the current value
createRequiredTieInterface
AdorneeConditionUtils.
createRequiredTieInterface
(
tieInterfaceDefinition:
TieDefinition
) →
BindableFunction
Creates a new condition that a tie interface must be implemented for the object
createOrConditionGroup
Creates a new "or" condition group where conditions are "or"ed together. Conditions should be parented underneath this BindableFunction.
createAndConditionGroup
Creates a new "and" condition group where conditions are "and"ed together. Conditions should be parented underneath this BindableFunction.
getRequiredTag
AdorneeConditionUtils.
getRequiredTag
(
) →
string
Conditions must be tagged with a specific tag to make sure we don't invoke random code, or code on the wrong host.
getConditionNamePostfix
AdorneeConditionUtils.
getConditionNamePostfix
(
) →
string
Gets the postfix for the condition name to make it clear to users if this condition is on the server or the client.
setValueWhenEmpty
AdorneeConditionUtils.
setValueWhenEmpty
(
value:
boolean
--
Value to default to
) →
(
)
Sets the default value if we have no value
getValueWhenEmpty
Gets the default value on a container when empty
observeValueWhenEmpty
Sets the default value if we have no value