Create account / Log in

module python library

Talk about module design ideas and techniques.

Moderators: uckelman, Tim M

module python library

Postby pelle » May 31st, 2009, 8:38 pm

Hi,

This is a long shot, but is there a Python module to read and write VASSAL module files? I'd like some nice API to be able to easily add some images and counters that use those images from a Python script. I don't want to spend a lot of time implementing one myself if there already is one I can use. :D

(To be exact I'm planning to add a new feature to my Inkscape countersheet generator to allow the user to automatically export all created counters to a choosen VASSAL module.)
pelle
 
Posts: 17
Joined: March 3rd, 2008, 3:52 pm

module python library

Postby Brent Easton » May 31st, 2009, 10:13 pm

No, there is not Python Module to do it, but Vassal version 3.2 will allow you to do this. It includes a new feature to create counters in bulk from a directory full of images.

B.


Hi,

This is a long shot, but is there a Python module to read and write VASSAL
module files? I'd like some nice API to be able to easily add some images
and counters that use those images from a Python script. I don't want to
spend a lot of time implementing one myself if there already is one I can
use. :D

(To be exact I'm planning to add a new feature to my Inkscape countersheet
generator (http://www.boardgamegeek.com/thread/299033/page/1) to allow the
user to automatically export all created counters to a choosen VASSAL
module.)



_______________________________________________
Messages mailing list
Messages@forums.vassalengine.org
http://forums.vassalengine.org/mailman/ ... engine.org

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
Brent Easton
 
Posts: 3230
Joined: December 21st, 2007, 3:06 am
Location: Berry, NSW, Australia

Postby pelle » May 31st, 2009, 10:34 pm

OK, thanks! I heard about that feature, and it sounds very useful. I still think I want to add this to my countersheet generator though. Generating everything from one spreadsheet document in one go feels like a good thing to have (at least to me, personally, for my current project). I also intend to have (optional) columns in the spreadsheet to tell which panel to put each counter on and what prototypes each counter should have. Connection between front and back of each counter is already available in the generator, and I hope it will not be too much work to automatically add that connection to the VASSAL XML file for each counter. So it's more to it than just importing the graphics into the ZIP file, I also want to make use of as much meta data as I can think of to add, that I will not have access to later by just looking at the generated countersheet PNGs (or SVGs).

Besides I can see other uses for a Python (or other scripting language) API. There will always be things that are easier (or at least faster, and more easily done over and over) using a script rather than manually with a GUI. I know I have several times resorted to batch-editing things manually in the VASSAL module XML files in a text editor.
pelle
 
Posts: 17
Joined: March 3rd, 2008, 3:52 pm

module python library

Postby Brent Easton » May 31st, 2009, 10:51 pm

So it's more
to it than just importing the graphics into the ZIP file, I also want to
make use of as much meta data as I can think of to add,

The new Add Multiple Piece feature does more than just import the graphics - You specify a counter template including all of the traits and prototypes you wish to use, plus rules to identify front/back and Layer levels and it builds the entire counters.

However, I understand what you are saying about keeping an external 'Source' for your module build.

B



_______________________________________________
Messages mailing list
Messages@forums.vassalengine.org
http://forums.vassalengine.org/mailman/ ... engine.org

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
Brent Easton
 
Posts: 3230
Joined: December 21st, 2007, 3:06 am
Location: Berry, NSW, Australia

module python library

Postby uckelman » June 3rd, 2009, 10:52 am

Thus spake "pelle":
Hi,

This is a long shot, but is there a Python module to read and write VASSAL mo
dule files? I'd like some nice API to be able to easily add some images and c
ounters that use those images from a Python script. I don't want to spend a l
ot of time implementing one myself if there already is one I can use. :D

(To be exact I'm planning to add a new feature to my Inkscape countersheet ge
nerator (http://www.boardgamegeek.com/thread/299033/page/1) to allow the user
to automatically export all created counters to a choosen VASSAL module.)



I think a Python module for manipulating modulue files is a good idea. (I
wouldn't use it myself, I'd write a Perl module for it instead, as I prefer
Perl to Python.) But I support this kind of thing, as it would save module
designers who want to build modules programatically from having to mess with
the awful buildFile syntax.

--
J.

_______________________________________________
Messages mailing list
Messages@forums.vassalengine.org
http://forums.vassalengine.org/mailman/ ... engine.org

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
uckelman
Site Admin
 
Posts: 9023
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

Postby pelle » June 3rd, 2009, 11:25 am

in the end, it turned out that a generic Python module to handle VASSAL modules was a bit too much work to get into at the moment. Instead I settled for a more limited implemenation that can do exactly the things I need (add counters, optionally with a flip-side, and optionally with a given Prototype added, to a given Panel).

I haven't even bothered to fully understand the format used to store game pieces. I expected it to be XML, but it turned out to be some sort of hack to get nested string values quoted into an XML string. Even a simple thing like adding a second Prototype turned out to completely alter the way the string must look like. I postponed reading DataSequence.java for now. I guess most things I need to know are in there, but I also noticed some other values that seems to randomly vary even when I create a duplicate of a counter.

Probably because of my bad implementation of the piece data string there is a weird bug now: If I edit a module after importing images, then save it, all the images disappear. They are completely gone from the zip, but the counters remain in the buildFile. If I don't edit it it works fine though (and that's fine to me really, since I intended anyway to keep a module without counters for doing all editing, and just batch-add all counters to get a copy that I will not edit anyway; but still it could be nice to fix it).

The first release can be found at that boardgamegeek thread linked to above if someone wants to have a look. It has only been tested on Linux, and I fully expect the bitmap export feature (required by the VASSAL export) to be tricky to use on Windows (and possibly on MacOS), especially if you don't have inkscape.exe in your PATH.

Everything related to VASSAL is in vassal.py, not depending on anything else in the distribution, so it can be easily reused (but it depends on the lxml library for xml parsing).
pelle
 
Posts: 17
Joined: March 3rd, 2008, 3:52 pm

module python library

Postby uckelman » June 3rd, 2009, 11:45 am

Thus spake "pelle":
I haven't even bothered to fully understand the format used to store game pie
ces. I expected it to be XML, but it turned out to be some sort of hack to ge
t nested string values quoted into an XML string.

One of my long-term goals is to expose the data as XML elements and
attributes, rather than as XML elements containing unintelligible blobs.

Probably because of my bad implementation of the piece data string there is a
weird bug now: If I edit a module after importing images, then save it, all
the images disappear. They are completely gone from the zip, but the counters
remain in the buildFile. If I don't edit it it works fine though (and that's
fine to me really, since I intended anyway to keep a module without counters
for doing all editing, and just batch-add all counters to get a copy that I
will not edit anyway; but still it could be nice to fix it).


Yeah, this doesn't surprise me all that much. It's very easy to screw up
a buildFile right now be hand-editing it.

--
J.

_______________________________________________
Messages mailing list
Messages@forums.vassalengine.org
http://forums.vassalengine.org/mailman/ ... engine.org

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
uckelman
Site Admin
 
Posts: 9023
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

Postby pelle » June 3rd, 2009, 11:59 am

I think I pretty much got what I deserved for just hacking away without properly understanding the problem first. It would have been REALLY weird if the generated data blobs worked perfectly as intended. At least I have seen no problems with playing the module, as long as I don't try to edit it first. :oops:
pelle
 
Posts: 17
Joined: March 3rd, 2008, 3:52 pm

module python library

Postby mkiefte » June 3rd, 2009, 12:07 pm


I think a Python module for manipulating modulue files is a good idea. (I
wouldn't use it myself, I'd write a Perl module for it instead, as I prefer
Perl to Python.) But I support this kind of thing, as it would save module
designers who want to build modules programatically from having to mess with
the awful buildFile syntax.


A Python module would be very limited in what it could do.  One of the advantages of using the native Java code for that is that it would keep up with the changes in the actual VASSAL code.  How the buildFile is created is not that difficult to understand -- the only problem being that it's not well documented.   It wouldn't be a bad idea to add methods to the existing Java code to serve as an API for other applications to manipulate the buildFile.  For example, it's obvious from the Java code that no one really intended for the existing methods to be used for any other purposes.

- M.

P.S.: I would also prefer a Perl module, but I don't know Python at all.

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
mkiefte
 
Posts: 1144
Joined: January 5th, 2008, 1:29 am
Location: Halifax, Nova Scotia, Canada

module python library

Postby mkiefte » June 3rd, 2009, 12:09 pm

One of my long-term goals is to expose the data as XML elements and
attributes, rather than as XML elements containing unintelligible blobs.

They're not _that_ bad.  It gets a little weird with nested elements due to the quoting mechanism, but that doesn't happen really often.

- M.

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
mkiefte
 
Posts: 1144
Joined: January 5th, 2008, 1:29 am
Location: Halifax, Nova Scotia, Canada

module python library

Postby uckelman » June 3rd, 2009, 12:24 pm

Thus spake Michael Kiefte:
A Python module would be very limited in what it could do. One of the
advantages of using the native Java code for that is that it would keep up
with the changes in the actual VASSAL code. How the buildFile is created is
not that difficult to understand -- the only problem being that it's not
well documented. It wouldn't be a bad idea to add methods to the existing
Java code to serve as an API for other applications to manipulate the
buildFile. For example, it's obvious from the Java code that no one really
intended for the existing methods to be used for any other purposes.

No, I don't mean adding any hooks to VASSAL for other apps---what I want
is a file format which is human-readable.

--
J.

_______________________________________________
Messages mailing list
Messages@forums.vassalengine.org
http://forums.vassalengine.org/mailman/ ... engine.org

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
uckelman
Site Admin
 
Posts: 9023
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

module python library

Postby uckelman » June 3rd, 2009, 12:27 pm

Thus spake Michael Kiefte:
One of my long-term goals is to expose the data as XML elements and
attributes, rather than as XML elements containing unintelligible blobs.


They're not _that_ bad. It gets a little weird with nested elements due to
the quoting mechanism, but that doesn't happen really often.


They _are_ that bad. They make it impossible to leverage all of the XML
slurping code which is already out there, and not easy to do scripting.
That by itself is going set the bar too high for almost everyone to get
useful results.

--
J.

_______________________________________________
Messages mailing list
Messages@forums.vassalengine.org
http://forums.vassalengine.org/mailman/ ... engine.org

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
uckelman
Site Admin
 
Posts: 9023
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

module python library

Postby mkiefte » June 3rd, 2009, 12:29 pm



No, I don't mean adding any hooks to VASSAL for other apps---what I want
is a file format which is human-readable.





I agree with that, but it is another issue entirely.

- M.

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
mkiefte
 
Posts: 1144
Joined: January 5th, 2008, 1:29 am
Location: Halifax, Nova Scotia, Canada

module python library

Postby uckelman » June 3rd, 2009, 12:31 pm

Thus spake Michael Kiefte:
No, I don't mean adding any hooks to VASSAL for other apps---what I want
is a file format which is human-readable.


I agree with that, but it is another issue entirely.


Then I don't understand your original reply. If the file format is either
(1) human-readable, or (2) well-documented, then it should not be hard to
write a Python or Perl module for manipulating it.

--
J.

_______________________________________________
Messages mailing list
Messages@forums.vassalengine.org
http://forums.vassalengine.org/mailman/ ... engine.org

Post generated using Mail2Forum (http://www.mail2forum.com)
User avatar
uckelman
Site Admin
 
Posts: 9023
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

Postby pelle » June 3rd, 2009, 12:53 pm

To me it would be much easier to work with XML than a mix of XML and some other format. But I perfectly well see how most VASSAL users and developers have no reason to change the way it is now.

The quoting is quite complex btw, not as simple as suggested above. As an example, here are the data blob for two very simple counters I created using VASSAL for reverse-engineering purposes:

Code: Select all
+/null/emb2;Flip;2;F;;0;;;0;;;;1;false;0;0;c_r.png;;true;;;;false;;1       prototype;PPP\  piece;;;e_d.png;FRONT/1;F       \       null;0;0;0

Code: Select all
+/null/prototype;P2       emb2;Flip;2;F;;0;;;0;;;;1;false;0;0;g_f.png;;true;;;;false;;1\  prototype;PPP\\ piece;;;c_f.png;FRONT2/ -1;\    \\      null;5;0;


The only difference is that one has two Prototypes (PPP and P2) while whe other has only one (PPP). The second was created by copy-paste from the first from within the VASSAL editor, and nothing was edited except adding the second Prototype. This tiny change makes the quoting all different, in ways that are not easy to guess without further studying the source code I think. For instane look at that last \ that suddenly becomes \\. Also it is not obvious why one ends in 0;0;0, while the other ends in 5;0;. There are also a few other minor differences that is in no obvious way connected to the addition of a Prototype.
[/code]
pelle
 
Posts: 17
Joined: March 3rd, 2008, 3:52 pm

Next

Return to Module Design

Who is online

Users browsing this forum: No registered users and 2 guests