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 }
// New initialized a default state for the scoreboard. Additional setup // of the scoreboard is required from either a saved state or via // the web interface. Returns a *Scoreboard func New() *Scoreboard { sb := &Scoreboard{} sb.teams = append(sb.teams, newTeam(sb, 1), newTeam(sb, 2)) sb.masterClock = newMasterClock(sb) sb.stateIDs = make(map[string]string) sb.stateIDs["state"] = sb.stateBase() + ".State" statemanager.RegisterUpdaterString(sb.stateIDs["state"], 0, sb.setState) statemanager.RegisterCommand("Scoreboard.StartJam", sb.startJam) statemanager.RegisterCommand("Scoreboard.StopJam", sb.stopJam) statemanager.RegisterCommand("Scoreboard.Timeout", sb.timeout) statemanager.RegisterCommand("Scoreboard.EndTimeout", sb.endTimeout) statemanager.RegisterCommand("Scoreboard.Undo", sb.undo) statemanager.RegisterCommand("Scoreboard.Reset", sb.reset) // Setup Updaters for stateSnapshots (functions located in state_snapshot.go) statemanager.RegisterPatternUpdaterString(sb.stateBase()+".Snapshot(*).State", 0, sb.ssSetState) statemanager.RegisterPatternUpdaterBool(sb.stateBase()+".Snapshot(*).InProgress", 0, sb.ssSetInProgress) statemanager.RegisterPatternUpdaterBool(sb.stateBase()+".Snapshot(*).CanRevert", 0, sb.ssSetCanRevert) statemanager.RegisterPatternUpdaterInt64(sb.stateBase()+".Snapshot(*).StartTicks", 0, sb.ssSetStartTicks) statemanager.RegisterPatternUpdaterInt64(sb.stateBase()+".Snapshot(*).EndTicks", 0, sb.ssSetEndTicks) statemanager.RegisterPatternUpdaterInt64(sb.stateBase()+".Snapshot(*).Length", 0, sb.ssSetLength) statemanager.RegisterPatternUpdaterTime(sb.stateBase()+".Snapshot(*).StartTime", 0, sb.ssSetStartTime) statemanager.RegisterPatternUpdaterTime(sb.stateBase()+".Snapshot(*).EndTime", 0, sb.ssSetEndTime) statemanager.RegisterPatternUpdaterInt64(sb.stateBase()+".Snapshot(*).Clock(*).Number", 0, sb.sscSetNumber) statemanager.RegisterPatternUpdaterInt64(sb.stateBase()+".Snapshot(*).Clock(*).StartTime", 0, sb.sscSetStartTime) statemanager.RegisterPatternUpdaterInt64(sb.stateBase()+".Snapshot(*).Clock(*).EndTime", 0, sb.sscSetEndTime) statemanager.RegisterPatternUpdaterBool(sb.stateBase()+".Snapshot(*).Clock(*).Running", 0, sb.sscSetRunning) statemanager.RegisterPatternUpdaterInt64(sb.stateBase()+".Snapshot(*).Team(*).Timeouts", 0, sb.sstSetTimeouts) statemanager.RegisterPatternUpdaterInt64(sb.stateBase()+".Snapshot(*).Team(*).OfficialReviews", 0, sb.sstSetOfficialReviews) statemanager.RegisterPatternUpdaterBool(sb.stateBase()+".Snapshot(*).Team(*).OfficialReviewRetained", 0, sb.sstSetOfficialReviewRetained) sb.reset(nil) return sb }
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 }