Skip to content

Commit 5cc99a4

Browse files
Merge branch 'main' into feature/util_additions
2 parents 20037fa + 8d09d04 commit 5cc99a4

17 files changed

Lines changed: 424 additions & 96 deletions

Models/AbilityIdentifier.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
1-
using System;
21
using System.Collections.Generic;
32
using DiskCardGame;
4-
using UnityEngine;
53

64
namespace APIPlugin
75
{
86
public class AbilityIdentifier
97
{
10-
private static List<AbilityIdentifier> ids = new List<AbilityIdentifier>();
8+
private static List<AbilityIdentifier> ids = new();
119
private string guid;
12-
private string name;
13-
public Ability id;
10+
private string name;
11+
public Ability id;
1412

1513
private AbilityIdentifier(string guid, string name)
1614
{
1715
this.guid = guid;
1816
this.name = name;
19-
ids.Add(this);
17+
ids.Add(this);
2018
}
2119

22-
public static AbilityIdentifier GetAbilityIdentifier(string guid, string name)
23-
{
24-
if (ids.Exists((AbilityIdentifier x) => x.guid == guid && x.name == name))
25-
{
26-
return ids.Find((AbilityIdentifier x) => x.guid == guid && x.name == name);
27-
}
28-
else
29-
{
30-
return new AbilityIdentifier(guid, name);
31-
}
32-
}
20+
public static AbilityIdentifier GetAbilityIdentifier(string guid, string name)
21+
{
22+
return ids.Exists(x => x.guid == guid && x.name == name)
23+
? ids.Find(x => x.guid == guid && x.name == name)
24+
: new AbilityIdentifier(guid, name);
25+
}
3326

34-
public override String ToString()
27+
public override string ToString()
3528
{
36-
return $"{this.guid}({this.name})";
29+
return $"{guid}({name})";
3730
}
3831
}
39-
}
32+
}

Models/CustomCard.cs

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
using System.Collections.Generic;
2+
using System.Linq;
3+
using CardLoaderPlugin.lib;
24
using DiskCardGame;
35
using UnityEngine;
46

