Skip to content

Commit

Permalink
Naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmylo committed Jun 8, 2023
1 parent 2b04ad7 commit 9f380e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
bin/
obj/
.vs/
.idea/
.idea/
*.dll
*.pdb
*.cache
26 changes: 16 additions & 10 deletions TavernAICardLib/TavernAiCard.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand All @@ -9,7 +9,7 @@ namespace TavernAICardLib;

public class TavernAiCard
{
public Image image;
public Image? Image;


// Card Fields:
Expand All @@ -29,22 +29,24 @@ public class TavernAiCard
[JsonInclude] [JsonPropertyName("system_prompt")] public string? SystemPrompt { get; set; }
[JsonInclude] [JsonPropertyName("tags")] public List<string>? Tags { get; set; }

public TavernAiCard(Image image)
public TavernAiCard(Image? image)
{
this.image = image;
this.Image = image;
}

public static string[] FileTypes = {".png", ".webp", ".jpg", ".jpeg"};

private static Dictionary<string[], CardLoader> FilePathEndsWith = new Dictionary<string[], CardLoader>()
private static Dictionary<string[], CardLoader> _filePathEndsWith = new()
{
{new []{".png", ".webp", ".jpg", ".jpeg"}, new ImageCardLoader()},
{FileTypes, new ImageCardLoader()},
};

public static TavernAiCard? Load(string filePath)
{
foreach (var key in FilePathEndsWith.Keys)
foreach (var key in _filePathEndsWith.Keys)
foreach (var end in key)
if (filePath.ToLower().EndsWith(end))
return FilePathEndsWith[key].Load(filePath);
return _filePathEndsWith[key].Load(filePath);

return null;
}
Expand All @@ -64,7 +66,11 @@ public class ImageCardLoader : CardLoader
{
public override TavernAiCard Load(string filePath)
{
Image image = new Bitmap(filePath);
Image? image = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
image = new Bitmap(filePath);
}
var directories = ImageMetadataReader.ReadMetadata(filePath);
foreach (var dir in directories)
{
Expand All @@ -80,7 +86,7 @@ public override TavernAiCard Load(string filePath)
});
if (card != null)
{
card.image = image;
card.Image = image;
return card;
}
}
Expand Down
4 changes: 3 additions & 1 deletion TavernAICardLibTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using TavernAICardLib;

TavernAiCard? card = TavernAiCard.Load("main_Raiden Shogun and Ei_tavern.png");
TavernAiCard? card = TavernAiCard.Load("main_Walter White_tavern.png");

if (card != null)
{
Console.WriteLine(card.Name);
card.Name = "Waltuh White";

}

0 comments on commit 9f380e9

Please sign in to comment.