// package section -- типовая секция работы части игры (банк, арсенал и т.п.) package section import ( "fmt" "log" "wartank/pkg/components/lst_string" "wartank/pkg/components/section/count_time" "wartank/pkg/components/section/section_mode" "wartank/pkg/components/section/zone" "wartank/pkg/types" ) // Section -- секция игры type Section struct { *zone.Zone countDown types.ICountTime // Обратный отсчёт до окончания работы режима mode types.IMode // Объект режима работы lstString *lst_string.LstString // Список строк из сети для анализа секции } // NewSection -- возвращает новую секцию игры func NewSection(bot types.IBot, strControl string) (*Section, error) { log.Printf("NewSection(): strControl=%q\n", strControl) zone, err := zone.NewZone(bot) if err != nil { return nil, fmt.Errorf("NewSection(): in create IZone, err=\n\t%w", err) } sf := &Section{ Zone: zone, countDown: count_time.NewCountTime(zone), mode: section_mode.NewSectionMode(), } sf.lstString, err = lst_string.NewLstString(strControl) if err != nil { return nil, fmt.Errorf("NewSection(): in create *LstString, err=\n\t%w", err) } return sf, nil } // Update -- обновляет список строк секции по требованию func (sf *Section) Update(lstString []string) error { if err := sf.lstString.Set(lstString); err != nil { return fmt.Errorf("Section.Update(): in set lstString, err=\n\t%w", err) } return nil } // GetLst -- возвращает список строк секции func (sf *Section) GetLst() []string { return sf.lstString.Get() } // SetCountDown -- устанавливает новое значение обратного счётчика времени func (sf *Section) SetCountDown(sec int) error { sf.countDown = count_time.NewCountTime(sf) if err := sf.countDown.Set(sec); err != nil { return fmt.Errorf("Section.SetCountDown(): err=\n\t%w", err) } return nil } // CountDown -- объект оставшегося времени func (sf *Section) CountDown() types.ICountTime { return sf.countDown } // ModeCurrent -- текущий режим работы func (sf *Section) ModeCurrent() types.IMode { return sf.mode }