Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions Models/AbilityIdentifier.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
using System;
using System.Collections.Generic;
using DiskCardGame;
using UnityEngine;

namespace APIPlugin
{
public class AbilityIdentifier
{
private static List<AbilityIdentifier> ids = new List<AbilityIdentifier>();
private static List<AbilityIdentifier> ids = new();
private string guid;
private string name;
public Ability id;
private string name;
public Ability id;

private AbilityIdentifier(string guid, string name)
{
this.guid = guid;
this.name = name;
ids.Add(this);
ids.Add(this);
}

public static AbilityIdentifier GetAbilityIdentifier(string guid, string name)
{
if (ids.Exists((AbilityIdentifier x) => x.guid == guid && x.name == name))
{
return ids.Find((AbilityIdentifier x) => x.guid == guid && x.name == name);
}
else
{
return new AbilityIdentifier(guid, name);
}
}
public static AbilityIdentifier GetAbilityIdentifier(string guid, string name)
{
return ids.Exists(x => x.guid == guid && x.name == name)
? ids.Find(x => x.guid == guid && x.name == name)
: new AbilityIdentifier(guid, name);
}

public override String ToString()
public override string ToString()
{
return $"{this.guid}({this.name})";
return $"{guid}({name})";
}
}
}
}
65 changes: 46 additions & 19 deletions Models/CustomCard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using CardLoaderPlugin.lib;
using DiskCardGame;
using UnityEngine;
Expand All @@ -7,11 +8,12 @@ namespace APIPlugin
{
public class CustomCard
{
public static List<CustomCard> cards = new List<CustomCard>();
public static Dictionary<int,List<AbilityIdentifier>> abilityIds = new Dictionary<int,List<AbilityIdentifier>>();
public static Dictionary<int,EvolveIdentifier> evolveIds = new Dictionary<int,EvolveIdentifier>();
public static Dictionary<int,IceCubeIdentifier> iceCubeIds = new Dictionary<int,IceCubeIdentifier>();
public static Dictionary<int,TailIdentifier> tailIds = new Dictionary<int,TailIdentifier>();
public static List<CustomCard> cards = new();
public static Dictionary<int,List<AbilityIdentifier>> abilityIds = new();
public static Dictionary<int, List<SpecialAbilityIdentifier>> specialAbilityIds = new();
public static Dictionary<int,EvolveIdentifier> evolveIds = new();
public static Dictionary<int,IceCubeIdentifier> iceCubeIds = new();
public static Dictionary<int,TailIdentifier> tailIds = new();
public string name;
public List<CardMetaCategory> metaCategories;
public CardComplexity? cardComplexity;
Expand All @@ -28,8 +30,8 @@ public class CustomCard
public SpecialStatIcon? specialStatIcon;
public List<Tribe> tribes;
public List<Trait> traits;
public List<SpecialTriggeredAbility> specialAbilities;
public List<Ability> abilities;
public List<SpecialTriggeredAbility> specialAbilities = new();
public List<Ability> abilities = new();
public EvolveParams evolveParams;
public string defaultEvolutionName;
public TailParams tailParams;
Expand All @@ -51,32 +53,57 @@ public class CustomCard
public IceCubeIdentifier iceCubeId;
public TailIdentifier tailId;

public CustomCard(string name, List<AbilityIdentifier> abilityId=null, EvolveIdentifier evolveId=null, IceCubeIdentifier iceCubeId=null, TailIdentifier tailId=null)
public CustomCard(
string name,
List<AbilityIdentifier> abilityIdParam=null,
List<SpecialAbilityIdentifier> specialAbilityIdParam=null,
EvolveIdentifier evolveId=null,
IceCubeIdentifier iceCubeId=null,
TailIdentifier tailId=null)
{
this.name = name;
CustomCard.cards.Add(this);

// Handle AbilityIdentifier
List<AbilityIdentifier> toRemove = new List<AbilityIdentifier>();
if (this.abilityId is not null)
List<AbilityIdentifier> abilitiesToRemove = new List<AbilityIdentifier>();
if (abilityIdParam is not null)
{
foreach (AbilityIdentifier id in abilityId)
foreach (var id in abilityIdParam.Where(id => id.id != 0))
{
if (id.id != 0)
{
this.abilities.Add(id.id);
}
this.abilities.Add(id.id);
}
foreach (AbilityIdentifier id in toRemove)

foreach (AbilityIdentifier id in abilitiesToRemove)
{
this.abilityId.Remove(id);
abilityIdParam.Remove(id);
}

if (abilityIdParam.Count > 0)
{
CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityIdParam;
}
}
if (abilityId is not null && this.abilityId.Count > 0)

List<SpecialAbilityIdentifier> specialAbilitiesToRemove = new List<SpecialAbilityIdentifier>();
if (specialAbilityIdParam is not null)
{
CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityId;
foreach (var id in specialAbilityIdParam.Where(id => id.id != 0))
{
this.specialAbilities.Add(id.id);
}

foreach (SpecialAbilityIdentifier id in specialAbilitiesToRemove)
{
specialAbilityIdParam.Remove(id);
}

if (specialAbilityIdParam.Count > 0)
{
CustomCard.specialAbilityIds[CustomCard.cards.Count - 1] = specialAbilityIdParam;
}
}


// Handle EvolveIdentifier
if (evolveId is not null)
{
Expand Down
8 changes: 4 additions & 4 deletions Models/NewAbility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace APIPlugin
{
public class NewAbility
{
public static List<NewAbility> abilities = new List<NewAbility>();
public static List<NewAbility> abilities = new();
public Ability ability;
public AbilityInfo info;
public Type abilityBehaviour;
Expand All @@ -16,14 +16,14 @@ public class NewAbility

public NewAbility(AbilityInfo info, Type abilityBehaviour, Texture tex, AbilityIdentifier id = null)
{
this.ability = (Ability) 100 + NewAbility.abilities.Count;
info.ability = this.ability;
ability = (Ability) 100 + abilities.Count;
info.ability = ability;
this.info = info;
this.abilityBehaviour = abilityBehaviour;
tex.filterMode = FilterMode.Point;
this.tex = tex;
this.id = id;
NewAbility.abilities.Add(this);
abilities.Add(this);
if (id != null){
id.id = ability;
}
Expand Down
71 changes: 48 additions & 23 deletions Models/NewCard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using CardLoaderPlugin.lib;
using DiskCardGame;
using UnityEngine;
Expand All @@ -7,17 +8,21 @@ namespace APIPlugin
{
public static class NewCard
{
public static List<CardInfo> cards = new List<CardInfo>();
public static Dictionary<int,List<AbilityIdentifier>> abilityIds = new Dictionary<int,List<AbilityIdentifier>>();
public static Dictionary<int,EvolveIdentifier> evolveIds = new Dictionary<int,EvolveIdentifier>();
public static Dictionary<int,IceCubeIdentifier> iceCubeIds = new Dictionary<int,IceCubeIdentifier>();
public static Dictionary<int,TailIdentifier> tailIds = new Dictionary<int,TailIdentifier>();

public static void Add(CardInfo card, List<AbilityIdentifier> abilityIds = null, EvolveIdentifier evolveId = null,
public static List<CardInfo> cards = new();

public static Dictionary<int, List<AbilityIdentifier>> abilityIds = new();
public static Dictionary<int, List<SpecialAbilityIdentifier>> specialAbilityIds = new();
public static Dictionary<int, EvolveIdentifier> evolveIds = new();
public static Dictionary<int, IceCubeIdentifier> iceCubeIds = new();
public static Dictionary<int, TailIdentifier> tailIds = new();

public static void Add(CardInfo card, List<AbilityIdentifier> abilityIdsParam = null,
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam = null,
EvolveIdentifier evolveId = null,
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null)
{
NewCard.cards.Add(card);
handleIdentifiers(card, abilityIds, evolveId, iceCubeId, tailId);
HandleIdentifiers(card, abilityIdsParam, specialAbilitiesIdsParam, evolveId, iceCubeId, tailId);
Plugin.Log.LogInfo($"Loaded custom card {card.name}!");
}

Expand All @@ -30,7 +35,8 @@ public static void Add(string name, List<CardMetaCategory> metaCategories, CardC
bool hideAttackAndHealth = false, int cost = 0, int bonesCost = 0, int energyCost = 0,
List<GemType> gemsCost = null, SpecialStatIcon specialStatIcon = SpecialStatIcon.None,
List<Tribe> tribes = null, List<Trait> traits = null, List<SpecialTriggeredAbility> specialAbilities = null,
List<Ability> abilities = null, List<AbilityIdentifier> abilityIds = null, EvolveParams evolveParams = null,
List<Ability> abilities = null, List<AbilityIdentifier> abilityIdsParam = null,
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam = null, EvolveParams evolveParams = null,
string defaultEvolutionName = null, TailParams tailParams = null, IceCubeParams iceCubeParams = null,
bool flipPortraitForStrafe = false, bool onePerDeck = false,
List<CardAppearanceBehaviour.Appearance> appearanceBehaviour = null, Texture2D tex = null,
Expand Down Expand Up @@ -133,33 +139,51 @@ public static void Add(string name, List<CardMetaCategory> metaCategories, CardC

NewCard.cards.Add(card);

handleIdentifiers(card, abilityIds, evolveId, iceCubeId, tailId);
HandleIdentifiers(card, abilityIdsParam, specialAbilitiesIdsParam, evolveId, iceCubeId, tailId);

Plugin.Log.LogInfo($"Loaded custom card {name}!");
}

private static void handleIdentifiers(CardInfo card, List<AbilityIdentifier> abilityIds, EvolveIdentifier evolveId,
IceCubeIdentifier iceCubeId, TailIdentifier tailId)
private static void HandleIdentifiers(
CardInfo card,
List<AbilityIdentifier> abilityIdsParam,
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam,
EvolveIdentifier evolveId,
IceCubeIdentifier iceCubeId,
TailIdentifier tailId)
{
// Handle AbilityIdentifier
List<AbilityIdentifier> toRemove = new List<AbilityIdentifier>();
if (abilityIds is not null)
if (abilityIdsParam is not null)
{
foreach (AbilityIdentifier id in abilityIds)
foreach (var id in abilityIdsParam.Where(id => id.id != 0))
{
if (id.id != 0)
{
card.abilities.Add(id.id);
}
card.abilities.Add(id.id);
}

foreach (AbilityIdentifier id in toRemove)
{
abilityIds.Remove(id);
abilityIdsParam.Remove(id);
}

if (abilityIdsParam.Count > 0)
{
NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIdsParam;
}
}
if (abilityIds is not null && abilityIds.Count > 0)

// Handle SpecialAbilityIds
if (specialAbilitiesIdsParam is not null)
{
NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIds;
foreach (var id in specialAbilitiesIdsParam.Where(id => id.id != 0))
{
card.specialAbilities.Add(id.id);
}

if (specialAbilitiesIdsParam.Count > 0)
{
NewCard.specialAbilityIds[NewCard.cards.Count - 1] = specialAbilitiesIdsParam;
}
}

// Handle EvolveIdentifier
Expand Down Expand Up @@ -209,9 +233,10 @@ private static void DetermineAndSetCardArt(
pixelTex.name = newName;
pixelTex.filterMode = FilterMode.Point;

card.pixelPortrait = Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2);
card.pixelPortrait =
Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2);
card.pixelPortrait.name = newName;
}
}
}
}
}
61 changes: 61 additions & 0 deletions Models/NewSpecialAbility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using DiskCardGame;
using UnityEngine;

namespace APIPlugin
{
public class NewSpecialAbility
{
public static List<NewSpecialAbility> specialAbilities = new();
public SpecialTriggeredAbility specialTriggeredAbility;
public StatIconInfo statIconInfo;
public Type abilityBehaviour;
public SpecialAbilityIdentifier id;

public NewSpecialAbility(
Type abilityBehaviour,
SpecialAbilityIdentifier id,
StatIconInfo statIconInfo = null
)
{
specialTriggeredAbility = (SpecialTriggeredAbility)26 + specialAbilities.Count;
var logNameOrIdNumber = specialTriggeredAbility.ToString();
if (statIconInfo)
{
this.statIconInfo = statIconInfo;
HandleStatIconInfo(statIconInfo);
logNameOrIdNumber = this.statIconInfo.rulebookName;
}
this.abilityBehaviour = abilityBehaviour;
this.id = id;
id.id = specialTriggeredAbility;

HandleStatIconInfo(statIconInfo);

specialAbilities.Add(this);
Plugin.Log.LogInfo($"Loaded custom special ability [{logNameOrIdNumber}]!");
}

// is only called if StatIconInfo is not null
private static void HandleStatIconInfo(StatIconInfo statIconInfo)
{
statIconInfo.iconType = (SpecialStatIcon)8 + specialAbilities.Count;

if (statIconInfo.iconGraphic is not null)
{
// the reason for this is just one less step for the end user to setup
statIconInfo.iconGraphic.filterMode = FilterMode.Point;
}

// a lazy initializer
if (statIconInfo.metaCategories.Count == 0)
{
statIconInfo.metaCategories = new List<AbilityMetaCategory>
{
AbilityMetaCategory.Part1Modular, AbilityMetaCategory.Part1Rulebook
};
}
}
}
}
Loading