Update atlas_builder.py, commander.py and eleven other files

This commit is contained in:
Richard Bronkhorst 2023-07-11 22:09:57 +02:00
parent 97296e1859
commit 00db50687a
13 changed files with 29 additions and 47 deletions

View File

@ -26,7 +26,6 @@ class AtlasBuilder:
def all_specials(self, waypoints):
for w in waypoints:
print(w)
if self.stop_auto:
break
if 'UNCHARTED' in w.traits:

View File

@ -50,11 +50,22 @@ class Commander(CommandLine):
agents = self.store.all(Agent)
agent = next(agents, None)
if agent is None:
agent = self.agent_setup()
return agent
def agent_setup(self):
symbol = input('agent name: ')
agent = self.store.get(Agent, symbol, create=True)
api = Api(self.store, agent)
self.api = api
faction = input('faction: ')
api.register(faction.upper().strip())
print('=== agent:')
print(agent)
print('=== ships')
self.do_ships('r')
print('=== contracts')
self.do_contracts('r')
self.store.flush()
return agent
@ -194,6 +205,7 @@ class Commander(CommandLine):
system = self.ship.location.system
else:
system = self.store.get(System, system_str)
print(f'=== waypoints in {system}')
r = self.store.all_members(system, 'Waypoint')
for w in r:
traits = []

View File

@ -8,9 +8,6 @@ class Agent(Base):
def update(self, d):
self.seta('credits', d)
def path(self):
return f'{self.symbol}.{self.ext()}'
@classmethod
def ext(self):
return 'agt'

View File

@ -40,7 +40,7 @@ class Base:
return hash((str(type(self)), self.symbol))
def __eq__(self, other):
return self.symbol == other.symbol and type(self) == type(other)
return type(self) == type(other) and self.symbol == other.symbol
def seta(self, attr, d, name=None, interp=None):
if name is None:

View File

@ -18,9 +18,6 @@ class Contract(Base):
def ext(cls):
return 'cnt'
def path(self):
return f'contracts/{self.symbol}.{self.ext()}'
def is_expired(self):
return time() > self.expires

View File

@ -16,10 +16,6 @@ class Jumpgate(Base):
def ext(self):
return 'jmp'
def path(self):
sector, system, _ = self.symbol.split('-')
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
def f(self, detail=1):
r = self.symbol
if detail > 1:

View File

@ -51,10 +51,6 @@ class Marketplace(Base):
return 'X'
return '?'
def path(self):
sector, system, _ = self.symbol.split('-')
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
def f(self, detail=1):
r = self.symbol
if detail > 1:

View File

@ -22,10 +22,6 @@ class Ship(Base):
def ext(self):
return 'shp'
def path(self):
agent = self.symbol.split('-')[0]
return f'{agent}/{self.symbol}.{self.ext()}'
def update(self, d):
self.seta('status', d, 'nav.status')
getter = self.store.getter(Waypoint, create=True)

View File

@ -18,11 +18,6 @@ class Survey(Base):
def ext(cls):
return 'svy'
def path(self):
sector, system, waypoint, signature = self.symbol.split('-')
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
def is_expired(self):
return time() > self.expires or self.exhausted

View File

@ -17,10 +17,6 @@ class System(Base):
def ext(self):
return 'stm'
def path(self):
sector, symbol = self.symbol.split('-')
return f'atlas/{sector}/{symbol[0:1]}/{self.symbol}.{self.ext()}'
def distance(self, other):
return int(sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2))

View File

@ -28,6 +28,3 @@ class Waypoint(Base):
def ext(self):
return 'way'
def path(self):
sector, system, _ = self.symbol.split('-')
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'

View File

@ -99,7 +99,7 @@ class Store:
self.fil.seek(0)
offset = 0
while (hdr := ChunkHeader.parse(self.fil)):
print(hdr)
# print(hdr)
if not hdr.in_use:
self.fil.seek(hdr.size, 1)
continue
@ -150,7 +150,7 @@ class Store:
if obj.file_offset is None:
obj.file_offset, hdr = self.allocate_chunk(osize)
print(type(obj).__name__, hdr)
# print(type(obj).__name__, hdr)
self.fil.write(data)
slack = b'\x00' * (hdr.size - hdr.used)
self.fil.write(slack)
@ -160,7 +160,8 @@ class Store:
symbol = obj.symbol
obj.store = self
self.data[typ][symbol] = obj
if hasattr(typ, 'system'):
print(type(obj).__name__, 'has?')
if hasattr(obj, 'system') and obj.system != None:
system_str = obj.system.symbol
if system_str not in self.system_members:
self.system_members[system_str] = set()
@ -216,9 +217,9 @@ class Store:
if type(system) == System:
system = system.symbol
if 'system' not in self.system_members:
if system not in self.system_members:
return
print('typ', typ)
for m in self.system_members[system]:
if typ is None or type(m) == typ:
yield m

View File

@ -53,7 +53,7 @@ def pretty(d, ident=0, detail=2):
return d.f(detail)
r = ''
idt = ' ' * ident
if type(d) == list:
if type(d) in [list, set]:
r += 'lst'
for i in d:
r += '\n' + idt + pretty(i, ident + 1, detail)