condition
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kaigouthro
// @version=5

// @description True/False Condition tools and toggles for booleans and utility.
// suggested use is checking if a calculation is required, or can be skipped
// speeding up script calculations in realtime and historical scenarios.
library("condition")

// @function  output is true only if first true and second false
// @param     _first_cond (bool) First Condition
// @param     _second_cond (bool) Second Condition
// @returns   True if coditions met
export isonlywihtout   ( bool _first_cond , bool _second_cond   ) =>
    varip _state = bool(na)
    _state := switch
        _first_cond and not _second_cond => true
        _first_cond and _second_cond     => false
        => bool(na)

// @function  output is true only for the first condition if the second condition is also true
// @param     _first_cond (bool) First Condition
// @param     _second_cond (bool) Second Condition
// @returns   True if coditions met
export isonlywih       ( bool _first_cond , bool _second_cond   ) =>
    varip _state = bool(na)
    _state := switch
        _first_cond  and _second_cond => true
        _first_cond  and not _second_cond => false
        => bool(na)
	
// @function  output is true active only while actively true
// @param     _cond (bool) Condition met
// @returns   True if coditions met
export isactive        ( bool _cond                       ) =>
    varip _state = bool(na)
    _state := switch
        _cond  => true
        => false

// @function  output is true only while condition is not active
// @param     _cond (bool) Condition met
// @returns   True if coditions met
export isnotactive     ( bool _cond                       ) =>
    varip _state = bool(na)
    _state := switch
        _cond  => true
        => false

// @function  output is true and holds on True activation , na input has no effect, only a false will disengage
// @param     _cond (bool) Condition met
// @returns   True if coditions met
export isontoggle      ( bool _cond                       ) =>
    varip _state = bool(na)
    _state := switch
        _cond     => true
        not _cond => false
        => _state

// @function  output is true and holds on False activation, na input has no effect, only a true will disengage
// @param     _cond (bool) Condition met
// @returns   True if coditions met
export isofftoggle     ( bool _cond                       ) =>
    varip _state = bool(na)
    _state := switch
        not _cond => true
        _cond     => false
        => _state

// @function  output is false only if both are active, either or neither pass true
// @param     _first_cond (bool) First Condition
// @param     _second_cond (bool) Second Condition
// @returns   True if coditions met
export isnotboth       ( bool _first_cond , bool _second_cond   ) =>
    varip _state = bool(na)
    _state := switch
        _first_cond and _second_cond => false
        => true

// @function  output is false only if both are active, either or neither pass true
// @param     _first_cond (bool) First Condition
// @param     _second_cond (bool) Second Condition
// @returns   True if coditions met
export isneither       ( bool _first_cond , bool _second_cond   ) =>
    varip _state = bool(na)
    _state := switch
        _first_cond and _second_cond => false
        => true

// @function  output is true and held when both trigger true, and only disengages if both are false at once
// @param     _first_cond (bool) First Condition
// @param     _second_cond (bool) Second Condition
// @returns   True if coditions met
export isbothtoggled   ( bool _first_cond , bool _second_cond   ) =>
    varip _state = bool(na)
    _state := switch
        _first_cond and _second_cond => true
        not _first_cond and not _second_cond  => false
        => _state
