Author Topic: Python script map loader! (can be used to convert maps to e.g. JSON files)  (Read 2368 times)

jammyjamjamman

  • Administrator
  • Horseman
  • ********
  • Posts: 210
    • View Profile
==COPIED FROM MEGAGLEST BOARD==
I wanted to read megaglest maps so I could use them in other things. So, I wrote this *dirty* python 3 script to read a map into a python dictionary. The dictionary is formatted such that it can be easily written to disk as e.g. a JSON file.
Here's a link if anyone else is interested in reading maps in python: https://drive.google.com/file/d/190gXUyiuNKR3ITFtN_zF5MFc6Qogca_f/view?usp=sharing

  • Maps  included were made by atze.
  • The script no longer requires numpy! It should be completely compatible with cpython3.
  • There is example code, commented out, under if __name__ == "__main__":, which demonstrates previewing atze's 6player.mgm map data in matplotlib and saving the map as a JSON object file.
  • The original map data is is stored as a flat, 1d array of numbers, but the script converts the flat array into a 2d array in the shape of the map.

The code is very badly written and has the following problems (in descending order of importance):
  • Does not support  "version 1" maps (glest maps?).
  • Needs numpy to read map data (unnecessary as performance not an issue + requires extra dependencies).
  • Code is generally a mess which leads to memory inefficiencies in various places.

I may fix these problems sometime, or feel free to fix them yourself if you want :).
The code is licensed under the MIT License.
« Last Edit: 11 December 2017, 23:20:16 by jammyjamjamman »
"All right, I've been thinking. When life gives you lemons? Don't make lemonade. Make life take the lemons back! Get mad! 'I don't want your damn lemons! What am I supposed to do with these?'" ~Cave Johnson, Portal 2

tomreyn

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 2,764
    • View Profile
    • MegaGlest - the free and open source cross platform 3D real-time strategy game
Sounds like a handy utility. Maybe put it on a public source code repository (GitHub, Gitlab, Bitbucket etc.) so it's easier to inspect the code and provide patches?

I've placed a backup copy of today's state at https://downloads.megaglest.org/tools/read_map_a2.zip
atibox: Ryzen 1800X (8 cores @3.6GHz), 32 GB RAM, MSI Radeon RX 580 Gaming X 8G, PCI subsystem ID [1462:3417], (Radeon RX 580 chipset, POLARIS10) @3440x1440; latest stable Ubuntu release, (open source) radeon (amdgpu) / mesa video driver
atibox (old): Core2Quad Q9400 (4 cores @2.66GHz), 8 GB RAM, XFX HD-467X-DDF2, PCI subsystem ID [1682:2931], (Radeon HD 4670, RV730 XT) @1680x1050; latest stable Ubuntu release, (open source) radeon / mesa video driver
notebook: HP envy13d020ng
internet access: VDSL2+

· · · How YOU can contribute to MG · Latest development snapshot · How to build yourself · Megapack techtree · Currently hosted MG games · · ·

jammyjamjamman

  • Administrator
  • Horseman
  • ********
  • Posts: 210
    • View Profile
Sounds like a handy utility. Maybe put it on a public source code repository (GitHub, Gitlab, Bitbucket etc.) so it's easier to inspect the code and provide patches?

I've placed a backup copy of today's state at https://downloads.megaglest.org/tools/read_map_a2.zip

Thanks for backing it up! Yeah I shouldn't really be using g-drive for storing the script especially since I think there's some clause that "they own the data there"  :O  :look: (don't quote me on that). I'll try to move it over to a git repo asap.

P.s. I've added the license for the script to my post, And I will add it to the top of my script later.
"All right, I've been thinking. When life gives you lemons? Don't make lemonade. Make life take the lemons back! Get mad! 'I don't want your damn lemons! What am I supposed to do with these?'" ~Cave Johnson, Portal 2

 

anything