config.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from typing import Any, Dict
  5. from pydantic import (Field,
  6. model_validator,
  7. ValidationError,
  8. model_serializer,
  9. WithJsonSchema,
  10. SerializerFunctionWrapHandler,
  11. GetJsonSchemaHandler)
  12. from tasks.Component.config_scheduler import Scheduler
  13. from tasks.Component.config_base import ConfigBase, Time
  14. from tasks.Component.GeneralBattle.config_general_battle import GreenMarkType
  15. class DuelConfig(ConfigBase):
  16. # 一键切换斗技御魂
  17. switch_all_soul: bool = Field(default=False, description='switch_all_soul_help')
  18. # 限制时间
  19. limit_time: Time = Field(default=Time(minute=30), description='limit_time_help')
  20. # 目标分数
  21. target_score: int = Field(default=2000, description='target_score_help')
  22. # 刷满荣誉就退出
  23. honor_full_exit: bool = Field(default=False, description='honor_full_exit_help')
  24. # 是否开启绿标
  25. green_enable: bool = Field(default=False, description='green_enable_help')
  26. # 选哪一个绿标
  27. green_mark: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1, description='green_mark_help')
  28. class Duel(ConfigBase):
  29. scheduler: Scheduler = Field(default_factory=Scheduler)
  30. duel_config: DuelConfig = Field(default_factory=DuelConfig)
  31. # test_list: list[DuelConfig]
  32. #
  33. # @model_validator(mode='before')
  34. # @classmethod
  35. # def check_list(cls, data: dict) -> Any:
  36. # if 'test_list' not in data:
  37. # data['test_list'] = []
  38. # for key, value in data.items():
  39. # if isinstance(value, list):
  40. # continue
  41. # if 'test_list' not in key:
  42. # continue
  43. # try:
  44. # DuelConfig(**value)
  45. # data['test_list'].append(value)
  46. # except ValidationError as e:
  47. # pass
  48. # # 补全list
  49. # while len(data['test_list']) < data['scheduler']['priority']:
  50. # data['test_list'].append(DuelConfig())
  51. # return data
  52. #
  53. # @model_serializer()
  54. # def serializer_model(self, value: Any) -> Dict[str, Any]:
  55. # properties = self.__dict__
  56. # data = {}
  57. # for key,value in properties.items():
  58. # if isinstance(value, list):
  59. # for index, v in enumerate(value):
  60. # data[f'{key}_{index+1}'] = v.model_dump()
  61. # else:
  62. # data[key] = value.model_dump()
  63. # return data