1
0
Fork 0
spacetac/core/ui/command.gd

39 lines
688 B
GDScript3
Raw Normal View History

2022-10-20 23:16:48 +00:00
@tool
extends Composer
class_name Command
signal clicked
@export var icon: Texture2D:
set(val):
if val is Texture2D:
icon = val
else:
icon = PlaceholderTexture2D.new()
_check_compose()
2022-10-23 22:50:48 +00:00
2022-10-26 18:29:17 +00:00
@export var player: Node:
2022-10-23 22:50:48 +00:00
set(val):
2022-10-26 18:29:17 +00:00
if val is Player:
player = val
2022-10-23 22:50:48 +00:00
else:
2022-10-26 18:29:17 +00:00
player = null
2022-10-23 22:50:48 +00:00
_check_compose()
2022-10-20 23:16:48 +00:00
@export var code: String
func _compose():
2022-10-23 23:09:57 +00:00
%icon.texture = icon
2022-10-26 18:29:17 +00:00
%badge.self_modulate = player.color if player else Color.GRAY
2022-10-20 23:16:48 +00:00
super._compose()
2022-10-23 23:09:57 +00:00
2022-10-20 23:16:48 +00:00
func apply(container: Node2D, pos: Vector2):
if get_parent() != container:
if get_parent():
get_parent().remove_child(self)
container.add_child(self)
position = pos
2022-10-23 23:09:57 +00:00
func _on_badge_pressed():
clicked.emit()