BSData / phalanx

Project Phalanx is a roster editor handling BattleScribe datafiles
https://www.phalanx.tools/
MIT License
154 stars 25 forks source link

Documenting Querying in BattleScribe #45

Open amis92 opened 2 years ago

amis92 commented 2 years ago

We need to document queries: what are legal combinations, how do they work, what are the results.

BS Nodes

The elements in BattleScribe that use queries are: condition, constraint, repeat.

These elements appear as children in other BattleScribe elements:

It's important to list all elements that can contain modifiers, since then they can also contain conditions and repeats within those modifiers. modifier can be child of:

Query components

The elements of a query are:

Known options

Field

Allowed values for a field in a Query:

Special cases:

Scope

Scope can be one of:

Special cases:

Filter

Filter can be one of:

When filter has specified value:

Special cases:

Value

Generally, negative values work as expected. The exception here is a -1 value for a type=max constraint - in that case, it is interpreted as "infinity" or "no limit". Further modifications of the value (e.g. by Modifiers) are calculated as normal, e.g. when a constraint of -1 is modifed to increase value by 1, now the maximum is 0 so the selections are not allowed. Any other negative value (e.g. -2) is treated normally (no special behavior).

Comparison

Special cases:

Options

shared - the query should sum up all instances of childId/filter in scope, disregarding the selection path. BS author explainer. ❓ When is this option allowed in Data Editor UI?

value-is-percentage - the value should be interpreted as percentage, and is limited to the range [0; 100].

include-child-selections - the scope includes selection subtrees (recursive/all descendants).

include-child-forces - the scope includes force subtrees (recursive/all descendants).

round-up - used in repeat calculations, rounds the division of result by value up, instead of down as is by default.

Loose notes

❓ What are other unobvious interactions?

amis92 commented 2 years ago

Negative value

I've investigated negative values in detail.

Generally, negative values work "as normal", except "-1" for a type=max constraint, which is equivalent to no limit. The logic might not be tied to max, but for min a non-positive value is the same as no limit anyway. Do note, that any other negative value for a max is processed as that value (and not as "no limit").

BattleScribe Data Editor does some additional validations on value:

As an interesting quirk, when an entry has a constraint of type=min scope=parent value=0, the entry is hidden in Roster Editor, as it's not allowed to be selected. As expected, using a Modifier to Set that constraint's value to -1 makes this entry selectable (unlimited) and it's correctly shown in Roster Editor. However, when using a Modifier to Decrease the value by 1 (making it 0 - 1 = -1 - unlimited), the Roster Editor does not show the entry (incorrectly?), as that entry is unlimited due to the new value of max constraint.

amis92 commented 2 years ago

Filter entries

In different comparison/field/scope combinations, different entries are allowed as filters. We'll use numeric comparison to mean all comparison operators that operate on numbers - that excludes the (not)-instance-of comparisons. Those will be called instance-of comparison.

Field selections or Costs

When field is selections or a specific Cost or Cost Limit, the following rules apply.

The comparison must be numeric (for instance-of the field is disabled, and so cannot have value).

scope=self and scope=parent allows filter to be:

scope=force and scope=roster allows filter to be:

scope=specific entry allows filter to be:

Field disabled

When comparison is instance-of, the field is disabled and the following rules apply.

scope=self, scope=parent and scope=ancestor allows filter to be:

scope=primary-category allows filter to be:

scope=force allows filter to be:

scope=primary-catalogue allows filter to be:

scope=specific entry allows filter to be:

Field forces

When field is forces, the following rules apply.

The comparison must be numeric (for instance-of the field is disabled, and so cannot have value).

scope=force and scope=roster allows filter to be:

scope=specific Force Entry allows filter to be: