section.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // package section -- типовая секция работы части игры (банк, арсенал и т.п.)
  2. package section
  3. import (
  4. "fmt"
  5. "log"
  6. "wartank/pkg/components/lst_string"
  7. "wartank/pkg/components/section/count_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, strControl string) (*Section, error) {
  21. log.Printf("NewSection(): strControl=%q\n", strControl)
  22. zone, err := zone.NewZone(bot)
  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: count_time.NewCountTime(zone),
  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 -- устанавливает новое значение обратного счётчика времени
  49. func (sf *Section) SetCountDown(sec int) error {
  50. sf.countDown = count_time.NewCountTime(sf)
  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. // CountDown -- объект оставшегося времени
  57. func (sf *Section) CountDown() types.ICountTime {
  58. return sf.countDown
  59. }
  60. // ModeCurrent -- текущий режим работы
  61. func (sf *Section) ModeCurrent() types.IMode {
  62. return sf.mode
  63. }