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

Binary file not shown.

View file

@ -0,0 +1,35 @@
[remap]
importer="font_data_dynamic"
type="FontFile"
uid="uid://dn8qanm8tctb2"
path="res://.godot/imported/Montserrat-Regular.ttf-15e5248c373097bdb910cdf2cfc29eaa.fontdata"
[deps]
source_file="res://assets/fonts/Montserrat-Regular.ttf"
dest_files=["res://.godot/imported/Montserrat-Regular.ttf-15e5248c373097bdb910cdf2cfc29eaa.fontdata"]
[params]
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=4
keep_rounding_remainders=true
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}

66
export_presets.cfg Normal file
View file

@ -0,0 +1,66 @@
[preset.0]
name="Windows Desktop"
platform="Windows Desktop"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../../Builds/SantJordiJam25/LaPlacetaDelDrac.exe"
patches=PackedStringArray()
encryption_include_filters=""
encryption_exclude_filters=""
seed=0
encrypt_pck=false
encrypt_directory=false
script_export_mode=2
[preset.0.options]
custom_template/debug=""
custom_template/release=""
debug/export_console_wrapper=0
binary_format/embed_pck=true
texture_format/s3tc_bptc=true
texture_format/etc2_astc=false
binary_format/architecture="x86_64"
codesign/enable=false
codesign/timestamp=true
codesign/timestamp_server_url=""
codesign/digest_algorithm=1
codesign/description=""
codesign/custom_options=PackedStringArray()
application/modify_resources=true
application/icon=""
application/console_wrapper_icon=""
application/icon_interpolation=4
application/file_version=""
application/product_version=""
application/company_name=""
application/product_name=""
application/file_description=""
application/copyright=""
application/trademarks=""
application/export_angle=0
application/export_d3d12=0
application/d3d12_agility_sdk_multiarch=true
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
ssh_remote_deploy/extra_args_ssh=""
ssh_remote_deploy/extra_args_scp=""
ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'
$trigger = New-ScheduledTaskTrigger -Once -At 00:00
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true
Start-ScheduledTask -TaskName godot_remote_debug
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue"
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue
Remove-Item -Recurse -Force '{temp_dir}'"

View file

@ -0,0 +1,32 @@
[gd_scene load_steps=6 format=3 uid="uid://tubxrqxjic6r"]
[ext_resource type="PackedScene" uid="uid://bs45hvb2mpw4k" path="res://scenes/dragon_list/dragon_properties.tscn" id="1_4vct3"]
[ext_resource type="Script" uid="uid://dm8d0ikf1n8qa" path="res://scenes/dragon_list/dragon_list_view.gd" id="1_q7g8i"]
[ext_resource type="Resource" uid="uid://cnhwn6kfcbjl5" path="res://assets/outfits/hats.tres" id="3_xxwat"]
[ext_resource type="Resource" uid="uid://etegcak2sphs" path="res://assets/outfits/shirts.tres" id="4_7mhmu"]
[ext_resource type="Resource" uid="uid://ba5684xylts3f" path="res://assets/outfits/shoes.tres" id="5_h4iwm"]
[node name="DragonList" type="Window" node_paths=PackedStringArray("dragon_list_view")]
size = Vector2i(450, 700)
transient = true
exclusive = true
script = ExtResource("1_q7g8i")
dragon_list_entry = ExtResource("1_4vct3")
dragon_list_view = NodePath("CanvasLayer/ScrollContainer/VBoxContainer")
hat_outfits = ExtResource("3_xxwat")
shirt_outfits = ExtResource("4_7mhmu")
shoes_outfits = ExtResource("5_h4iwm")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="ScrollContainer" type="ScrollContainer" parent="CanvasLayer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/ScrollContainer"]
layout_mode = 2
[connection signal="close_requested" from="." to="." method="_on_close_requested"]

View file

@ -0,0 +1,17 @@
extends Control
class_name DragonListEntry
@export var texture_rect: TextureRect
@export var name_label: Label
@export var code_label: Label
var code_generator: CodeGenerator
@export var hat_outfits: DragonOutfit
@export var shirt_outfits: DragonOutfit
@export var shoes_outfits: DragonOutfit
func set_properties(name: String, hat: Texture2D, shirt: Texture2D, shoes: Texture2D) -> void:
name_label.text = name
code_label.text = CodeGenerator.new(hat_outfits, shirt_outfits, shoes_outfits).encrypt(hat, shirt, shoes, name)

View file

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

View file

