Skip to content

Commit

Permalink
satisfactorymodding#22: Implement support for modules not found in GQ…
Browse files Browse the repository at this point in the history
…L, somewhat
  • Loading branch information
surdaft committed Aug 1, 2023
1 parent eb64c48 commit 6b47409
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions tea/scenes/mods/installed_mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,36 @@ func (m installedModsList) LoadModData() {
return
}

if len(mods.Mods.Mods) == 0 {
return
items := make([]list.Item, 0)

// create a pre-defined list of the mods in the profile, to then update
// with modsmodsmodsmods info after
for reference := range currentProfile.Mods {
items = append(items, utils.SimpleItemExtra[installedModsList, ficsit.ModsModsGetModsModsMod]{
SimpleItem: utils.SimpleItem[installedModsList]{
ItemTitle: reference,
Activate: func(msg tea.Msg, currentModel installedModsList) (tea.Model, tea.Cmd) {
return NewModMenu(m.root, currentModel, utils.Mod{
Name: reference,
Reference: reference,
}), nil
},
},
})
}

items := make([]list.Item, len(mods.Mods.Mods))
for i, mod := range mods.Mods.Mods {
var index *int
for exIndex, exItem := range items {
if exItem.(utils.SimpleItemExtra[installedModsList, ficsit.ModsModsGetModsModsMod]).SimpleItem.ItemTitle == mod.Mod_reference {
index = &exIndex
break
}
}

// Re-reference struct
mod := mod
items[i] = utils.SimpleItemExtra[installedModsList, ficsit.ModsModsGetModsModsMod]{
item := utils.SimpleItemExtra[installedModsList, ficsit.ModsModsGetModsModsMod]{
SimpleItem: utils.SimpleItem[installedModsList]{
ItemTitle: mods.Mods.Mods[i].Name,
Activate: func(msg tea.Msg, currentModel installedModsList) (tea.Model, tea.Cmd) {
Expand All @@ -154,6 +175,14 @@ func (m installedModsList) LoadModData() {
},
Extra: mod,
}

// if it already exists then replace it with the proper mod,
// otherwise we will add it to the end
if index != nil {
items[*index] = item
} else {
items = append(items, item)
}
}

items = m.sortItems(items, m.sortingField, m.sortingOrder)
Expand Down

0 comments on commit 6b47409

Please sign in to comment.