section.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // package section -- типовая секция работы части игры (банк, арсенал и т.п.)
  2. package section
  3. import (
  4. "fmt"
  5. "log"
  6. "wartank/pkg/components/lst_string"
  7. "wartank/pkg/components/section/down_time"
  8. "wartank/pkg/components/section/section_mode"
  9. "wartank/pkg/components/section/zone"
  10. "wartank/pkg/types"
  11. )
  12. // Section -- секция игры
  13. type Section struct {
  14. *zone.Zone
  15. countDown types.ICountTime // Обратный отсчёт до окончания работы режима
  16. mode types.IMode // Объект режима работы
  17. lstString *lst_string.LstString // Список строк из сети для анализа секции
  18. }
  19. // NewSection -- возвращает новую секцию игры
  20. func NewSection(bot types.IBot, zoneName, strControl string) (*Section, error) {
  21. log.Printf("NewSection(): strControl=%q\n", strControl)
  22. zone, err := zone.NewZone(bot, zoneName)
  23. if err != nil {
  24. return nil, fmt.Errorf("NewSection(): in create IZone, err=\n\t%w", err)
  25. }
  26. sf := &Section{
  27. Zone: zone,
  28. countDown: down_time.NewCountTime(zone, 5),
  29. mode: section_mode.NewSectionMode(),
  30. }
  31. sf.lstString, err = lst_string.NewLstString(strControl)
  32. if err != nil {
  33. return nil, fmt.Errorf("NewSection(): in create *LstString, err=\n\t%w", err)
  34. }
  35. return sf, nil
  36. }
  37. // Update -- обновляет список строк секции по требованию
  38. func (sf *Section) Update(lstString []string) error {
  39. if err := sf.lstString.Set(lstString); err != nil {
  40. return fmt.Errorf("Section.Update(): in set lstString, err=\n\t%w", err)
  41. }
  42. return nil
  43. }
  44. // GetLst -- возвращает список строк секции
  45. func (sf *Section) GetLst() []string {
  46. return sf.lstString.Get()
  47. }
  48. // SetCountDown -- устанавливает новое значение обратного счётчика времени (int)
  49. func (sf *Section) SetCountDown(sec int) error {
  50. sf.countDown = down_time.NewCountTime(sf, sec)
  51. // if err := sf.countDown.Set(sec); err != nil {
  52. // return fmt.Errorf("Section.SetCountDown(): err=\n\t%w", err)
  53. // }
  54. return nil
  55. }
  56. // ParseCountDown -- устанавливает новое значение обратного счётчика времени (string)
  57. func (sf *Section) ParseCountDown(sec string) error {
  58. sf.countDown = down_time.ParseCountTime(sf, sec)
  59. // if err := sf.countDown.Set(sec); err != nil {
  60. // return fmt.Errorf("Section.SetCountDown(): err=\n\t%w", err)
  61. // }
  62. return nil
  63. }
  64. // CountDown -- объект оставшегося времени
  65. func (sf *Section) CountDown() types.ICountTime {
  66. return sf.countDown
  67. }
  68. // ModeCurrent -- текущий режим работы
  69. func (sf *Section) ModeCurrent() types.IMode {
  70. return sf.mode
  71. }