Update api.py, commander.py and one other file
This commit is contained in:
		
							parent
							
								
									ffd094df87
								
							
						
					
					
						commit
						92a5a02180
					
				@ -101,4 +101,22 @@ class Api:
 | 
			
		||||
    data = self.request('get', 'my/ships')
 | 
			
		||||
    return self.store.update_list(Ship, data)
 | 
			
		||||
  
 | 
			
		||||
  def navigate(self, ship, wp):
 | 
			
		||||
    data = {'waypointSymbol': str(wp)}
 | 
			
		||||
    response = self.request('post', f'my/ships/{ship}/navigate', data)
 | 
			
		||||
    ship.update(response)
 | 
			
		||||
  
 | 
			
		||||
  def dock(self, ship):
 | 
			
		||||
    data = self.request('post', f'my/ships/{ship}/dock')
 | 
			
		||||
    ship.update(data)
 | 
			
		||||
    return data
 | 
			
		||||
    
 | 
			
		||||
  def orbit(self, ship):
 | 
			
		||||
    data = self.request('post', f'my/ships/{ship}/orbit')
 | 
			
		||||
    ship.update(data)
 | 
			
		||||
    return data
 | 
			
		||||
    
 | 
			
		||||
  def refuel(self, ship):
 | 
			
		||||
    data =  self.request('post', f'my/ships/{ship}/refuel')
 | 
			
		||||
    ship.update(data)
 | 
			
		||||
    return data
 | 
			
		||||
 | 
			
		||||
@ -22,10 +22,23 @@ class Commander(CommandLine):
 | 
			
		||||
    self.api = Api(self.store, self.agent)
 | 
			
		||||
    self.atlas_builder = AtlasBuilder(self.store, self.api)
 | 
			
		||||
    self.analyzer = Analyzer(self.store)
 | 
			
		||||
    self.ship = None
 | 
			
		||||
    
 | 
			
		||||
    self.stop_auto= False
 | 
			
		||||
    super().__init__()
 | 
			
		||||
  
 | 
			
		||||
  def prompt(self):
 | 
			
		||||
    if self.ship:
 | 
			
		||||
      return f'{self.ship.symbol}> '
 | 
			
		||||
    else:
 | 
			
		||||
      return '> '
 | 
			
		||||
    
 | 
			
		||||
  def has_ship(self):
 | 
			
		||||
    if self.ship is not None:
 | 
			
		||||
      return True
 | 
			
		||||
    else:
 | 
			
		||||
      print('set a ship')
 | 
			
		||||
      
 | 
			
		||||
  def ask_obj(self, typ, prompt):
 | 
			
		||||
    obj = None
 | 
			
		||||
    while obj is None:
 | 
			
		||||
@ -59,10 +72,17 @@ class Commander(CommandLine):
 | 
			
		||||
    r = self.api.list_systems(int(page))
 | 
			
		||||
    pprint(self.api.last_meta)
 | 
			
		||||
  
 | 
			
		||||
  def do_waypoints(self, system_str):
 | 
			
		||||
    system = self.store.get(System, system_str.upper())
 | 
			
		||||
    r = self.api.list_waypoints(system)
 | 
			
		||||
    pprint(r)
 | 
			
		||||
  
 | 
			
		||||
  def do_waypoints(self, system_str=''):
 | 
			
		||||
    if system_str == '':
 | 
			
		||||
      if not self.has_ship(): return
 | 
			
		||||
      system = self.ship.location().system()
 | 
			
		||||
    else:
 | 
			
		||||
      system = self.store.get(System, system_str)
 | 
			
		||||
    r = self.store.all_members(system, 'Waypoint')
 | 
			
		||||
    for w in r:
 | 
			
		||||
      traits = ','.join(w.traits)
 | 
			
		||||
      print(w.symbol, traits)
 | 
			
		||||
 | 
			
		||||
  def do_marketplace(self, waypoint_str):
 | 
			
		||||
    waypoint = self.store.get(Waypoint, waypoint_str.upper())
 | 
			
		||||
@ -99,5 +119,35 @@ class Commander(CommandLine):
 | 
			
		||||
      r = list(self.store.all('Ship'))
 | 
			
		||||
    pprint(r)
 | 
			
		||||
  
 | 
			
		||||
  def do_ship(self, arg=''):
 | 
			
		||||
    if arg != '':
 | 
			
		||||
      symbol = f'{self.agent.symbol}-{arg}'
 | 
			
		||||
      ship = self.store.get('Ship', symbol)
 | 
			
		||||
      if ship is None:
 | 
			
		||||
        print('not found')
 | 
			
		||||
        return
 | 
			
		||||
      else:
 | 
			
		||||
        self.ship = ship
 | 
			
		||||
    pprint(ship)
 | 
			
		||||
  
 | 
			
		||||
  def do_pp(self):
 | 
			
		||||
    pprint(self.api.last_result)
 | 
			
		||||
  
 | 
			
		||||
  def do_go(self, arg):
 | 
			
		||||
    if not self.has_ship(): return
 | 
			
		||||
    system = self.ship.location().system()
 | 
			
		||||
    symbol = f'{system}-{arg}'
 | 
			
		||||
    dest = self.store.get('Waypoint', symbol)
 | 
			
		||||
    self.api.navigate(self.ship, dest)
 | 
			
		||||
    pprint(self.ship)
 | 
			
		||||
  
 | 
			
		||||
  def do_dock(self):
 | 
			
		||||
    if not self.has_ship(): return
 | 
			
		||||
    self.api.dock(self.ship)
 | 
			
		||||
    pprint(self.ship)
 | 
			
		||||
  
 | 
			
		||||
  def do_orbit(self):
 | 
			
		||||
    if not self.has_ship(): return
 | 
			
		||||
    self.api.orbit(self.ship)
 | 
			
		||||
    pprint(self.ship)
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
@ -82,7 +82,7 @@ class Store:
 | 
			
		||||
  def get(self, typ, symbol, create=False):
 | 
			
		||||
    if type(typ) == str and typ in self.model_names:
 | 
			
		||||
      typ = self.model_names[typ]
 | 
			
		||||
      
 | 
			
		||||
    symbol = symbol.upper()
 | 
			
		||||
    if typ not in self.data:
 | 
			
		||||
      return None
 | 
			
		||||
    if symbol not in self.data[typ]:
 | 
			
		||||
@ -108,8 +108,12 @@ class Store:
 | 
			
		||||
      yield m
 | 
			
		||||
  
 | 
			
		||||
  def all_members(self, system, typ=None):
 | 
			
		||||
    if type(typ) == str and typ in self.model_names:
 | 
			
		||||
      typ = self.model_names[typ]
 | 
			
		||||
    
 | 
			
		||||
    if type(system) == System:
 | 
			
		||||
      system = system.symbol
 | 
			
		||||
  
 | 
			
		||||
    if system not in self.system_members:
 | 
			
		||||
      return 
 | 
			
		||||
    for m in self.system_members[system]:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user