Skip to content

Commit

Permalink
fix: refactor for previous changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Dec 6, 2023
1 parent a37ad9a commit a6075d6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cli/installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func (i *Installation) UpdateMods(ctx *GlobalContext, mods []string) error {
return errors.Wrap(err, "failed to read lock file")
}

resolver := NewDependencyResolver(ctx.APIClient)
resolver := NewDependencyResolver(ctx.Provider)

gameVersion, err := i.GetGameVersion(ctx)
if err != nil {
Expand All @@ -489,7 +489,7 @@ func (i *Installation) UpdateMods(ctx *GlobalContext, mods []string) error {
}

for _, modReference := range mods {
delete(lockFile, modReference)
lockFile = lockFile.Remove(modReference)
}

newLockFile, err := profile.Resolve(resolver, lockFile, gameVersion)
Expand Down
8 changes: 8 additions & 0 deletions cli/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ func (l LockFile) Clone() LockFile {
}
return lockFile
}

func (l *LockFile) Remove(modID ...string) *LockFile {
out := *l
for _, s := range modID {
delete(out, s)
}
return &out
}
2 changes: 1 addition & 1 deletion tea/scenes/main_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewMainMenu(root components.RootModel) tea.Model {
utils.SimpleItem[mainMenu]{
ItemTitle: "Update Mods",
Activate: func(msg tea.Msg, currentModel mainMenu) (tea.Model, tea.Cmd) {
newModel := NewUpdateMods(root, currentModel)
newModel := mods.NewUpdateMods(root, currentModel)
return newModel, newModel.Init()
},
},
Expand Down
11 changes: 6 additions & 5 deletions tea/scenes/update_mods.go → tea/scenes/mods/update_mods.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package scenes
package mods

import (
"context"
Expand All @@ -17,6 +17,7 @@ import (
"github.com/satisfactorymodding/ficsit-cli/cli"
"github.com/satisfactorymodding/ficsit-cli/ficsit"
"github.com/satisfactorymodding/ficsit-cli/tea/components"
"github.com/satisfactorymodding/ficsit-cli/tea/scenes/keys"
"github.com/satisfactorymodding/ficsit-cli/tea/utils"
)

Expand Down Expand Up @@ -110,7 +111,7 @@ func (m updateModsList) LoadModData() {
return
}

resolver := cli.NewDependencyResolver(m.root.GetAPIClient())
resolver := cli.NewDependencyResolver(m.root.GetProvider())

updatedLockfile, err := currentProfile.Resolve(resolver, nil, gameVersion)
if err != nil {
Expand All @@ -119,7 +120,7 @@ func (m updateModsList) LoadModData() {

items := make([]list.Item, 0)
i := 0
for reference, currentLockedMod := range currentLockfile {
for reference, currentLockedMod := range *currentLockfile {
r := reference
updatedLockedMod, ok := updatedLockfile[reference]
if !ok {
Expand Down Expand Up @@ -239,7 +240,7 @@ func (m updateModsList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

switch keypress := msg.String(); keypress {
case KeyControlC:
case keys.KeyControlC:
return m, tea.Quit
case "q":
if m.parent != nil {
Expand All @@ -257,7 +258,7 @@ func (m updateModsList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m.processActivation(i2.SimpleItem, msg)
}
return m, nil
case KeyEnter:
case keys.KeyEnter:
if len(m.selectedMods) > 0 {
err := m.root.GetCurrentInstallation().UpdateMods(m.root.GetGlobal(), m.selectedMods)
if err != nil {
Expand Down

0 comments on commit a6075d6

Please sign in to comment.