From 00db50687ace8e957d56098b846cc313051f1eaf Mon Sep 17 00:00:00 2001 From: Richard Bronkhorst Date: Tue, 11 Jul 2023 22:09:57 +0200 Subject: [PATCH] Update atlas_builder.py, commander.py and eleven other files --- nullptr/atlas_builder.py | 1 - nullptr/commander.py | 24 ++++++++++++++++++------ nullptr/models/agent.py | 3 --- nullptr/models/base.py | 2 +- nullptr/models/contract.py | 3 --- nullptr/models/jumpgate.py | 4 ---- nullptr/models/marketplace.py | 4 ---- nullptr/models/ship.py | 6 +----- nullptr/models/survey.py | 7 +------ nullptr/models/system.py | 4 ---- nullptr/models/waypoint.py | 3 --- nullptr/store.py | 13 +++++++------ nullptr/util.py | 2 +- 13 files changed, 29 insertions(+), 47 deletions(-) diff --git a/nullptr/atlas_builder.py b/nullptr/atlas_builder.py index fbddfd8..3c15eaf 100644 --- a/nullptr/atlas_builder.py +++ b/nullptr/atlas_builder.py @@ -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: diff --git a/nullptr/commander.py b/nullptr/commander.py index d4c509c..2f337e7 100644 --- a/nullptr/commander.py +++ b/nullptr/commander.py @@ -50,12 +50,23 @@ class Commander(CommandLine): agents = self.store.all(Agent) agent = next(agents, None) if agent is None: - symbol = input('agent name: ') - agent = self.store.get(Agent, symbol, create=True) - api = Api(self.store, agent) - faction = input('faction: ') - api.register(faction.upper().strip()) - self.store.flush() + 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 def resolve(self, typ, arg): @@ -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 = [] diff --git a/nullptr/models/agent.py b/nullptr/models/agent.py index 5ebb0b4..63dec10 100644 --- a/nullptr/models/agent.py +++ b/nullptr/models/agent.py @@ -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' diff --git a/nullptr/models/base.py b/nullptr/models/base.py index 883f690..ead312c 100644 --- a/nullptr/models/base.py +++ b/nullptr/models/base.py @@ -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: diff --git a/nullptr/models/contract.py b/nullptr/models/contract.py index 0f5356d..9ea15c1 100644 --- a/nullptr/models/contract.py +++ b/nullptr/models/contract.py @@ -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 diff --git a/nullptr/models/jumpgate.py b/nullptr/models/jumpgate.py index 72ae7d0..8d2979a 100644 --- a/nullptr/models/jumpgate.py +++ b/nullptr/models/jumpgate.py @@ -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: diff --git a/nullptr/models/marketplace.py b/nullptr/models/marketplace.py index b71c9c9..65bf4eb 100644 --- a/nullptr/models/marketplace.py +++ b/nullptr/models/marketplace.py @@ -50,10 +50,6 @@ class Marketplace(Base): if r in self.exchange: 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 diff --git a/nullptr/models/ship.py b/nullptr/models/ship.py index 2350d1b..42fac30 100644 --- a/nullptr/models/ship.py +++ b/nullptr/models/ship.py @@ -21,11 +21,7 @@ class Ship(Base): @classmethod 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) diff --git a/nullptr/models/survey.py b/nullptr/models/survey.py index 7ea3dd8..4b248a5 100644 --- a/nullptr/models/survey.py +++ b/nullptr/models/survey.py @@ -17,12 +17,7 @@ class Survey(Base): @classmethod 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 diff --git a/nullptr/models/system.py b/nullptr/models/system.py index fb3370a..9ee91ba 100644 --- a/nullptr/models/system.py +++ b/nullptr/models/system.py @@ -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)) diff --git a/nullptr/models/waypoint.py b/nullptr/models/waypoint.py index 152c187..b1c9663 100644 --- a/nullptr/models/waypoint.py +++ b/nullptr/models/waypoint.py @@ -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()}' diff --git a/nullptr/store.py b/nullptr/store.py index 2328fb9..8910a04 100644 --- a/nullptr/store.py +++ b/nullptr/store.py @@ -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() @@ -215,10 +216,10 @@ 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 diff --git a/nullptr/util.py b/nullptr/util.py index c2d9157..c63fbca 100644 --- a/nullptr/util.py +++ b/nullptr/util.py @@ -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)