57
namespace APIPlugin
68
{
79
public class CustomCard
810
{
9-
public static List<CustomCard> cards = new List<CustomCard>();
10-
11-
public static Dictionary<int, List<AbilityIdentifier>> abilityIds = new();
12-
public static Dictionary<int, EvolveIdentifier> evolveIds = new();
13-
public static Dictionary<int, IceCubeIdentifier> iceCubeIds = new();
14-
public static Dictionary<int, TailIdentifier> tailIds = new();
15-
11+
public static List<CustomCard> cards = new();
12+
13+
public static Dictionary<int,List<AbilityIdentifier>> abilityIds = new();
14+
public static Dictionary<int, List<SpecialAbilityIdentifier>> specialAbilityIds = new();
15+
public static Dictionary<int,EvolveIdentifier> evolveIds = new();
16+
public static Dictionary<int,IceCubeIdentifier> iceCubeIds = new();
17+
public static Dictionary<int,TailIdentifier> tailIds = new();
1618
public string name;
1719
public List<CardMetaCategory> metaCategories;
1820
public CardComplexity? cardComplexity;
@@ -29,7 +31,7 @@ public class CustomCard
2931
public SpecialStatIcon? specialStatIcon;
3032
public List<Tribe> tribes;
3133
public List<Trait> traits;
32-
public List<SpecialTriggeredAbility> specialAbilities;
34+
public List<SpecialTriggeredAbility> specialAbilities = new();
3335
public List<Ability> abilities = new();
3436
public EvolveParams evolveParams;
3537
public string defaultEvolutionName;
@@ -49,36 +51,59 @@ public class CustomCard
4951
public IceCubeIdentifier iceCubeId;
5052
public TailIdentifier tailId;
5153

52-
public CustomCard(string name, List<AbilityIdentifier> abilityIdListParam = null,
53-
EvolveIdentifier evolveId = null,
54-
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null)
54+
public CustomCard(
55+
string name,
56+
List<AbilityIdentifier> abilityIdParam=null,
57+
List<SpecialAbilityIdentifier> specialAbilityIdParam=null,
58+
EvolveIdentifier evolveId=null,
59+
IceCubeIdentifier iceCubeId=null,
60+
TailIdentifier tailId=null)
5561
{
5662
this.name = name;
5763
CustomCard.cards.Add(this);
5864

5965
// Handle AbilityIdentifier
60-
List<AbilityIdentifier> toRemove = new List<AbilityIdentifier>();
61-
if (abilityIdListParam is not null)
66+
List<AbilityIdentifier> abilitiesToRemove = new List<AbilityIdentifier>();
67+
if (abilityIdParam is not null)
6268
{
63-
foreach (AbilityIdentifier id in abilityIdListParam)
69+
foreach (var id in abilityIdParam.Where(id => id.id != 0))
6470
{
65-
if (id.id != 0)
66-
{
67-
this.abilities.Add(id.id);
68-
}
71+
this.abilities.Add(id.id);
72+
abilitiesToRemove.Add(id);
6973
}
70-
71-
foreach (AbilityIdentifier id in toRemove)
74+
75+
foreach (AbilityIdentifier id in abilitiesToRemove)
7276
{
73-
this.abilityIdList.Remove(id);
77+
abilityIdParam.Remove(id);
78+
}
79+
80+
if (abilityIdParam.Count > 0)
81+
{
82+
CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityIdParam;
7483
}
7584
}
7685

77-
if (abilityIdListParam is not null && this.abilityIdList.Count > 0)
86+
List<SpecialAbilityIdentifier> specialAbilitiesToRemove = new List<SpecialAbilityIdentifier>();
87+
if (specialAbilityIdParam is not null)
7888
{
79-
CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityIdListParam;
89+
foreach (var id in specialAbilityIdParam.Where(id => id.id != 0))
90+
{
91+
this.specialAbilities.Add(id.id);
92+
specialAbilitiesToRemove.Add(id);
93+
}
94+
95+
foreach (SpecialAbilityIdentifier id in specialAbilitiesToRemove)
96+
{
97+
specialAbilityIdParam.Remove(id);
98+
}
99+
100+
if (specialAbilityIdParam.Count > 0)
101+
{
102+
CustomCard.specialAbilityIds[CustomCard.cards.Count - 1] = specialAbilityIdParam;
103+
}
80104
}
81105

106+
82107
// Handle EvolveIdentifier
83108
if (evolveId is not null)
84109
{

Models/EvolveIdentifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private void SetParams(CardInfo card)
4343

4444
evolution.turnsToEvolve = this.turnsToEvolve;
4545

46-
evolution.evolution = CardLoader.Clone(card);
46+
evolution.evolution = card;
4747

4848
if (this.mods != null)
4949
{

Models/IceCubeIdentifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private void SetParams(CardInfo card)
3939
{
4040
IceCubeParams iceCube = new IceCubeParams();
4141

42-
iceCube.creatureWithin = CardLoader.Clone(card);
42+
iceCube.creatureWithin = card;
4343

4444
if (this.mods != null)
4545
{

Models/NewAbility.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace APIPlugin
77
{
88
public class NewAbility
99
{
10-
public static List<NewAbility> abilities = new List<NewAbility>();
10+
public static List<NewAbility> abilities = new();
1111
public Ability ability;
1212
public AbilityInfo info;
1313
public Type abilityBehaviour;
@@ -16,14 +16,14 @@ public class NewAbility
1616

1717
public NewAbility(AbilityInfo info, Type abilityBehaviour, Texture tex, AbilityIdentifier id = null)
1818
{
19-
this.ability = (Ability) 100 + NewAbility.abilities.Count;
20-
info.ability = this.ability;
19+
ability = (Ability) 100 + abilities.Count;
20+
info.ability = ability;
2121
this.info = info;
2222
this.abilityBehaviour = abilityBehaviour;
2323
tex.filterMode = FilterMode.Point;
2424
this.tex = tex;
2525
this.id = id;
26-
NewAbility.abilities.Add(this);
26+
abilities.Add(this);
2727
if (id != null){
2828
id.id = ability;
2929
}

Models/NewCard.cs

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
using System.Collections.Generic;
2+
using System.Linq;
3+
using CardLoaderPlugin.lib;
24
using DiskCardGame;
35
using UnityEngine;
46

57
namespace APIPlugin
68
{
79
public static class NewCard
810
{
9-
public static List<CardInfo> cards = new List<CardInfo>();
11+
public static List<CardInfo> cards = new();
1012

1113
public static Dictionary<int, List<AbilityIdentifier>> abilityIds = new();
14+
public static Dictionary<int, List<SpecialAbilityIdentifier>> specialAbilityIds = new();
1215
public static Dictionary<int, EvolveIdentifier> evolveIds = new();
1316
public static Dictionary<int, IceCubeIdentifier> iceCubeIds = new();
1417
public static Dictionary<int, TailIdentifier> tailIds = new();
15-
18+
1619
public static void Add(CardInfo card, List<AbilityIdentifier> abilityIdsParam = null,
17-
EvolveIdentifier evolveId = null, IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null
18-
)
20+
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam = null,
21+
EvolveIdentifier evolveId = null,
22+
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null)
1923
{
2024
NewCard.cards.Add(card);
21-
handleIdentifiers(abilityIdsParam, evolveId, iceCubeId, tailId);
25+
HandleIdentifiers(card, abilityIdsParam, specialAbilitiesIdsParam, evolveId, iceCubeId, tailId);
2226
Plugin.Log.LogInfo($"Loaded custom card {card.name}!");
2327
}
2428

@@ -32,8 +36,8 @@ public static void Add(string name, string displayedName, int baseAttack, int ba
3236
int bloodCost = 0, int bonesCost = 0, int energyCost = 0,
3337
List<GemType> gemsCost = null, SpecialStatIcon specialStatIcon = SpecialStatIcon.None,
3438
List<Tribe> tribes = null, List<Trait> traits = null, List<SpecialTriggeredAbility> specialAbilities = null,
35-
List<Ability> abilities = null, List<AbilityIdentifier> abilityIdsParam = null,
36-
EvolveParams evolveParams = null,
39+
List<Ability> abilities = null, List<AbilityIdentifier> abilityIdsParam = null,
40+
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam = null, EvolveParams evolveParams = null,
3741
string defaultEvolutionName = null, TailParams tailParams = null, IceCubeParams iceCubeParams = null,
3842
bool flipPortraitForStrafe = false, bool onePerDeck = false,
3943
List<CardAppearanceBehaviour.Appearance> appearanceBehaviour = null, Texture2D defaultTex = null,
@@ -134,28 +138,60 @@ public static void Add(string name, string displayedName, int baseAttack, int ba
134138
card.titleGraphic = titleGraphic;
135139
}
136140

137-
NewCard.Add(card, abilityIdsParam, evolveId, iceCubeId, tailId);
141+
NewCard.cards.Add(card);
142+
143+
HandleIdentifiers(card, abilityIdsParam, specialAbilitiesIdsParam, evolveId, iceCubeId, tailId);
144+
145+
Plugin.Log.LogInfo($"Loaded custom card {name}!");
138146
}
139147

140-
private static void handleIdentifiers(
141-
List<AbilityIdentifier> abilityIdsParam = null, EvolveIdentifier evolveId = null,
142-
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null
143-
)
148+
private static void HandleIdentifiers(
149+
CardInfo card,
150+
List<AbilityIdentifier> abilityIdsParam,
151+
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam,
152+
EvolveIdentifier evolveId,
153+
IceCubeIdentifier iceCubeId,
154+
TailIdentifier tailId)
144155
{
145-
List<AbilityIdentifier> toRemove = new List<AbilityIdentifier>();
156+
List<AbilityIdentifier> abilitiesToRemove = new List<AbilityIdentifier>();
146157
if (abilityIdsParam is not null)
147158
{
148-
foreach (AbilityIdentifier id in toRemove)
159+
foreach (var id in abilityIdsParam.Where(id => id.id != 0))
160+
{
161+
card.abilities.Add(id.id);
162+
abilitiesToRemove.Add(id);
163+
}
164+
165+
foreach (AbilityIdentifier id in abilitiesToRemove)
149166
{
150167
abilityIdsParam.Remove(id);
151168
}
169+
170+
if (abilityIdsParam.Count > 0)
171+
{
172+
NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIdsParam;
173+
}
152174
}
153175

154-
// Handle AbilityIdentifier
155-
156-
if (abilityIdsParam is not null && abilityIdsParam.Count > 0)
176+
// Handle SpecialAbilityIds
177+
List<SpecialAbilityIdentifier> specialAbilitiesToRemove = new List<AbilityIdentifier>();
178+
if (specialAbilitiesIdsParam is not null)
157179
{
158-
NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIdsParam;
180+
foreach (var id in specialAbilitiesIdsParam.Where(id => id.id != 0))
181+
{
182+
card.specialAbilities.Add(id.id);
183+
specialAbilitiesToRemove.Add(id);
184+
}
185+
186+
foreach (SpecialAbilityIdentifier id in specialAbilitiesToRemove)
187+
{
188+
specialAbilitiesIdsParam.Remove(id);
189+
}
190+
191+
if (specialAbilitiesIdsParam.Count > 0)
192+
{
193+
NewCard.specialAbilityIds[NewCard.cards.Count - 1] = specialAbilitiesIdsParam;
194+
}
159195
}
160196

161197
// Handle EvolveIdentifier

Models/NewSpecialAbility.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using DiskCardGame;
4+
using UnityEngine;
5+
6+
namespace APIPlugin
7+
{
8+
public class NewSpecialAbility
9+
{
10+
public static List<NewSpecialAbility> specialAbilities = new();
11+
public SpecialTriggeredAbility specialTriggeredAbility;
12+
public StatIconInfo statIconInfo;
13+
public Type abilityBehaviour;
14+
public SpecialAbilityIdentifier id;
15+
16+
public NewSpecialAbility(
17+
Type abilityBehaviour,
18+
SpecialAbilityIdentifier id,
19+
StatIconInfo statIconInfo = null
20+
)
21+
{
22+
specialTriggeredAbility = (SpecialTriggeredAbility)26 + specialAbilities.Count;
23+
var logNameOrIdNumber = specialTriggeredAbility.ToString();
24+
if (statIconInfo)
25+
{
26+
this.statIconInfo = statIconInfo;
27+
HandleStatIconInfo(statIconInfo);
28+
logNameOrIdNumber = this.statIconInfo.rulebookName;
29+
}
30+
this.abilityBehaviour = abilityBehaviour;
31+
this.id = id;
32+
id.id = specialTriggeredAbility;
33+
34+
HandleStatIconInfo(statIconInfo);
35+
36+
specialAbilities.Add(this);
37+
Plugin.Log.LogInfo($"Loaded custom special ability [{logNameOrIdNumber}]!");
38+
}
39+
40+
// is only called if StatIconInfo is not null
41+
private static void HandleStatIconInfo(StatIconInfo statIconInfo)
42+
{
43+
statIconInfo.iconType = (SpecialStatIcon)8 + specialAbilities.Count;
44+
45+
if (statIconInfo.iconGraphic is not null)
46+
{
47+
// the reason for this is just one less step for the end user to setup
48+
statIconInfo.iconGraphic.filterMode = FilterMode.Point;
49+
}
50+
51+
// a lazy initializer
52+
if (statIconInfo.metaCategories.Count == 0)
53+
{
54+
statIconInfo.metaCategories = new List<AbilityMetaCategory>
55+
{
56+
AbilityMetaCategory.Part1Modular, AbilityMetaCategory.Part1Rulebook
57+
};
58+
}
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)