feat: start adding new sharing method
This commit is contained in:
parent
72013e48eb
commit
46726bca32
10 changed files with 132 additions and 46 deletions
|
@ -2,7 +2,7 @@ extends Node
|
|||
class_name DragonLibrary
|
||||
|
||||
|
||||
var dragons: Array = []
|
||||
var dragons: Array[DragonProperties] = []
|
||||
|
||||
var hat_outfits: DragonOutfit
|
||||
var shirt_outfits: DragonOutfit
|
||||
|
@ -15,21 +15,13 @@ 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) -> 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)
|
||||
var id: int = RandomNumberGenerator.new().randi()
|
||||
_push_dragon(id, name, hat_index, shirt_index, shoes_index)
|
||||
return id
|
||||
func add_dragon(properties: DragonProperties) -> int:
|
||||
if properties.id == 0:
|
||||
properties.id = randi()
|
||||
dragons.push_back(properties)
|
||||
return properties.id
|
||||
|
||||
|
||||
func add_dragons(dragons: Array) -> void:
|
||||
func add_dragons(dragons: Array[DragonProperties]) -> void:
|
||||
for d in dragons:
|
||||
_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}
|
||||
)
|
||||
dragons.push_back(d)
|
||||
|
|
24
src/dragon_properties.gd
Normal file
24
src/dragon_properties.gd
Normal file
|
@ -0,0 +1,24 @@
|
|||
class_name DragonProperties
|
||||
|
||||
|
||||
var name: String
|
||||
var origin: String
|
||||
var color: int
|
||||
var hat: int
|
||||
var shirt: int
|
||||
var decor: int
|
||||
var position: Vector2i
|
||||
var id: int
|
||||
|
||||
|
||||
func _init(name: String, origin: String, color: int, hat: int, shirt: int, decor: int) -> void:
|
||||
self.name = name
|
||||
self.origin = origin
|
||||
self.color = color
|
||||
self.hat = hat
|
||||
self.shirt = shirt
|
||||
self.decor = 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]
|
1
src/dragon_properties.gd.uid
Normal file
1
src/dragon_properties.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://jyglnbx4cxwm
|
|
@ -44,8 +44,25 @@ func add_dragon(id: int, name: String, hat: int, shirt: int, shoes: int, pos: Ve
|
|||
contents_to_save['dragons'].push_back({'id': id, 'name': name, 'hat': hat, 'shirt': shirt, 'shoes': shoes, 'pos': pos})
|
||||
|
||||
|
||||
func get_dragons() -> Array:
|
||||
return contents_to_save['dragons']
|
||||
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 position: Vector2i = dragon['pos']
|
||||
var properties = DragonProperties.new(name, origin, color, hat, shirt, decor)
|
||||
properties.position = position
|
||||
properties.id = randi()
|
||||
return properties
|
||||
|
||||
|
||||
func get_dragons() -> Array[DragonProperties]:
|
||||
var dragons: Array[DragonProperties] = []
|
||||
for dragon in contents_to_save['dragons']:
|
||||
dragons.push_back(get_dragon(dragon))
|
||||
return dragons
|
||||
|
||||
|
||||
func add_item(id: int, position: Vector2i) -> void:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue