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']}")
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))
class categories(v.SequenceSchema): category = v.SchemaNode(v.String(), validator=v.OneOf(c.value for c in FigureCategory))
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))
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'))
class AdvantageSchema(v.Schema): name = v.SchemaNode(v.String(), validator=v.Length(max=20)) procedure = v.SchemaNode(v.String(), validator=v.Length(max=20))
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
class RegionSchema(v.Schema): name = v.SchemaNode(v.String(), validator=v.Length(1, 20)) reward = v.SchemaNode(v.Instance('rising_sun.models.gains:Gain'))
class ClanReserveSchema(v.Schema): clan = v.SchemaNode(v.Instance('rising_sun.models.clan:Clan'))
class shrines(v.SequenceSchema): shrine = v.SchemaNode(v.Instance(Shrine))
class BoardSchema(v.Schema): map = v.SchemaNode(v.Instance(Map)) @v.instantiate(missing=()) class shrines(v.SequenceSchema): shrine = v.SchemaNode(v.Instance(Shrine))
class connections(v.SequenceSchema): connection = v.SchemaNode(v.Instance(Connection))
class regions(v.SequenceSchema): region = v.SchemaNode(v.Instance(Region))
# -*- 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'))