diff --git a/app.py b/app.py index 682d76f..b141228 100644 --- a/app.py +++ b/app.py @@ -1,13 +1,14 @@ from flask import Flask from flask_cors import CORS from flask_restx import Api, Resource -from marshmallow import Schema, fields, validate from models import dice_model, ability_model, hp_model, character_model, encounter_model, ma_model +from schemas import DiceSchema, CharacterSchema, EncounterSchema, MentalAttackSchema from encounters import EncounterTable from mentattack import MentalAttackMatrix from mutations import Mutations + import random app = Flask(__name__) @@ -24,72 +25,25 @@ ma = api.namespace('ma', description='Mental Attack operations') character = api.namespace('character', description='Character operations') encounter = api.namespace('encounter', description='Encounter operations') -dice_model = dice.model('Dice', dice_model) ability_model = ability.model('Ability', ability_model) +# TODO: Add ability schema + hp_model = hp.model('HP', hp_model) -ma_model = ma.model('MA', ma_model) -character_model = character.model('Character', character_model) -encounter_model = encounter.model('Encounter', encounter_model) - - -class DiceSchema(Schema): - quantity = fields.Int(required=True, validate=validate.Range(min=1), description='The number of dice to roll') - geometry = fields.Int(required=True, validate=validate.Range(min=2), description='The number of sides on each die') - discard_lowest = fields.Bool(default=False, description='Drop the lowest score') - +# TODO: Add hitpoint schema +dice_model = dice.model('Dice', dice_model) dice_schema = DiceSchema() +ma_model = ma.model('MA', ma_model) +ma_schema = MentalAttackSchema() -class CharacterSchema(Schema): - chartype = fields.String( - required=True, - validate=validate.OneOf(["human", "mutant", "android", "robot"]), - description='The characters type of being' - ) - emphasis = fields.String( - required=True, - validate=validate.OneOf(["physical", "mental", "random"]), - description='Valid inputs: physical, mental, random' - ) - - +character_model = character.model('Character', character_model) character_schema = CharacterSchema() - -class EncounterSchema(Schema): - terrain = fields.String( - required=True, - validate=validate.OneOf(["clear", "mountains", "forest", "desert", "watery", "ruins", "deathlands"]), - description='The terrain traversed at the time of the encounter roll' - ) - - +encounter_model = encounter.model('Encounter', encounter_model) encounter_schema = EncounterSchema() -class MentalAttackSchema(Schema): - ams = fields.Integer( - required=True, - validate=validate.Range(min=3, max=18), - description='The Attackers Mental Strength' - ) - dms = fields.Integer( - required=True, - validate=validate.Range(min=3, max=18), - description='The Defenders Mental Strength' - ) - modifier = fields.Integer( - required=False, - default=0, - validate=validate.Range(min=-100, max=100), - description='Roll modifier for mental attack' - ) - - -ma_schema = MentalAttackSchema() - - @api.route('/roll/dice', methods=['POST']) class RollDice(Resource): @dice.expect(dice_model) diff --git a/schemas.py b/schemas.py new file mode 100644 index 0000000..8e4886a --- /dev/null +++ b/schemas.py @@ -0,0 +1,48 @@ +from marshmallow import Schema, fields, validate + + +class DiceSchema(Schema): + quantity = fields.Int(required=True, validate=validate.Range(min=1), description='The number of dice to roll') + geometry = fields.Int(required=True, validate=validate.Range(min=2), description='The number of sides on each die') + discard_lowest = fields.Bool(default=False, description='Drop the lowest score') + + +class CharacterSchema(Schema): + chartype = fields.String( + required=True, + validate=validate.OneOf(["human", "mutant", "android", "robot"]), + description='The characters type of being' + ) + emphasis = fields.String( + required=True, + validate=validate.OneOf(["physical", "mental", "random"]), + description='Valid inputs: physical, mental, random' + ) + + +class EncounterSchema(Schema): + terrain = fields.String( + required=True, + validate=validate.OneOf(["clear", "mountains", "forest", "desert", "watery", "ruins", "deathlands"]), + description='The terrain traversed at the time of the encounter roll' + ) + + +class MentalAttackSchema(Schema): + ams = fields.Integer( + required=True, + validate=validate.Range(min=3, max=18), + description='The Attackers Mental Strength' + ) + dms = fields.Integer( + required=True, + validate=validate.Range(min=3, max=18), + description='The Defenders Mental Strength' + ) + modifier = fields.Integer( + required=False, + default=0, + validate=validate.Range(min=-100, max=100), + description='Roll modifier for mental attack' + ) +