@ -0,0 +1,30 @@
extends Window
class_name DragonList
@export var dragon_list_entry: PackedScene
@export var dragon_list_view: VBoxContainer
@export var hat_outfits: DragonOutfit
@export var shirt_outfits: DragonOutfit
@export var shoes_outfits: DragonOutfit
var _library: DragonLibrary
func set_library(library: DragonLibrary):
_library = library
for d in _library.dragons:
var hat: Texture2D = hat_outfits.get_texture(d['hat'])
var shirt: Texture2D = shirt_outfits.get_texture(d['shirt'])
var shoes: Texture2D = shoes_outfits.get_texture(d['shoes'])
append_dragon(d['name'], hat, shirt, shoes)
func append_dragon(name: String, hat: Texture2D, shirt: Texture2D, shoes: Texture2D):
var dragon: DragonListEntry = dragon_list_entry.instantiate()
dragon.set_properties(name, hat, shirt, shoes)
dragon_list_view.add_child(dragon)
func _on_close_requested() -> void:
queue_free()

View file

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

View file

@ -0,0 +1,52 @@
[gd_scene load_steps=7 format=3 uid="uid://bs45hvb2mpw4k"]
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="1_4i8li"]
[ext_resource type="Script" uid="uid://d1bq5f35wptxt" path="res://scenes/dragon_list/dragon_list_entry.gd" id="1_s7he7"]
[ext_resource type="FontFile" uid="uid://dn8qanm8tctb2" path="res://assets/fonts/Montserrat-Regular.ttf" id="2_s7he7"]
[ext_resource type="Resource" uid="uid://cnhwn6kfcbjl5" path="res://assets/outfits/hats.tres" id="2_y33em"]
[ext_resource type="Resource" uid="uid://etegcak2sphs" path="res://assets/outfits/shirts.tres" id="3_84ie0"]
[ext_resource type="Resource" uid="uid://ba5684xylts3f" path="res://assets/outfits/shoes.tres" id="4_xvxt0"]
[node name="DragonProperties" type="Control" node_paths=PackedStringArray("texture_rect", "name_label", "code_label")]
custom_minimum_size = Vector2(0, 128)
layout_mode = 3
anchors_preset = 0
script = ExtResource("1_s7he7")
texture_rect = NodePath("TextureRect")
name_label = NodePath("Name")
code_label = NodePath("Code")
hat_outfits = ExtResource("2_y33em")
shirt_outfits = ExtResource("3_84ie0")
shoes_outfits = ExtResource("4_xvxt0")
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 0
offset_left = 8.0
offset_top = 8.0
offset_right = 128.0
offset_bottom = 128.0
texture = ExtResource("1_4i8li")
expand_mode = 1
[node name="Name" type="Label" parent="."]
layout_mode = 0
offset_left = 132.0
offset_top = 4.0
offset_right = 449.0
offset_bottom = 128.0
scale = Vector2(0.8, 1)
theme_override_fonts/font = ExtResource("2_s7he7")
theme_override_font_sizes/font_size = 36
text = "AAAAAAAA"
[node name="Code" type="Label" parent="."]
layout_mode = 0
offset_left = 132.0
offset_top = 8.0
offset_right = 530.0
offset_bottom = 72.0
scale = Vector2(0.8, 1)
theme_override_fonts/font = ExtResource("2_s7he7")
theme_override_font_sizes/font_size = 21
text = "AAAAAAAAAAAAAAAAAAAAAA"
vertical_alignment = 2

18
scenes/list_button.gd Normal file
View file

@ -0,0 +1,18 @@
extends Button
@export var dragon_list: PackedScene
@onready var base: GameManager = $"../.."
func _on_pressed() -> void:
var list: DragonList = dragon_list.instantiate()
list.set_library(base._library)
var window_position: Vector2i = DisplayServer.window_get_position()
var window_size: Vector2i = DisplayServer.window_get_size()
list.position = window_position - list.size / 2
list.show()
add_child(list)

View file

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

View file

