Exemplo n.º 1
0
Arquivo: jam.go Projeto: obowersa/crg
func (j *jam) clearTeamPositions(t *team) {
	base := fmt.Sprintf("%v.Team(%v)", j.base, t.id)
	j.teams[t.id-1].jammer = ""
	statemanager.StateDelete(base + ".Jammer")
	j.teams[t.id-1].pivot = ""
	statemanager.StateDelete(base + ".Pivot")
	for idx, _ := range j.teams[t.id-1].blockers {
		statemanager.StateDelete(fmt.Sprintf("%v.Blocker(%v)", base, idx))
	}
	j.teams[t.id-1].blockers = nil
}
Exemplo n.º 2
0
func (bt *boxTrip) setOutJamIdx(v int64) {
	if v >= 0 && v < int64(len(bt.sb.jams)) {
		jam := bt.sb.jams[v]
		bt.out.jamIdx = jam.idx
		statemanager.StateUpdateInt64(bt.stateIDs["out.jamIdx"], jam.idx)
		statemanager.StateUpdateInt64(bt.stateIDs["out.period"], jam.period)
		statemanager.StateUpdateInt64(bt.stateIDs["out.jam"], jam.jam)
	}

	statemanager.StateDelete(bt.stateIDs["out.jamIdx"])
	statemanager.StateDelete(bt.stateIDs["out.period"])
	statemanager.StateDelete(bt.stateIDs["out.jam"])
}
Exemplo n.º 3
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
}
Exemplo n.º 4
0
func setSettings(k, v string) error {
	v = strings.TrimSpace(v)
	if v == "" {
		return statemanager.StateDelete(k)
	}
	return statemanager.StateUpdateString(k, v)
}
Exemplo n.º 5
0
func (bt *boxTrip) setInJamIdx(v int64) error {
	if v >= 0 && v < int64(len(bt.sb.jams)) {
		jam := bt.sb.jams[v]
		bt.in.jamIdx = jam.idx
		statemanager.StateUpdateInt64(bt.stateIDs["in.jamIdx"], jam.idx)
		statemanager.StateUpdateInt64(bt.stateIDs["in.period"], jam.period)
		statemanager.StateUpdateInt64(bt.stateIDs["in.jam"], jam.jam)
		return nil
	}

	bt.in.jamIdx = -1
	statemanager.StateDelete(bt.stateIDs["in.jamIdx"])
	statemanager.StateDelete(bt.stateIDs["in.period"])
	statemanager.StateDelete(bt.stateIDs["in.jam"])
	return nil
}
Exemplo n.º 6
0
Arquivo: team.go Projeto: obowersa/crg
func (t *team) deleteSkater(data []string) error {
	if len(data) < 1 {
		return errSkaterNotFound
	}

	if _, ok := t.skaters[data[0]]; !ok {
		return errSkaterNotFound
	}
	delete(t.skaters, data[0])
	return statemanager.StateDelete(t.base + ".Skater(" + data[0] + ")")
}
Exemplo n.º 7
0
Arquivo: team.go Projeto: 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())
		}
	}
}
Exemplo n.º 8
0
func (ss *stateSnapshot) delete() {
	statemanager.StateDelete(ss.base)
	ss.sb = nil
}
Exemplo n.º 9
0
Arquivo: jam.go Projeto: obowersa/crg
func (j *jam) delete() {
	statemanager.StateDelete(j.base)
	j.sb = nil
}