Skip to content

Commit

Permalink
Actually add check for .png files
Browse files Browse the repository at this point in the history
  • Loading branch information
MADH95 committed Nov 12, 2021
1 parent 20265b5 commit c760fea
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Code/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Plugin : BaseUnityPlugin
{
private const string PluginGuid = "MADH.inscryption.JSONCardLoader";
private const string PluginName = "JSONCardLoader";
private const string PluginVersion = "1.3.9.0";
private const string PluginVersion = "1.3.10.0";

internal static ManualLogSource Log;

Expand Down
12 changes: 8 additions & 4 deletions Code/Utils/JLUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ private record struct AbilityData( EvolveData evolveData, TailData tailData, Ice

private static readonly Dictionary< string, AbilityData > cardsWithParams = new();

private static bool ValidateTexture( string texture )
=> TryLog( () => texture.Substring( texture.Length - 4 ) is not ".png" ? throw new Exception() : true, $"\"{ texture }\" is not a .png file" );


private static Texture2D LoadTexture2D( string image )
=> !string.IsNullOrEmpty( image ) && ValidateTexture( image ) ? new Texture2D( 2, 2 ).WithImage( image ) : null;

private static T TryLog<T>( Func<T> func, string message )
{
try
Expand All @@ -30,9 +37,6 @@ private static T TryLog<T>( Func<T> func, string message )
return default;
}

private static Texture2D LoadTexture2D( string image )
=> String.IsNullOrEmpty( image ) && TryLog( () => image.Substring(image.Length - 4) is not ".png", $"\"{ image }\" must be a .png file" ) ? null : new Texture2D( 2, 2 ).WithImage( image );

#region Assignment Helpers

private static string Message( string cardName, string value, string field )
Expand All @@ -46,7 +50,7 @@ public static T Assign<T>( CardData card, string fieldData, string fieldName, Di
=> string.IsNullOrEmpty( fieldData ) ? default : TryLog( () => dict[ fieldData ], Message( card.name, fieldData, fieldName ) );

public static Texture2D Assign( CardData card, string fieldData, string fieldName )
=> string.IsNullOrEmpty( fieldData ) ? null : TryLog( () => LoadTexture2D( fieldData ), Message( card.name, fieldData, fieldName ) );
=> TryLog( () => LoadTexture2D( fieldData ), Message( card.name, fieldData, fieldName ) );

public static List<Texture> Assign( CardData card, List<string> fieldData, string fieldName )
=> fieldData?.Select( elem => TryLog( () => ( Texture ) LoadTexture2D( elem ), Message( card.name, elem, fieldName ) ) ).ToList();
Expand Down
Binary file modified JSONLoader/JSONLoader.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JSONCardLoader",
"version_number": "1.3.10",
"version_number": "1.3.11",
"website_url": "https://github.com/MADH95/JSONCardLoaderPlugin",
"description": "This is a BepInEx plugin made for Incryption to create custom cards using JSON files and the API by Cyantist. It can currently parse custom cards and pass them to APIPlugin to load them into the game.",
"dependencies": [
Expand Down

0 comments on commit c760fea

Please sign in to comment.