Files
Aurora.3/tools/mapmerge2/travis_mapcheck.py
Mykhailo Bykhovtsev 779f8a0733 Integrating mapmerge2 checks into Travis (#5616)
Okay, this update is kinda big. Summary:

- Trimmed unused keys in Exodus telecomms

- Adds script that will run mapmerge2 on Travis to check branch for unused keys or key overflow, etc.

- Fixes matching indentation style in tag-matcher and converts it to use Python 3.6

- Converts mapmerge2 to be used by Python 3.4 and above. Instead of 3.6

- Removes Windows 1252 characters from Communication-blackout.dm that were not able to be seen in UTF-8 format.

Note: the last commit will fail because currently main level is broken

Example of no map issues:
![2018-11-15_li](https://user-images.githubusercontent.com/25555314/48592180-0fd7be80-e8fc-11e8-80b9-cd5af32540e3.jpg)

Example of issues:
![2018-11-15_li 2](https://user-images.githubusercontent.com/25555314/48592190-15cd9f80-e8fc-11e8-99bd-6da4b4c2b9d8.jpg)
2018-11-20 20:14:21 +01:00

82 lines
3.1 KiB
Python

#!/usr/bin/env python3
import os
from collections import defaultdict
import shutil
import pathlib
from dmm import *
def map_check(map, name):
key_length, size = map.key_length, map.size
merged = DMM(key_length, size)
merged.dictionary = map.dictionary.copy()
known_keys = dict() # mapping fron 'new' key to 'merged' key
unused_keys = set(map.dictionary.keys()) # keys going unused
# step one: parse the new version, compare it to the old version, merge both
for z, y, x in map.coords_zyx:
new_key = map.grid[x, y, z]
# if this key has been processed before, it can immediately be merged
try:
merged.grid[x, y, z] = known_keys[new_key]
continue
except KeyError:
pass
def select_key(assigned):
merged.grid[x, y, z] = known_keys[new_key] = assigned
old_key = map.grid[x, y, z]
old_tile = map.dictionary[old_key]
new_tile = map.dictionary[new_key]
# this tile is the exact same as before, so the old key is used
if new_tile == old_tile:
select_key(old_key)
unused_keys.remove(old_key)
# the tile is different here, but if it exists in the merged dictionary, that key can be used
elif new_tile in merged.dictionary.inv:
newold_key = merged.dictionary.inv[new_tile]
select_key(newold_key)
unused_keys.remove(newold_key)
# the tile is brand new and it needs a new key, but if the old key isn't being used any longer it can be used instead
elif old_tile not in map.dictionary.inv and old_key in unused_keys:
merged.dictionary[old_key] = new_tile
select_key(old_key)
unused_keys.remove(old_key)
# all other options ruled out, a brand new key is generated for the brand new tile
else:
fresh_key = merged.generate_new_key()
merged.dictionary[fresh_key] = new_tile
select_key(fresh_key)
# step two: delete unused keys
if unused_keys:
print("Error: {} unused dictionary keys. Please run mapmerge2 on {} locally to trim them.".format(len(unused_keys), name[42:len(name)]))
exit(1)
try:
merged._ensure_free_keys(0)
max_key = max_key_for(merged.key_length)
except KeyTooLarge:
print("\nKey is too large, run mapmerge2 on {} locally and fix errors.".format(fname[42:len(fname)]))
exit(1)
bad_keys = {key: 0 for key in merged.dictionary.keys() if key > max_key}
if bad_keys:
print("\nBad keys detected, please run mapmerge2 on {} locally and fix errors.".format(fname[42:len(fname)]))
exit(1)
if __name__ == '__main__':
list_of_files = list()
for root, directories, filenames in os.walk("/home/travis/build/Aurorastation/Aurora.3/maps/"):
for filename in [f for f in filenames if f.endswith(".dmm")]:
list_of_files.append(str(pathlib.Path(root, filename)))
for fname in list_of_files:
map = DMM.from_file(fname)
map_check(map, fname)
print("Maps scanning complete, no issues were found.")