Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
1.9 adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Artentus committed Nov 7, 2018
1 parent 4f19222 commit 5f2b2f7
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 107 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#### 1.9.0pre1
#### 1.9.0
* Added proper handling for inverted mod dependencies.
* Added theme support (light and dark theme available now).
* Removed autosaves from the save selection when creating a link.
* Fixed crash when adding Factorio from folder.
* Fixed an issue that caused some mods to not be shown in the online list.
* Fixed bug that caused deactivated releases in the online mods window to be selected.

#### 1.8.6
Expand Down
2 changes: 1 addition & 1 deletion ModMyFactory/ModMyFactory/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace ModMyFactory
{
public partial class App : Application
{
private const int PreReleaseVersion = 2;
private const int PreReleaseVersion = -1;

/// <summary>
/// The current application instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public static bool TryGetSavedValue<T>(IHasModSettings mod, IModSetting<T> setti

public static bool HasSavedDataPresent(IHasModSettings mod)
{
if (modSettings == null) return false;
return modSettings.ContainsKey(mod.UniqueID);
}

Expand Down
18 changes: 9 additions & 9 deletions ModMyFactory/ModMyFactory/Models/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ private set
dependenciesView.CustomSort = new ModDependencySorter();
DependenciesView = dependenciesView;

var settings = file.GetSettings().Select(info => info.ToSetting(this)).ToList();
Settings = new ReadOnlyCollection<IModSetting>(settings);
source = new CollectionViewSource() { Source = Settings };
var settingsView = (ListCollectionView)source.View;
settingsView.CustomSort = new ModSettingSorter();
settingsView.GroupDescriptions.Add(new PropertyGroupDescription("LoadTime"));
SettingsView = settingsView;
//var settings = file.GetSettings().Select(info => info.ToSetting(this)).ToList();
//Settings = new ReadOnlyCollection<IModSetting>(settings);
//source = new CollectionViewSource() { Source = Settings };
//var settingsView = (ListCollectionView)source.View;
//settingsView.CustomSort = new ModSettingSorter();
//settingsView.GroupDescriptions.Add(new PropertyGroupDescription("LoadTime"));
//SettingsView = settingsView;

OnPropertyChanged(new PropertyChangedEventArgs(nameof(Version)));
OnPropertyChanged(new PropertyChangedEventArgs(nameof(FactorioVersion)));
Expand Down Expand Up @@ -180,7 +180,7 @@ private set
/// <summary>
/// Indicates whether this mod has any settings.
/// </summary>
public bool HasSettings => Settings.Count > 0;
public bool HasSettings => (Settings == null) ? false : (Settings.Count > 0);

/// <summary>
/// Additional information about this mod to be displayed in a tooltip.
Expand Down Expand Up @@ -323,7 +323,7 @@ public void ViewSettings()
settingsViewModel.SetMod(this);
settingsWindow.ShowDialog();

ModSettingsManager.SaveSettings(this);
//ModSettingsManager.SaveSettings(this);
}

private bool KeepOldFile(ModFile newFile)
Expand Down
88 changes: 3 additions & 85 deletions ModMyFactory/ModMyFactory/Models/ModFile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ModMyFactory.Helpers;
using ModMyFactory.ModSettings;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -160,93 +159,12 @@ private ModFile(FileSystemInfo file, InfoFile infoFile, bool isFile)
InfoFile = infoFile;
this.isFile = isFile;
}

private static ModSettingInfo[] ParseSettingsFile(Stream stream)
{
string content = string.Empty;
using (var reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (!line.TrimStart().StartsWith("--")) content += line;
}
}

content = content.Trim();
content = content.Substring(4).TrimStart(); // Remove 'data'
content = content.Substring(1).TrimStart(); // Remove ':'
content = content.Substring(6).TrimStart(); // Remove 'extend'
if (content[0] == '(') content = content.Substring(1).TrimStart(); // Remove '(' if present
if (content[content.Length - 1] == ')') content = content.Substring(0, content.Length - 1).TrimEnd(); // Remove ')' if present
content = content.Substring(1, content.Length - 2).Trim(); // Remove outer {} brackets
content = content.Replace('=', ':'); // Replace assignment char
content = '[' + content + ']'; // Add array brackets

// ToDo: add support for 'require' statements

try
{
return JsonHelper.Deserialize<ModSettingInfo[]>(content);
}
catch (JsonReaderException)
{
return new ModSettingInfo[0];
}
}

