feat: dragon list view

This commit is contained in:
Gerard Gascón 2025-04-09 13:59:41 +02:00
parent 577926e8fc
commit 3919df1805
17 changed files with 409 additions and 4 deletions

29
src/dragon_library.gd Normal file
View file

@ -0,0 +1,29 @@
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):
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)
dragons.push_back({'name': name, 'hat': hat_index, 'shirt': shirt_index, 'shoes': shoes_index})
func add_dragons(dragons: Array) -> void:
for d in dragons:
self.dragons.push_back(
{'name': d['name'], 'hat': d['hat'], 'shirt': d['shirt'], 'shoes': d['shoes']}
)

View file

@ -0,0 +1 @@
uid://b20tldewrh01n

56
src/save_load.gd Normal file
View file

@ -0,0 +1,56 @@
class_name SaveLoad
const save_location = "user://save.json"
var contents_to_save: Dictionary = {
}
func save() -> void:
var file: FileAccess = FileAccess.open(save_location, FileAccess.WRITE)
file.store_var(contents_to_save.duplicate(true))
file.close()
print('Saved game at: %s' % file.get_path_absolute())
func load() -> void:
if FileAccess.file_exists(save_location):
var file: FileAccess = FileAccess.open(save_location, FileAccess.READ)
var data: Dictionary = file.get_var()
file.close()
contents_to_save = data.duplicate(true)
else:
contents_to_save.get_or_add('coins', 0)
contents_to_save.get_or_add('dragons', [])
contents_to_save.get_or_add('items', [])
func get_coins() -> int:
return contents_to_save['coins']
func set_coins(coins: int) -> void:
contents_to_save['coins'] = coins
func clear_dragons() -> void:
contents_to_save['dragons'] = []
func add_dragon(name: String, hat: int, shirt: int, shoes: int) -> void:
contents_to_save['dragons'].push_back({'name': name, 'hat': hat, 'shirt': shirt, 'shoes': shoes})
func get_dragons() -> Array:
return contents_to_save['dragons']
func add_item(id: int, position: Vector2i) -> void:
contents_to_save['items'].push_back({'id': id, 'position': position})
func get_items() -> Array:
return contents_to_save['items']

1
src/save_load.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://dca55o11cmjd3