def starsystem(self, must_have_garden="False", open_cluster=None, num_stars=0, age=None, naming="", use_chain=False, depth=1, seed=None): input_seed = None if seed == '' or None else seed # Correctly interpret "no input" self.set_seed(input_seed) # reseed the PRNG, so that there is a unique seed every time r.seed(self.random_seed) if num_stars == "": num_stars = None elif int(num_stars) < 1 or int(num_stars) > 3: num_stars = None else: num_stars = int(num_stars) namegen = None if naming != "": # A naming scheme has been selected that is not the simple "A-1", "B-1" scheme. namegen = namegenerator.NameGenerator(int(depth), self.random_seed) namegen.read_file(naming) namegen.use_chain = use_chain cherrypy.session['namegen'] = namegen else: cherrypy.session['namegen'] = None arguments = { 'open_cluster': open_cluster == "True", 'num_stars': num_stars, 'age': age } # Generate star systems until one is made that contains a Garden world if it's required. if must_have_garden == "True": garden = False while garden is not True: mysys = starsys.StarSystem(**arguments) garden = mysys.has_garden() else: mysys = starsys.StarSystem(**arguments) for star in mysys.stars: for key, v in star.planetsystem.get_orbitcontents().items(): if namegen is not None: simple_name = v.get_name().replace("-", "") if cherrypy.session.get('name_of_' + simple_name) is None: name = namegen.get_random_name() star.planetsystem.get_orbitcontents()[key].set_name(name) # For some reason, using simple_name here leads to storing stuff improperly and # generating new names every time. No idea why. cherrypy.session['name_of_' + v.get_name().replace("-", "")] = name else: name = cherrypy.session.get('name_of_' + simple_name) star.planetsystem.get_orbitcontents()[key].set_name(name) cherrypy.session.save() tmpl = env.get_template('overview.html') cherrypy.session['starsystem'] = mysys cherrypy.response.cookie['names'] = {} return tmpl.render(starsystem=mysys, seed=self.random_seed)
def starsystem(self, must_have_garden="False", open_cluster=None, num_stars=0, age=None, naming="", use_chain=False, depth=1): if num_stars == "": num_stars = None elif int(num_stars) < 1 or int(num_stars) > 3: num_stars = None else: num_stars = int(num_stars) if naming != "": # A naming scheme has been selected that is not the simple "A-1", "B-1" scheme. namegen = namegenerator.NameGenerator(int(depth)) namegen.read_file(naming) namegen.use_chain = use_chain cherrypy.session['namegen'] = namegen else: cherrypy.session['namegen'] = None arguments = { 'open_cluster': open_cluster == "True", 'num_stars': num_stars, 'age': age } # Generate star systems until one is made that contains a Garden world if it's required. if must_have_garden == "True": garden = False while garden is not True: mysys = starsys.StarSystem(**arguments) garden = mysys.has_garden() else: mysys = starsys.StarSystem(**arguments) tmpl = env.get_template('overview.html') cherrypy.session['starsystem'] = mysys cherrypy.response.cookie['names'] = {} return tmpl.render(starsystem=mysys)
def setUp(self): self.unisystem = starsystem.StarSystem(num_stars=1) self.bisystem = starsystem.StarSystem(num_stars=2) self.trisystem = starsystem.StarSystem(num_stars=3) self.randomsystem = starsystem.StarSystem()
def test_descending_sort(self): arguments = {'num_stars': 2} testsystem = starsystem.StarSystem(**arguments) self.assertTrue( testsystem.stars[0].get_mass() >= testsystem.stars[1].get_mass())
def test_generate_starsystem_open_cluster_one_star(self): arguments = {'open_cluster': "True", 'num_stars': 1, 'age': None} self.testsystem = starsystem.StarSystem(**arguments)
"""This is an example script for automated star system generation""" import gurpsspace.starsystem as starsys # Change from None to a value if you want to set an argument args = { 'opencluster': None, # True or False 'numstars': None, # 1, 2 or 3 'age': None # Number > 0 } # Generate starsystems until one is made that contains a Garden world. garden = False cyclenum = 0 while garden is not True: cyclenum += 1 mysys = starsys.StarSystem(**args) garden = mysys.hasgarden() mysys.printinfo() print('Total number of cycles: {}'.format(cyclenum)) # mysys.writelatex() mysys.writexml()