summaryrefslogtreecommitdiff
path: root/modules/ships.py
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-08-31 01:06:58 +0200
committerBotond Hende <nettingman@gmail.com>2024-08-31 01:06:58 +0200
commit254a5eda7d17ff28d4604d95dba6f102120189b8 (patch)
treeeb9990386d9d32b903a0912010229ee1cdc114f1 /modules/ships.py
parent9b686d79871c6f76b8ea36d8a8a43d3edb32def7 (diff)
ship data initialization on startup
Diffstat (limited to 'modules/ships.py')
-rw-r--r--modules/ships.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/ships.py b/modules/ships.py
new file mode 100644
index 0000000..0a296ca
--- /dev/null
+++ b/modules/ships.py
@@ -0,0 +1,27 @@
+from . import tasks
+from .database import cursor, conn
+
+
+class Ship:
+ def __init__(self, symbol: str):
+ self.symbol = symbol
+ self.callsign = "-".split(symbol)[0]
+
+ self.task = None
+
+ def load_task(self):
+ cursor.execute("SELECT task, params FROM ships WHERE symbol = ?", (self.symbol,))
+ row = cursor.fetchone()
+ if row is None:
+ cursor.execute("INSERT INTO ships (symbol, task, params) VALUES (?, ?, ?)", (self.symbol, tasks.IDLE, None))
+ conn.commit()
+
+ self.task = tasks.IDLE
+ else:
+ self.task = row[0]
+
+ def set_task(self, task):
+ self.task = task
+ if task != tasks.ERROR:
+ cursor.execute("UPDATE ships SET task = ? WHERE symbol = ?", (task, self.symbol))
+ conn.commit()