feat: ability to share dragons
This commit is contained in:
parent
3919df1805
commit
029ad6d45f
15 changed files with 203 additions and 30 deletions
|
@ -115,6 +115,8 @@ func _char_to_bin(character: String) -> String:
|
|||
|
||||
|
||||
func _bin_to_char(character: String) -> String:
|
||||
if not alphabet_inverse.has(character):
|
||||
return ""
|
||||
return alphabet_inverse[character]
|
||||
|
||||
|
||||
|
@ -136,6 +138,8 @@ func read_code(code: String) -> Dictionary:
|
|||
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}
|
||||
|
|
|
@ -10,9 +10,11 @@ func _init(dragon: PackedScene, viewport: Viewport, window: Window) -> void:
|
|||
_dragon_template = dragon
|
||||
|
||||
|
||||
func instantiate(position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String) -> Node:
|
||||
func instantiate(position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String, drag: bool) -> Node:
|
||||
if drag == false:
|
||||
return _instantiate_dragon(position, hat, shirt, shoes, dragon_name, drag)
|
||||
var relative_position: Vector2i = _calculate_relative_position(position)
|
||||
return _instantiate_dragon(relative_position, hat, shirt, shoes, dragon_name)
|
||||
return _instantiate_dragon(relative_position, hat, shirt, shoes, dragon_name, drag)
|
||||
|
||||
|
||||
func _calculate_window_scale() -> Vector2:
|
||||
|
@ -27,13 +29,16 @@ func _calculate_relative_position(position: Vector2) -> Vector2i:
|
|||
return Vector2i(Vector2(position) * scale)
|
||||
|
||||
|
||||
func _instantiate_dragon(relative_position: Vector2i, hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String) -> Node:
|
||||
func _instantiate_dragon(relative_position: Vector2i, hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String, drag: bool) -> Node:
|
||||
var dragon: Dragon = _dragon_template.instantiate()
|
||||
|
||||
var window_position: Vector2i = DisplayServer.window_get_position()
|
||||
var window_size: Vector2i = DisplayServer.window_get_size()
|
||||
|
||||
dragon.position = window_position + relative_position - dragon.size / 2
|
||||
if drag == false:
|
||||
dragon.position = relative_position
|
||||
else:
|
||||
dragon.position = window_position + relative_position - dragon.size / 2
|
||||
dragon.dress(hat, shirt, shoes)
|
||||
dragon.set_dragon_name(dragon_name)
|
||||
|
||||
|
@ -42,4 +47,7 @@ func _instantiate_dragon(relative_position: Vector2i, hat: Texture2D, shirt: Tex
|
|||
dragon.main_window_rect = Rect2i(window_position, window_size)
|
||||
dragon.show()
|
||||
|
||||
if drag:
|
||||
dragon.start_dragon_drag()
|
||||
|
||||
return dragon
|
||||
|
|
|
@ -15,15 +15,21 @@ func _init(hat_outfits: DragonOutfit, shirt_outfits: DragonOutfit, shoes_outfits
|
|||
self.shoes_outfits = shoes_outfits
|
||||
|
||||
|
||||
func add_dragon(name: String, hat: Texture2D, shirt: Texture2D, shoes: Texture2D):
|
||||
func add_dragon(name: String, hat: Texture2D, shirt: Texture2D, shoes: Texture2D) -> int:
|
||||
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})
|
||||
var id: int = RandomNumberGenerator.new().randi()
|
||||
_push_dragon(id, name, hat_index, shirt_index, shoes_index)
|
||||
return id
|
||||
|
||||
|
||||
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']}
|
||||
)
|
||||
_push_dragon(d['id'], d['name'], d['hat'], d['shirt'], d['shoes'])
|
||||
|
||||
|
||||
func _push_dragon(id: int, name: String, hat: int, shirt: int, shoes: int):
|
||||
dragons.push_back(
|
||||
{'id': id, 'name': name, 'hat': hat, 'shirt': shirt, 'shoes': shoes}
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class_name SaveLoad
|
||||
|
||||
|
||||
const save_location = "user://save.json"
|
||||
const save_location = "user://save.data"
|
||||
|
||||
var contents_to_save: Dictionary = {
|
||||
|
||||
|
@ -40,8 +40,8 @@ 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 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 get_dragons() -> Array:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue