Skip to main content

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

AdorneeConditionUtils.observeConditionsMet(
conditionObjBindableFunction,--

Condition to invoke

adorneeInstance--

Adornee to check conditions on

) → Observable<boolean>

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

AdorneeConditionUtils.promiseQueryConditionsMet(
conditionObjBindableFunction,--

Condition to invoke

adorneeInstance,--

Adornee to check conditions on

cancelTokenCancelToken?
) → Promise<boolean>

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

AdorneeConditionUtils.createConditionContainer() → BindableFunction

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

AdorneeConditionUtils.create(observeCallbackfunction) → BindableFunction

Creates a new adornee condition

createRequiredProperty

AdorneeConditionUtils.createRequiredProperty(
propertyNamestring,
requiredValueany
) → BindableFunction

Creates a new condition that a property is a set value.

createRequiredAttribute

AdorneeConditionUtils.createRequiredAttribute(
attributeNamestring,
attributeValueany
) → BindableFunction

Creates a new condition that an attribute must be set to the current value

createRequiredTieInterface

AdorneeConditionUtils.createRequiredTieInterface(tieInterfaceDefinitionTieDefinition) → BindableFunction

Creates a new condition that a tie interface must be implemented for the object

createOrConditionGroup

AdorneeConditionUtils.createOrConditionGroup() → BindableFunction

Creates a new "or" condition group where conditions are "or"ed together. Conditions should be parented underneath this BindableFunction.

createAndConditionGroup

AdorneeConditionUtils.createAndConditionGroup() → BindableFunction

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(
containerBindableFunction,
valueboolean--

Value to default to

) → ()

Sets the default value if we have no value

getValueWhenEmpty

AdorneeConditionUtils.getValueWhenEmpty(containerBindableFunction) → boolean

Gets the default value on a container when empty

observeValueWhenEmpty

AdorneeConditionUtils.observeValueWhenEmpty(containerBindableFunction) → Observable<boolean>

Sets the default value if we have no value

Show raw api
{
    "functions": [
        {
            "name": "observeConditionsMet",
            "desc": "Observes whether conditions are met or not.\n\n```lua\nAdorneeConditionUtils.observeConditionsMet(gun.AmmoAllowedConditions, ammo):Subscribe(function(allowed)\n\tif allowed then\n\t\tprint(\"Can use this ammo to refill this gun\")\n\tend\nend)\n```",
            "params": [
                {
                    "name": "conditionObj",
                    "desc": "Condition to invoke",
                    "lua_type": "BindableFunction"
                },
                {
                    "name": "adornee",
                    "desc": "Adornee to check conditions on",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<boolean>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 77,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "promiseQueryConditionsMet",
            "desc": "Promises a query result of whether conditions are met or not. Unlike the observable, this will return\na result once all combinations are met.",
            "params": [
                {
                    "name": "conditionObj",
                    "desc": "Condition to invoke",
                    "lua_type": "BindableFunction"
                },
                {
                    "name": "adornee",
                    "desc": "Adornee to check conditions on",
                    "lua_type": "Instance"
                },
                {
                    "name": "cancelToken",
                    "desc": "",
                    "lua_type": "CancelToken?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<boolean>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 93,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "createConditionContainer",
            "desc": "Creates a new condition container which conditions can be parented to. By default this is an\n\"and\" container, that is, all conditions underneath this container must be met for something to be allowed.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 106,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "create",
            "desc": "Creates a new adornee condition",
            "params": [
                {
                    "name": "observeCallback",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 121,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "createRequiredProperty",
            "desc": "Creates a new condition that a property is a set value.",
            "params": [
                {
                    "name": "propertyName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "requiredValue",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 139,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "createRequiredAttribute",
            "desc": "Creates a new condition that an attribute must be set to the current value",
            "params": [
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "attributeValue",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 163,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "createRequiredTieInterface",
            "desc": "Creates a new condition that a tie interface must be implemented for the object",
            "params": [
                {
                    "name": "tieInterfaceDefinition",
                    "desc": "",
                    "lua_type": "TieDefinition"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 186,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "createOrConditionGroup",
            "desc": "Creates a new \"or\" condition group where conditions are \"or\"ed together.\nConditions should be parented underneath this BindableFunction.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 205,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "createAndConditionGroup",
            "desc": "Creates a new \"and\" condition group where conditions are \"and\"ed together.\nConditions should be parented underneath this BindableFunction.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 227,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "getRequiredTag",
            "desc": "Conditions must be tagged with a specific tag to make sure we don't invoke random code,\nor code on the wrong host.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 250,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "getConditionNamePostfix",
            "desc": "Gets the postfix for the condition name to make it clear to users\nif this condition is on the server or the client.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 264,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "setValueWhenEmpty",
            "desc": "Sets the default value if we have no value",
            "params": [
                {
                    "name": "container",
                    "desc": "",
                    "lua_type": "BindableFunction"
                },
                {
                    "name": "value",
                    "desc": "Value to default to",
                    "lua_type": "boolean"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 278,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "getValueWhenEmpty",
            "desc": "Gets the default value on a container when empty",
            "params": [
                {
                    "name": "container",
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 291,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        },
        {
            "name": "observeValueWhenEmpty",
            "desc": "Sets the default value if we have no value",
            "params": [
                {
                    "name": "container",
                    "desc": "",
                    "lua_type": "BindableFunction"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<boolean>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 302,
                "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "AdorneeConditionUtils",
    "desc": "Utility library that defines a generalized interface for scriptable conditions. These conditions are rooted in [Rx] and\ncan be scripted by a variety of systems. For example, we may have conditions on what ammo we can consume, or whether\nor not an action can be activated.\n\nThis library provides an interface for this to happen in. Conditions are marshalled through a BindableFunction and\nmust be defined on both the client and server. However, these conditions can be reactive. It would be very simple\nto create a condition that also just links to a bool value if conditions should be only on the server.\n\n```lua\nlocal conditionFolder = AdorneeConditionUtils.createConditionContainer()\nconditionFolder.Parent = workspace\n\nlocal orGroup = AdorneeConditionUtils.createOrConditionGroup()\norGroup.Parent = conditionFolder\n\nAdorneeConditionUtils.createRequiredProperty(\"Name\", \"Allowed\").Parent = orGroup\n\nlocal andGroup = AdorneeConditionUtils.createAndConditionGroup()\nandGroup.Parent = orGroup\n\nAdorneeConditionUtils.createRequiredProperty(\"Name\", \"Allow\").Parent = andGroup\nAdorneeConditionUtils.createRequiredAttribute(\"IsEnabled\", true).Parent = andGroup\n\nlocal testInst = Instance.new(\"Folder\")\ntestInst.Name = \"Deny\"\ntestInst:SetAttribute(\"IsEnabled\", false)\ntestInst.Parent = workspace\n\nAdorneeConditionUtils.observeConditionsMet(conditionFolder, testInst):Subscribe(function(isAllowed)\n\tprint(\"Is allowed\", isAllowed)\nend) --> Is allowed false\n\ntask.delay(0.1, function()\n\ttestInst.Name = \"Allowed\" --> Is allowed true\nend)\n```",
    "source": {
        "line": 41,
        "path": "src/conditions/src/Shared/AdorneeConditionUtils.lua"
    }
}