Exemple #1
0
func newMinMaxNumber(p parent, id string, countdown bool, min, max, num, updateOn int64) *minMaxNumber {
	mmn := &minMaxNumber{
		parent:    p,
		base:      fmt.Sprintf("%s.%s", p.stateBase(), id),
		countdown: countdown,
		updateOn:  updateOn,
		stateIDs:  make(map[string]string),
	}

	mmn.stateIDs["min"] = mmn.base + ".Min"
	mmn.stateIDs["max"] = mmn.base + ".Max"
	mmn.stateIDs["num"] = mmn.base + ".Num"
	mmn.stateIDs["precise"] = mmn.base + ".PreciseNum"

	statemanager.RegisterUpdaterInt64(mmn.stateIDs["min"], 1, mmn.setMin)
	statemanager.RegisterUpdaterInt64(mmn.stateIDs["max"], 2, mmn.setMax)
	statemanager.RegisterUpdaterInt64(mmn.stateIDs["precise"], 3, mmn.setNum)

	mmn.setMin(min)
	mmn.setMax(max)
	mmn.setNum(num)

	return mmn
}
Exemple #2
0
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
}
Exemple #3
0
func newMasterClock(sb *Scoreboard) *masterClock {
	mc := &masterClock{
		sb:         sb,
		syncClocks: true,
		clocks:     make(map[string]*clock),
		stateIDs:   make(map[string]string),
	}

	ticksPerSecond := int64(1000)
	minutes2 := 2 * 60 * ticksPerSecond
	minutes15 := 15 * 60 * ticksPerSecond
	minutes30 := 30 * 60 * ticksPerSecond

	mc.period = newClock(
		sb,
		clockPeriod,
		1, 2,
		0, minutes30,
		true,
		false,
	)
	mc.jam = newClock(
		sb,
		clockJam,
		1, 99,
		0, minutes2,
		true,
		false,
	)
	mc.lineup = newClock(
		sb,
		clockLineup,
		1, 99,
		0, minutes30,
		false,
		false,
	)
	mc.timeout = newClock(
		sb,
		clockTimeout,
		1, 99,
		0, minutes30,
		false,
		false,
	)
	mc.intermission = newClock(
		sb,
		clockIntermission,
		1, 2,
		0, minutes15,
		true,
		false,
	)
	mc.clocks[clockPeriod] = mc.period
	mc.clocks[clockJam] = mc.jam
	mc.clocks[clockLineup] = mc.lineup
	mc.clocks[clockTimeout] = mc.timeout
	mc.clocks[clockIntermission] = mc.intermission
	for _, c := range mc.clocks {
		c.reset(true, false)
	}

	mc.stateIDs["startTime"] = sb.stateBase() + ".MasterClock.StartTime"
	mc.stateIDs["ticks"] = sb.stateBase() + ".MasterClock.Ticks"

	statemanager.RegisterUpdaterTime(mc.stateIDs["startTime"], 0, mc.setStartTime)
	statemanager.RegisterUpdaterInt64(mc.stateIDs["ticks"], 0, mc.setTicks)

	go mc.tickClocks()

	return mc
}