Skip to content

Commit c8d829d

Browse files
committed
restructure files
1 parent 2127fed commit c8d829d

File tree

7 files changed

+220
-224
lines changed

7 files changed

+220
-224
lines changed

Source/IconMaterialPatch.cs renamed to Source/MaterialReplacement/IconMaterialReplacement.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ You should have received a copy of the GNU General Public License
2727
namespace Shabby;
2828

2929
[HarmonyPatch(typeof(PartLoader), "SetPartIconMaterials")]
30-
internal class SetPartIconMaterialsPatch
30+
internal class PartLoader_SetPartIconMaterials_Patch
3131
{
32-
private static MethodInfo mInfo_ShaderFind =
32+
private static readonly MethodInfo mInfo_ShaderFind =
3333
AccessTools.Method(typeof(Shader), nameof(Shader.Find));
3434

35-
private static MethodInfo mInfo_FindOverrideIconShader =
36-
AccessTools.Method(typeof(SetPartIconMaterialsPatch), nameof(FindOverrideIconShader));
35+
private static readonly MethodInfo mInfo_FindOverrideIconShader = AccessTools.Method(
36+
typeof(PartLoader_SetPartIconMaterials_Patch), nameof(FindOverrideIconShader));
3737

38-
private static Shader FindOverrideIconShader(Material material) =>
39-
Shabby.TryFindIconShader(material.shader.name) ?? Shabby.FindShader("KSP/ScreenSpaceMask");
38+
private static Shader FindOverrideIconShader(Material material)
39+
{
40+
var iconShader = Shabby.TryFindIconShader(material.shader.name);
41+
if (iconShader != null)
42+
return iconShader;
43+
return Shabby.FindShader("KSP/ScreenSpaceMask");
44+
}
4045

4146
/// <summary>
4247
/// The stock method iterates through every material in the icon prefab and replaces some
@@ -87,7 +92,7 @@ private static IEnumerable<CodeInstruction> Transpiler(
8792
}
8893

8994
[HarmonyPatch(TargetType, "GetIconShader")]
90-
internal class KSPCFGetIconShaderPatch
95+
internal class KSPCF_PartParsingPerf_GetIconShader_Patch
9196
{
9297
private const string TargetType = "KSPCommunityFixes.Performance.PartParsingPerf";
9398

@@ -99,4 +104,4 @@ private static void Postfix(string materialShaderName, ref Shader __result)
99104
if (Shabby.TryFindIconShader(materialShaderName) is not Shader iconShader) return;
100105
__result = iconShader;
101106
}
102-
}
107+
}

Source/MaterialDef.cs renamed to Source/MaterialReplacement/MaterialDef.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,10 @@ public class MaterialDef : ILogContextProvider
6565

6666
public readonly bool isValid = true;
6767

68-
internal readonly string logPrefix;
69-
7068
public MaterialDef(ConfigNode node)
7169
{
7270
ConfigNode.LoadObjectFromConfig(this, node);
7371

74-
logPrefix = $"[Shabby][MaterialDef {name}] ";
75-
7672
if (shaderName != null) {
7773
shader = Shabby.FindShader(shaderName);
7874
if (shader == null) {
@@ -90,7 +86,7 @@ public MaterialDef(ConfigNode node)
9086
floats = LoadDictionary<float>(node, "FLOAT");
9187
colors = LoadDictionary<Color>(
9288
node, "COLOR",
93-
value => ParseColor(value, out var color) ? (object)color : null);
89+
value => ParseColor(value, out var color) ? color : null);
9490
vectors = LoadDictionary<Vector4>(node, "VECTOR");
9591
textures = LoadDictionary<Texture>(
9692
node, "TEXTURE",
@@ -114,8 +110,7 @@ private Dictionary<string, T> LoadDictionary<T>(ConfigNode defNode, string propK
114110
if (value is T parsed) {
115111
items[item.name] = parsed;
116112
} else {
117-
this.LogError(
118-
$"failed to load {propKind} property {item.name} = {item.value}");
113+
this.LogError($"failed to load {propKind} property {item.name} = {item.value}");
119114
}
120115
}
121116

@@ -130,10 +125,10 @@ public static bool ParseColor(string value, out Color color)
130125
return false;
131126
}
132127

133-
private static bool CheckProperty(Material mat, string propName)
128+
private bool CheckProperty(Material mat, string propName)
134129
{
135130
var exists = mat.HasProperty(propName);
136-
if (!exists) Log.Warning($"shader {mat.shader.name} does not have property {propName}");
131+
if (!exists) this.LogWarning($"shader {mat.shader.name} does not have property {propName}");
137132
return exists;
138133
}
139134

@@ -182,8 +177,5 @@ public Material Instantiate(Material referenceMaterial)
182177
return material;
183178
}
184179

185-
public string context()
186-
{
187-
return name;
188-
}
189-
}
180+
public string context() => $"MaterialDef {name}";
181+
}
File renamed without changes.
File renamed without changes.

Source/ShabLoader.cs renamed to Source/ShabBundleLoader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ You should have received a copy of the GNU General Public License
2323

2424
namespace Shabby;
2525

26-
[DatabaseLoaderAttrib(new string[] { "shab" })]
26+
[DatabaseLoaderAttrib(["shab"])]
2727
public class DatabaseLoaderTexture_SHAB : DatabaseLoader<GameDatabase.TextureInfo>
2828
{
2929
public override IEnumerator Load(UrlDir.UrlFile urlFile, FileInfo file)
3030
{
31-
Log.Message($"loading '{urlFile.fullPath}'");
31+
Log.Message($"loading `{urlFile.fullPath}`");
3232
var bundle = AssetBundle.LoadFromFile(urlFile.fullPath);
3333
if (!bundle) {
34-
Log.Warning($"could not load {urlFile.fullPath}");
34+
Log.Warning($"could not load `{urlFile.fullPath}`");
3535
} else {
3636
var shaders = bundle.LoadAllAssets<Shader>();
3737
foreach (var shader in shaders) {
38-
Log.Debug($"adding {shader.name}");
38+
Log.Debug($"adding custom shader `{shader.name}`");
3939
Shabby.AddShader(shader);
4040
}
4141
}

0 commit comments

Comments
 (0)