Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod Manager Lua engine integration and Presets #858

Merged
merged 40 commits into from
Dec 6, 2023

Conversation

shananas
Copy link
Collaborator

@shananas shananas commented Aug 31, 2023

Adds Presets and Lua Engine integration.
When saving a new preset you will need to restart mod manager for the preset to show under Load Presets. If you save a preset with the same name as one that already exists it will override it and a restart will not be necessary. If you try to include characters in the name that windows does not let be in a filename it will automatically be replaced by +.

Adds an install Lua Engine option into the setup wizard if you chose PC version. Can either download and configure Lua Engine to automatically load scripts installed in Mod Manager. Or if you have it installed already can locate where Lua Engine is installed and use it from there and configure it to load scripts from Mod Manager.
Can also install a Lua Script directly into mod manager as an easy way to enable or disable them.
image
When you install a script it will generate a mod.yml based on MetaData in the Lua or using defaults. The script will be copied to be in mod/"chosen game"/scripts which the Lua Engine configuration step in the setup wizard will set it so Lua Engine can load scripts from there. If you have Lua Engine installed either through Mod Manager or by selecting where you installed it and use Build and Run or Run only it will load the game and then load start Lua Engine.

Taken from osdanovas PR to my fork.
Changes the presets to its own menu. Backend remains mostly the same.
266825917-7eaac0ef-ba31-428d-9c83-8c068b5a1a1f

shananas and others added 16 commits August 11, 2023 18:48
Load Preset menu doesnt update when saving a new preset until you restart Mod Manager.
Any text that isnt A-Z or 0-9 will be replcaed by + so the file can save.
…anager then remove preset from the folder)

other small changes.
…a zip.

Also merged Preset Regex improvement.
…rease.

Basically done for when Lua Engine is ready for full release.
# Conflicts:
#	OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs
# Conflicts:
#	OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs
@osdanova
Copy link
Contributor

osdanova commented Sep 6, 2023

I haven't messed around with presets but I don't think the basic structure for them is ready.

  1. Reloading the app is unnecessary, simply assign the MenuItem's ItemSource to an ObservableList in the ViewModel. Then, when the app loads, initialize and fill the list and whenever a new preset is saved add to that list.

Presets

Sample code:

public ObservableCollection<ModViewModel> ModsList { get; set; }
public ObservableCollection<MenuItem> ModPresets { get; set; }

---

SavePreset = new RelayCommand(_ =>
{
    var view = new SavePreset();
    if (view.ShowDialog() != true)
        return;
    string name = string.Join("+", view.PresetName.Split(Path.GetInvalidFileNameChars()));
    var enabledMods =  ModsList
    .Where(x => x.Enabled)
    .Select(x => x.Source)
    .ToList();
    File.WriteAllLines(Path.Combine(ConfigurationService.PresetPath, name + ".txt"), enabledMods);

    if(ModPresets == null)
        ModPresets = new ObservableCollection<MenuItem>();

    ModPresets.Clear();
    foreach (string file in Directory.GetFiles(ConfigurationService.PresetPath))
    {
        MenuItem item = new MenuItem();
        item.Header = file.Replace(ConfigurationService.PresetPath, "").Replace(".txt", "").Trim("\\".ToCharArray());
        item.SetBinding(Button.CommandProperty, new Binding("LoadPreset"));
        item.CommandParameter = file.Replace(ConfigurationService.PresetPath, "").Replace(".txt", "").Trim("\\".ToCharArray());
        ModPresets.Add(item);
    }
});   
  1. I do not think not being able to remove presets is acceptable.

Copy link
Collaborator

@TopazTK TopazTK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a way to remove presets.

@shananas
Copy link
Collaborator Author

Delete confirmation Box. everything else thanks to osdanova
image

@shananas shananas requested a review from TopazTK September 10, 2023 16:53
@TopazTK TopazTK marked this pull request as ready for review September 11, 2023 00:58
@TopazTK
Copy link
Collaborator

TopazTK commented Sep 11, 2023

LGTM!

@shananas shananas marked this pull request as draft September 11, 2023 01:10
@shananas
Copy link
Collaborator Author

shananas commented Sep 11, 2023

Back to draft until Lua Engine and common Lua scripts work nicely together unless Topaz is happy with current Lua Engine

@TopazTK
Copy link
Collaborator

TopazTK commented Sep 11, 2023

I am happy with the state of the current LuaEngine, but give time for 1-2 more releases.

@Vladabdf Vladabdf merged commit 5471a58 into OpenKH:master Dec 6, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants