Skip to content

Commit

Permalink
Fixed: #24 added button to make web to menu item Tools:Make Web Map
Browse files Browse the repository at this point in the history
  • Loading branch information
kk49 committed Apr 13, 2019
1 parent 0cf0446 commit 679077a
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 38 deletions.
10 changes: 5 additions & 5 deletions deca/cmds/process_adf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


if len(sys.argv) < 2:
in_file = '/home/krys/prj/deca/work/gzb/extracted/models/manmade/props/interior/civilian_01_answering_machine.hrmeshc'
in_file = '/home/krys/prj/deca/work/gzb/extracted/models/manmade/props/interior/civilian_01_answering_machine.modelc'
in_file = '/home/krys/prj/deca/work/gzb/extracted/graphs/check_region_difficulty.graphc'
in_file = '/home/krys/prj/deca/work/gzb/extracted/graphs/check_region_difficulty.graphc'
in_file = '/home/krys/prj/deca/work/gzb/extracted/gdc/global.gdcc'
in_file = '/home/krys/prj/work/gzb/extracted/models/manmade/props/interior/civilian_01_answering_machine.hrmeshc'
in_file = '/home/krys/prj/work/gzb/extracted/models/manmade/props/interior/civilian_01_answering_machine.modelc'
in_file = '/home/krys/prj/work/gzb/extracted/graphs/check_region_difficulty.graphc'
in_file = '/home/krys/prj/work/gzb/extracted/graphs/check_region_difficulty.graphc'
in_file = '/home/krys/prj/work/gzb/extracted/gdc/global.gdcc'
else:
in_file = sys.argv[1]

Expand Down
51 changes: 33 additions & 18 deletions plugin_make_web_map.py → deca/cmds/tool_make_web_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import io
import matplotlib.pyplot as plt
import shutil


def process_translation_adf(f, sz):
Expand All @@ -29,17 +30,18 @@ def process_translation_adf(f, sz):
name = tf.read_strz().decode('utf-8')
tr[name] = text

with open('docs/text_debug.txt', 'w') as dt:
for k, v in tr.items():
dt.write('{}\t{}\n'.format(k, v.replace('\n', '<br>')))
if os.path.exists(os.path.join('scratch', 'gz')):
with open(os.path.join('scratch', 'gz', 'text_debug.txt'), 'w') as dt:
for k, v in tr.items():
dt.write('{}\t{}\n'.format(k, v.replace('\n', '<br>')))

return tr


def tileset_make(img, tile_path, tile_size=256, max_zoom=-1):
# save full image, mainly for debugging
os.makedirs(tile_path, exist_ok=True)
img.save(tile_path + '/full.png')
img.save(os.path.join(tile_path, 'full.png'))

# determine zoom levels
sz = img.size
Expand All @@ -64,27 +66,27 @@ def tileset_make(img, tile_path, tile_size=256, max_zoom=-1):

if not os.path.isdir(zpath):
for x in range(0, 2 ** zlevel):
dpath = zpath + '/{}'.format(x)
dpath = os.path.join(zpath, '{}'.format(x))
os.makedirs(dpath, exist_ok=True)
for y in range(0, 2 ** zlevel):
fpath = dpath + '/{}.png'.format(y)
fpath = os.path.join(dpath, '{}.png'.format(y))
zimgs[zlevel].crop((x * tile_size, y * tile_size, (x + 1) * tile_size, (y + 1) * tile_size)).save(
fpath)

for zlevel in range(zooms, max_zoom+1):
width = tile_size >> (zlevel - (zooms-1))
zpath = tile_path + '/{}'.format(zlevel)
zpath = os.path.join(tile_path, '{}'.format(zlevel))
print('Generate Zoom: {}'.format(zpath))
if not os.path.isdir(zpath):
for x in range(0, 2 ** zlevel):
dpath = zpath + '/{}'.format(x)
dpath = os.path.join(zpath, '{}'.format(x))
os.makedirs(dpath, exist_ok=True)
for y in range(0, 2 ** zlevel):
fpath = dpath + '/{}.png'.format(y)
fpath = os.path.join(dpath, '{}.png'.format(y))
zimgs[(zooms-1)].crop((x * width, y * width, (x + 1) * width, (y + 1) * width)).resize((tile_size, tile_size), Image.NEAREST).save(fpath)


def plugin_make_web_map(vfs, wdir):
def tool_make_web_map(vfs, wdir, copy_support_files):
force_topo_tiles = False

# BUILD topo map
Expand Down Expand Up @@ -129,7 +131,7 @@ def plugin_make_web_map(vfs, wdir):
cimg = cm(aimg)
img = Image.fromarray((cimg[:, :, :3] * 255).astype(np.uint8))

tileset_make(img, wdir + 'map/z0/tile_h')
tileset_make(img, os.path.join(wdir, 'map', 'z0', 'tile_h'))

# BUILD water nvwaveworks map
# extract full res image
Expand All @@ -148,7 +150,7 @@ def plugin_make_web_map(vfs, wdir):
cimg = cm(aimg)
img = Image.fromarray((cimg[:, :, :3] * 255).astype(np.uint8))

tileset_make(img, wdir + 'map/z0/tile_wn')
tileset_make(img, os.path.join(wdir, 'map', 'z0', 'tile_wn'))

# BUILD water gerstner map
# extract full res image
Expand All @@ -167,7 +169,7 @@ def plugin_make_web_map(vfs, wdir):
cimg = cm(aimg)
img = Image.fromarray((cimg[:, :, :3] * 255).astype(np.uint8))

tileset_make(img, wdir + 'map/z0/tile_wg')
tileset_make(img, os.path.join(wdir, 'map', 'z0', 'tile_wg'))

