Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Compound Conditionals API

Open sovdeeth opened this issue 1 year ago • 0 comments

Description

This PR adds a new interface, Conditional, which Conditions now implement. It's intended to provide more flexibility to evaluable elements within Skript that deal with trues and falses.

It deals in Kleeneans, allowing us to return Unknown from conditionals which are deemed invalid, or ambiguous, or otherwise. Currently, nothing takes advantage of this feature. Conditions simply forward the boolean result of check() into a Kleenean.

It comes with default methods for and, or, and not, which attempt to minimize evaluations wherever possible.

There is also the CompoundConditional class, which is the main reason for this PR. It represents a set of Conditionals all joined by an operator: a && b && c, or b || d, or the special case of NOT, where only one conditional is allowed: !a. The motivation for this ability is the upcoming raytracing PR, which will feature complex conditional cases due to the proposed ignore sections, thought it could be used to expand on existing SecConditional features, or in filtering.

Conditional also comes with a builder that will automatically generate a DNF (see here) CompoundConditional from a combination of ANDs, ORs, and NOTs:

Conditional.builder()
    .and(condA)
    .or(condB)
    .andNot(compoundCondC)
    .build()

Current issues: ~~Since DNF takes advantage of the result of a condition being used in multiple places, this could lead to conditions being evaluated multiple times since there's no sharing of state over the hierarchy. May just want to scrap the DNF idea. A solution could be passing a Context down the evaluation tree which has a map of evaluated conditions. Also some of the docs are outdated or missing, WIP.~~


Target Minecraft Versions: any Requirements: none Related Issues: none

sovdeeth avatar Sep 08 '24 04:09 sovdeeth