@ -6,12 +6,22 @@ class_name GameManager
@export var dragon_ingame: PackedScene
@export var dragon_spots: Array[Node2D]
@export var hat_outfits: DragonOutfit
@export var shirt_outfits: DragonOutfit
@export var shoes_outfits: DragonOutfit
var _instantiator: DragonInstantiator
var _save_load: SaveLoad
var _library: DragonLibrary
func _ready():
_library = DragonLibrary.new(hat_outfits, shirt_outfits, shoes_outfits)
_instantiator = DragonInstantiator.new(dragon_template, get_viewport(), get_window())
_save_load = SaveLoad.new()
_load_game()
await get_tree().process_frame
move_window_to_bottom_right()
@ -33,7 +43,13 @@ func move_window_to_bottom_right():
func add_dragon(hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String):
# TODO: Check for free positon
_instantiate_dragon_ingame(dragon_spots[0].position, hat, shirt, shoes, dragon_name)
# TODO: Add to dragon library
_library.add_dragon(dragon_name, hat, shirt, shoes)
func _load_game():
_save_load.load()
_library.add_dragons(_save_load.get_dragons())
print(_save_load.contents_to_save)
func _instantiate_dragon_ingame(position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String):
@ -53,3 +69,16 @@ func _pick_dragon(position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Te
func _dragon_place_back(dragon: Dragon):
print(dragon)
func _on_close_pressed() -> void:
_save_load.clear_dragons()
for d in _library.dragons:
_save_load.add_dragon(d['name'], d['hat'], d['shirt'], d['shoes'])
_save_load.save()
await get_tree().process_frame
await get_tree().process_frame
await get_tree().process_frame
await get_tree().process_frame
await get_tree().process_frame
get_tree().quit()

View file

@ -1,21 +1,29 @@
[gd_scene load_steps=7 format=3 uid="uid://ctytpqaed0yqx"]
[gd_scene load_steps=12 format=3 uid="uid://ctytpqaed0yqx"]
[ext_resource type="Script" uid="uid://3kyt3shje5r1" path="res://scenes/main.gd" id="1_sugp2"]
[ext_resource type="PackedScene" uid="uid://c7nfcgjxqeg7l" path="res://scenes/window/dragon_popup.tscn" id="2_jyhfs"]
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="3_tbgi4"]
[ext_resource type="Resource" uid="uid://cnhwn6kfcbjl5" path="res://assets/outfits/hats.tres" id="4_85g3d"]
[ext_resource type="PackedScene" uid="uid://miutbdsgccd1" path="res://scenes/dragons/dragon.tscn" id="4_jyhfs"]
[ext_resource type="Script" uid="uid://cj4l3a6a8ro0r" path="res://scenes/create_button.gd" id="4_tbgi4"]
[ext_resource type="Resource" uid="uid://etegcak2sphs" path="res://assets/outfits/shirts.tres" id="5_choun"]
[ext_resource type="PackedScene" uid="uid://fut42ruut302" path="res://scenes/dragon_editor/dragon_editor.tscn" id="5_tefeu"]
[ext_resource type="Resource" uid="uid://ba5684xylts3f" path="res://assets/outfits/shoes.tres" id="6_ya4ey"]
[ext_resource type="Script" uid="uid://oc6mw86npbii" path="res://scenes/list_button.gd" id="9_choun"]
[ext_resource type="PackedScene" uid="uid://tubxrqxjic6r" path="res://scenes/dragon_list/dragon_list.tscn" id="10_ya4ey"]
[node name="Base" type="Node2D" node_paths=PackedStringArray("dragon_spots")]
script = ExtResource("1_sugp2")
dragon_template = ExtResource("2_jyhfs")
dragon_ingame = ExtResource("4_jyhfs")
dragon_spots = [NodePath("DragonSpot1"), NodePath("DragonSpot2"), NodePath("DragonSpot3")]
hat_outfits = ExtResource("4_85g3d")
shirt_outfits = ExtResource("5_choun")
shoes_outfits = ExtResource("6_ya4ey")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="Button" type="Button" parent="CanvasLayer"]
[node name="Create" type="Button" parent="CanvasLayer"]
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
@ -28,6 +36,30 @@ text = "crea"
script = ExtResource("4_tbgi4")
dragon_editor = ExtResource("5_tefeu")
[node name="Close" type="Button" parent="CanvasLayer"]
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -156.0
offset_top = 168.0
offset_right = -56.0
offset_bottom = 268.0
grow_horizontal = 0
text = "tanca"
[node name="List" type="Button" parent="CanvasLayer"]
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -156.0
offset_top = 288.0
offset_right = -56.0
offset_bottom = 388.0
grow_horizontal = 0
text = "llista"
script = ExtResource("9_choun")
dragon_list = ExtResource("10_ya4ey")
[node name="Icon" type="Sprite2D" parent="."]
position = Vector2(576, 324)
scale = Vector2(9, 5.0625)
@ -42,4 +74,8 @@ position = Vector2(557, 239)
[node name="DragonSpot3" type="Node2D" parent="."]
position = Vector2(850, 360)
[connection signal="button_up" from="CanvasLayer/Button" to="CanvasLayer/Button" method="_on_button_up"]
[connection signal="tree_entered" from="." to="." method="_on_tree_entered"]
[connection signal="tree_exiting" from="." to="." method="_on_tree_exiting"]
[connection signal="button_up" from="CanvasLayer/Create" to="CanvasLayer/Create" method="_on_button_up"]
[connection signal="pressed" from="CanvasLayer/Close" to="." method="_on_close_pressed"]
[connection signal="pressed" from="CanvasLayer/List" to="CanvasLayer/List" method="_on_pressed"]

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