implementing api changes since 5 months ago

This commit is contained in:
Richard
2023-12-28 19:49:00 +01:00
parent 1ba10260c0
commit a287897da9
9 changed files with 174 additions and 87 deletions

View File

@@ -9,3 +9,8 @@ class Atlas(Base):
self.total_pages = 0
self.seen_pages = 0
def f(self, detail=1):
r = super().f(detail)
if detail >2:
r += f' {self.seen_pages}/{self.total_pages}'
return r

View File

@@ -57,15 +57,16 @@ class Base:
val = interp(val)
setattr(self, attr, val)
def setlst(self, attr, d, name, member, interp=None):
def setlst(self, attr, d, name, member=None, interp=None):
val = sg(d, name)
if val is not None:
lst = []
for x in val:
val = sg(x, member)
if member is not None:
x = sg(x, member)
if interp is not None:
val = interp(val)
lst.append(val)
x = interp(x)
lst.append(x)
setattr(self, attr, lst)
def __setattr__(self, name, value):

View File

@@ -1,19 +1,15 @@
from .base import Base
from .system import System
from .waypoint import Waypoint
from dataclasses import field
class Jumpgate(Base):
def define(self):
self.range: int = 0
self.faction: str = ''
self.systems: list = []
self.connections: list = []
self.system = self.get_system()
def update(self, d):
getter = self.store.getter(System, create=True)
self.setlst('systems', d, 'connectedSystems', 'symbol', interp=getter)
self.seta('faction', d, 'factionSymbol')
self.seta('range', d, 'jumpRange')
getter = self.store.getter(Waypoint, create=True)
self.setlst('connections', d, 'connections', interp=getter)
@classmethod
def ext(self):
@@ -23,5 +19,5 @@ class Jumpgate(Base):
r = self.symbol
if detail > 1:
r += '\n'
r += '\n'.join([s.symbol for s in self.systems])
r += '\n'.join([s.symbol for s in self.connections])
return r

View File

@@ -54,13 +54,26 @@ class Ship(Base):
if typ not in self.cargo:
return 0
return self.cargo[typ]
def take_cargo(self, typ, amt):
if typ not in self.cargo:
return
if self.cargo[typ] <= amt:
del self.cargo[typ]
else:
self.cargo[typ] -= amt
self.cargo_units = sum(self.cargo.values())
def load_cargo(self, cargo):
result = {}
total = 0
for i in cargo:
symbol = must_get(i, 'symbol')
units = must_get(i, 'units')
result[symbol] = units
total += units
self.cargo_units = total
self.cargo = result
def deliverable_cargo(self, contract):

View File

@@ -10,14 +10,17 @@ class Waypoint(Base):
self.type:str = 'unknown'
self.traits:list = []
self.faction:str = ''
self.is_under_construction:bool = False
self.system = self.get_system()
self.uncharted = True
def update(self, d):
self.seta('x', d)
self.seta('y', d)
self.seta('type', d)
self.seta('faction', d, 'faction.symbol')
self.seta('is_under_construction', d, 'isUnderConstruction')
self.setlst('traits', d, 'traits', 'symbol')
self.uncharted = 'UNCHARTED' in self.traits