Compare commits

...

2 Commits

Author SHA1 Message Date
Richard Bronkhorst
3010a8186d Update central_command.py, commander.py and one other file 2023-07-03 19:13:24 +02:00
Richard Bronkhorst
d6fe1cf183 Add store.md 2023-07-02 15:17:53 +02:00
4 changed files with 55 additions and 9 deletions

View File

@ -30,14 +30,6 @@ class CentralCommand:
mission = self.missions[ship]
mission.step()
return True
def wait_for_stop(self):
try:
input()
except EOFError:
pass
self.stopping = True
print('stopping...')
def run_interactive(self):
print('auto mode. hit enter to stop')
@ -46,7 +38,17 @@ class CentralCommand:
t.start()
self.run()
print('manual mode')
def wait_for_stop(self):
try:
input()
except EOFError:
pass
self.stopping = True
print('stopping...')
def run(self):
self.update_missions()
while not self.stopping:

View File

@ -123,6 +123,8 @@ class Commander(CommandLine):
def do_chaul(self):
if not self.has_ship(): return
if len(ship.cargo) > 0:
raise CommandError('please dump cargo first')
contract = self.active_contract()
delivery = contract.unfinished_delivery()
if delivery is None:

View File

@ -25,6 +25,7 @@ class Marketplace(SystemMember):
price['symbol'] = symbol
price['buy'] = mg(g, 'purchasePrice')
price['sell'] = mg(g, 'sellPrice')
price['volume'] = mg(g, 'tradeVolume')
prices[symbol] = price
self.prices = prices

41
store.md Normal file
View File

@ -0,0 +1,41 @@
# The store format
This project uses a custom database format just because we can.
The script reads the entire store on startup. Each object can br altered in memory. A 'dirty' status is set when an object is changed. periodically the script will flush the store, writing all changes back to disk.
## Objects
First lets discuss what we are storing.
Objects are identified by type and symbol. A symbol is an uppercase alphanumeric string that optionally contains '-' chars. the type is a lowecase alphanumeric string of length 3.
For each type, the store has a class defined that is used to load objects of that type.
An object identifier is its symbol and type joined with a '.' character.
Some examples of object identifiers:
* X1-J84.sys
* X1-J84-0828772.way
* CAPT-J-1.shp
A waypoint is always part of a system. This is also visible because the waypoint symbol is prefixed by the system symbol. However, this relation is not enforced or used by the store. The symbol is an opaque string.
An object has attributes. Values of attributes can be strings, ints, floats, bools, lists, dicts and references. lists and dicts can also only contain the values listed. References are pointers to other objects in the store.
## Indices
An index is a dict with a string as key and a list of objects as value. The dict is built when loading the store. when the index is iterated, each object is re-checked and removed if necessary.
## API
* store.load(fil) loads all objects
* store.get(type, symbol, create=False) fetches the object. If create==False: None if it wasnt present
* store.all(type) generator for all objects of a goven type
* store.cleanup() removes all expired objects
* store.flush() writes all dirty objects to disk
*
type may be a class or a string containing the name of a class. The type should be a subclass of models.base.Base
# file format
the file format is a header followed by a number of blocks. the size and number of blocks are dictated by the header.