mlpcardgame/Scenes/Shared/CardList.gd

95 lines
2.1 KiB
GDScript3
Raw Normal View History

extends VBoxContainer
onready var blocks = {
"mane": $Mane,
"entry": $Entry,
"friend": $Friends,
"resource": $Resources,
"event": $Events,
"troublemaker": $Troublemakers,
"problem": $Problems
}
onready var labels = {
"mane": $ManeLabel,
"entry": $EntryLabel,
"friend": $FriendsLabel,
"resource": $ResourcesLabel,
"event": $EventsLabel,
"troublemaker": $TroublemakersLabel,
"problem": $ProblemsLabel
}
var CardListItem := preload("res://Scenes/Shared/CardList/CardListItem.tscn")
func add_card(cardID: String):
# Get card data from ID
var data := CardData.get_by_id(cardID)
var item := CardListItem.instance()
item.cardName = data.name
item.cardSubname = data.subname
item.showCost = has_cost(data.type)
item.cardCost = data.cost
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",
"Generosity": "white",
"Magic": "purple",
"Laughter": "pink",
"Kindness": "yellow",
"Honesty": "orange"
}
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():
0:
return "none"
1:
return newcol[0]
_:
var multistr := "multi|"
for col in newcol:
multistr += col+"+"
return multistr.trim_suffix("+")
func has_cost(type: String) -> bool:
match type:
"Friend", "Resource", "Event":
return true
_:
return false