game loop improvement
This commit is contained in:
67
scenes/seat/seat.gd
Normal file
67
scenes/seat/seat.gd
Normal file
@@ -0,0 +1,67 @@
|
||||
@tool
|
||||
extends Area2D
|
||||
class_name Seat
|
||||
|
||||
signal seat_clicked(Seat)
|
||||
|
||||
@export var guest: MaskedChara:
|
||||
set(new_resource):
|
||||
guest = new_resource
|
||||
_on_chara_resource_changed()
|
||||
|
||||
@onready var character: Character = $Character
|
||||
@onready var empty: Sprite2D = $Empty
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
character.scale.x = 0.15
|
||||
character.scale.y = 0.15
|
||||
character.position.y = -135
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
guest = null
|
||||
character.visible = false
|
||||
empty.visible = true
|
||||
|
||||
|
||||
func _on_chara_resource_changed() -> void:
|
||||
if guest == null:
|
||||
return
|
||||
|
||||
if character != null:
|
||||
empty.visible = false
|
||||
character.visible = true
|
||||
character.chara_resource = guest.character
|
||||
character.mask_eyes.mask_resource = guest.face_mask
|
||||
character.mask_mouth.mask_resource = guest.mouth_mask
|
||||
|
||||
|
||||
func set_guest(p_guest: MaskedChara) -> void:
|
||||
if p_guest == null:
|
||||
return
|
||||
|
||||
guest = p_guest
|
||||
empty.visible = false
|
||||
character.visible = true
|
||||
character.chara_resource = guest.character
|
||||
character.mask_eyes.mask_resource = guest.face_mask
|
||||
character.mask_mouth.mask_resource = guest.mouth_mask
|
||||
|
||||
func _on_mouse_entered() -> void:
|
||||
if guest != null:
|
||||
return
|
||||
Input.set_default_cursor_shape(Input.CursorShape.CURSOR_POINTING_HAND)
|
||||
|
||||
|
||||
func _on_mouse_exited() -> void:
|
||||
if guest != null:
|
||||
return
|
||||
Input.set_default_cursor_shape(Input.CursorShape.CURSOR_ARROW)
|
||||
|
||||
|
||||
func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
if event is InputEventMouseButton and event.is_pressed() and guest == null:
|
||||
Input.set_default_cursor_shape(Input.CursorShape.CURSOR_ARROW)
|
||||
seat_clicked.emit(self)
|
||||
1
scenes/seat/seat.gd.uid
Normal file
1
scenes/seat/seat.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cuojjiwxidmwu
|
||||
25
scenes/seat/seat.tscn
Normal file
25
scenes/seat/seat.tscn
Normal file
@@ -0,0 +1,25 @@
|
||||
[gd_scene format=3 uid="uid://l0hl170iqkgx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cuojjiwxidmwu" path="res://scenes/seat/seat.gd" id="1_pceab"]
|
||||
[ext_resource type="Resource" uid="uid://ca2fcdibf0mdm" path="res://resources/guests/queen_unracist.tres" id="2_wnjs1"]
|
||||
[ext_resource type="PackedScene" uid="uid://bvpyqyftqhy45" path="res://scenes/character/character.tscn" id="3_dxmy0"]
|
||||
[ext_resource type="Texture2D" uid="uid://cftllq6l7xclt" path="res://icon.svg" id="4_wnjs1"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_rofvo"]
|
||||
size = Vector2(128, 128)
|
||||
|
||||
[node name="Seat" type="Area2D" unique_id=1604639021]
|
||||
script = ExtResource("1_pceab")
|
||||
guest = ExtResource("2_wnjs1")
|
||||
|
||||
[node name="Character" parent="." unique_id=138741531 instance=ExtResource("3_dxmy0")]
|
||||
|
||||
[node name="Empty" type="Sprite2D" parent="." unique_id=357649392]
|
||||
texture = ExtResource("4_wnjs1")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1054126207]
|
||||
shape = SubResource("RectangleShape2D_rofvo")
|
||||
|
||||
[connection signal="input_event" from="." to="." method="_on_input_event"]
|
||||
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
|
||||
Reference in New Issue
Block a user