Refactoring crap
This commit is contained in:
48
scripts/entities/NPC.gd
Normal file
48
scripts/entities/NPC.gd
Normal file
@@ -0,0 +1,48 @@
|
||||
class_name NPC extends CharacterBody3D
|
||||
|
||||
enum InteractType {
|
||||
NONE,
|
||||
TEXTBOX,
|
||||
CUTSCENE
|
||||
}
|
||||
|
||||
# Movement speed in units per second
|
||||
@export var gravity: float = 24.8
|
||||
@export var interactType:InteractType = InteractType.NONE
|
||||
@export_multiline var interactTexts:Array[String] = []
|
||||
@export var cutscene:Cutscene = null
|
||||
var nextTextIndex:int = 0
|
||||
|
||||
func _enter_tree() -> void:
|
||||
$InteractableArea.interactEvent.connect(_on_interact)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
$InteractableArea.interactEvent.disconnect(_on_interact)
|
||||
UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing)
|
||||
|
||||
func _physics_process(delta):
|
||||
# Apply gravity if not on floor
|
||||
if !is_on_floor():
|
||||
velocity += PHYSICS.GRAVITY * delta
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func _on_interact() -> void:
|
||||
nextTextIndex = 0
|
||||
match interactType:
|
||||
InteractType.TEXTBOX:
|
||||
UI.TEXTBOX.setText(interactTexts[nextTextIndex])
|
||||
UI.TEXTBOX.textboxClosing.connect(onTextboxClosing)
|
||||
InteractType.CUTSCENE:
|
||||
if cutscene:
|
||||
cutscene.start()
|
||||
_:
|
||||
return
|
||||
|
||||
|
||||
func onTextboxClosing() -> void:
|
||||
nextTextIndex += 1
|
||||
if nextTextIndex < interactTexts.size():
|
||||
UI.TEXTBOX.setText(interactTexts[nextTextIndex])
|
||||
else:
|
||||
UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing)
|
Reference in New Issue
Block a user