feat: start adding new sharing method
This commit is contained in:
parent
72013e48eb
commit
46726bca32
10 changed files with 132 additions and 46 deletions
|
@ -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)
|
||||
|
@ -43,32 +45,41 @@ 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()
|
||||
|
||||
|
||||
func _instantiate_random_dragon():
|
||||
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()
|
||||
|
||||
|
||||
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'])
|
||||
return _instantiate_dragon_ingame(pos, hat, shirt, shoes, dragon_name, id)
|
||||
|
||||
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):
|
||||
return spot
|
||||
return null
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
func move_window_to_bottom_right():
|
||||
var display_index: int = DisplayServer.window_get_current_screen()
|
||||
|
||||
|
@ -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…
Add table
Add a link
Reference in a new issue