makhidkarun / traveller_pyroute

Traveller trade route generator
MIT License
14 stars 5 forks source link

Harden wiki templates against null/NoneType keys #82

Closed CyberiaResurrection closed 11 months ago

CyberiaResurrection commented 11 months ago

Status quo had the wiki templates (especially the summary-stats template) prone to blithely accepting NoneType keys and blowing up in Yankovic-level ways, which are a pain to chase down.

It looks like the proximate cause is the new, nonstellar, primary options - D, BD, BH, PSR, NS, that each have a non-None size attribute, but a None spectral attribute, which the template dictionary keys were blithely using.

This PR tackles that weirdness in two ways: 1 - Adds a defaultDict subtype that blows up loudly when fed a NoneType key. 2 - Backfills None spectral types with the system primary's size, since @tjoneslo wanted to break out the nonstellar primaries by type, rather than lumping them in with each other.

Having to handle nonstellar primaries also rumbled a potential single-point-of-truth violation across uwpCode generation in Star parsing and StatCalculation.addStats. To splat that, I pulled the primary type determination behind a property and hooked that property up where it was needed.