Skip to content

Commit 7d911b6

Browse files
committed
See description for details
-Fixed PNG, strings, and OBJ exceptions while loading -Added optional Version property to ModBase -Added method to easily get framework version -Updated assembly version
1 parent 8f099a7 commit 7d911b6

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

FrameworkMod.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
using Planetbase;
1+
using System;
2+
using System.Reflection;
3+
using Planetbase;
24

35
namespace PlanetbaseFramework
46
{
5-
class FrameworkMod : ModBase
7+
public class FrameworkMod : ModBase
68
{
9+
public override Version ModVersion => Assembly.GetExecutingAssembly().GetName().Version;
10+
711
public FrameworkMod()
812
{
913
Utils.ErrorTexture = ModTextures.Find(x => x.name.Equals("error.png"));

ModBase.cs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,48 @@ public abstract class ModBase
1111
public List<Texture2D> ModTextures { get; protected set; }
1212
public List<GameObject> ModObjects { get; protected set; }
1313

14+
public virtual Version ModVersion => new Version(0, 0, 0, 0);
15+
1416
protected ModBase()
1517
{
1618
try
1719
{
18-
Debug.Log("Loaded " + LoadAllString("assets" + Path.DirectorySeparatorChar + "strings" + Path.DirectorySeparatorChar) + " string file(s)");
20+
LoadAllString(Path.Combine("assets", "strings"));
1921
}
20-
catch (Exception)
22+
catch (Exception e)
2123
{
22-
Debug.Log("Couldn't/no strings filies to load");
24+
Debug.Log("Failed to load strings files due to exception:");
25+
Utils.LogException(e);
2326
}
2427

2528
try
2629
{
27-
ModTextures = LoadAllPng("assets" + Path.DirectorySeparatorChar + "png" + Path.DirectorySeparatorChar);
30+
ModTextures = LoadAllPng(Path.Combine("assets","png"));
31+
32+
if (ModTextures.Count > 0)
33+
{
34+
Debug.Log("Successfully loaded " + ModTextures.Count + " texture(s)");
35+
}
2836
}
29-
catch (Exception)
37+
catch (Exception e)
3038
{
31-
Debug.Log("Couldn't/no PNG files to load");
39+
Debug.Log("Failed to load PNG files due to exception:");
40+
Utils.LogException(e);
3241
}
3342

3443
try
3544
{
36-
ModObjects = LoadAllObj("assets" + Path.DirectorySeparatorChar + "obj" + Path.DirectorySeparatorChar);
45+
ModObjects = LoadAllObj(Path.Combine("assets", "obj"));
3746

47+
if(ModObjects.Count > 0)
48+
{
49+
Debug.Log("Successfully loaded " + ModObjects.Count + " object(s)");
50+
}
3851
}
39-
catch (Exception)
52+
catch (Exception e)
4053
{
41-
Debug.Log("Couldn't/no OBJ files to load");
54+
Debug.Log("Failed to load OBJ files due to exception:");
55+
Utils.LogException(e);
4256
}
4357
}
4458

@@ -62,6 +76,8 @@ public int LoadAllString(string subfolder = null)
6276
{
6377
string[] files = GetFilesMatchingFiletype("xml", subfolder);
6478

79+
Debug.Log("Found " + files.Length + " strings files");
80+
6581
foreach (string file in files)
6682
{
6783
Utils.LoadStringsFromFile(file);
@@ -74,6 +90,8 @@ public List<Texture2D> LoadAllPng(string subfolder = null)
7490
{
7591
string[] files = GetFilesMatchingFiletype("png", subfolder);
7692

93+
Debug.Log("Found " + files.Length + " PNG files");
94+
7795
List<Texture2D> loadedFiles = new List<Texture2D>(files.Length);
7896
foreach (String file in files)
7997
{
@@ -85,9 +103,10 @@ public List<Texture2D> LoadAllPng(string subfolder = null)
85103

86104
public List<GameObject> LoadAllObj(string subfolder = null)
87105
{
88-
89106
string[] files = GetFilesMatchingFiletype("obj", subfolder);
90107

108+
Debug.Log("Found " + files.Length + " OBJ files");
109+
91110
List<GameObject> loadedFiles = new List<GameObject>(files.Length);
92111
foreach (String file in files)
93112
{
@@ -108,14 +127,7 @@ private string[] GetFilesMatchingFiletype(string filetype, string subfolder = nu
108127
subfolder = string.Empty;
109128
}
110129

111-
if (Directory.Exists(this.ModPath + subfolder))
112-
{
113-
return Directory.GetFiles(this.ModPath + subfolder, "*." + filetype);
114-
}
115-
else
116-
{
117-
throw new Exception("Could not load " + filetype.ToUpper() + " files from invalid folder " + this.ModPath + subfolder + Path.DirectorySeparatorChar.ToString());
118-
}
130+
return Directory.Exists(ModPath + subfolder) ? Directory.GetFiles(ModPath + subfolder, "*." + filetype) : new string[0];
119131
}
120132
}
121133
}

Modloader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace PlanetbaseFramework
1313
public class Modloader
1414
{
1515
public static List<ModBase> ModList = new List<ModBase>();
16+
1617
public static void LoadMods()
1718
{
1819
Debug.Log("Loading mod \"Planetbase Framework\"");

PlanetbaseFramework.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2020
4+
VisualStudioVersion = 15.0.27130.2024
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlanetbaseFramework", "PlanetbaseFramework.csproj", "{74541FF9-9E89-4A95-9C9D-8215BBFACE26}"
77
EndProject
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Planetbase-XMLModloaderMod"
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMLModloaderMod", "..\XMLModloaderModV2\XMLModloaderMod.csproj", "{3C4CDA74-6FD6-4E6A-8120-3D2A866E47E4}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatcherV2", "..\PatcherV2\PatcherV2.csproj", "{D046FF94-10E1-458D-A64C-2FB2F85F1AFE}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
3941
{3C4CDA74-6FD6-4E6A-8120-3D2A866E47E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
4042
{3C4CDA74-6FD6-4E6A-8120-3D2A866E47E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
4143
{3C4CDA74-6FD6-4E6A-8120-3D2A866E47E4}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{D046FF94-10E1-458D-A64C-2FB2F85F1AFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{D046FF94-10E1-458D-A64C-2FB2F85F1AFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{D046FF94-10E1-458D-A64C-2FB2F85F1AFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{D046FF94-10E1-458D-A64C-2FB2F85F1AFE}.Release|Any CPU.Build.0 = Release|Any CPU
4248
EndGlobalSection
4349
GlobalSection(SolutionProperties) = preSolution
4450
HideSolutionNode = FALSE

Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("solidDoWant")]
1111
[assembly: AssemblyProduct("PlanetbaseFramework")]
12-
[assembly: AssemblyCopyright("Copyright © 2017")]
12+
[assembly: AssemblyCopyright("Copyright © 2018")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("1.0.0.0")]
34+
[assembly: AssemblyVersion("2.1.2.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

Utils.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
namespace PlanetbaseFramework
1212
{
1313
public static class Utils
14-
{ public static Texture2D ErrorTexture { get; internal set; }
14+
{
15+
public static Texture2D ErrorTexture { get; internal set; }
1516

1617
public static void LoadStringsFromFile(string absolutePath)
1718
{
@@ -346,5 +347,10 @@ public static void RecursivelyAddColliders(this Transform t)
346347
}
347348
}
348349
}
350+
351+
public static FrameworkMod GetFrameworkMod()
352+
{
353+
return Modloader.ModList.Find(mod => mod.ModName.Equals("Planetbase Framework")) as FrameworkMod;
354+
}
349355
}
350356
}

0 commit comments

Comments
 (0)