diff options
author | Botond Hende <nettingman@gmail.com> | 2024-09-01 00:58:59 +0200 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-09-01 00:58:59 +0200 |
commit | f55028d8d7d703f348190598d2fce93103070d17 (patch) | |
tree | 68fd302176de71220b63e38462871d99668a20a5 /modules/ships.py | |
parent | e66fb136c8fd10fe8bafb273c938a3d332d997ba (diff) |
ship customization: renaming
Diffstat (limited to 'modules/ships.py')
-rw-r--r-- | modules/ships.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/modules/ships.py b/modules/ships.py index 8dfe41a..e35cdd2 100644 --- a/modules/ships.py +++ b/modules/ships.py @@ -1,3 +1,5 @@ +from typing import Dict + from . import task_type from .database import cursor, conn @@ -8,20 +10,32 @@ class Ship: self.callsign = "-".split(symbol)[0] self.task = None + self.name = None + + def get_data(self) -> Dict: + return {"name": self.name, "symbol": self.symbol, "task": self.task} def load_task(self): - cursor.execute("SELECT task, params FROM ships WHERE symbol = ?", (self.symbol,)) + cursor.execute("SELECT name, 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, task_type.IDLE, None)) + cursor.execute("INSERT INTO ships (symbol, task, params, name) VALUES (?, ?, ?, ?)", + (self.symbol, task_type.IDLE, None, self.symbol)) conn.commit() self.task = task_type.IDLE + self.task = self.symbol else: - self.task = row[0] + self.name = row[0] + self.task = row[1] def set_task(self, task): self.task = task if task != task_type.ERROR: cursor.execute("UPDATE ships SET task = ? WHERE symbol = ?", (task, self.symbol)) conn.commit() + + def rename(self, name): + self.name = name + cursor.execute("UPDATE ships SET name = ? WHERE symbol = ?", (name, self.symbol)) + conn.commit() |