Skip to content

Commit

Permalink
Abstract out game-specific logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 15, 2020
1 parent 042c3f5 commit 3123ee6
Show file tree
Hide file tree
Showing 190 changed files with 2,728 additions and 2,560 deletions.
4 changes: 2 additions & 2 deletions Cmdline/Action/AuthToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AuthToken() { }
/// <returns>
/// Exit code
/// </returns>
public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptions unparsed)
public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCommandOptions unparsed)
{
string[] args = unparsed.options.ToArray();
int exitCode = Exit.OK;
Expand All @@ -41,7 +41,7 @@ public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptio
user = new ConsoleUser(options.Headless);
if (manager == null)
{
manager = new KSPManager(user);
manager = new GameInstanceManager(user);
}
exitCode = options.Handle(manager, user);
if (exitCode == Exit.OK)
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Available.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public Available(IUser user)
this.user = user;
}

public int RunCommand(CKAN.KSP ksp, object raw_options)
public int RunCommand(CKAN.GameInstance ksp, object raw_options)
{
AvailableOptions opts = (AvailableOptions)raw_options;
IRegistryQuerier registry = RegistryManager.Instance(ksp).registry;
Expand Down
8 changes: 4 additions & 4 deletions Cmdline/Action/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ private class SetLimitOptions : CommonOptions
/// <summary>
/// Execute a cache subcommand
/// </summary>
/// <param name="mgr">KSPManager object containing our instances and cache</param>
/// <param name="mgr">GameInstanceManager object containing our instances and cache</param>
/// <param name="opts">Command line options object</param>
/// <param name="unparsed">Raw command line options</param>
/// <returns>
/// Exit code for shell environment
/// </returns>
public int RunSubCommand(KSPManager mgr, CommonOptions opts, SubCommandOptions unparsed)
public int RunSubCommand(GameInstanceManager mgr, CommonOptions opts, SubCommandOptions unparsed)
{
string[] args = unparsed.options.ToArray();

Expand All @@ -103,7 +103,7 @@ public int RunSubCommand(KSPManager mgr, CommonOptions opts, SubCommandOptions u
CommonOptions options = (CommonOptions)suboptions;
options.Merge(opts);
user = new ConsoleUser(options.Headless);
manager = mgr ?? new KSPManager(user);
manager = mgr ?? new GameInstanceManager(user);
exitCode = options.Handle(manager, user);
if (exitCode != Exit.OK)
return;
Expand Down Expand Up @@ -235,7 +235,7 @@ private void printCacheInfo()
user.RaiseMessage($"{fileCount} files, {CkanModule.FmtSize(bytes)}");
}

private KSPManager manager;
private GameInstanceManager manager;
private IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Cache));
Expand Down
20 changes: 10 additions & 10 deletions Cmdline/Action/Compat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class CompatForgetOptions : InstanceSpecificOptions
[ValueOption(0)] public string Version { get; set; }
}

public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptions options)
public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCommandOptions options)
{
var exitCode = Exit.OK;

Expand All @@ -77,7 +77,7 @@ public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptio
CommonOptions comOpts = (CommonOptions)suboptions;
comOpts.Merge(opts);
_user = new ConsoleUser(comOpts.Headless);
_kspManager = manager ?? new KSPManager(_user);
_kspManager = manager ?? new GameInstanceManager(_user);
exitCode = comOpts.Handle(_kspManager, _user);
if (exitCode != Exit.OK)
return;
Expand Down Expand Up @@ -148,11 +148,11 @@ public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptio
var ksp = MainClass.GetGameInstance(_kspManager);
var addOptions = (CompatAddOptions)suboptions;
KspVersion kspVersion;
if (KspVersion.TryParse(addOptions.Version, out kspVersion))
GameVersion GameVersion;
if (GameVersion.TryParse(addOptions.Version, out GameVersion))
{
var newCompatibleVersion = ksp.GetCompatibleVersions();
newCompatibleVersion.Add(kspVersion);
newCompatibleVersion.Add(GameVersion);
ksp.SetCompatibleVersions(newCompatibleVersion);
}
else
Expand All @@ -168,13 +168,13 @@ public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptio
var ksp = MainClass.GetGameInstance(_kspManager);
var addOptions = (CompatForgetOptions)suboptions;
KspVersion kspVersion;
if (KspVersion.TryParse(addOptions.Version, out kspVersion))
GameVersion GameVersion;
if (GameVersion.TryParse(addOptions.Version, out GameVersion))
{
if (kspVersion != ksp.Version())
if (GameVersion != ksp.Version())
{
var newCompatibleVersion = ksp.GetCompatibleVersions();
newCompatibleVersion.RemoveAll(i => i == kspVersion);
newCompatibleVersion.RemoveAll(i => i == GameVersion);
ksp.SetCompatibleVersions(newCompatibleVersion);
}
else
Expand All @@ -200,7 +200,7 @@ public int RunSubCommand(KSPManager manager, CommonOptions opts, SubCommandOptio
return exitCode;
}

private KSPManager _kspManager;
private GameInstanceManager _kspManager;
private IUser _user;
}
}
Loading

0 comments on commit 3123ee6

Please sign in to comment.