from flask import request from flask_restx import Resource, Namespace, reqparse from app.functions.roll_encounter import roll_encounter namespace = Namespace('gameplay', description='Gamma World Game Play') parser = reqparse.RequestParser() parser.add_argument('terrain', type=str, default='clear', help='The terrain being traversed. ("clear", "mountains", "forest", "desert",' '"watery", "ruins", "deathlands")') @namespace.route('/encounter') # resolves to: /gameplay/encounter class RollEncounter(Resource): @namespace.expect(parser) def get(self): terrain = request.args.get('terrain', default="clear", type=str) valid_terrains = ["clear", "mountains", "forest", "desert", "watery", "ruins", "deathlands"] if terrain: if terrain.lower() in valid_terrains: return roll_encounter(terrain.lower()), 200 else: return { 'error': 'Invalid terrain type provided.', 'valid_terrains': valid_terrains }, 400 else: return {'error': 'No terrain type provided', 'valid_terrains': valid_terrains}, 400