Skip to content

🚨 refactor: Remove unused mission configuration and simplify data loading#2181

Merged
mkmccarty merged 1 commit intomainfrom
mm-branch-1
Feb 9, 2026
Merged

🚨 refactor: Remove unused mission configuration and simplify data loading#2181
mkmccarty merged 1 commit intomainfrom
mm-branch-1

Conversation

@mkmccarty
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 9, 2026 19:27
@mkmccarty mkmccarty merged commit eaaaa8b into main Feb 9, 2026
14 checks passed
@mkmccarty mkmccarty deleted the mm-branch-1 branch February 9, 2026 19:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
_ = 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")
}

Copilot uses AI. Check for mistakes.
type ShipData struct {
Name string `json:"Name"`
Art string `json:"Art"`
ArtDev string `json:"ArtDev"`
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
ArtDev string `json:"ArtDev"`

Copilot uses AI. Check for mistakes.
Comment on lines 36 to 38
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)
}
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant