Disable flare based on a module option

Hello, guys, this is a feature request. I’ll start with a preliminary consideration. Flare is great when playing online, but not so great when reviewing past game log files. So, I would like to be able to turn Flare off when reviewing a log file. I thought, but maybe I’m wrong, that a way to do it would be to have an option in the module preferences to ignore the related key, so that I’m able to switch the flare off when replaying old games. Another approach could be to avoid saving the flare key in the log. But maybe you guys have a better idea.

Best,

g

this is a feature request.

This kind of request is best suited for Feature Requests sub-forum, or opening an issue on GitHub. Check the sub-forum descriptions in the pinned posts in each sub-forum, or see How to format forum posts for a short overview.

I’m able to switch the flare off when replaying old games. Another approach could be to avoid saving the flare key in the log.

I think the first option is the most attractive. There are use cases for flares in logs. It would likely require some code changes in the BasicCommandEncoder and similar.

Yours,
Christian

1 Like

Thanks, Christian. You already moved the post where it was supposed to be, right? Thanks! And for the second point. I wasn’t clear, sorry. I meant “Having an option that avoids saving the flare key in the log.” Of course, flare might be useful in logs too.

I cannot do that, so I think it was either @uckelman or @Tim_M

That makes more sense. One could argue, why use Flare when writing a log if you know the recipient does not like that :smiley: In that sense, it makes more - well - sense to allow the recipient to disable play-back of flares.

Yours,
Christian

Christian,

Maybe it is possible to “clean” the saved file of some keys in post-production. What about your pywargame? I understand that it is meant to work on modules. But maybe you could make a similar tool that decodes a log file, removes user-selected keys, and repacks it?

g

pywargame works on modules (.vmod) as well as saves (.vsav), logs (.vlog), and extensions (.vmdx), though the support for logs is far from complete, and there’s stuff in saves that need to be coded by the user.

You can use the utility vsavdump.py to show the content of a save or log file in somewhat plain text.

If you look at the code used by vsavdump.py - in particular pywargame.vassal.SaveIO.dumpSave - you will see that log and save files consists of lines. Lines generally start with a tag - for example + to add a piece.

If you look at VASSAL.build.module.map.Flare you see that the tag of flares is the string FLARE\t followed by an identifier (set by the module developer), then a \t, the X (pixel) coordinate, another \t and the Y (pixel) coordinate (see also VASSAL.module.build.map.Flare#encode and VASSAL.module.build.map.Flare#decode).

Thus, if you use If you look at the code used by vsavdump.py - in particular pywargame.vassal.SaveIO.readSave to read in the save and split into lines, then you can filter out any lines that contain the FLARE tag:

#!/usr/bin/env python

if __name__ == '__main__':
    from argparse import ArgumentParser, FileType
    from pywargame.vassal.save import SaveIO

    ap = ArgumentParser(description='Remove flares from log')
    ap.add_argument('input', type=FileType('r'), help='Input file')
    ap.add_argument('output',type=FileType('w'), help='Output file')

    args = ap.parse_args()

    key, lines, savemeta, modulemeta = SaveIO.readSave(args.input, True)
    newlines = [line for line in lines if not line.startswith('FLARE\t')]
    SaveIO.writeSave(args.output, key, newlines, savemeta, modulemeta)

(above is untested).

See if that does the trick for you.

I will leave that as an exercise for the interested reader :smiley: Of course, I will gladly accept contributions to pywargame - and give proper credit.

Yours,
Christian

1 Like

Hello Christian,

It turns out that lines with the flare command don’t start with FLARE but with “LOG”, followed by whitespace or tabs, then “FLARE”.

The following seems to work

#!/home/giulio/Desktop/Varia/venv/bin/python
if __name__ == '__main__':
   from argparse import ArgumentParser, FileType
   from pywargame.vassal.save import SaveIO

   ap = ArgumentParser(description='Remove commans matching a tag string from log')
   ap.add_argument('tag', type=str, help='Tag of lines to be removed')
   ap.add_argument('input', type=FileType('r'), help='Input file')
   ap.add_argument('output',type=FileType('w'), help='Output file')

   args = ap.parse_args()
   key, lines, savemeta, modulemeta = SaveIO.readSave(args.input.name, True)
   newlines = [line for line in lines if not args.tag in line]
   SaveIO.writeSave(args.output.name, key, newlines, savemeta, modulemeta)

Thanks for yor help. This is actually better than a VASSAL option. Now I can deflare anybody’s saves! This pywargame of yours is really nice. Kudos!