🚨 refactor: Remove unused mission configuration and simplify data loading#2181
🚨 refactor: Remove unused mission configuration and simplify data loading#2181
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors mission ship data loading to rely solely on embedded JSON, removing the unused on-disk mission/artifact configuration and associated hot-reload wiring.
Changes:
- Removed mission/artifact config structs, disk loading, and reload API from
ei_missions.go. - Initialized mission ship art/duration data exclusively from the embedded
missionJSON. - Removed fsnotify watching/reload of the mission config file from
main.go.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/ei/ei_missions.go |
Deletes on-disk config loader and related types; loads MissionArt from embedded JSON during init. |
main.go |
Removes fsnotify wiring for mission config reload and drops the now-unused ei import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| func formatDurationPart(value int, unit string) string { | ||
| return strconv.Itoa(value) + unit | ||
| _ = json.Unmarshal([]byte(missionJSON), &MissionArt) |
There was a problem hiding this comment.
json.Unmarshal error is ignored in init; if missionJSON is ever edited into invalid JSON, MissionArt will silently remain empty and callers indexing MissionArt.Ships[...] can panic or show wrong data. Handle the error (e.g., panic/log.Fatal) or at least assert len(MissionArt.Ships) > 0 after unmarshal.
| _ = json.Unmarshal([]byte(missionJSON), &MissionArt) | |
| if err := json.Unmarshal([]byte(missionJSON), &MissionArt); err != nil { | |
| panic(err) | |
| } | |
| if len(MissionArt.Ships) == 0 { | |
| panic("missionJSON unmarshaled successfully but contains no ships") | |
| } |
| type ShipData struct { | ||
| Name string `json:"Name"` | ||
| Art string `json:"Art"` | ||
| ArtDev string `json:"ArtDev"` |
There was a problem hiding this comment.
ArtDev is added to ShipData but the embedded missionJSON does not provide an artDev/ArtDev field and there are no references to ShipData.ArtDev in the codebase, so this field is currently always empty and adds dead surface area. Either remove it until it’s used, or update the JSON (and tags) plus consuming code to populate and use it.
| ArtDev string `json:"ArtDev"` |
| func init() { | ||
| if !loadMissionDataFromConfig(MissionConfigPath) { | ||
| _ = json.Unmarshal([]byte(missionJSON), &MissionArt) | ||
| } | ||
| } | ||
|
|
||
| // ReloadMissionConfig reloads mission, artifact, and crafting data from disk. | ||
| func ReloadMissionConfig() bool { | ||
| return loadMissionDataFromConfig(MissionConfigPath) | ||
| } | ||
|
|
||
| func loadMissionDataFromConfig(path string) bool { | ||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| log.Printf("Mission config read failed: %v", err) | ||
| return false | ||
| } | ||
|
|
||
| var cfg missionConfig | ||
| if err := json.Unmarshal(data, &cfg); err != nil { | ||
| log.Printf("Mission config parse failed: %v", err) | ||
| return false | ||
| } | ||
|
|
||
| ArtifactParameters = cfg.ArtifactParameters | ||
| CraftingLevelInfos = cfg.CraftingLevelInfos | ||
|
|
||
| var md missionData | ||
| for _, param := range cfg.MissionParameters { | ||
| info, ok := missionShipInfo[param.Ship] | ||
| if !ok { | ||
| continue | ||
| } | ||
| info.Duration = pickMissionDurations(param.Durations) | ||
| md.Ships = append(md.Ships, info) | ||
| } | ||
|
|
||
| if len(md.Ships) == 0 { | ||
| return false | ||
| } | ||
|
|
||
| MissionArt = md | ||
| return true | ||
| } | ||
|
|
||
| func pickMissionDurations(durations []missionDuration) []string { | ||
| preferred := []string{"SHORT", "LONG", "EPIC"} | ||
| byType := make(map[string]int, len(durations)) | ||
| for _, d := range durations { | ||
| if d.Seconds <= 0 { | ||
| continue | ||
| } | ||
| byType[d.DurationType] = d.Seconds | ||
| } | ||
|
|
||
| var result []string | ||
| for _, key := range preferred { | ||
| if seconds, ok := byType[key]; ok { | ||
| result = append(result, formatMissionDuration(seconds)) | ||
| } | ||
| } | ||
|
|
||
| if len(result) > 0 { | ||
| return result | ||
| } | ||
|
|
||
| sort.Slice(durations, func(i, j int) bool { | ||
| return durations[i].Seconds < durations[j].Seconds | ||
| }) | ||
| for _, d := range durations { | ||
| if d.Seconds <= 0 { | ||
| continue | ||
| } | ||
| result = append(result, formatMissionDuration(d.Seconds)) | ||
| if len(result) == 3 { | ||
| break | ||
| } | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| func formatMissionDuration(seconds int) string { | ||
| d := time.Duration(seconds) * time.Second | ||
| if d <= 0 { | ||
| return "0m" | ||
| } | ||
|
|
||
| days := d / (24 * time.Hour) | ||
| d -= days * 24 * time.Hour | ||
| hours := d / time.Hour | ||
| d -= hours * time.Hour | ||
| minutes := d / time.Minute | ||
|
|
||
| parts := "" | ||
| if days > 0 { | ||
| parts += formatDurationPart(int(days), "d") | ||
| } | ||
| if hours > 0 { | ||
| parts += formatDurationPart(int(hours), "h") | ||
| } | ||
| if minutes > 0 || parts == "" { | ||
| parts += formatDurationPart(int(minutes), "m") | ||
| } | ||
|
|
||
| return parts | ||
| } | ||
|
|
||
| func formatDurationPart(value int, unit string) string { | ||
| return strconv.Itoa(value) + unit | ||
| _ = json.Unmarshal([]byte(missionJSON), &MissionArt) | ||
| } |
There was a problem hiding this comment.
With the on-disk mission config loader removed, consider adding a small unit test that unmarshals missionJSON and asserts ship count/order matches the MissionInfo.Spaceship enum values. This would protect callers that index MissionArt.Ships[shipID] from silent breakage if the embedded JSON is edited.
No description provided.