Added support for different files for different versions in mod

This commit is contained in:
strongleong 2022-02-13 01:26:00 +11:00
parent 02d9df8160
commit 515aa519a4
4 changed files with 54 additions and 29 deletions

View File

@ -1,4 +1,4 @@
WIP ScrapModLoader
WIP ScrapModLoader
==============
This applications is for managing mods for Scrapland.
@ -24,11 +24,29 @@ ScrapModLoader supports both original and remastered versions of Scrapland.
For now mod for Scrapland is a *.sm file that basically is a zip arhive with following content:
| Filename | Description |
|--------------------|----------------------------------------------|
| icon.png | Icon for mod that will show up in mod loader |
| config.toml | Information about mod |
| <filename\>.packed | Container with all mod game assets |
| Filename | Description |
|------------------------|--------------------------------------------------|
| icon.png | Icon for mod that will show up in mod loader |
| config.toml | Information about mod |
| <game_version\>\ | Folder that named as game version mod made for |
| <filename\>.packed | Container with all mod game assets |
You can have as many .packed files as you want. Mod loader will load everything.
.packed files in the root of mod will be copied to the `Mods` folder of Scrapland.
.pakced files under game version folder will load only to the appopriate game version.
### .sm structure sample
```
│ icon.png
│ config.toml
│ mod_assets.packed
├──1.0/
│ only_for_original.packed
└──1.1/
only_for_remastered.packed
```
### config.toml sample
```toml
@ -37,7 +55,7 @@ description = "Mod description"
category = "Mod category"
version = "1.0"
requiredLauncher = "1.0"
requiredGame = "1.0"
supportedGameVersions = ["1.0", "1.1"]
authors = [
{ name = "Author 1" },
@ -64,9 +82,10 @@ credits = [
- [X] Support for custom *.packed
- [X] Supoprt for Scrapland Remastered
- [ ] Support for both Scrapland versions in single .sm file
- [ ] Support for custom game files (i.e. `\Traslation\` files or custom `QuickConsole.py`)
- [ ] Recompiling *.py to *.pyc
- [ ] Mod settings.
- [ ] More meta info in `config.xml`
- [ ] More meta info in `config.toml`
- [ ] Multilanguage support
- [ ] More mods :wink:

View File

@ -34,8 +34,9 @@
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Category" DisplayMemberBinding="{Binding Category}" />
<GridViewColumn Header="Mod Version" DisplayMemberBinding="{Binding Version}" />
<GridViewColumn Header="Game Version" DisplayMemberBinding="{Binding RequiredGame}" />
<GridViewColumn Header="Game Version" DisplayMemberBinding="{Binding SupportedGameVersionsDisplay}" />
</GridView>
</ListView.View>
<ListView.ItemContainerStyle>

View File

@ -86,19 +86,16 @@ namespace ScrapModLoader
foreach (ScrapMod mod in Mods)
{
if (mod.RequiredGame != SelectedGameVersion)
// TODO: Warning about not loading mods that not supports selected version
if (!mod.SupportedGameVersions.Contains(SelectedGameVersion))
continue;
if (mod.Checked)
{
if (!mod.IsEnabled(gamePath))
mod.Enable(gamePath);
}
mod.Enable(gamePath, SelectedGameVersion);
else
{
if (mod.IsEnabled(gamePath))
mod.Disable(gamePath);
}
}
}
}

View File

@ -20,7 +20,16 @@ namespace ScrapModLoader
public String Category { get; private set; }
public String Version { get; private set; }
public String RequiredLauncher { get; private set; }
public String RequiredGame { get; private set; }
public List<String> SupportedGameVersions { get; private set; }
public String SupportedGameVersionsDisplay {
get
{
String result = String.Empty;
foreach (String version in SupportedGameVersions)
result += version + ", ";
return result.TrimEnd(',', ' ');
}
}
public List<String> Authors { get; private set; }
public Dictionary<String, List<String>> Credits { get; private set; }
@ -34,7 +43,7 @@ namespace ScrapModLoader
Category = String.Empty;
Version = String.Empty;
RequiredLauncher = String.Empty;
RequiredGame = String.Empty;
SupportedGameVersions = new List<String>();
Authors = new List<String>();
Credits = new Dictionary<String, List<String>>();
LoadFromFile(path);
@ -58,19 +67,17 @@ namespace ScrapModLoader
return false;
}
public void Enable(String gamePath)
public void Enable(String gamePath, String gameVersion)
{
if (!IsLoaded(gamePath))
LoadModToGame(gamePath);
LoadModToGame(gamePath, gameVersion);
if (IsEnabled(gamePath))
return;
foreach (String file in Directory.EnumerateFiles(gamePath + @"Mods\" + Name))
{
if (Path.GetExtension(file) == ".disabled")
File.Move(file, Path.ChangeExtension(file, null));
}
}
public void Disable(String gamePath)
@ -79,13 +86,11 @@ namespace ScrapModLoader
return;
foreach (String file in Directory.EnumerateFiles(gamePath + @"Mods\" + Name))
{
if (Path.GetExtension(file) == ".packed")
File.Move(file, file + ".disabled");
}
}
private void LoadModToGame(String gamePath)
private void LoadModToGame(String gamePath, String gameVersion)
{
gamePath += @"Mods\" + Name;
Directory.CreateDirectory(gamePath);
@ -94,10 +99,11 @@ namespace ScrapModLoader
{
foreach (ZipEntry zipEntry in zipFile)
{
if (!Path.GetFullPath(zipEntry.FileName).Contains(gameVersion))
continue;
if (Path.GetExtension(zipEntry.FileName) == ".packed")
{
zipEntry.Extract(gamePath);
}
}
}
}
@ -151,7 +157,9 @@ namespace ScrapModLoader
Category = config["category"];
Version = config["version"];
RequiredLauncher = config["requiredLauncher"];
RequiredGame = config["requiredGame"];
foreach (TomlNode version in config["supportedGameVersions"])
SupportedGameVersions.Add(version);
foreach (TomlNode author in config["authors"])
Authors.Add(author["name"]);
@ -185,8 +193,8 @@ namespace ScrapModLoader
if (!config.HasKey("requiredLauncher"))
throw new FileFormatException("No 'name' key in 'config.toml'");
if (!config.HasKey("requiredGame"))
throw new FileFormatException("No 'requiredGame' key in 'config.toml'");
if (!config.HasKey("supportedGameVersions"))
throw new FileFormatException("No 'supportedGameVersions' key in 'config.toml'");
}
}
}