Loading assets/outfits/dragons.tres +1 −0 Original line number Diff line number Diff line Loading @@ -7,5 +7,6 @@ [resource] script = ExtResource("4_sxi2r") allow_null = false outfits = Array[Texture2D]([ExtResource("1_3e6qx"), ExtResource("2_lvc22"), ExtResource("3_8ji77")]) metadata/_custom_type_script = "uid://rw26nny160xh" scenes/dragon_editor/dragon_editor.tscn +1 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,7 @@ offset_bottom = 276.0 texture = ExtResource("12_qppok") [node name="LineEdit" type="LineEdit" parent="CanvasLayer/NameLabel"] layout_mode = 0 offset_left = 10.0 offset_top = 8.0 offset_right = 138.0 Loading scenes/dragon_sharing.gd 0 → 100644 +34 −0 Original line number Diff line number Diff line extends HTTPRequest class_name DragonSharing signal on_dragon_received(dragon: DragonProperties) func _ready() -> void: request_completed.connect(_on_request_completed) func _on_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray): if response_code != 200: print("HTTP request returned error: ", response_code) return if body.size() != 0: var json = JSON.parse_string(body.get_string_from_utf8()) var properties = DragonProperties.new(json['name'], json['origin'], json['color'], json['hat'], json['shirt'], json['decor']) print(properties) on_dragon_received.emit(properties) func send(origin: String, name: String, color: int, shirt: int, hat: int, decor: int) -> void: var url: String = 'http://torreta.gerardgascon.com/add/%s/%s/%s/%s/%s/%s/' % [origin, name, color, shirt, hat, decor] var err = request(url) if err != OK: print("HTTP request failed: ", err) func receive(origin: String) -> void: var url: String = 'http://torreta.gerardgascon.com/get/%s/' % origin var err = request(url) if err != OK: print("HTTP request failed: ", err) scenes/dragon_sharing.gd.uid 0 → 100644 +1 −0 Original line number Diff line number Diff line uid://bg58e3dobon4j scenes/main.gd +35 −24 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ var rng: RandomNumberGenerator = RandomNumberGenerator.new() @export var min_dragon_instantiation_time: float @export var max_dragon_instantiation_time: float @onready var dragon_sharing: DragonSharing = $HTTPRequest func _ready(): _library = DragonLibrary.new(hat_outfits, shirt_outfits, shoes_outfits) Loading @@ -43,31 +45,40 @@ func _ready(): func _queue_dragon_instantiation(): await get_tree().create_timer(rng.randf_range(min_dragon_instantiation_time, max_dragon_instantiation_time)).timeout _instantiate_random_dragon() _queue_dragon_instantiation() func _instantiate_random_dragon(): var spot: Node2D = _get_free_spot() if spot == null: return for i in range(5): dragon_sharing.receive("potato") var dragon: DragonProperties = await dragon_sharing.on_dragon_received for d in _library.dragons: # TODO: Search for dragon and if is in library or in instantiated dragons continue next iteration pass var dragon_entity: DragonEntity = _generate_entity(spot.position, dragon) _filled_spots[spot] = dragon_entity.id return func _get_free_spot() -> Node2D: for spot in dragon_spots: if not _filled_spots.has(spot): var dragon: DragonEntity = _pick_random_dragon(spot.position) if dragon != null: _filled_spots[spot] = dragon.id break _queue_dragon_instantiation() return spot return null func _pick_random_dragon(pos: Vector2) -> DragonEntity: for dragon in _library.dragons: var id: int = dragon['id'] if _instantiated_dragons.has(id) or _dragon_entities.has(id): continue var dragon_name: String = dragon['name'] var hat: Texture2D = hat_outfits.get_texture(dragon['hat']) var shirt: Texture2D = shirt_outfits.get_texture(dragon['shirt']) var shoes: Texture2D = shoes_outfits.get_texture(dragon['shoes']) func _generate_entity(pos: Vector2, properties: DragonProperties) -> DragonEntity: var id: int = rng.randi() var hat: Texture2D = hat_outfits.get_texture(properties.hat) var shirt: Texture2D = shirt_outfits.get_texture(properties.shirt) var shoes: Texture2D = shoes_outfits.get_texture(properties.decor) var dragon_name: String = properties.name return _instantiate_dragon_ingame(pos, hat, shirt, shoes, dragon_name, id) return null func move_window_to_bottom_right(): var display_index: int = DisplayServer.window_get_current_screen() Loading @@ -94,14 +105,14 @@ func add_dragon(hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: func _load_game(): _save_load.load() var dragons: Array = _save_load.get_dragons() var dragons: Array[DragonProperties] = _save_load.get_dragons() _library.add_dragons(dragons) for d in dragons: if d['pos'] != Vector2i(0, 0): 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']) _pick_dragon(d['id'], d['pos'], hat, shirt, shoes, false) for d: DragonProperties in dragons: if d.position != Vector2i(0, 0): 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.decor) _pick_dragon(rng.randi(), d.position, hat, shirt, shoes, false) print(_save_load.contents_to_save) Loading Loading
assets/outfits/dragons.tres +1 −0 Original line number Diff line number Diff line Loading @@ -7,5 +7,6 @@ [resource] script = ExtResource("4_sxi2r") allow_null = false outfits = Array[Texture2D]([ExtResource("1_3e6qx"), ExtResource("2_lvc22"), ExtResource("3_8ji77")]) metadata/_custom_type_script = "uid://rw26nny160xh"
scenes/dragon_editor/dragon_editor.tscn +1 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,7 @@ offset_bottom = 276.0 texture = ExtResource("12_qppok") [node name="LineEdit" type="LineEdit" parent="CanvasLayer/NameLabel"] layout_mode = 0 offset_left = 10.0 offset_top = 8.0 offset_right = 138.0 Loading
scenes/dragon_sharing.gd 0 → 100644 +34 −0 Original line number Diff line number Diff line extends HTTPRequest class_name DragonSharing signal on_dragon_received(dragon: DragonProperties) func _ready() -> void: request_completed.connect(_on_request_completed) func _on_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray): if response_code != 200: print("HTTP request returned error: ", response_code) return if body.size() != 0: var json = JSON.parse_string(body.get_string_from_utf8()) var properties = DragonProperties.new(json['name'], json['origin'], json['color'], json['hat'], json['shirt'], json['decor']) print(properties) on_dragon_received.emit(properties) func send(origin: String, name: String, color: int, shirt: int, hat: int, decor: int) -> void: var url: String = 'http://torreta.gerardgascon.com/add/%s/%s/%s/%s/%s/%s/' % [origin, name, color, shirt, hat, decor] var err = request(url) if err != OK: print("HTTP request failed: ", err) func receive(origin: String) -> void: var url: String = 'http://torreta.gerardgascon.com/get/%s/' % origin var err = request(url) if err != OK: print("HTTP request failed: ", err)
scenes/dragon_sharing.gd.uid 0 → 100644 +1 −0 Original line number Diff line number Diff line uid://bg58e3dobon4j
scenes/main.gd +35 −24 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ var rng: RandomNumberGenerator = RandomNumberGenerator.new() @export var min_dragon_instantiation_time: float @export var max_dragon_instantiation_time: float @onready var dragon_sharing: DragonSharing = $HTTPRequest func _ready(): _library = DragonLibrary.new(hat_outfits, shirt_outfits, shoes_outfits) Loading @@ -43,31 +45,40 @@ func _ready(): func _queue_dragon_instantiation(): await get_tree().create_timer(rng.randf_range(min_dragon_instantiation_time, max_dragon_instantiation_time)).timeout _instantiate_random_dragon() _queue_dragon_instantiation() func _instantiate_random_dragon(): var spot: Node2D = _get_free_spot() if spot == null: return for i in range(5): dragon_sharing.receive("potato") var dragon: DragonProperties = await dragon_sharing.on_dragon_received for d in _library.dragons: # TODO: Search for dragon and if is in library or in instantiated dragons continue next iteration pass var dragon_entity: DragonEntity = _generate_entity(spot.position, dragon) _filled_spots[spot] = dragon_entity.id return func _get_free_spot() -> Node2D: for spot in dragon_spots: if not _filled_spots.has(spot): var dragon: DragonEntity = _pick_random_dragon(spot.position) if dragon != null: _filled_spots[spot] = dragon.id break _queue_dragon_instantiation() return spot return null func _pick_random_dragon(pos: Vector2) -> DragonEntity: for dragon in _library.dragons: var id: int = dragon['id'] if _instantiated_dragons.has(id) or _dragon_entities.has(id): continue var dragon_name: String = dragon['name'] var hat: Texture2D = hat_outfits.get_texture(dragon['hat']) var shirt: Texture2D = shirt_outfits.get_texture(dragon['shirt']) var shoes: Texture2D = shoes_outfits.get_texture(dragon['shoes']) func _generate_entity(pos: Vector2, properties: DragonProperties) -> DragonEntity: var id: int = rng.randi() var hat: Texture2D = hat_outfits.get_texture(properties.hat) var shirt: Texture2D = shirt_outfits.get_texture(properties.shirt) var shoes: Texture2D = shoes_outfits.get_texture(properties.decor) var dragon_name: String = properties.name return _instantiate_dragon_ingame(pos, hat, shirt, shoes, dragon_name, id) return null func move_window_to_bottom_right(): var display_index: int = DisplayServer.window_get_current_screen() Loading @@ -94,14 +105,14 @@ func add_dragon(hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: func _load_game(): _save_load.load() var dragons: Array = _save_load.get_dragons() var dragons: Array[DragonProperties] = _save_load.get_dragons() _library.add_dragons(dragons) for d in dragons: if d['pos'] != Vector2i(0, 0): 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']) _pick_dragon(d['id'], d['pos'], hat, shirt, shoes, false) for d: DragonProperties in dragons: if d.position != Vector2i(0, 0): 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.decor) _pick_dragon(rng.randi(), d.position, hat, shirt, shoes, false) print(_save_load.contents_to_save) Loading