35 lines
1 KiB
GDScript
35 lines
1 KiB
GDScript
extends Node
|
|
class_name DragonLibrary
|
|
|
|
|
|
var dragons: Array = []
|
|
|
|
var hat_outfits: DragonOutfit
|
|
var shirt_outfits: DragonOutfit
|
|
var shoes_outfits: DragonOutfit
|
|
|
|
|
|
func _init(hat_outfits: DragonOutfit, shirt_outfits: DragonOutfit, shoes_outfits: DragonOutfit) -> void:
|
|
self.hat_outfits = hat_outfits
|
|
self.shirt_outfits = shirt_outfits
|
|
self.shoes_outfits = shoes_outfits
|
|
|
|
|
|
func add_dragon(name: String, hat: Texture2D, shirt: Texture2D, shoes: Texture2D) -> int:
|
|
var hat_index: int = hat_outfits.get_index(hat)
|
|
var shirt_index: int = shirt_outfits.get_index(shirt)
|
|
var shoes_index: int = shoes_outfits.get_index(shoes)
|
|
var id: int = RandomNumberGenerator.new().randi()
|
|
_push_dragon(id, name, hat_index, shirt_index, shoes_index)
|
|
return id
|
|
|
|
|
|
func add_dragons(dragons: Array) -> void:
|
|
for d in dragons:
|
|
_push_dragon(d['id'], d['name'], d['hat'], d['shirt'], d['shoes'])
|
|
|
|
|
|
func _push_dragon(id: int, name: String, hat: int, shirt: int, shoes: int):
|
|
dragons.push_back(
|
|
{'id': id, 'name': name, 'hat': hat, 'shirt': shirt, 'shoes': shoes}
|
|
)
|