Filter overlays

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Filter overlays

Post by Toranks »

I have searched the forum and have not found any information and I'd like when I find the right way, it's registered somewhere easy to find, like the forum or the wiki. According to the wiki...:

overlays: a comma-separated list of images that are overlayed on the unit.
(Version 1.15.0 and later only) This key is supported when creating a unit from WML, but will be empty when writing the unit back to WML; the overlays will instead be stored as [modifications].
So a StandardUnitFilter like this will always give empty:

Code: Select all

[filter_wml]
       overlays="misc/hero-icon.png"
[/filter_wml]
And I have already seen it used in 3 different addons, without working in any of them, because they are obsolete.
So... what is the proper way to filter now? I don't know how to filter inside modifications because overlays usually have this form inside [unit][modifications]:

Code: Select all

					[effect]
						add="misc/loyal-icon.png"
						apply_to="overlay"
					[/effect]
Sometimes inside [trait], sometimes inside [object], or other tags with [effect] support.

SOLUTION EXAMPLES:

To filter loyals with loyal icon, typically the "true loyals" (not heroes, leaders, etc...):

Code: Select all

							[filter_wml]
							  [modifications]
								[trait]
								  [effect]
									apply_to=overlay
									add="misc/loyal-icon.png"
								  [/effect]
								[/trait]
							  [/modifications]
							 [/filter_wml]

To filter heroes with hero icon, for example Delfador in the tutorial:

Code: Select all

 
						       [filter_wml]
							  [modifications]
								[trait]
								  [effect]
									apply_to=overlay
									add="misc/hero-icon.png"
								  [/effect]
								[/trait]
							  [/modifications]
							 [/filter_wml]
To filter overlays applied with objects:

Code: Select all

							[filter_wml]
							  [modifications]
								[object]
								  [effect]
									apply_to=overlay
									add="misc/hero-icon.png" ## or any other overlay
								  [/effect]
								[/object]
							  [/modifications]
							 [/filter_wml]
IMPORTANT: In some cases, there may be replace= instead of add=, this case should be covered independently with another filter with [or]
Last edited by Toranks on December 23rd, 2022, 4:19 pm, edited 2 times in total.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Filter overlays

Post by Helmet »

I'm not sure about how to do the filter, but maybe this example will help.

From Descent into Darkness, scenario 8.

Code: Select all

        [unit_overlay]
            x,y=$x1,$y1
            image="misc/book-icon.png"
            object_id="book_icon"
        [/unit_overlay]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: Filter overlays

Post by Toranks »

What this code does is add an overlay to the units that meet the StandardUnitFilter conditions. I want to filter overlays themselves as StandardUnitFilter.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Filter overlays

Post by Helmet »

Oh. I don't know how to filter for that.
Maybe you could gave a new status to the unit, along with the overlay, then filter for the status?

Something like...

Code: Select all

[event]
	name=new turn
	first_time_only=no	
	[store_unit]
		[filter]
			side=2  
            		status=has_overlay
		[/filter]
		variable=target_units
	[/store_unit]
	[foreach]
		array=target_units
		[do]
			[if]
                		[variable]
#				 etc.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: Filter overlays

Post by Toranks »

I already do that, using [objects]. But my intention is to filter by those who already have the units. For example, I want to filter all heroes that have the silver crown from many campaigns. Or filter only loyals who have the loyal bracelet. (There are some loyals without a bracelet)
User avatar
Ravana
Forum Moderator
Posts: 3008
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filter overlays

Post by Ravana »

It is conceptually not possible with filter_wml. You can filter and see that unit has specific overlay, but it is not possible anymore to check that it is the only overlay.
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: Filter overlays

Post by Toranks »

Ravana wrote: December 23rd, 2022, 12:38 am It is conceptually not possible with filter_wml. You can filter and see that unit has specific overlay, but it is not possible anymore to check that it is the only overlay.
How? I'm not interested on detect if is the only overlay. I want to filter a specific overlay, it doesn't matter if the unit have more
User avatar
Ravana
Forum Moderator
Posts: 3008
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filter overlays

Post by Ravana »

> Sometimes inside [trait], sometimes inside [object], or other tags with [effect] support.
There is limited number of tags where effect can appear, so filter_wml for them all with [or]
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: Filter overlays

Post by Toranks »

Ravana wrote: December 23rd, 2022, 12:45 am > Sometimes inside [trait], sometimes inside [object], or other tags with [effect] support.
There is limited number of tags where effect can appear, so filter_wml for them all with [or]

Code: Select all

[filter_wml]
    [trait]
        overlay="misc/hero-icon.png"
    [/trait]
[filter_wml]
Overlay? Overlays?
User avatar
Ravana
Forum Moderator
Posts: 3008
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filter overlays

Post by Ravana »

Exact tag structure as is in units wml.
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: Filter overlays

Post by Toranks »

Ravana wrote: December 23rd, 2022, 1:58 am Exact tag structure as is in units wml.
This doesn't makes much sense for me, but is exactly what appears on the [unit] I want to filter

Code: Select all

[filter_wml]
    [trait]
	[effect]
	   add="misc/loyal-icon.png"
	   apply_to="overlay"
	[/effect]
    [/trait]
[filter_wml]
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Filter overlays

Post by beetlenaut »

I'm pretty sure that the [trait] tag is in inside a [modifications] tag in that unit's WML. Adding that should fix it.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: Filter overlays

Post by Toranks »

beetlenaut wrote: December 23rd, 2022, 7:32 am I'm pretty sure that the [trait] tag is in inside a [modifications] tag in that unit's WML. Adding that should fix it.
I knew it, I forgot when answering Ravana. It finally worked for me. I edit the first post to include working examples.
User avatar
Celtic_Minstrel
Developer
Posts: 2222
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Filter overlays

Post by Celtic_Minstrel »

Ravana wrote: December 23rd, 2022, 12:38 am It is conceptually not possible with filter_wml. You can filter and see that unit has specific overlay, but it is not possible anymore to check that it is the only overlay.
You can do almost anything with filter_wml. It would be pretty tricky, but I think it should be possible to verify that an overlay is the only overlay if you wanted that. (I won't try to work it out, since no-one said they wanted it.)
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply