section.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/types"
  10. )
  11. /*
  12. Базовый объект игры -- секция.
  13. Основа множества зданий игры.
  14. */
  15. // Section -- секция игры
  16. type Section struct {
  17. countDown types.ICountTime // Обратный отсчёт до окончания работы режима
  18. mode types.IMode // Объект режима работы
  19. lstString *lst_string.LstString // Список строк из сети для анализа секции
  20. }
  21. // NewSection -- возвращает новую секцию игры
  22. func NewSection(bot types.IBot, strControl string) (*Section, error) {
  23. log.Printf("NewSection(): strControl=%q\n", strControl)
  24. sf := &Section{
  25. countDown: count_time.NewCountTime(bot),
  26. mode: section_mode.NewSectionMode(),
  27. }
  28. var err error
  29. sf.lstString, err = lst_string.NewLstString(strControl)
  30. if err != nil {
  31. return nil, fmt.Errorf("NewSection(): in create *LstString, err=\n\t%w", err)
  32. }
  33. return sf, nil
  34. }
  35. // Update -- обновляет список строк секции по требованию
  36. func (sf *Section) Update(lstString []string) error {
  37. if err := sf.lstString.Set(lstString); err != nil {
  38. return fmt.Errorf("Section.Update(): in set lstString, err=\n\t%w", err)
  39. }
  40. return nil
  41. }
  42. // GetLst -- возвращает список строк секции
  43. func (sf *Section) GetLst() []string {
  44. return sf.lstString.Get()
  45. }
  46. // CountDown -- объект оставшегося времени
  47. func (sf *Section) CountDown() types.ICountTime {
  48. return sf.countDown
  49. }
  50. // ModeCurrent -- текущий режим работы
  51. func (sf *Section) ModeCurrent() types.IMode {
  52. return sf.mode
  53. }