예제 #1
0
class ConnectionSchema(v.Schema):
    a = v.SchemaNode(v.Instance(Region))
    b = v.SchemaNode(v.Instance(Region))
    is_sea = v.SchemaNode(v.Bool(), missing=False)

    @staticmethod
    def validator(form, value):
        if value['a'] == value['b']:
            raise v.Invalid(
                form,
                f"Source and destination should be different: {value['a']}")
예제 #2
0
class FigureTypeSchema(v.Schema):
    name = v.SchemaNode(v.String(), validator=v.Length(1, 20))
    # image
    # ruleset

    @v.instantiate(missing=())
    class categories(v.SequenceSchema):
        category = v.SchemaNode(v.String(),
                                validator=v.OneOf(c.value
                                                  for c in FigureCategory))
예제 #3
0
 class categories(v.SequenceSchema):
     category = v.SchemaNode(v.String(),
                             validator=v.OneOf(c.value
                                               for c in FigureCategory))
예제 #4
0
 class SerializingSchema(v.Schema):
     attr_int = v.SchemaNode(v.Integer(), validator=v.Range(1, 10))
     attr_str = v.SchemaNode(v.String(), validator=v.Length(1, 10))
예제 #5
0
class ClanTypeSchema(v.Schema):
    name = v.SchemaNode(v.String(), validator=v.Length(max=20))
    color = v.SchemaNode(v.String(), validator=v.OneOf(c.value for c in ClanColors))
    starting_honor = v.SchemaNode(v.Integer(), validator=v.Range(1, 10))
    starting_coins = v.SchemaNode(v.Integer(), validator=v.Range(1, 10))
    region = v.SchemaNode(v.Instance('rising_sun.models.board:Region'))
예제 #6
0
class AdvantageSchema(v.Schema):
    name = v.SchemaNode(v.String(), validator=v.Length(max=20))
    procedure = v.SchemaNode(v.String(), validator=v.Length(max=20))
예제 #7
0
class ShrineSchema(v.Schema):
    name = v.SchemaNode(v.String(), validator=v.Length(1, 20))
    # kami = v.SchemaNode(v.Instance('rising_sun.models.kami:Kami'), default=None)
    pass
예제 #8
0
class RegionSchema(v.Schema):
    name = v.SchemaNode(v.String(), validator=v.Length(1, 20))
    reward = v.SchemaNode(v.Instance('rising_sun.models.gains:Gain'))
예제 #9
0
class ClanReserveSchema(v.Schema):
    clan = v.SchemaNode(v.Instance('rising_sun.models.clan:Clan'))
예제 #10
0
 class shrines(v.SequenceSchema):
     shrine = v.SchemaNode(v.Instance(Shrine))
예제 #11
0
class BoardSchema(v.Schema):
    map = v.SchemaNode(v.Instance(Map))

    @v.instantiate(missing=())
    class shrines(v.SequenceSchema):
        shrine = v.SchemaNode(v.Instance(Shrine))
예제 #12
0
 class connections(v.SequenceSchema):
     connection = v.SchemaNode(v.Instance(Connection))
예제 #13
0
 class regions(v.SequenceSchema):
     region = v.SchemaNode(v.Instance(Region))
예제 #14
0
# -*- coding: utf-8 -*-
from enum import Enum

from rising_sun.base_model import BaseModel
from utils import validation as v


class GainType(Enum):
    VICTORY_POINTS = 'vps'
    COINS = 'coins'
    RONINS = 'ronins'
    HONOR = 'honor'


GainSchema = type(
    'Reward', (v.Schema, ), {
        gain_type.value: v.SchemaNode(
            v.Int(), validator=v.Range(-10, 10), missing=v.drop, default=0)
        for gain_type in GainType
    })


class Gain(BaseModel):
    __pks__ = tuple(gain_type.value for gain_type in GainType)
    __schema__ = GainSchema(v.Mapping(unknown='raise'))