// BuildRaceOpts builds a quick race form
BuildRaceOpts builds a quick race form
// BuildRaceOpts builds a quick race form
func (rm *RaceManager) BuildRaceOpts(r *http.Request) (map[string]interface{}, error) {
	cars, err := ListCars()
	if err != nil {
		return nil, err
	}
	tracks, err := ListTracks()
	if err != nil {
		return nil, err
	}
	weather, err := ListWeather()
	if err != nil {
		return nil, err
	}
	race := ConfigIniDefault
	templateID := r.URL.Query().Get("from")
	var entrants EntryList
	if templateID != "" {
		customRace, err := rm.raceStore.FindCustomRaceByID(templateID)
		if err != nil {
			return nil, err
		}
		race.CurrentRaceConfig = customRace.RaceConfig
		entrants = customRace.EntryList
	}
	templateIDForEditing := chi.URLParam(r, "uuid")
	isEditing := templateIDForEditing != ""
	var customRaceName string
	if isEditing {
		customRace, err := rm.raceStore.FindCustomRaceByID(templateIDForEditing)
		if err != nil {
			return nil, err
		}
		customRaceName = customRace.Name
		race.CurrentRaceConfig = customRace.RaceConfig
		entrants = customRace.EntryList
	}
	possibleEntrants, err := rm.raceStore.ListEntrants()
	if err != nil {
		return nil, err
	}
	solIsInstalled := false
	for availableWeather := range weather {
		if strings.HasPrefix(availableWeather, "sol_") {
			solIsInstalled = true
			break
		}
	}
	for _, weather := range race.CurrentRaceConfig.Weather {
		if weather.CMWFXDate == 0 {
			weather.CMWFXDate = int(time.Now().Unix())
			weather.CMWFXDateUnModified = int(time.Now().Unix())
		}
	}
	opts := map[string]interface{}{
		"CarOpts":           cars,
		"TrackOpts":         tracks,
		"AvailableSessions": AvailableSessions,
		"Weather":           weather,
		"SolIsInstalled":    solIsInstalled,
		"Current":           race.CurrentRaceConfig,
		"CurrentEntrants":   entrants,
		"PossibleEntrants":  possibleEntrants,
		"IsChampionship":    false, 
		"IsEditing":         isEditing,
		"EditingID":         templateIDForEditing,
		"CustomRaceName":    customRaceName,
		"SurfacePresets":    DefaultTrackSurfacePresets,
	}
	err = rm.applyCurrentRaceSetupToOptions(opts, race.CurrentRaceConfig)
	if err != nil {
		return nil, err
	}
	return opts, nil
}
func ( rm * RaceManager ) BuildRaceOpts ( r * http . Request ) ( map [ string ] interface { } , error ) { cars , err := ListCars ( ) if err != nil { return nil , err } tracks , err := ListTracks ( ) if err != nil { return nil , err } weather , err := ListWeather ( ) if err != nil { return nil , err } race := ConfigIniDefault templateID := r . URL . Query ( ) . Get ( " " ) var entrants EntryList if templateID != " " { customRace , err := rm . raceStore . FindCustomRaceByID ( templateID ) if err != nil { return nil , err } race . CurrentRaceConfig = customRace . RaceConfig entrants = customRace . EntryList } templateIDForEditing := chi . URLParam ( r , " " ) isEditing := templateIDForEditing != " " var customRaceName string if isEditing { customRace , err := rm . raceStore . FindCustomRaceByID ( templateIDForEditing ) if err != nil { return nil , err } customRaceName = customRace . Name race . CurrentRaceConfig = customRace . RaceConfig entrants = customRace . EntryList } possibleEntrants , err := rm . raceStore . ListEntrants ( ) if err != nil { return nil , err } solIsInstalled := false for availableWeather := range weather { if strings . HasPrefix ( availableWeather , " " ) { solIsInstalled = true break } } for _ , weather := range race . CurrentRaceConfig . Weather { if weather . CMWFXDate == 0 { weather . CMWFXDate = int ( time . Now ( ) . Unix ( ) ) weather . CMWFXDateUnModified = int ( time . Now ( ) . Unix ( ) ) } } opts := map [ string ] interface { } { " " : cars , " " : tracks , " " : AvailableSessions , " " : weather , " " : solIsInstalled , " " : race . CurrentRaceConfig , " " : entrants , " " : possibleEntrants , " " : false , " " : isEditing , " " : templateIDForEditing , " " : customRaceName , " " : DefaultTrackSurfacePresets , } err = rm . applyCurrentRaceSetupToOptions ( opts , race . CurrentRaceConfig ) if err != nil { return nil , err } return opts , nil }
BuildRaceOpts builds a quick race form
BuildRaceOpts builds a quick race form
// load a from a custom race template // default sol time to now // this flag is overridden by championship setup