func (j *jam) setTeamPosition(s *skater) { base := fmt.Sprintf("%v.Team(%v)", j.base, s.t.id) switch s.position { case positionJammer: j.teams[s.t.id-1].jammer = s.id statemanager.StateUpdateString(base+".Jammer", s.id) case positionPivot: j.teams[s.t.id-1].jammer = s.id statemanager.StateUpdateString(base+".Pivot", s.id) case positionBlocker: j.teams[s.t.id-1].blockers = append(j.teams[s.t.id-1].blockers, s.id) statemanager.StateUpdateString(fmt.Sprintf("%v.Blocker(%v)", base, len(j.teams[s.t.id-1].blockers)-1), s.id) } }
func addFileWatcher(mediaType, prefix, path string) (*fsnotify.Watcher, error) { fullpath := filepath.Join(statemanager.BaseFilePath(), prefix, path) os.MkdirAll(fullpath, 0775) watcher, err := fsnotify.NewWatcher() if err != nil { return nil, err } err = watcher.Add(fullpath) if err != nil { watcher.Close() return nil, err } f, err := os.Open(fullpath) if err != nil { return nil, err } names, err := f.Readdirnames(-1) f.Close() for _, name := range names { short := filepath.Base(name) full := filepath.Join(path, short) statemanager.StateUpdateString(fmt.Sprintf("Media.Type(%v).File(%v)", mediaType, full), short) } go func() { for { select { case event := <-watcher.Events: short := filepath.Base(event.Name) full := filepath.Join(path, short) if event.Op&fsnotify.Create == fsnotify.Create { statemanager.StateUpdateString(fmt.Sprintf("Media.Type(%v).File(%v)", mediaType, full), short) } else if event.Op&fsnotify.Rename == fsnotify.Rename { statemanager.StateDelete(fmt.Sprintf("Media.Type(%v).File(%v)", mediaType, full)) } else if event.Op&fsnotify.Remove == fsnotify.Remove { statemanager.StateDelete(fmt.Sprintf("Media.Type(%v).File(%v)", mediaType, full)) } case err := <-watcher.Errors: log.Println("error:", err) } } }() return watcher, nil }
func setSettings(k, v string) error { v = strings.TrimSpace(v) if v == "" { return statemanager.StateDelete(k) } return statemanager.StateUpdateString(k, v) }
func (s *skater) setPosition(v string) error { var set = func(v string) error { s.position = v s.t.updatePositions() return statemanager.StateUpdateString(s.stateIDs["position"], v) } if v == s.position { // Nothing to see, move along return nil } if s.inBox() { return errSkaterInBox } if v == positionBench { return set(v) } if v == positionJammer { s2, ok := s.t.skaters[s.t.jammer] if ok { if err := s2.setPosition(positionBench); err != nil { return err } } return set(v) } if v == positionPivot { s2, ok := s.t.skaters[s.t.pivot] if ok { to := positionBench if s.position == positionBlocker { to = positionBlocker } if err := s2.setPosition(to); err != nil { return err } } return set(v) } // Must be blocker open := 3 if s.t.pivot == "" || s.position == positionPivot { open = 4 } for _, s2 := range s.t.skaters { if s2.position == positionBlocker { open = open - 1 } } if open < 1 { return errPositionFull } return set(v) }
func (s *skater) setDescription() { var long, short []string if s.isAlt { long = append(long, "Alternate") short = append(short, "Alt") } if s.isCaptain { long = append(long, "Captain") short = append(short, "C") } if s.isAltCaptain { long = append(long, "Alternate Captain") short = append(short, "A") } if s.isBenchStaff { long = append(long, "Bench Staff") short = append(short, "B") } statemanager.StateUpdateString(s.stateIDs["description"], strings.Join(long, ", ")) statemanager.StateUpdateString(s.stateIDs["shortDescription"], strings.Join(short, "")) }
func (sb *Scoreboard) setState(state string) error { log.Printf("scoreboard: setState(%+v)", state) sb.state = state statemanager.StateUpdateString(sb.stateIDs["state"], state) adjustable := false if isTimeoutState(state) { adjustable = true } sb.masterClock.setClockAdjustable(clockPeriod, adjustable) return nil }
// setup default settings func initSettings(saveFile string) *statemanager.Saver { defaults := []struct{ name, value string }{ {"BackgroundStyle", "bg_blacktowhite"}, {"BoxStyle", "box_flat"}, {"CurrentView", "scoreboard"}, {"HideJamTotals", "false"}, {"SwapTeams", "false"}, {"Image", "/images/fullscreen/American Flag.jpg"}, {"Video", "/videos/American Flag.webm"}, {"CustomHtml", "/customhtml/example"}, } views := []string{"View", "Preview"} statemanager.Lock() for _, v := range views { for _, d := range defaults { statemanager.StateUpdateString(fmt.Sprintf("Settings.%v.%v", v, d.name), d.value) } } statemanager.RegisterPatternUpdaterString("Settings", 0, setSettings) statemanager.Unlock() return statemanager.NewSaver(saveFile, "Settings", time.Duration(5)*time.Second, true, true) }
func (t *team) updatePositions() { t.jammer = "" t.pivot = "" statemanager.StateDelete(t.base + ".Jammer") statemanager.StateDelete(t.base + ".Pivot") t.sb.activeJam.clearTeamPositions(t) for _, s := range t.skaters { t.sb.activeJam.setTeamPosition(s) if s.position == positionJammer { t.jammer = s.id statemanager.StateUpdateString(t.base+".Jammer.ID", s.id) statemanager.StateUpdateString(t.base+".Jammer.Name", s.name) statemanager.StateUpdateString(t.base+".Jammer.Number", s.number) statemanager.StateUpdateBool(t.base+".Jammer.InBox", s.inBox()) } else if s.position == positionPivot { t.pivot = s.id statemanager.StateUpdateString(t.base+".Pivot.ID", s.id) statemanager.StateUpdateString(t.base+".Pivot.Name", s.name) statemanager.StateUpdateString(t.base+".Pivot.Number", s.number) statemanager.StateUpdateBool(t.base+".Pivot.InBox", s.inBox()) } } }
func (t *team) setName(v string) error { t.name = v return statemanager.StateUpdateString(t.stateIDs["name"], v) }
func (p *Person) SetNumber(v string) error { p.number = v return statemanager.StateUpdateString(p.stateIDs["number"], v) }
func (p *Person) SetInsuranceNumber(v string) error { p.insuranceNumber = v return statemanager.StateUpdateString(p.stateIDs["insuranceNumber"], v) }
func (p *Person) SetLegalName(v string) error { p.legalName = v return statemanager.StateUpdateString(p.stateIDs["legalName"], v) }
// SetID sets the ID to `v` func (p *Person) SetID(v string) error { p.id = v return statemanager.StateUpdateString(p.stateIDs["id"], v) }
func (l *League) SetName(v string) error { l.name = v return statemanager.StateUpdateString(l.stateIDs["name"], v) }
func (l *League) SetID(v string) error { l.id = v return statemanager.StateUpdateString(l.stateIDs["id"], v) }
func (s *skater) setLegalName(v string) error { s.legalName = v return statemanager.StateUpdateString(s.stateIDs["legalName"], v) }
func (t *team) setLead(v string) error { t.lead = v return statemanager.StateUpdateString(t.stateIDs["lead"], v) }
func (s *skater) setInsuranceNumber(v string) error { s.insuranceNumber = v return statemanager.StateUpdateString(s.stateIDs["insuranceNumber"], v) }
func (c *clock) setName(name string) error { c.name = name statemanager.StateUpdateString(c.stateIDs["name"], name) return nil }
func (ss *stateSnapshot) setState(v string) { ss.state = v statemanager.StateUpdateString(ss.stateIDs["state"], v) }
func (s *skater) setID(v string) error { s.id = v return statemanager.StateUpdateString(s.stateIDs["id"], v) }
func (s *skater) setNumber(v string) error { s.number = v return statemanager.StateUpdateString(s.stateIDs["number"], v) }
func (t *team) setColor(v string) error { t.color = v return statemanager.StateUpdateString(t.stateIDs["color"], v) }
func (bt *boxTrip) setSkater(s *skater) { bt.s = s statemanager.StateUpdateString(bt.stateIDs["skater"], s.id) }