Commit b080ab7b authored by Gerard Gascón's avatar Gerard Gascón
Browse files

feat: pulling dragons from server working

parent 50bc8143
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
[gd_scene load_steps=6 format=3 uid="uid://tubxrqxjic6r"]
[gd_scene load_steps=3 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)
@@ -12,9 +9,6 @@ always_on_top = 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="."]

+4 −6
Original line number Diff line number Diff line
@@ -3,15 +3,13 @@ class_name DragonListEntry

@export var texture_rect: TextureRect
@export var name_label: Label
@export var code_label: Label

var code_generator: CodeGenerator
@export var origin_label: Label

@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)
func set_properties(properties: DragonProperties) -> void:
	name_label.text = properties.name
	origin_label.text = properties.origin
+4 −11
Original line number Diff line number Diff line
@@ -4,25 +4,18 @@ 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)
#
		append_dragon(d)


func append_dragon(name: String, hat: Texture2D, shirt: Texture2D, shoes: Texture2D):
func append_dragon(properties: DragonProperties):
	var dragon: DragonListEntry = dragon_list_entry.instantiate()
	dragon.set_properties(name, hat, shirt, shoes)
	dragon.set_properties(properties)
	dragon_list_view.add_child(dragon)


+3 −3
Original line number Diff line number Diff line
@@ -7,14 +7,14 @@
[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")]
[node name="DragonProperties" type="Control" node_paths=PackedStringArray("texture_rect", "name_label", "origin_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")
origin_label = NodePath("Origin")
hat_outfits = ExtResource("2_y33em")
shirt_outfits = ExtResource("3_84ie0")
shoes_outfits = ExtResource("4_xvxt0")
@@ -39,7 +39,7 @@ theme_override_fonts/font = ExtResource("2_s7he7")
theme_override_font_sizes/font_size = 36
text = "AAAAAAAA"

[node name="Code" type="Label" parent="."]
[node name="Origin" type="Label" parent="."]
layout_mode = 0
offset_left = 132.0
offset_top = 8.0
+7 −3
Original line number Diff line number Diff line
@@ -128,6 +128,9 @@ func _pick_dragon(properties: DragonProperties, drag: bool = true):
	add_child(dragon)
	_instantiated_dragons.erase(properties.id)
	
	if not _library.has(properties):
		_library.add_dragon(properties)
	
	for spot in _filled_spots:
		if _filled_spots[spot] == properties.id:
			_filled_spots.erase(spot)
@@ -148,10 +151,11 @@ func _dragon_place_back(dragon: Dragon):
func _on_close_pressed() -> void:
	_save_load.clear_dragons()
	for d in _library.dragons:
		if _dragon_entities.has(d['id']) and _dragon_entities[d['id']] != null:
			_save_load.add_dragon(d['id'], d['name'], d['hat'], d['shirt'], d['shoes'], _dragon_entities[d['id']].position)
		if _dragon_entities.has(d.id) and _dragon_entities[d.id] != null:
			_save_load.add_dragon(d)
		else:
			_save_load.add_dragon(d['id'], d['name'], d['hat'], d['shirt'], d['shoes'], Vector2i(0, 0))
			d.position = Vector2i(0, 0)
			_save_load.add_dragon(d)
	_save_load.save()
	await get_tree().process_frame
	await get_tree().process_frame
Loading