private static bool TryLoadSettingsFromFile(FileInfo archiveFile, out ModSettingInfo[] settings)
{
using (var archive = ZipFile.OpenRead(archiveFile.FullName))
{
foreach (var entry in archive.Entries)
{
if ((entry.Name == "settings.lua") && (entry.FullName.Count(c => c == '/') == 1))
{
using (var stream = entry.Open())
{
settings = ParseSettingsFile(stream);
return true;
}
}
}
}

settings = null;
return false;
}

private static bool TryLoadSettingsFromDirectory(DirectoryInfo directory, out ModSettingInfo[] settings)
{
var settingsFile = directory.EnumerateFiles("settings.lua").FirstOrDefault();
if (settingsFile == null)
{
settings = null;
return false;
}

using (var stream = settingsFile.OpenRead())
{
settings = ParseSettingsFile(stream);
return true;
}
}

private bool TryLoadSettings(out ModSettingInfo[] settings)
{
if (isFile)
return TryLoadSettingsFromFile((FileInfo)file, out settings);
else
return TryLoadSettingsFromDirectory((DirectoryInfo)file, out settings);
}


public ModSettingInfo[] GetSettings()
{
if (settings != null) return settings;

if (!TryLoadSettings(out settings))
settings = new ModSettingInfo[0];
// ToDo: read settings using Lua interpreter

if (settings == null) settings = new ModSettingInfo[0];
return settings;
}

Expand Down
26 changes: 19 additions & 7 deletions ModMyFactory/ModMyFactory/Models/ModSettingsProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,21 @@ public ModSettingsProxy(IHasModSettings baseMod, Modpack parent)

private void CreateView()
{
var list = baseMod.Settings.Select(setting => setting.CreateProxy()).ToList();
settings = new ReadOnlyCollection<IModSettingProxy>(list);
var source = new CollectionViewSource() { Source = settings };
var settingsView = (ListCollectionView)source.View;
settingsView.CustomSort = new ModSettingSorter();
settingsView.GroupDescriptions.Add(new PropertyGroupDescription("LoadTime"));
SettingsView = settingsView;
if (HasSettings)
{
var list = baseMod.Settings.Select(setting => setting.CreateProxy()).ToList();
settings = new ReadOnlyCollection<IModSettingProxy>(list);
var source = new CollectionViewSource() { Source = settings };
var settingsView = (ListCollectionView)source.View;
settingsView.CustomSort = new ModSettingSorter();
settingsView.GroupDescriptions.Add(new PropertyGroupDescription("LoadTime"));
SettingsView = settingsView;
}
else
{
settings = null;
SettingsView = null;
}

OnPropertyChanged(new PropertyChangedEventArgs(nameof(Settings)));
OnPropertyChanged(new PropertyChangedEventArgs(nameof(SettingsView)));
Expand All @@ -96,6 +104,10 @@ private void PropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
CreateView();
}
else if (e.PropertyName == nameof(IHasModSettings.HasSettings))
{
OnPropertyChanged(new PropertyChangedEventArgs(nameof(HasSettings)));
}
}

public void ViewSettings()
Expand Down
15 changes: 13 additions & 2 deletions ModMyFactory/ModMyFactory/Models/Modpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,18 @@ private set
/// <summary>
/// Indicates whether any mods in this modpack have settings;
/// </summary>
public bool HasSettings => ModProxies.Any(proxy => proxy.HasSettings);
public bool HasSettings
{
get
{
foreach (var proxy in ModProxies)
{
if (proxy.HasSettings)
return true;
}
return false;
}
}

public ICommand ViewSettingsCommand { get; }

Expand All @@ -231,7 +242,7 @@ public void ViewSettings()
settingsViewModel.SetMods(proxyList);
settingsWindow.ShowDialog();

ModSettingsManager.SaveSettings(proxyList);
//ModSettingsManager.SaveSettings(proxyList);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions ModMyFactory/ModMyFactory/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,9 @@ private void Refresh()
{
ModManager.LoadTemplates();
LoadFactorioVersions();
ModSettingsManager.LoadSettings();
//ModSettingsManager.LoadSettings();
LoadModsAndModpacks();
ModSettingsManager.SaveSettings(Mods);
//ModSettingsManager.SaveSettings(Mods);
}

private bool ModsSelected() => Mods.Any(mod => mod.IsSelected);
Expand Down

0 comments on commit 5f2b2f7

Please sign in to comment.