[Suggestion] Simplify item filter file with new block type ActionGroup

When creating an item filter files, I found that I often want to use the same set of actions (e.g. in-game ground item label styling) for different conditions. Right now, I have to repeat the same set of actions again and again, unnecessarily make the long file even longer.

Here is a simple example: we want to highlight uncut gems and the highlight will be based on the area level. When we're leveling, the low level gems will be highlighted and when we're mapping, only the high level gems will be highlighted. An example filter will be:

Example filter
# Always highlight spirit gems
Show
BaseType "Uncut Spirit Gem"
SetTextColor 20 240 240
SetBorderColor 20 240 240
PlayAlertSound 2 300
PlayEffect Cyan
MinimapIcon 1 Cyan Triangle
SetFontSize 40

# Highlight support gems during campaign
Show
BaseType "Uncut Support Gem"
AreaLevel < 68
SetTextColor 20 240 240
SetBorderColor 20 240 240
PlayAlertSound 2 300
PlayEffect Cyan
MinimapIcon 1 Cyan Triangle
SetFontSize 40

# After campaign, show support gems without highlight
Show
BaseType "Uncut Support Gem"
SetTextColor 20 240 240
SetBorderColor 20 240 240
SetFontSize 35

# Highlight skill gems during campaign
Show
BaseType "Uncut Skill Gem"
AreaLevel < 65
SetTextColor 20 240 240
SetBorderColor 20 240 240
PlayAlertSound 2 300
PlayEffect Cyan
MinimapIcon 1 Cyan Triangle
SetFontSize 40

# After campaign, only highlight level 19+ skill gems
Show
BaseType "Uncut Skill Gem"
ItemLevel >= 19
SetTextColor 20 240 240
SetBorderColor 20 240 240
PlayAlertSound 2 300
PlayEffect Cyan
MinimapIcon 1 Cyan Triangle
SetFontSize 40

# After campaign, show level 18- skill gems without hightlight
Show
BaseType "Uncut Skill Gem"
SetTextColor 20 240 240
SetBorderColor 20 240 240
SetFontSize 35

Notice that the same highlight actions are repeated 4 times in this simple example. Now imagine you want to use the same highlight for every equipment slots.

Highlight actions
SetTextColor 20 240 240
SetBorderColor 20 240 240
PlayAlertSound 2 300
PlayEffect Cyan
MinimapIcon 1 Cyan Triangle
SetFontSize 40

One solution is to first define a new block type ActionGroup. Where it predefines a set of actions that can later be used in other blocks. The format of ActionGroup can be as follows:

ActionGroup <name>
{one or more actions}

where <name> is a user defined string to reference the group in other blocks.

ActionGroup exmaple
ActionGroup "gem highlight"
SetTextColor 20 240 240
SetBorderColor 20 240 240
PlayAlertSound 2 300
PlayEffect Cyan
MinimapIcon 1 Cyan Triangle
SetFontSize 40

Then we will also define a new action type RunActionGroup to execute all actions in a given group.

Format: RunActionGroup <name>
Example: RunActionGroup "gem highlight"

The name must exists or the filter will fail to load.

With both, we can simplify the filter a lot:
Example filter
ActionGroup "gem highlight"
SetTextColor 20 240 240
SetBorderColor 20 240 240
PlayAlertSound 2 300
PlayEffect Cyan
MinimapIcon 1 Cyan Triangle
SetFontSize 40

ActionGroup "gem default"
SetTextColor 20 240 240
SetBorderColor 20 240 240
SetFontSize 35

# Always highlight spirit gems
Show
BaseType "Uncut Spirit Gem"
RunActionGroup "gem highlight"

# Highlight support gems during campaign
Show
BaseType "Uncut Support Gem"
AreaLevel < 68
RunActionGroup "gem highlight"

# After campaign, show support gems without highlight
Show
BaseType "Uncut Support Gem"
RunActionGroup "gem default"

# Highlight skill gems during campaign
Show
BaseType "Uncut Skill Gem"
AreaLevel < 65
RunActionGroup "gem highlight"

# After campaign, only highlight level 19+ skill gems
Show
BaseType "Uncut Skill Gem"
ItemLevel >= 19
RunActionGroup "gem highlight"

# After campaign, show level 18- skill gems without hightlight
Show
BaseType "Uncut Skill Gem"
RunActionGroup "gem default"

The file is no only shorter, but also easier to read and edit.

Note:
1. If we want to keep the parser simple, we can disallow the RunActionGroup action to be used inside a ActionGroup block. This will prevent nested action groups and thus recursion is impossible.

On the other hand, if we want more flexibility, we can allow nesting. If there's recursion, the filter will fail to load.

2. The RunActionGroup can be mixed with other primitive actions as well.

An example of mixing
ActionGroup "highlight"
SetTextColor 20 240 240
SetBorderColor 20 240 240
SetFontSize 40

Show
BaseType "Uncut Skill Gem"
PlayEffect Cyan
RunActionGroup "highlight"
PlayAlertSound 2 300

3. When parsing the filter, all actions will be flattened to an ordered list based on their appearance order in the file. If a primitive action appears multiple times, only the last one (or first one depends on the implementation) is kept. For example,

An example of overwriting
ActionGroup "highlight"
SetTextColor 20 240 240
SetBorderColor 20 240 240
SetFontSize 40

Show
BaseType "Uncut Skill Gem"
RunActionGroup "highlight"
SetFontSize 45

Show
BaseType "Uncut Support Gem"
SetFontSize 45
RunActionGroup "highlight"

The font size of skill gem will be 45 and support gem will be 40.
Last bumped on Jan 13, 2025, 2:31:18 AM
(Reserved)
actually would like that - usually I just copy paste blocks I use more commonly, the qustion is if you can implement defining variables into it
Farming salt on the forums since 2024
This would be cool.

Report Forum Post

Report Account:

Report Type

Additional Info