section.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package section
  2. import (
  3. "fmt"
  4. "log"
  5. "wartank/pkg/components/counttime"
  6. "wartank/pkg/components/lststring"
  7. "wartank/pkg/components/section/sectionmode"
  8. "wartank/pkg/types"
  9. )
  10. /*
  11. Базовый объект игры -- секция.
  12. Основа множества зданий игры.
  13. */
  14. // Section -- секция игры
  15. type Section struct {
  16. countDown types.ICountTime
  17. lstString *lststring.LstString
  18. mode types.IMode
  19. }
  20. // NewSection -- возвращает новый *Section
  21. func NewSection(app types.IServer, strControl string) (*Section, error) {
  22. log.Printf("NewSection(): strControl=%q\n", strControl)
  23. sf := &Section{
  24. countDown: counttime.NewCountTime(app),
  25. mode: sectionmode.NewSectionMode(),
  26. }
  27. var err error
  28. sf.lstString, err = lststring.NewLstString(strControl)
  29. if err != nil {
  30. return nil, fmt.Errorf("NewSection(): in create *LstString, err=\n\t%w", err)
  31. }
  32. return sf, nil
  33. }
  34. // Update -- обновляет список строк секции
  35. func (sf *Section) Update(lstString []string) error {
  36. if err := sf.lstString.Set(lstString); err != nil {
  37. return fmt.Errorf("Section.Update(): in set lstString, err=\n\t%w", err)
  38. }
  39. return nil
  40. }
  41. // GetLst -- возвращает список строк арсенала
  42. func (sf *Section) GetLst() []string {
  43. return sf.lstString.Get()
  44. }
  45. // CountDown -- возвращает объект оставшегося времени
  46. func (sf *Section) CountDown() types.ICountTime {
  47. return sf.countDown
  48. }
  49. // ModeCurrent -- текущий режим работы
  50. func (sf *Section) ModeCurrent() types.IMode {
  51. return sf.mode
  52. }