From d4fff245bcd0106ff0aa800140814f49ced5aff9 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Sat, 29 Jun 2019 14:06:55 +0200 Subject: [PATCH] Add cards to proper categories, fix problem colors --- Classes/CardInfo.gd | 42 +++++++++++++++++++++++++++++++++++++++ Scenes/Global/CardData.gd | 40 ------------------------------------- Scenes/Shared/CardList.gd | 33 ++++++++++++++++++++++++++++-- project.godot | 6 ++++++ 4 files changed, 79 insertions(+), 42 deletions(-) create mode 100644 Classes/CardInfo.gd diff --git a/Classes/CardInfo.gd b/Classes/CardInfo.gd new file mode 100644 index 0000000..349a9ee --- /dev/null +++ b/Classes/CardInfo.gd @@ -0,0 +1,42 @@ +extends Object + +class_name CardInfo + +var id := "unknown" +var name := "Unknown card" +var subname := "--" +var colors := [] +var keywords := [] +var traits := [] +var requirements := {} +var cost := 0 +var power := 0 +var type := "None" +var text := "This card does not exist, if you see it it's because something failed loading" +var rarity := "UR" +var bonus := 0 +var opponentPower := 0 + +func _init(cardEntry: Dictionary): + if not cardEntry.empty(): + id = cardEntry.ID + name = cardEntry.Name + subname = cardEntry.Subname + colors = cardEntry.Element + keywords = cardEntry.Keywords + traits = cardEntry.Traits + type = cardEntry.Type + text = cardEntry.Text + rarity = cardEntry.Rarity + if cardEntry.has("Power"): + power = cardEntry.Power + if cardEntry.has("Cost"): + cost = cardEntry.Cost + if cardEntry.has("ProblemBonus"): + bonus = cardEntry.ProblemBonus + if cardEntry.has("Requirement"): + requirements = cardEntry.Requirement + elif cardEntry.has("ProblemRequirement"): + requirements = cardEntry.ProblemRequirement + if cardEntry.has("ProblemOpponentPower"): + opponentPower = cardEntry.ProblemOpponentPower \ No newline at end of file diff --git a/Scenes/Global/CardData.gd b/Scenes/Global/CardData.gd index cf7a706..167e8b6 100644 --- a/Scenes/Global/CardData.gd +++ b/Scenes/Global/CardData.gd @@ -3,46 +3,6 @@ extends Node var loadedSets := {} var loadedCards := {} -class CardInfo: - var id := "unknown" - var name := "Unknown card" - var subname := "--" - var colors := [] - var keywords := [] - var traits := [] - var requirements := {} - var cost := 0 - var power := 0 - var type := "None" - var text := "This card does not exist, if you see it it's because something failed loading" - var rarity := "UR" - var bonus := 0 - var opponentPower := 0 - - func _init(cardEntry: Dictionary): - if not cardEntry.empty(): - id = cardEntry.ID - name = cardEntry.Name - subname = cardEntry.Subname - colors = cardEntry.Element - keywords = cardEntry.Keywords - traits = cardEntry.Traits - type = cardEntry.Type - text = cardEntry.Text - rarity = cardEntry.Rarity - if cardEntry.has("Power"): - power = cardEntry.Power - if cardEntry.has("Cost"): - cost = cardEntry.Cost - if cardEntry.has("ProblemBonus"): - bonus = cardEntry.ProblemBonus - if cardEntry.has("Requirement"): - requirements = cardEntry.Requirement - elif cardEntry.has("ProblemRequirement"): - requirements = cardEntry.ProblemRequirement - if cardEntry.has("ProblemOpponentPower"): - opponentPower = cardEntry.ProblemOpponentPower - func _ready(): # Search for sets in MLPData var dir := Directory.new() diff --git a/Scenes/Shared/CardList.gd b/Scenes/Shared/CardList.gd index 2bf1e7b..e6a4364 100644 --- a/Scenes/Shared/CardList.gd +++ b/Scenes/Shared/CardList.gd @@ -30,8 +30,36 @@ func add_card(cardID: String): item.cardSubname = data.subname item.showCost = has_cost(data.type) item.cardCost = data.cost - item.color = to_color_ids(data.colors) - blocks["entry"].add_child(item) + if data.type == "Problem": + item.color = to_color_ids(data.requirements.keys()) + else: + item.color = to_color_ids(data.colors) + var cat := get_card_group(data) + add_to_card_group(cat, item) + +func get_card_group(item: CardInfo) -> String: + match item.type: + "Friend": + # Entry if req is 0, friend otherwise + if item.requirements.size() < 1: + return "entry" + return "friend" + "Event": + #TODO some events are entry (color-fixing) + return "event" + "Resource": + #TODO some resources are entry (color-fixing) + return "resource" + "Troublemaker": + return "troublemaker" + "Problem": + return "problem" + "Mane Character": + return "mane" + +func add_to_card_group(cat: String, item: Node): + blocks[cat].add_child(item) + labels[cat].visible = true var colorTable = { "Loyalty": "blue", @@ -45,6 +73,7 @@ var colorTable = { func to_color_ids(ogcolors: Array) -> String: var newcol := [] for ogcol in ogcolors: + ogcol = (ogcol as String).trim_prefix("Not ") if colorTable.has(ogcol): newcol.push_back(colorTable[ogcol]) match newcol.size(): diff --git a/project.godot b/project.godot index 5fa1d5e..912be54 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://Scenes/Board/Card.gd" }, { +"base": "Object", +"class": "CardInfo", +"language": "GDScript", +"path": "res://Classes/CardInfo.gd" +}, { "base": "Reference", "class": "Resources", "language": "GDScript", @@ -37,6 +42,7 @@ _global_script_classes=[ { _global_script_class_icons={ "Board": "", "Card": "", +"CardInfo": "", "Resources": "", "ScatterCard": "", "Stack": ""