Generates FOW maps for diplomacy games
- Install the
requirements.txt - Add asset files to assets:
- They must all be the same dimensions
- They should all be PNGs
- One file must contain just the background image (Test.png)
- Anything black (255, 255, 255) will be treated as a border
- Territories are regions of continuous color (diagonals are connected); sorry for anyone who likes to draw canals/whatever
- It should be able to handle borders up to 12px thickness just fine, but I've only tested with 6px. If you need to tune this just search for
expand_labelsin the code and change the distance (should be able to handle2*distance)
- One file must contain just supply centers (Testcenters.png)
- Anywhere the centers map is not invisible (alpha = 0), it will mark that territory as a center
- One file must contain just territory names (Testnames.png)
- Territory names should not be on borders; they should be entirely within a region
- It will attempt to use
pytesseractto do image recognition and guess what your regions are named, but if you don't want to have to install pytesseract, comment that out
- One file must contain just units (Testunits/Testunitsalt.png)
- It's okay for regions to touch borders or even poke into other areas. If this happens it should take the region with the most unit on it
- Units should not touch. A unit is recognized by a connected (including diagonals) region of non-invisible pixels. If you have two units touching, they will be thought of as the same unit.
- It cannot tell boats from armies currently
- Change hardcoded values in the code:
- Filenames in the bottom of main.py
- constants throughout the file used for mapping:
COLOR_REGION_TYPE_MAPPINGmaps an rgb color for a territory to the player that owns itCOLOR_UNIT_MAPPINGmaps an rgb color on a unit to the player that owns it (if units are multicolored, the most common color that has an existant matching will be used)NON_PLAYER_REGIONSwill probably just contain"neutral"and"ocean"but you can add other items defined in a/b that are not to be treated as players herePLAYER_PREVIOUSLY_SEEN_COLOR_MAPPINGmaps players to what rgb color should be used to represent regions they own players used to see but currently do not. I personally like to just use Paint.Net's "brightness/contrast" tool to turn down brightness by 50% for this
python main.py- The first time it runs, it will take longer because it needs to generate region information. On later runs this information will be re-used so it should be faster
- Output files should be generated in
outputs/
There's some commented out code in the parse_names function that may be useful for problems with name parsing.
The plot_region_info function can be used on any label graph (currently it's unused in the code; it's only here for debugging).
It will output a matplotlib graph that shows which region has which label as well as other info.
If you have very tiny borders between territories, you may find that territory labelling jumping over diagonals is a detriment.
If this is the case, you can change the structure argument passed to ndimage.label in load_images_and_bg_labels.
The current setup has it look for neighbors like this:
[[ 1, 1, 1],
[ 1, 1, 1],
[ 1, 1, 1]]
If you imagine the center of the matrix is your pixel, it will be connected everywhere there is a 1.
The current setup has it look at diagonal spots but if you change those to 0's you can make it orthogonal only.
You don't need pytesseract really - I already had it installed from trying to use felixludos' digi-diplo months ago (shoutout to them; the name parsing part of this is based on the code in the jupyter notebooks of that project)