chore: dragon editor
This commit is contained in:
parent
44a36a4e67
commit
a8b292aa03
3 changed files with 70 additions and 1154 deletions
|
@ -2,14 +2,14 @@ extends Window
|
|||
class_name DragonEditor
|
||||
|
||||
|
||||
@onready var hat: TextureRect = $CanvasLayer/Dragon/Hat
|
||||
@onready var shirt: TextureRect = $CanvasLayer/Dragon/Shirt
|
||||
@onready var shoes: TextureRect = $CanvasLayer/Dragon/Shoes
|
||||
@onready var dragon: TextureRect = $CanvasLayer/Dragon
|
||||
@onready var hat: AnimatedSprite2D = $CanvasLayer/Dragon/Hat
|
||||
@onready var shirt: AnimatedSprite2D = $CanvasLayer/Dragon/Shirt
|
||||
@onready var decor: AnimatedSprite2D = $CanvasLayer/Dragon/Decor
|
||||
@onready var dragon: AnimatedSprite2D = $CanvasLayer/Dragon
|
||||
|
||||
@export var hat_outfits: DragonOutfit
|
||||
@export var shirt_outfits: DragonOutfit
|
||||
@export var shoes_outfits: DragonOutfit
|
||||
@export var decor_outfits: DragonOutfit
|
||||
@export var dragon_colors: DragonOutfit
|
||||
|
||||
@onready var dragon_name: LineEdit = $CanvasLayer/NameLabel/LineEdit
|
||||
|
@ -20,9 +20,15 @@ signal on_create_dragon(properties: DragonProperties)
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
hat.texture = null
|
||||
shirt.texture = null
|
||||
shoes.texture = null
|
||||
hat.visible = false
|
||||
shirt.visible = false
|
||||
decor.visible = false
|
||||
dragon.play('idle')
|
||||
|
||||
hat_outfits.index = 0
|
||||
shirt_outfits.index = 0
|
||||
decor_outfits.index = 0
|
||||
dragon_colors.index = 0
|
||||
|
||||
dragger.on_drag.connect(_on_drag)
|
||||
|
||||
|
@ -32,34 +38,50 @@ func _on_drag(offset: Vector2i):
|
|||
|
||||
|
||||
func _on_next_color_pressed() -> void:
|
||||
dragon.texture = dragon_colors.pick_next()
|
||||
_pick_next_animation(dragon, dragon_colors)
|
||||
|
||||
|
||||
func _on_previous_color_pressed() -> void:
|
||||
dragon.texture = dragon_colors.pick_previous()
|
||||
_pick_previous_animation(dragon, dragon_colors)
|
||||
|
||||
|
||||
func _on_change_hat_pressed() -> void:
|
||||
hat.texture = hat_outfits.pick_next()
|
||||
_pick_next_animation(hat, hat_outfits)
|
||||
|
||||
|
||||
func _on_change_shirt_pressed() -> void:
|
||||
shirt.texture = shirt_outfits.pick_next()
|
||||
_pick_next_animation(shirt, shirt_outfits)
|
||||
|
||||
|
||||
func _on_change_shoes_pressed() -> void:
|
||||
shoes.texture = shoes_outfits.pick_next()
|
||||
_pick_next_animation(decor, decor_outfits)
|
||||
|
||||
|
||||
func _pick_next_animation(sprite: AnimatedSprite2D, outfits: DragonOutfit):
|
||||
var animation: SpriteFrames = outfits.pick_next()
|
||||
if animation == null:
|
||||
sprite.visible = false
|
||||
return
|
||||
sprite.visible = true
|
||||
sprite.set_sprite_frames(animation)
|
||||
sprite.play('idle')
|
||||
|
||||
|
||||
func _pick_previous_animation(sprite: AnimatedSprite2D, outfits: DragonOutfit):
|
||||
var animation: SpriteFrames = outfits.pick_previous()
|
||||
if animation == null:
|
||||
sprite.visible = false
|
||||
return
|
||||
sprite.visible = true
|
||||
sprite.set_sprite_frames(animation)
|
||||
sprite.play('idle')
|
||||
|
||||
|
||||
func _on_create_pressed() -> void:
|
||||
if dragon_name.text.is_empty():
|
||||
return
|
||||
|
||||
var hat_index: int = hat_outfits.get_index(hat.texture)
|
||||
var shirt_index: int = shirt_outfits.get_index(shirt.texture)
|
||||
var decor_index: int = shoes_outfits.get_index(shoes.texture)
|
||||
var color_index: int = dragon_colors.get_index(dragon.texture)
|
||||
var properties = DragonProperties.new(dragon_name.text, "tower", color_index, hat_index, shirt_index, decor_index)
|
||||
var properties = DragonProperties.new(dragon_name.text, "tower", hat_outfits.index, shirt_outfits.index, decor_outfits.index, dragon_colors.index)
|
||||
on_create_dragon.emit(properties)
|
||||
queue_free()
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,7 @@ func _init(outfits: Array[SpriteFrames] = []):
|
|||
self.outfits = outfits
|
||||
|
||||
|
||||
func pick_next() -> Texture2D:
|
||||
func pick_next() -> SpriteFrames:
|
||||
index += 1
|
||||
if allow_null:
|
||||
return _pick_nullable()
|
||||
|
@ -19,7 +19,7 @@ func pick_next() -> Texture2D:
|
|||
return _pick_non_nullable()
|
||||
|
||||
|
||||
func pick_previous() -> Texture2D:
|
||||
func pick_previous() -> SpriteFrames:
|
||||
index -= 1
|
||||
if allow_null:
|
||||
return _pick_nullable()
|
||||
|
@ -27,7 +27,7 @@ func pick_previous() -> Texture2D:
|
|||
return _pick_non_nullable()
|
||||
|
||||
|
||||
func _pick_nullable():
|
||||
func _pick_nullable() -> SpriteFrames:
|
||||
index %= (len(outfits) + 1)
|
||||
if index == 0:
|
||||
return null
|
||||
|
@ -35,15 +35,11 @@ func _pick_nullable():
|
|||
return outfits[index - 1]
|
||||
|
||||
|
||||
func _pick_non_nullable():
|
||||
func _pick_non_nullable() -> SpriteFrames:
|
||||
index %= len(outfits)
|
||||
return outfits[index]
|
||||
|
||||
|
||||
func get_index(texture: Texture2D) -> int:
|
||||
return outfits.find(texture)
|
||||
|
||||
|
||||
func get_texture(index: int) -> SpriteFrames:
|
||||
if index < 0 or index >= len(outfits):
|
||||
return null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue