示例#1
0
文件: jam.go 项目: obowersa/crg
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)
	}
}
示例#2
0
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
}
示例#3
0
文件: settings.go 项目: obowersa/crg
func setSettings(k, v string) error {
	v = strings.TrimSpace(v)
	if v == "" {
		return statemanager.StateDelete(k)
	}
	return statemanager.StateUpdateString(k, v)
}
示例#4
0
文件: skater.go 项目: obowersa/crg
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)
}
示例#5
0
文件: skater.go 项目: obowersa/crg
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, ""))
}
示例#6
0
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
}
示例#7
0
文件: settings.go 项目: obowersa/crg
// 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)
}
示例#8
0
文件: team.go 项目: obowersa/crg
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())
		}
	}
}
示例#9
0
文件: team.go 项目: obowersa/crg
func (t *team) setName(v string) error {
	t.name = v
	return statemanager.StateUpdateString(t.stateIDs["name"], v)
}
示例#10
0
文件: person.go 项目: obowersa/crg
func (p *Person) SetNumber(v string) error {
	p.number = v
	return statemanager.StateUpdateString(p.stateIDs["number"], v)
}
示例#11
0
文件: person.go 项目: obowersa/crg
func (p *Person) SetInsuranceNumber(v string) error {
	p.insuranceNumber = v
	return statemanager.StateUpdateString(p.stateIDs["insuranceNumber"], v)
}
示例#12
0
文件: person.go 项目: obowersa/crg
func (p *Person) SetLegalName(v string) error {
	p.legalName = v
	return statemanager.StateUpdateString(p.stateIDs["legalName"], v)
}
示例#13
0
文件: person.go 项目: obowersa/crg
// SetID sets the ID to `v`
func (p *Person) SetID(v string) error {
	p.id = v
	return statemanager.StateUpdateString(p.stateIDs["id"], v)
}
示例#14
0
文件: league.go 项目: obowersa/crg
func (l *League) SetName(v string) error {
	l.name = v
	return statemanager.StateUpdateString(l.stateIDs["name"], v)
}
示例#15
0
文件: league.go 项目: obowersa/crg
func (l *League) SetID(v string) error {
	l.id = v
	return statemanager.StateUpdateString(l.stateIDs["id"], v)
}
示例#16
0
文件: skater.go 项目: obowersa/crg
func (s *skater) setLegalName(v string) error {
	s.legalName = v
	return statemanager.StateUpdateString(s.stateIDs["legalName"], v)
}
示例#17
0
文件: team.go 项目: obowersa/crg
func (t *team) setLead(v string) error {
	t.lead = v
	return statemanager.StateUpdateString(t.stateIDs["lead"], v)
}
示例#18
0
文件: skater.go 项目: obowersa/crg
func (s *skater) setInsuranceNumber(v string) error {
	s.insuranceNumber = v
	return statemanager.StateUpdateString(s.stateIDs["insuranceNumber"], v)
}
示例#19
0
文件: clock.go 项目: obowersa/crg
func (c *clock) setName(name string) error {
	c.name = name
	statemanager.StateUpdateString(c.stateIDs["name"], name)
	return nil
}
示例#20
0
func (ss *stateSnapshot) setState(v string) {
	ss.state = v
	statemanager.StateUpdateString(ss.stateIDs["state"], v)
}
示例#21
0
文件: skater.go 项目: obowersa/crg
func (s *skater) setID(v string) error {
	s.id = v
	return statemanager.StateUpdateString(s.stateIDs["id"], v)
}
示例#22
0
文件: skater.go 项目: obowersa/crg
func (s *skater) setNumber(v string) error {
	s.number = v
	return statemanager.StateUpdateString(s.stateIDs["number"], v)
}
示例#23
0
文件: team.go 项目: obowersa/crg
func (t *team) setColor(v string) error {
	t.color = v
	return statemanager.StateUpdateString(t.stateIDs["color"], v)
}
示例#24
0
文件: box_trip.go 项目: obowersa/crg
func (bt *boxTrip) setSkater(s *skater) {
	bt.s = s
	statemanager.StateUpdateString(bt.stateIDs["skater"], s.id)
}