Skip to content

Commit bb23cb7

Browse files
committed
Added CardUtils for commonly used pieces of static code.
1 parent 228e05d commit bb23cb7

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

Models/CustomCard.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using CardLoaderPlugin.lib;
23
using DiskCardGame;
34
using UnityEngine;
45

@@ -56,21 +57,21 @@ public CardInfo AdjustCard(CardInfo card)
5657
{
5758
tex.name = "portrait_" + name;
5859
tex.filterMode = FilterMode.Point;
59-
card.portraitTex = Sprite.Create(tex, new Rect(0.0f, 0.0f, 114.0f, 94.0f), new Vector2(0.5f, 0.5f));
60+
card.portraitTex = Sprite.Create(tex, CardUtils.DefaultCardArtRect, CardUtils.DefaultVector2);
6061
card.portraitTex.name = "portrait_" + name;
6162
}
6263
if (this.altTex is not null)
6364
{
6465
altTex.name = "portrait_" + name;
6566
altTex.filterMode = FilterMode.Point;
66-
card.alternatePortrait = Sprite.Create(altTex, new Rect(0.0f, 0.0f, 114.0f, 94.0f), new Vector2(0.5f, 0.5f));
67+
card.alternatePortrait = Sprite.Create(altTex, CardUtils.DefaultCardArtRect, CardUtils.DefaultVector2);
6768
card.alternatePortrait.name = "portrait_" + name;
6869
}
6970
if (this.pixelTex is not null)
7071
{
7172
pixelTex.name = "portrait_" + name;
7273
pixelTex.filterMode = FilterMode.Point;
73-
card.pixelPortrait = Sprite.Create(pixelTex, new Rect(0.0f, 0.0f, 41.0f, 28.0f), new Vector2(0.5f, 0.5f));
74+
card.pixelPortrait = Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2);
7475
card.pixelPortrait.name = "portrait_" + name;
7576
}
7677
Plugin.Log.LogInfo($"Adjusted default card {name}!");

Models/NewCard.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using CardLoaderPlugin.lib;
23
using DiskCardGame;
34
using UnityEngine;
45

@@ -7,9 +8,6 @@ namespace APIPlugin
78
public static class NewCard
89
{
910
public static List<CardInfo> cards = new List<CardInfo>();
10-
private static readonly Vector2 DefaultVector2 = new Vector2(0.5f, 0.5f);
11-
private static readonly Rect DefaultCardArtRect = new Rect(0.0f, 0.0f, 114.0f, 94.0f);
12-
private static readonly Rect DefaultCardPixelArtRect = new Rect(0.0f, 0.0f, 41.0f, 28.0f);
1311

1412
public static void Add(CardInfo card)
1513
{
@@ -140,7 +138,7 @@ private static void DetermineAndSetCardArt(
140138
tex.name = newName;
141139
tex.filterMode = FilterMode.Point;
142140

143-
card.portraitTex = Sprite.Create(tex, DefaultCardArtRect, DefaultVector2);
141+
card.portraitTex = Sprite.Create(tex, CardUtils.DefaultCardArtRect, CardUtils.DefaultVector2);
144142
card.portraitTex.name = newName;
145143
}
146144

@@ -149,7 +147,7 @@ private static void DetermineAndSetCardArt(
149147
altTex.name = newName;
150148
altTex.filterMode = FilterMode.Point;
151149

152-
card.alternatePortrait = Sprite.Create(altTex, DefaultCardArtRect, DefaultVector2);
150+
card.alternatePortrait = Sprite.Create(altTex, CardUtils.DefaultCardArtRect, CardUtils.DefaultVector2);
153151
card.alternatePortrait.name = newName;
154152
}
155153

@@ -158,7 +156,7 @@ private static void DetermineAndSetCardArt(
158156
pixelTex.name = newName;
159157
pixelTex.filterMode = FilterMode.Point;
160158

161-
card.pixelPortrait = Sprite.Create(pixelTex, DefaultCardPixelArtRect, DefaultVector2);
159+
card.pixelPortrait = Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2);
162160
card.pixelPortrait.name = newName;
163161
}
164162
}

Utils/CardUtils.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using DiskCardGame;
4+
using UnityEngine;
5+
6+
namespace CardLoaderPlugin.lib
7+
{
8+
public class CardUtils
9+
{
10+
11+
public static readonly Vector2 DefaultVector2 = new Vector2(0.5f, 0.5f);
12+
public static readonly Rect DefaultCardArtRect = new Rect(0.0f, 0.0f, 114.0f, 94.0f);
13+
public static readonly Rect DefaultCardPixelArtRect = new Rect(0.0f, 0.0f, 41.0f, 28.0f);
14+
15+
public static List<CardAppearanceBehaviour.Appearance> getRareAppearance =
16+
new List<CardAppearanceBehaviour.Appearance>() { CardAppearanceBehaviour.Appearance.RareCardBackground };
17+
18+
public static List<CardMetaCategory> getNormalCardMetadata = new List<CardMetaCategory>()
19+
{ CardMetaCategory.ChoiceNode };
20+
21+
public static List<CardMetaCategory> getRareCardMetadata = new List<CardMetaCategory>()
22+
{ CardMetaCategory.ChoiceNode, CardMetaCategory.Rare };
23+
24+
public static Texture2D loadImage(string pathCardArt)
25+
{
26+
if (!System.IO.File.Exists(pathCardArt))
27+
{
28+
throw new Exception($"Unable to find image for {pathCardArt}");
29+
}
30+
else
31+
{
32+
Texture2D texture = new Texture2D(2, 2);
33+
byte[] imgBytes = System.IO.File.ReadAllBytes(pathCardArt);
34+
bool isLoaded = texture.LoadImage(imgBytes);
35+
return texture;
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)