diff --git a/app/functions/roll_dices.py b/app/functions/roll_dices.py index e769dcf..a52d6ea 100644 --- a/app/functions/roll_dices.py +++ b/app/functions/roll_dices.py @@ -6,7 +6,8 @@ def roll_dices(dice_count, dice_sides, discard_lowest): discarded = [] for _ in range(dice_count): roll_results.append(random.randint(1, dice_sides)) - if discard_lowest and len(roll_results) > 0: + + if discard_lowest and len(roll_results) > 1: discarded.append(min(roll_results)) roll_results.remove(min(roll_results)) diff --git a/app/routes/roll_dice.py b/app/routes/roll_dice.py index 7cfb653..89faced 100644 --- a/app/routes/roll_dice.py +++ b/app/routes/roll_dice.py @@ -1,13 +1,18 @@ from flask_restx import Resource, Namespace, reqparse from app.functions.roll_dices import roll_dices + +def str_to_bool(val): + return str(val).lower() == 'true' + + namespace = Namespace('dice', description='Dice Operations') # Define the parser and request args: parser = reqparse.RequestParser() parser.add_argument('quantity', type=int, required=True, help='Quantity of dice to roll') parser.add_argument('geometry', type=int, required=True, help='Number of faces on the dice') -parser.add_argument('discard_lowest', type=bool, required=True, help='Whether to discard lowest roll') +parser.add_argument('discard_lowest', type=str_to_bool, required=True, help='Whether to discard lowest roll') @namespace.route('/') # resolves to: /dice diff --git a/web/config.js b/web/config.js new file mode 100644 index 0000000..41413b5 --- /dev/null +++ b/web/config.js @@ -0,0 +1,10 @@ +// config.js +let environment = window.location.hostname === 'parmenides' ? 'dev' : 'prod'; + +fetch('./config.json') + .then(response => response.json()) + .then(config => { + window.BASE_URL = config[environment].BASE_URL; + console.log("BASE URL:", window.BASE_URL); + }) + .catch(error => console.error('Error:', error)); diff --git a/web/config.json b/web/config.json new file mode 100644 index 0000000..e046d4d --- /dev/null +++ b/web/config.json @@ -0,0 +1,8 @@ +{ + "dev": { + "BASE_URL": "http://127.0.0.1:5000" + }, + "prod": { + "BASE_URL": "https://gammaworld.gmgauthier.com" + } +} \ No newline at end of file diff --git a/web/rolldice.html b/web/rolldice.html index d5e8c41..47b60dd 100644 --- a/web/rolldice.html +++ b/web/rolldice.html @@ -4,7 +4,7 @@