Skip to content

Commit

Permalink
feat: Add type (single- vs. multiplayer) to game profile
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Sep 26, 2022
1 parent 4235748 commit cb38f91
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/game/bf2/bf2.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ func GetProfiles(h game.Handler) ([]game.Profile, error) {
return nil, err
}

profileType := game.ProfileTypeMultiplayer
// Singleplayer profiles do not contain a password
if !profileCon.HasKey(ProfileConKeyPassword) {
profileType = game.ProfileTypeSingleplayer
}

profiles = append(profiles, game.Profile{
Key: profileKey,
Name: profileName.String(),
Type: profileType,
})
}

Expand Down
20 changes: 17 additions & 3 deletions pkg/game/bf2/bf2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,31 @@ func TestGetProfiles(t *testing.T) {
{
name: "successfully gets profiles",
expect: func(h *MockHandler) {
h.EXPECT().GetProfileKeys(handler.GameBf2).Return([]string{"0001"}, nil)
h.EXPECT().GetProfileKeys(handler.GameBf2).Return([]string{"0001", "0002"}, nil)
h.EXPECT().ReadProfileConfig(handler.GameBf2, "0001").Return(config.New(
"C:\\Users\\Documents\\Battlefield 2\\Profiles\\0001\\Profile.con",
map[string]config.Value{
ProfileConKeyName: *config.NewValue("some-profile"),
ProfileConKeyName: *config.NewValue("some-multiplayer-profile"),
ProfileConKeyPassword: *config.NewValue("some-password"),
},
), nil)
h.EXPECT().ReadProfileConfig(handler.GameBf2, "0002").Return(config.New(
"C:\\Users\\Documents\\Battlefield 2\\Profiles\\0002\\Profile.con",
map[string]config.Value{
ProfileConKeyName: *config.NewValue("some-singleplayer-profile"),
},
), nil)
},
wantProfiles: []game.Profile{
{
Key: "0001",
Name: "some-profile",
Name: "some-multiplayer-profile",
Type: game.ProfileTypeMultiplayer,
},
{
Key: "0002",
Name: "some-singleplayer-profile",
Type: game.ProfileTypeSingleplayer,
},
},
},
Expand All @@ -136,6 +149,7 @@ func TestGetProfiles(t *testing.T) {
{
Key: "0001",
Name: "some-profile",
Type: game.ProfileTypeSingleplayer,
},
},
},
Expand Down
8 changes: 8 additions & 0 deletions pkg/game/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ import (
"github.com/cetteup/conman/pkg/handler"
)

type ProfileType int

const (
ProfileTypeMultiplayer ProfileType = iota
ProfileTypeSingleplayer
)

type Profile struct {
Key string
Name string
Type ProfileType
}

type Handler interface {
Expand Down

0 comments on commit cb38f91

Please sign in to comment.