def __init__(self):
     # Basics
     ShowBase.__init__(self)
     # settings = Settings()
     base.disableMouse()
     base.setFrameRateMeter(True)
     base.camLens.set_near(0.1)
     base.setBackgroundColor(0, 0, 0)
     self.accept("escape", sys.exit)
     # Create the geometry
     self.geosphere = Geosphere()
     t1 = datetime.datetime.now()
     self.geosphere_np = self.geosphere.create_node()
     t2 = datetime.datetime.now()
     print(t2-t1)
     self.geosphere_np.reparent_to(self.render)
     self.bases = nx.Graph()
     self.add_bases()
     # Music
     self.music_player = MusicPlayer(self)
     # Game state
     self.game_state = GameState()
     self.game_state.start()
     # Controls
     self.accept("m", self.toggle_geosphere_unwrapping)
     self.accept("arrow_right", self.move_camera, [1, 0, 0])
     self.accept("arrow_left", self.move_camera, [-1, 0, 0])
     self.accept("arrow_up", self.move_camera, [0, 1, 0])
     self.accept("arrow_down", self.move_camera, [0, -1, 0])
     self.accept("wheel_up", self.move_camera, [0, 0, -1])
     self.accept("wheel_down", self.move_camera, [0, 0, 1])
     self.accept("c", self.game_state.set_clock_factor, [0.0])
     self.accept("v", self.game_state.set_clock_factor, [1.0])
     self.accept("b", self.game_state.set_clock_factor, [60.0])
     self.accept("n", self.game_state.set_clock_factor, [3600.0])
     self.accept("j", self.game_state.skip_to_next_event)
     self.accept("l", self.load, ["savegame.yml"])
     self.accept("s", self.save, ["savegame.yml"])
class Game(ShowBase, Settings):
    def __init__(self):
        # Basics
        ShowBase.__init__(self)
        # settings = Settings()
        base.disableMouse()
        base.setFrameRateMeter(True)
        base.camLens.set_near(0.1)
        base.setBackgroundColor(0, 0, 0)
        self.accept("escape", sys.exit)
        # Create the geometry
        self.geosphere = Geosphere()
        t1 = datetime.datetime.now()
        self.geosphere_np = self.geosphere.create_node()
        t2 = datetime.datetime.now()
        print(t2-t1)
        self.geosphere_np.reparent_to(self.render)
        self.bases = nx.Graph()
        self.add_bases()
        # Music
        self.music_player = MusicPlayer(self)
        # Game state
        self.game_state = GameState()
        self.game_state.start()
        # Controls
        self.accept("m", self.toggle_geosphere_unwrapping)
        self.accept("arrow_right", self.move_camera, [1, 0, 0])
        self.accept("arrow_left", self.move_camera, [-1, 0, 0])
        self.accept("arrow_up", self.move_camera, [0, 1, 0])
        self.accept("arrow_down", self.move_camera, [0, -1, 0])
        self.accept("wheel_up", self.move_camera, [0, 0, -1])
        self.accept("wheel_down", self.move_camera, [0, 0, 1])
        self.accept("c", self.game_state.set_clock_factor, [0.0])
        self.accept("v", self.game_state.set_clock_factor, [1.0])
        self.accept("b", self.game_state.set_clock_factor, [60.0])
        self.accept("n", self.game_state.set_clock_factor, [3600.0])
        self.accept("j", self.game_state.skip_to_next_event)
        self.accept("l", self.load, ["savegame.yml"])
        self.accept("s", self.save, ["savegame.yml"])

    def load(self, filename):
        self.game_state.shutdown()
        f = open(filename, 'r')
        state = yaml.load(f.read())
        f.close()
        self.game_state = GameState(state)
        self.accept("c", self.game_state.set_clock_factor, [0.0])
        self.accept("v", self.game_state.set_clock_factor, [1.0])
        self.accept("b", self.game_state.set_clock_factor, [60.0])
        self.accept("n", self.game_state.set_clock_factor, [3600.0])
        self.accept("j", self.game_state.skip_to_next_event)
        self.game_state.start()
    
    def save(self, filename):
        f = open(filename, 'w')
        f.write(yaml.dump(self.game_state.get_state()))
        f.close()

    def toggle_geosphere_unwrapping(self):
        self.geosphere.toggle_unwrap()
    
    def add_bases(self):
        # All your bases are belong to me.
        for base_id, base_def in bases.iteritems():
            if base_def['active']:
                u, v = base_def['coords']
                game_base = Base(u, v)
                self.bases.add_node(base_id)
                self.geosphere.add_base(game_base)
        # Now for a connection
        for b1, b2 in [(22, 3), (3, 135), (135, 112), (112, 54)]:
            self.bases.add_edge(b1, b2)
            c1, c2 = bases[b1]['coords'], bases[b2]['coords']
            self.geosphere.add_connection(c1, c2)
    
    def move_camera(self, x, y, zoom):
        self.geosphere.move_camera(x*0.05, y*0.05, zoom*0.5)