diff --git a/.gitignore b/.gitignore index 73a7fd0..2432694 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,5 @@ ENV/ .idea install.txt +Screenshots/ +.vscode \ No newline at end of file diff --git a/dsst/dsst_gtk3/dialogs.py b/dsst/dsst_gtk3/dialogs.py index 3986e1c..a51aa43 100644 --- a/dsst/dsst_gtk3/dialogs.py +++ b/dsst/dsst_gtk3/dialogs.py @@ -102,6 +102,13 @@ def create_death(app: 'gtk_ui.GtkUi'): :param app: Main Gtk application :return: Death object or None if dialog was canceled """ + # Set penalties + default_drink = app.drinks.data[0].name + store = app.ui.get_object('player_penalties_store') + store.clear() + for player in app.ui.get_object('episode_players_store'): + store.append([None, player[1], default_drink, player[0]]) + # Run the dialog dialog = app.ui.get_object("edit_death_dialog") # type: Gtk.Dialog result = dialog.run() diff --git a/dsst/dsst_gtk3/handlers/dialog_handlers.py b/dsst/dsst_gtk3/handlers/dialog_handlers.py index 14ca4ae..55cb8c0 100644 --- a/dsst/dsst_gtk3/handlers/dialog_handlers.py +++ b/dsst/dsst_gtk3/handlers/dialog_handlers.py @@ -29,7 +29,6 @@ class DialogHandlers: def do_add_enemy(self, entry): if entry.get_text(): - store = self.app.ui.get_object('enemy_season_store') enemy = models.Enemy() enemy.name = entry.get_text() enemy.season = self.app.get_selected_season_id() diff --git a/dsst/dsst_gtk3/reload.py b/dsst/dsst_gtk3/reload.py index bc1d386..0f232ff 100644 --- a/dsst/dsst_gtk3/reload.py +++ b/dsst/dsst_gtk3/reload.py @@ -96,12 +96,22 @@ def reload_episode_stats(app: 'gtk_ui.GtkUi'): drink_count = sum(len(death.penalties) for death in episode.deaths) app.ui.get_object('ep_drinks_label').set_text(str(drink_count)) app.ui.get_object('ep_player_drinks_label').set_text(str(len(episode.deaths))) + + # Compute booze stats dl_booze = sum(len(death.penalties) * death.penalties[0].size for death in episode.deaths) l_booze = round(dl_booze / 10, 2) + player_ml_booze = round((dl_booze * 100) / len(episode.players), 2) app.ui.get_object('ep_booze_label').set_text('{}l'.format(l_booze)) - dl_booze = sum(len(death.penalties) * death.penalties[0].size for death in episode.deaths) - ml_booze = round(dl_booze * 10, 0) - app.ui.get_object('ep_player_booze_label').set_text('{}ml'.format(ml_booze)) + app.ui.get_object('ep_player_booze_label').set_text('{}ml'.format(player_ml_booze)) + + # Compute pure alc stats + deaths = episode.deaths + dl_alc = 0 + for death in deaths: + dl_alc += sum((penalty.size / 100) * penalty.drink.vol for penalty in death.penalties) + ml_alc = round(dl_alc * 100, 2) + app.ui.get_object('ep_alc_label').set_text('{}ml'.format(ml_alc)) + # Compute hardest enemy stats enemy_list = [death.enemy.name for death in episode.deaths] sorted_list = Counter(enemy_list).most_common(1) if sorted_list: diff --git a/dsst/dsst_gtk3/resources/glade/window.glade b/dsst/dsst_gtk3/resources/glade/window.glade index c058222..70535b4 100644 --- a/dsst/dsst_gtk3/resources/glade/window.glade +++ b/dsst/dsst_gtk3/resources/glade/window.glade @@ -167,7 +167,7 @@ - + True False Add Episode @@ -220,7 +220,7 @@ True False - + True False Add Death @@ -230,7 +230,7 @@ - + True False Add Victory @@ -263,7 +263,7 @@ - + True False Manage Drinks @@ -549,50 +549,6 @@ 0 - - - True - False - Most Deaths: - 1 - - - 0 - 7 - - - - - True - False - Hardest Enemy: - 1 - - - 0 - 8 - - - - - True - False - - - 1 - 7 - - - - - True - False - - - 1 - 8 - - True @@ -731,6 +687,34 @@ 6 + + + True + False + Hardest Enemy: + 1 + + + 0 + 7 + + + + + True + False + + + 1 + 7 + + + + + + + + False diff --git a/dsst/dsst_gtk3/util.py b/dsst/dsst_gtk3/util.py index a535d99..2a71c0c 100644 --- a/dsst/dsst_gtk3/util.py +++ b/dsst/dsst_gtk3/util.py @@ -14,7 +14,7 @@ DEFAULT_CONFIG = { 'auto_connect': False, 'servers': [{ 'host': 'localhost', - 'port': 12345, + 'port': 55225, 'buffer_size': 1024, 'auth_token': ''} ] diff --git a/dsst/dsst_server/config.py b/dsst/dsst_server/config.py new file mode 100644 index 0000000..b80336e --- /dev/null +++ b/dsst/dsst_server/config.py @@ -0,0 +1,18 @@ +# This config will be copied on first launch. +# Edit the the copied file at '~/.config/dsst/server.json' before launching the server +DEFAULT_CONFIG = { + 'database': { + 'db_name': 'dsst', + 'user': 'dsst', + 'password': 'dsst' + }, + 'server': { + 'host': 'localhost', + 'port': 55225, + 'buffer_size': 1024 + }, + 'tokens': { + '': 'rw', + '': 'r' + } +} diff --git a/dsst/dsst_server/server.py b/dsst/dsst_server/server.py index a074838..d13812d 100644 --- a/dsst/dsst_server/server.py +++ b/dsst/dsst_server/server.py @@ -1,28 +1,23 @@ import json import pickle import socket - import sys - import os from common import util, models -from dsst_server import func_read, func_write, tokens +from dsst_server import func_read, func_write from dsst_server.func_proxy import FunctionProxy from dsst_server.data_access import sql, sql_func - -PORT = 12345 -HOST = socket.gethostname() -BUFFER_SIZE = 1024 +from dsst_server.config import DEFAULT_CONFIG class DsstServer: - def __init__(self, config={}): + def __init__(self, config): self.socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print('Created socket') - - self.socket_server.bind((HOST, PORT)) - print('Bound socket to {} on host {}'.format(PORT, HOST)) + server_conf = config.get('server') + self.socket_server.bind((server_conf.get('host'), server_conf.get('port'))) + print('Bound socket to {} on host {}'.format(server_conf.get('port'), server_conf.get('host'))) # Initialize database db_config = config.get('database') @@ -37,7 +32,7 @@ class DsstServer: 'r': read_actions, 'rw': read_actions + write_actions } - self.tokens = {token: parm_access[perms] for token, perms in tokens.TOKENS} + self.tokens = {token: parm_access[perms] for token, perms in config.get('tokens').items()} print('Loaded auth tokens: {}'.format(self.tokens.keys())) def run(self): @@ -85,8 +80,21 @@ def load_config(config_path: str) -> dict: return json.load(config_file) +def save_config(config: dict, config_path: str): + path = os.path.dirname(config_path) + if not os.path.isdir(path): + os.mkdir(path) + with open(config_path, 'wb') as file: + file.write(json.dumps(config, sort_keys=True, indent=4, separators=(',', ': ')).encode('utf-8')) + + def main(): config = os.path.join(os.path.expanduser('~'), '.config', 'dsst', 'server.json') + if not os.path.isfile(config): + save_config(DEFAULT_CONFIG, config) + print('No server config file found.\nCopied default config to "{}"\nPlease edit file before starting server.' + .format(config)) + sys.exit(0) server = DsstServer(load_config(config)) try: server.run() diff --git a/dsst/dsst_server/tokens.py b/dsst/dsst_server/tokens.py deleted file mode 100644 index 57c1d90..0000000 --- a/dsst/dsst_server/tokens.py +++ /dev/null @@ -1,5 +0,0 @@ -# Define access tokens here -# i.E: { 'read': ['a', 'b''], -# 'write': ['a'] -# } -TOKENS = [('a', 'rw'), ('b', 'r')] \ No newline at end of file