Now that we see how the whopairs are recognized, we can see that the magic comment accepts a comma-separated list, for macros that deal with more than one character.
We also see that if it is necessary to remove a character who leaves the party, this can be done with another entry prefixed by double minuses.
The "recognize" magic comment only covers one scenario; but what about macros that are used in many scenarios?
This new magic comment creates dictionary pairs of macros with the characters they are associated with. If this is not yet clear, hopefully the following commits will show the full picture.
Rather than overwhelming users with verbiage, I will hide most of my explanation unless it's asked for. My message is still not particularly brief, but it's no longer insanely long.
groggy: The ifdef_stack = [None] assignment made wmllint crash upon nested
#if blocks. The following block of wml should suffice to let it crash. The
inner #endif deletes the data about encountered #ifs.
...
#ifver WESNOTH_VERSION >= 1.11.0
#ifhave ~add-ons/UMC_Music_Book_1/_main.cfg
[binary_path]
path=data/add-ons/UMC_Music_Book_1
[/binary_path]
#endif
#else
#ifhave ~add-ons/UMC_Music/_main.cfg
[binary_path]
path=data/add-ons/UMC_Music
[/binary_path]
#endif
#endif
...
Rather than automatically putting the soundpath in the first frame, we collect a list of begin= keys and their locations. When it's time to convert, we check to see if any of those begin times match with the sound time, and if so, put sound in that [frame]. Only if there is no match do we default to the first frame, and we log a message noting the lack of a match.
Some [sound] tags include a sound_miss key as well. To preserve this data, I created two new variables to capture the sound_miss= and time= values, and use them to fill out the SOUND:HIT_AND_MISS macro. Because the macro is inserted before [frame] instead of after, 'if soundpath' needs to be moved up before the insertion so that the macro ends up under [attack_anim], rather than in the middle of [attack].
It's probably obvious what I tried to do. Unfortunately, only the first string works.
I also added another "and not" condition, to keep the same file from getting multiple entries in is_main.
After my last change, I noticed a puzzling failure by wmllint to convert a weapon special. This special was among some attributes that followed the [frame] sequence. It seems that Python does not wait for the earlier code block to complete before running the new one, and those lines aren't passed through the new block because they've been deleted and stashed in 'postframe'. When they're spewed back out, the new block has already passed those lines by.
I was relieved to find that this was not an issue introduced by my change, but an existing one. When I ran the original wmllint on the file, I found that the special= line got deleted, without being replaced by the [special] tags and macro. The latter is supposed to appear when wmllint hits the [/attack] tag, but never triggers because [/attack] has been changed to [/attack_anim].
Moving this code block up, so that abilities and specials are transformed before the [frame] lift (and 'postframe' stash), appeared to fix the problem. Hopefully, it won't cause a new on to show up.
This code block was actually producing some horrendous output, because key values were not reset to defaults at the closing [/attack] tag, even though many units have more than one attack. Also, the conversion was done when the first [frame] tag was encountered, although most authors put the [sound] block after [frame]s. So, what would typically happen is this:
* The first attack would be converted, usually without a soundpath. If there were any attributes after the [frame] sequence, the result would be non-functional, as the comment introducing this wmllint block warned (and wmllint would crash with an assertion error if "name=" happened to be one of them).
* Subsequent attacks would be converted, inheriting the sound and [attack_filter] from the soundpath and attackname of the *first* attack.
To fix these issues, I did the following:
* In order to do the conversion at a later stage, after the soundpath would normally have been picked up, the variable 'converting' was changed from a 0/1 value to a line index position.
* This enables the opportunity to move post-[frame] lines, for which purpose the new variables in_frame and postframe are created. When encountered, these lines are deleted and appended to postframe.
* When we get to [/attack], we still look to see if we are converting. If so, we go ahead with the replacement of lines[i], before the index position gets changed. Then we carry out the conversion that was originally carried out at the first [frame], using lines[converting] to do it at the same place.
* The lines in postframe are fed back in reverse order before the new closing [/attack] tag.
* Values are cleared to defaults, ready for the next [attack].
* It is no longer true that the frame sequence has to go last in [attack], so that part of the comment can be deleted.
First, the newline is added to "description = " rather than "new_line = ". But description was only changed if it didn't begin with a quotemark, meaning that those that *did* start with a quote weren't getting a newline.
Second, new_line was supposed to inherit indentation through "leader(syntactic)", but the line had already been stripped before "syntactic", in "fields = ".
I had noticed that the line replacing the get_hit_sound with DEFENSE_ANIM didn't have a newline, but assumed that it was part of 'comment'. Nope!
There are also two lines where a misplaced quotation mark led to an extraneous space being added to the end of a line.
I noticed that there were some additional weapon specials (marksman) and abilities (nightstalk, steadfast) that also had macros. I also saw examples of ability= keys that had comma-separated multiple values.
All of these variables are again defined as False when [unit] is in the line, but in_variation was missing from this earlier list. This caused wmllint to crash with an UnboundLocalError on a page of (UtBS) Kaleh-style macros that had no [unit] tag.
This came to my attention because of a Dark Elves scenario with a 'description=' key that was left blank for the value, crashing wmllint with an index error. More broadly, however, the operations in this section are pointless when there is no value.
I realized that there was no need to glob Windows arguments if there were no arguments. This meant moving my previous code block above the "if not arguments" statement, which actually creates an argument. And it meant moving Elvish Hunter's code, since the double quote issue will stop my block from working. Once this decision was made, it made sense to put both code blocks under the same "if" conditions, and to check if there were actually any wildcards during EH's block, before running the arguments through glob.
The Windows cmd shell does not expand wildcards by default, unlike UNIX shells. This imports glob.glob and runs arguments through it on Windows.
This will be frontported once I'm done on this branch and ready to check out master again.
We consider a file a main file if it contains either [campaign], [binary_path], or [textdomain]. (Almost all mainfiles have at least one of those.)
Eventually, we check that the campaign directory exists and that the _main.cfg doesn't already exist. If true, we rename.