Exemplo n.º 1
0
func newClock(sb *Scoreboard, name string, numMin, numMax, timeMin, timeMax int64, countdown, running bool) *clock {
	timeNum := timeMin
	if countdown {
		timeNum = timeMax
	}
	c := &clock{
		sb:   sb,
		base: fmt.Sprintf("%s.Clock(%s)", sb.stateBase(), name),
	}
	c.number = newMinMaxNumber(c, "Number", false, numMin, numMax, numMin, 1)
	c.time = newMinMaxNumber(c, "Time", countdown, timeMin, timeMax, timeNum, 1000)
	c.stateIDs = make(map[string]string)

	c.stateIDs["name"] = c.base + ".Name"
	c.stateIDs["countdown"] = c.base + ".CountDown"
	c.stateIDs["running"] = c.base + ".Running"
	c.stateIDs["adjustable"] = c.base + ".Adjustable"

	statemanager.RegisterCommand(c.time.stateIDs["num"]+".Inc", c.incTime)
	statemanager.RegisterCommand(c.time.stateIDs["num"]+".Dec", c.decTime)

	statemanager.RegisterUpdaterString(c.stateIDs["name"], 0, c.setName)
	statemanager.RegisterUpdaterBool(c.stateIDs["countdown"], 4, c.setCountDown)
	statemanager.RegisterUpdaterBool(c.stateIDs["running"], 4, c.setRunning)

	c.setName(name)
	c.setCountDown(countdown)
	c.setRunning(running)
	c.setAdjustable(false)

	return c
}
Exemplo n.º 2
0
Arquivo: team.go Projeto: obowersa/crg
func newTeam(sb *Scoreboard, id uint8) *team {
	t := &team{
		sb:       sb,
		base:     fmt.Sprintf("%s.Team(%d)", sb.stateBase(), id),
		id:       id,
		settings: make(map[string]*setting),
		skaters:  make(map[string]*skater),
		stateIDs: make(map[string]string),
	}

	t.stateIDs["id"] = fmt.Sprintf("%s.ID", t.base)
	t.stateIDs["name"] = fmt.Sprintf("%s.Name", t.base)
	t.stateIDs["color"] = fmt.Sprintf("%s.Color", t.base)
	t.stateIDs["score"] = fmt.Sprintf("%s.Score", t.base)
	t.stateIDs["lastScore"] = fmt.Sprintf("%s.LastScore", t.base)
	t.stateIDs["jamScore"] = fmt.Sprintf("%s.JamScore", t.base)
	t.stateIDs["timeouts"] = fmt.Sprintf("%s.Timeouts", t.base)
	t.stateIDs["officialReviews"] = fmt.Sprintf("%s.OfficialReviews", t.base)
	t.stateIDs["officialReviewRetained"] = fmt.Sprintf("%s.OfficialReviewRetained", t.base)
	t.stateIDs["lead"] = fmt.Sprintf("%s.Lead", t.base)
	t.stateIDs["starPass"] = fmt.Sprintf("%s.StarPass", t.base)
	t.stateIDs["jammer"] = fmt.Sprintf("%s.Jammer.ID", t.base)
	t.stateIDs["jammerInBox"] = fmt.Sprintf("%s.Jammer.InBox", t.base)
	t.stateIDs["pivot"] = fmt.Sprintf("%s.Pivot.ID", t.base)
	t.stateIDs["pivotInBox"] = fmt.Sprintf("%s.Pivot.InBox", t.base)

	statemanager.StateUpdateInt64(t.stateIDs["id"], int64(id))

	statemanager.RegisterUpdaterString(t.stateIDs["name"], 0, t.setName)
	statemanager.RegisterUpdaterString(t.stateIDs["color"], 0, t.setColor)
	statemanager.RegisterUpdaterInt64(t.stateIDs["score"], 0, t.setScore)
	statemanager.RegisterUpdaterInt64(t.stateIDs["lastScore"], 0, t.setLastScore)
	statemanager.RegisterUpdaterInt64(t.stateIDs["timeouts"], 0, t.setTimeouts)
	statemanager.RegisterUpdaterInt64(t.stateIDs["officialReviews"], 0, t.setOfficialReviews)
	statemanager.RegisterUpdaterBool(t.stateIDs["officialReviewRetained"], 0, t.setOfficialReviewRetained)
	statemanager.RegisterUpdaterString(t.stateIDs["lead"], 0, t.setLead)
	statemanager.RegisterUpdaterBool(t.stateIDs["starPass"], 0, t.setStarPass)

	statemanager.RegisterUpdaterString(t.stateIDs["jammer"], 1, t.setJammer)         // Must be after skaters are loaded
	statemanager.RegisterUpdaterString(t.stateIDs["pivot"], 1, t.setPivot)           // Must be after skaters are loaded
	statemanager.RegisterUpdaterBool(t.stateIDs["jammerInBox"], 1, t.setJammerInBox) // Must be after skaters are loaded
	statemanager.RegisterUpdaterBool(t.stateIDs["pivotInBox"], 1, t.setPivotInBox)   // Must be after skaters are loaded

	statemanager.RegisterCommand(t.stateIDs["score"]+".Inc", t.incScore)
	statemanager.RegisterCommand(t.stateIDs["score"]+".Dec", t.decScore)
	statemanager.RegisterCommand(t.stateIDs["lastScore"]+".Inc", t.incLastScore)
	statemanager.RegisterCommand(t.stateIDs["lastScore"]+".Dec", t.decLastScore)
	statemanager.RegisterCommand(t.stateIDs["timeouts"]+".Start", t.startTimeout)
	statemanager.RegisterCommand(t.stateIDs["officialReviews"]+".Start", t.startOfficialReview)
	statemanager.RegisterCommand(t.stateIDs["officialReviews"]+".Retained", t.retainOfficialReview)
	statemanager.RegisterCommand(t.base+".DeleteSkater", t.deleteSkater)

	// Setup Updaters for skaters (functions located in skater.go)
	statemanager.RegisterPatternUpdaterString(t.base+".Skater(*).ID", 0, t.sSetID)
	statemanager.RegisterPatternUpdaterString(t.base+".Skater(*).Name", 0, t.sSetName)
	statemanager.RegisterPatternUpdaterString(t.base+".Skater(*).LegalName", 0, t.sSetLegalName)
	statemanager.RegisterPatternUpdaterString(t.base+".Skater(*).InsuranceNumber", 0, t.sSetInsuranceNumber)
	statemanager.RegisterPatternUpdaterString(t.base+".Skater(*).Number", 0, t.sSetNumber)
	statemanager.RegisterPatternUpdaterString(t.base+".Skater(*).Position", 0, t.sSetPosition)
	statemanager.RegisterPatternUpdaterBool(t.base+".Skater(*).IsAlt", 0, t.sSetIsAlt)
	statemanager.RegisterPatternUpdaterBool(t.base+".Skater(*).IsCaptain", 0, t.sSetIsCaptain)
	statemanager.RegisterPatternUpdaterBool(t.base+".Skater(*).IsAltCaptain", 0, t.sSetIsAltCaptain)
	statemanager.RegisterPatternUpdaterBool(t.base+".Skater(*).IsBenchStaff", 0, t.sSetIsBenchStaff)
	statemanager.RegisterPatternUpdaterBool(t.base+".Skater(*).InBox", 0, t.sSetInBox)

	t.reset()
	return t
}