diff --git a/scenes/dragon_list/dragon_list.tscn b/scenes/dragon_list/dragon_list.tscn index 0102f4d..cdfd8a5 100644 --- a/scenes/dragon_list/dragon_list.tscn +++ b/scenes/dragon_list/dragon_list.tscn @@ -1,10 +1,7 @@ -[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="."] diff --git a/scenes/dragon_list/dragon_list_entry.gd b/scenes/dragon_list/dragon_list_entry.gd index 06670cb..9f49e7c 100644 --- a/scenes/dragon_list/dragon_list_entry.gd +++ b/scenes/dragon_list/dragon_list_entry.gd @@ -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 diff --git a/scenes/dragon_list/dragon_list_view.gd b/scenes/dragon_list/dragon_list_view.gd index 0dbbd29..5a873c0 100644 --- a/scenes/dragon_list/dragon_list_view.gd +++ b/scenes/dragon_list/dragon_list_view.gd @@ -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) diff --git a/scenes/dragon_list/dragon_properties.tscn b/scenes/dragon_list/dragon_properties.tscn index e386ae4..717aac3 100644 --- a/scenes/dragon_list/dragon_properties.tscn +++ b/scenes/dragon_list/dragon_properties.tscn @@ -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 diff --git a/scenes/main.gd b/scenes/main.gd index 33c006e..631e974 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -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 diff --git a/scenes/window/dragon.gd b/scenes/window/dragon.gd index 8e27860..4199764 100644 --- a/scenes/window/dragon.gd +++ b/scenes/window/dragon.gd @@ -63,6 +63,8 @@ func _process(delta: float) -> void: State.FLYING: _move_to_target(delta) + properties.position = position + func dress(): dragon.dress(properties) diff --git a/src/dragon_code_generator.gd b/src/dragon_code_generator.gd deleted file mode 100644 index d32f764..0000000 --- a/src/dragon_code_generator.gd +++ /dev/null @@ -1,147 +0,0 @@ -class_name CodeGenerator - -var hat_outfits: DragonOutfit -var shirt_outfits: DragonOutfit -var shoes_outfits: DragonOutfit - -var key: int = 123 - -var alphabet: Dictionary = { - 'A': '00', - 'B': '01', - 'C': '02', - 'D': '03', - 'E': '04', - 'F': '05', - 'G': '06', - 'H': '07', - 'I': '08', - 'J': '09', - 'K': '10', - 'L': '11', - 'M': '12', - 'N': '13', - 'O': '14', - 'P': '15', - 'Q': '16', - 'R': '17', - 'S': '18', - 'T': '19', - 'U': '20', - 'V': '21', - 'W': '22', - 'X': '23', - 'Y': '24', - 'Z': '25', - ' ': '26' -} - -var alphabet_inverse: Dictionary = { - '00': 'A', - '01': 'B', - '02': 'C', - '03': 'D', - '04': 'E', - '05': 'F', - '06': 'G', - '07': 'H', - '08': 'I', - '09': 'J', - '10': 'K', - '11': 'L', - '12': 'M', - '13': 'N', - '14': 'O', - '15': 'P', - '16': 'Q', - '17': 'R', - '18': 'S', - '19': 'T', - '20': 'U', - '21': 'V', - '22': 'W', - '23': 'X', - '24': 'Y', - '25': 'Z', - '26': ' ' -} - - -func _init(hat: DragonOutfit, shirt: DragonOutfit, shoes: DragonOutfit) -> void: - hat_outfits = hat - shirt_outfits = shirt - shoes_outfits = shoes - - -func encrypt(hat: Texture2D, shirt: Texture2D, shoes: Texture2D, name: String) -> String: - 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 code: String = generate_code(hat_index, shirt_index, shoes_index, name) - return xor_encrypt_decrypt(code) - - -func descrypt(input: String) -> Dictionary: - var decrypted_code: String = xor_encrypt_decrypt(input) - - if len(decrypted_code) % 2 != 0 or len(decrypted_code) <= 6: - return {'hat': null, 'shirt': null, 'shoes': null, 'name': null} - - return read_code(decrypted_code) - - -func generate_code(int1: int, int2: int, int3: int, input_string: String) -> String: - input_string = input_string.substr(0, 8) - - var binary_data: String = "" - binary_data += _int_to_bin(int1) - binary_data += _int_to_bin(int2) - binary_data += _int_to_bin(int3) - - for i in range(input_string.length()): - binary_data += _char_to_bin(input_string[i]) - - return binary_data - - -func _int_to_bin(value: int) -> String: - return "%02X" % value - - -func _bin_to_int(value: String) -> int: - return value.hex_to_int() - - -func _char_to_bin(character: String) -> String: - return alphabet[character] - - -func _bin_to_char(character: String) -> String: - if not alphabet_inverse.has(character): - return "" - return alphabet_inverse[character] - - -func xor_encrypt_decrypt(data: String) -> String: - var result: String = "" - for i in range(data.length()): - var c: int = data[i].unicode_at(0) - var encrypted_char: int = c ^ key - result += char(encrypted_char) - return result - - -func read_code(code: String) -> Dictionary: - var hat: Texture2D = hat_outfits.get_texture(_bin_to_int(code.substr(0, 2))) - var shirt: Texture2D = shirt_outfits.get_texture(_bin_to_int(code.substr(2, 2))) - var shoes: Texture2D = shoes_outfits.get_texture(_bin_to_int(code.substr(4, 2))) - - var name: String = "" - for i in range(code.substr(6).length()): - if i % 2 != 0: - continue - if _bin_to_char(code.substr(6 + i, 2)) == "": - return {'hat': null, 'shirt': null, 'shoes': null, 'name': null} - name += _bin_to_char(code.substr(6 + i, 2)) - - return {'hat': hat, 'shirt': shirt, 'shoes': shoes, 'name': name} diff --git a/src/dragon_code_generator.gd.uid b/src/dragon_code_generator.gd.uid deleted file mode 100644 index b5b6a11..0000000 --- a/src/dragon_code_generator.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bhnm8ysguu4u4 diff --git a/src/dragon_library.gd b/src/dragon_library.gd index 219b410..11bccee 100644 --- a/src/dragon_library.gd +++ b/src/dragon_library.gd @@ -5,6 +5,13 @@ class_name DragonLibrary var dragons: Array[DragonProperties] = [] +func has(properties: DragonProperties) -> bool: + for dragon in dragons: + if properties.equals(dragon): + return true + return false + + func add_dragon(properties: DragonProperties) -> int: if properties.id == 0: properties.id = randi() @@ -12,6 +19,6 @@ func add_dragon(properties: DragonProperties) -> int: return properties.id -func add_dragons(dragons: Array[DragonProperties]) -> void: - for d in dragons: +func add_dragons(new_dragons: Array[DragonProperties]) -> void: + for d in new_dragons: dragons.push_back(d) diff --git a/src/dragon_properties.gd b/src/dragon_properties.gd index 9ac5ff4..2e2cdd5 100644 --- a/src/dragon_properties.gd +++ b/src/dragon_properties.gd @@ -1,6 +1,6 @@ +extends RefCounted class_name DragonProperties - var name: String var origin: String var color: int @@ -22,3 +22,7 @@ func _init(name: String, origin: String, color: int, hat: int, shirt: int, decor func _to_string() -> String: return '%s: [origin: %s, color: %d, hat: %d, shirt: %d, decor: %d]' % [self.name, self.origin, self.color, self.hat, self.shirt, self.decor] + + +func equals(other: DragonProperties): + return name == other.name and origin == other.origin and color == other.color and hat == other.hat and shirt == other.shirt and decor == other.decor diff --git a/src/save_load.gd b/src/save_load.gd index 11b6e5e..0fc6ebe 100644 --- a/src/save_load.gd +++ b/src/save_load.gd @@ -1,11 +1,10 @@ class_name SaveLoad - const save_location = "user://save.data" var contents_to_save: Dictionary = { -} + } func save() -> void: @@ -20,7 +19,7 @@ func load() -> void: 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) @@ -40,19 +39,19 @@ func clear_dragons() -> void: contents_to_save['dragons'] = [] -func add_dragon(id: int, name: String, hat: int, shirt: int, shoes: int, pos: Vector2i) -> void: - contents_to_save['dragons'].push_back({'id': id, 'name': name, 'hat': hat, 'shirt': shirt, 'shoes': shoes, 'pos': pos}) +func add_dragon(dragon: DragonProperties) -> void: + contents_to_save['dragons'].push_back({'name': dragon.name, 'origin': dragon.origin, 'color': dragon.color, 'hat': dragon.hat, 'shirt': dragon.shirt, 'decor': dragon.decor, 'pos': dragon.position}) func get_dragon(dragon: Dictionary) -> DragonProperties: - var name: String = dragon['name'] - var origin: String = dragon['origin'] - var hat: int = dragon['hat'] - var shirt: int = dragon['shirt'] - var decor: int = dragon['decor'] - var color: int = dragon['color'] + var name: String = dragon['name'] + var origin: String = dragon['origin'] + var hat: int = dragon['hat'] + var shirt: int = dragon['shirt'] + var decor: int = dragon['decor'] + var color: int = dragon['color'] var position: Vector2i = dragon['pos'] - var properties = DragonProperties.new(name, origin, color, hat, shirt, decor) + var properties = DragonProperties.new(name, origin, color, hat, shirt, decor) properties.position = position properties.id = randi() return properties