Skip to content

Commit

Permalink
Merge pull request #118 from CyberiaResurrection/SwitchPDFGenerationP…
Browse files Browse the repository at this point in the history
…ackage

Switch PDF generation package
  • Loading branch information
CyberiaResurrection authored Jul 21, 2024
2 parents 8c42a3d + cd9df95 commit b9302a2
Show file tree
Hide file tree
Showing 27 changed files with 1,489 additions and 223 deletions.
4 changes: 2 additions & 2 deletions PyRoute/DeltaDebug/DeltaReduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from PyRoute.DeltaDebug.DeltaLogicError import DeltaLogicError
from PyRoute.DeltaDebug.DeltaDictionary import DeltaDictionary
from PyRoute.DeltaDebug.DeltaGalaxy import DeltaGalaxy
from PyRoute.Outputs.HexMap import HexMap
from PyRoute.DeltaPasses.AllegianceReducer import AllegianceReducer
from PyRoute.DeltaPasses.AuxiliaryLineReduce import AuxiliaryLineReduce
from PyRoute.DeltaPasses.Canonicalisation import Canonicalisation
Expand All @@ -27,6 +26,7 @@
from PyRoute.DeltaPasses.WidenHoleReducer import WidenHoleReducer
from PyRoute.SpeculativeTrade import SpeculativeTrade
from PyRoute.StatCalculation import StatCalculation
from PyRoute.Outputs.PDFHexMap import PDFHexMap
from PyRoute.Outputs.SubsectorMap2 import GraphicSubsectorMap


Expand Down Expand Up @@ -172,7 +172,7 @@ def _check_interesting(args, sectors):
stats.write_statistics(args.ally_count, args.ally_match, args.json_data)

if args.maps:
pdfmap = HexMap(galaxy, args.routes, args.route_btn)
pdfmap = PDFHexMap(galaxy, args.routes, args.route_btn)
pdfmap.write_maps()

if args.subsectors:
Expand Down
8 changes: 8 additions & 0 deletions PyRoute/Outputs/HexMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(self, galaxy, routes, min_btn=8):
self.min_btn = min_btn
self.y_start = 43
self.x_start = 15
self.sector = None
self.writer = None

def write_maps(self):
"""
Expand Down Expand Up @@ -514,6 +516,12 @@ def clipping(self, startx, starty, endx, endy):
logging.getLogger("PyRoute.HexMap").debug(result)
return (result[0], result[1]), (result[2], result[3])

@property
def compression(self):
if self.writer is None:
return True
return self.writer.session.compression


if __name__ == '__main__':
sector = Sector('# Core', '# 0,0')
Expand Down
55 changes: 17 additions & 38 deletions PyRoute/Outputs/Map.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"""
import logging

from PyRoute.StatCalculation import StatCalculation


class Map(object):
x_count = 33
Expand Down Expand Up @@ -75,53 +73,33 @@ def get_line(self, doc, start, end, colorname, width):
# color.set_color_by_name(colorname)
# hline = PDFLine(pdf.session, pdf.page, hlineStart, hlineEnd, stroke='solid', color=color, size=width)

def trade_line(self, pdf, edge, data):
raise NotImplementedError("Base Class")

@staticmethod
def string_width(font, string):
raise NotImplementedError("Base Class")

def place_system(self, doc, star):
"""
Write a single world information into the map
"""
raise NotImplementedError("Base Class")

def write_sector_pdf_map(self, gal_sector, is_live=True):
raise NotImplementedError("Base Class")

def system(self, pdf, star):
raise NotImplementedError("Base Class")

def write_maps(self):
"""
Starting point for writing PDF files.
Call this to output the trade maps
"""
logging.getLogger("PyRoute.Map").info("writing {:d} sector maps...".format(len(self.galaxy.sectors)))
for sector in self.galaxy.sectors.values():
doc = self.document(sector)
self.write_base_map(doc, sector)

self.draw_borders(doc, sector)

sector_trade = [star for star in self.galaxy.stars.edges(sector.worlds, True)
if star[2]['trade'] > 0 and StatCalculation.trade_to_btn(star[2]['trade']) >= self.min_btn]

logging.getLogger('PyRoute.Map').debug("Worlds with trade: {}".format(len(sector_trade)))

sector_trade.sort(key=lambda line: line[2]['trade'])

for (star, neighbor, data) in sector_trade:
self.galaxy.stars[star][neighbor]['trade btn'] = StatCalculation.trade_to_btn(data['trade'])
self.trade_line(doc, [star, neighbor], data)

# Get all the worlds in this sector
# for (star, neighbor, data) in self.galaxy.stars.edges(sector.worlds, True):
# if star.sector != sector:
# continue#
# if data['trade'] > 0 and self.trade_to_btn(data['trade']) >= self.min_btn:
# self.galaxy.stars[star][neighbor]['trade btn'] = self.trade_to_btn(data['trade'])
# self.trade_line(doc, [star, neighbor], data)
# elif star.sector != neighbor.sector:
# data = self.galaxy.stars.get_edge_data(neighbor, star)
# if data is not None and \
# data['trade'] > 0 and \
# self.trade_to_btn(data['trade']) >= self.min_btn:
# self.trade_line(doc, [star, neighbor], data)

for star in sector.worlds:
self.place_system(doc, star)

self.close()
logging.getLogger("PyRoute.HexMap").info("writing {:d} sector maps...".format(len(self.galaxy.sectors)))
for gal_sector in self.galaxy.sectors.values():
self.write_sector_pdf_map(gal_sector)

def write_base_map(self, doc, sector):
self.sector_name(doc, sector.name)
Expand Down Expand Up @@ -212,6 +190,7 @@ def _draw_borders(self, x, y, hline, lline, rline):
lline._draw()

def draw_borders(self, pdf, sector):
self.sector = sector
self.hex_grid(pdf, self._draw_borders, 1.5, 'salmon')

@staticmethod
Expand Down
Loading

0 comments on commit b9302a2

Please sign in to comment.