# TODO parse terrain/nv_water_cull_mask.rawc ? 1 bit per pixel 512x512 pixels
fn = b'terrain/nv_water_cull_mask.rawc'
Expand All @@ -190,7 +192,7 @@ def plugin_make_web_map(vfs, wdir):
cimg = np.flip(cimg, 0)
img = Image.fromarray(cimg)

tileset_make(img, wdir + 'map/z0/tile_wnm')
tileset_make(img, os.path.join(wdir, 'map', 'z0', 'tile_wnm'))

tile_overlays = []

Expand Down Expand Up @@ -250,7 +252,7 @@ def plugin_make_web_map(vfs, wdir):
# cimg = np.flip(cimg, 0)
img = Image.fromarray(cimg)

tileset_make(img, wdir + 'map/z0/{}'.format(tileo[1]))
tileset_make(img, os.path.join(wdir, 'map', 'z0', '{}'.format(tileo[1])))

# load translation
tr = {}
Expand Down Expand Up @@ -487,9 +489,9 @@ def plugin_make_web_map(vfs, wdir):
}
collectables.append(obj)

dpath = wdir + 'map/z0'
dpath = os.path.join(wdir, 'map', 'z0')
os.makedirs(dpath, exist_ok=True)
fpath = dpath + '/data.js'
fpath = os.path.join(dpath, 'data.js')

with open(fpath, 'w') as f:
f.write('var region_data = {};\n'.format(json.dumps(regions, indent=4)))
Expand All @@ -498,10 +500,23 @@ def plugin_make_web_map(vfs, wdir):
f.write('var bookmark_data = {};\n'.format(json.dumps(bookmarks, indent=4)))
f.write('var collectable_data = {};\n'.format(json.dumps(collectables, indent=4)))

if copy_support_files:
dst = os.path.join(dpath, 'index.html')
if os.path.exists(dst):
print('WARNING: {} already exists will not over-write'.format(dst))
else:
shutil.copyfile(os.path.join('.', 'tool_resources', 'make_web_map', 'index.html'), dst)

dst = os.path.join(dpath, 'lib')
if os.path.exists(dst):
print('WARNING: {} already exists will not over-write'.format(dst))
else:
shutil.copytree(os.path.join('.', 'tool_resources', 'make_web_map', 'lib'), dst)


def main():
vfs = vfs_structure_open('../work/gz/project.json')
plugin_make_web_map(vfs, vfs.working_dir)
tool_make_web_map(vfs, vfs.working_dir, False)


if __name__ == "__main__":
Expand Down
33 changes: 22 additions & 11 deletions deca/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from deca.gui.viewer_raw import DataViewerRaw
from deca.gui.viewer_text import DataViewerText
from deca.gui.viewer_sarc import DataViewerSarc
from deca.cmds.tool_make_web_map import tool_make_web_map
import PySide2
from PySide2.QtCore import \
QAbstractTableModel, QAbstractItemModel, QModelIndex, Qt, Slot, QSortFilterProxyModel, QRegExp
Expand Down Expand Up @@ -773,21 +774,27 @@ def __init__(self):

# Menu
self.menu = self.menuBar()
self.file_menu = self.menu.addMenu("File")
self.file_menu = self.menu.addMenu('File')
self.edit_menu = self.menu.addMenu('Edit')
self.tools_menu = self.menu.addMenu('Tools')

self.project_new_action = QAction("&New Project...")
self.project_new_action.triggered.connect(self.project_new)
self.action_project_new = QAction("&New Project...")
self.action_project_new.triggered.connect(self.project_new)

self.project_open_action = QAction("&Open Project...")
self.project_open_action.triggered.connect(self.project_open)
self.action_project_open = QAction("&Open Project...")
self.action_project_open.triggered.connect(self.project_open)

self.exit_action = QAction("E&xit", self)
self.exit_action.setShortcut("Ctrl+Q")
self.exit_action.triggered.connect(self.exit_app)
self.action_exit = QAction("E&xit", self)
self.action_exit.setShortcut("Ctrl+Q")
self.action_exit.triggered.connect(self.exit_app)

self.file_menu.addAction(self.project_new_action)
self.file_menu.addAction(self.project_open_action)
self.file_menu.addAction(self.exit_action)
self.action_make_web_map = QAction("Make &Web Map")
self.action_make_web_map.triggered.connect(self.tool_make_web_map)

self.file_menu.addAction(self.action_project_new)
self.file_menu.addAction(self.action_project_open)
self.file_menu.addAction(self.action_exit)
self.tools_menu.addAction(self.action_make_web_map)

# Status Bar
self.status = self.statusBar()
Expand Down Expand Up @@ -873,6 +880,10 @@ def project_open(self, checked):
def exit_app(self, checked):
self.close()

@Slot()
def tool_make_web_map(self, checked):
tool_make_web_map(self.vfs, self.vfs.working_dir, True)


def main():
# options = argparse.ArgumentParser()
Expand Down
10 changes: 6 additions & 4 deletions deca_gui.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
block_cipher = None

added_files = [
('resources/gz/*', 'resources/gz'),
('resources/gzb/*', 'resources/gzb'),
('resources/hp/*', 'resources/hp'),
('resources/gz', 'resources/gz'),
('resources/gzb', 'resources/gzb'),
('resources/hp', 'resources/hp'),
('tool_resources/make_web_map', 'tool_resources/make_web_map'),
]

a = Analysis(
Expand All @@ -23,7 +24,8 @@ a = Analysis(
noarchive=False)

pyz = PYZ(
a.pure, a.zipped_data,
a.pure,
a.zipped_data,
cipher=block_cipher)

exe = EXE(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 679077a

Please sign in to comment.