Skip to content

Commit

Permalink
Support to configure Lua Backend to load scripts from MM for all game…
Browse files Browse the repository at this point in the history
…s MM supports
  • Loading branch information
shananas committed Dec 6, 2023
1 parent 4c53c85 commit 5b19c3f
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 105 deletions.
56 changes: 20 additions & 36 deletions OpenKh.Tools.ModsManager/Services/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ private class Config
public string OpenKhGameEngineLocation { get; internal set; }
public string Pcsx2Location { get; internal set; }
public string PcReleaseLocation { get; internal set; }
public string LuaEnginePath { get; internal set; }
public bool LuaEngineInstalled { get; internal set; }
public string PcReleaseLanguage { get; internal set; } = "en";
public int RegionId { get; internal set; }
public bool PanaceaInstalled { get; internal set; }
Expand All @@ -46,10 +44,14 @@ private class Config
public bool DevView { get; internal set; } = false;
public bool AutoUpdateMods { get; internal set; }
public bool isEGSVersion { get; internal set; } = true;
public bool kh1 { get; internal set; }
public bool kh2 { get; internal set; } = true;
public bool bbs { get; internal set; }
public bool recom { get; internal set; }
public bool Extractkh1 { get; internal set; }
public bool Extractkh2 { get; internal set; } = true;
public bool Extractbbs { get; internal set; }
public bool Extractrecom { get; internal set; }
public bool LuaConfigkh1 { get; internal set; }
public bool LuaConfigkh2 { get; internal set; } = true;
public bool LuaConfigbbs { get; internal set; }
public bool LuaConfigrecom { get; internal set; }
public string LaunchGame { get; internal set; } = "kh2";

public void Save(string fileName)
Expand Down Expand Up @@ -336,39 +338,39 @@ public static bool IsEGSVersion
_config.Save(ConfigPath);
}
}
public static bool kh1
public static bool Extractkh1
{
get => _config.kh1;
get => _config.Extractkh1;
set
{
_config.kh1 = value;
_config.Extractkh1 = value;
_config.Save(ConfigPath);
}
}
public static bool kh2
public static bool Extractkh2
{
get => _config.kh2;
get => _config.Extractkh2;
set
{
_config.kh2 = value;
_config.Extractkh2 = value;
_config.Save(ConfigPath);
}
}
public static bool bbs
public static bool Extractbbs
{
get => _config.bbs;
get => _config.Extractbbs;
set
{
_config.bbs = value;
_config.Extractbbs = value;
_config.Save(ConfigPath);
}
}
public static bool recom
public static bool Extractrecom
{
get => _config.recom;
get => _config.Extractrecom;
set
{
_config.recom = value;
_config.Extractrecom = value;
_config.Save(ConfigPath);
}
}
Expand All @@ -381,23 +383,5 @@ public static string LaunchGame
_config.Save(ConfigPath);
}
}
public static string LuaEngineLocation
{
get => _config.LuaEnginePath ?? Path.Combine(StoragePath, "LuaEngine");
set
{
_config.LuaEnginePath = value;
_config.Save(ConfigPath);
}
}
public static bool LuaBackendInstalled
{
get => _config.LuaEngineInstalled;
set
{
_config.LuaEngineInstalled = value;
_config.Save(ConfigPath);
}
}
}
}
22 changes: 3 additions & 19 deletions OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ await ModsService.InstallMod(name, isZipFile, isLuaFile, progress =>
ConfigPcReleaseLanguage = ConfigurationService.PcReleaseLanguage,
ConfigRegionId = ConfigurationService.RegionId,
ConfigPanaceaInstalled = ConfigurationService.PanaceaInstalled,
ConfigIsEGSVersion = ConfigurationService.IsEGSVersion,
ConfigLuaEngineLocation = ConfigurationService.LuaEngineLocation,
ConfigIsEGSVersion = ConfigurationService.IsEGSVersion,
};
if (dialog.ShowDialog() == true)
{
Expand All @@ -462,8 +461,7 @@ await ModsService.InstallMod(name, isZipFile, isLuaFile, progress =>
ConfigurationService.RegionId = dialog.ConfigRegionId;
ConfigurationService.PanaceaInstalled = dialog.ConfigPanaceaInstalled;
ConfigurationService.IsEGSVersion = dialog.ConfigIsEGSVersion;
ConfigurationService.WizardVersionNumber = _wizardVersionNumber;
ConfigurationService.LuaEngineLocation = dialog.ConfigLuaEngineLocation;
ConfigurationService.WizardVersionNumber = _wizardVersionNumber;

const int EpicGamesPC = 2;
if (ConfigurationService.GameEdition == EpicGamesPC &&
Expand Down Expand Up @@ -616,21 +614,7 @@ private Task RunGame()
}
}
Process.Start(processStartInfo);
CloseAllWindows();
if(ConfigurationService.LuaBackendInstalled)
{
string startFile = ConfigurationService.LuaEngineLocation + "/LuaEngine-REBORN.exe";
if(File.Exists(startFile))
{
processStartInfo = new ProcessStartInfo
{
FileName = startFile,
WorkingDirectory = ConfigurationService.LuaEngineLocation,
UseShellExecute = false,
};
Process.Start(processStartInfo);
}
}
CloseAllWindows();
return Task.CompletedTask;
default:
return Task.CompletedTask;
Expand Down
Loading

0 comments on commit 5b19c3f

Please sign in to comment.