meat_madness_redux/godot/assets/meat_bore/npcs/npc.gd

56 lines
1.4 KiB
GDScript3
Raw Normal View History

2023-01-02 22:35:37 -07:00
extends Spatial
class_name NPC
enum Name {Clark, Guy, Lee, Wally, Jackie, Alexis}
export(Name) var who
export var body_texture: StreamTexture
export var face_texture: StreamTexture
2023-01-03 01:54:59 -07:00
export var initial_dialogic_timeline: String
2023-01-02 22:35:37 -07:00
func is_male() -> bool:
return not (who == Name.Jackie or who == Name.Alexis)
func set_material():
var body_mesh: MeshInstance
if is_male():
body_mesh = $NPC_Male_Shared/Skeleton/NPC_Male
else:
body_mesh = $NPC_female/Skeleton/NPC_Female
var mat: SpatialMaterial = body_mesh.get_active_material(0).duplicate()
body_mesh.set_surface_material(0, mat)
mat.albedo_texture = body_texture
if not is_male():
var face_mat: SpatialMaterial = body_mesh.get_active_material(1).duplicate()
body_mesh.set_surface_material(1, face_mat)
face_mat.albedo_texture = face_texture
func _ready():
set_material()
2023-01-03 01:54:59 -07:00
var _err = $npc_common/Area.connect("body_entered", self, "body_entered")
_err = $npc_common/Area.connect("body_exited", self, "body_exited")
func body_entered(body):
if body.get_parent() == Util.player:
player_entered()
func body_exited(body):
if body.get_parent() == Util.player:
player_exited()
var dialog = weakref(null)
func player_entered():
if dialog.get_ref() == null:
dialog = weakref(Dialogic.start(initial_dialogic_timeline))
add_child(dialog.get_ref())
func player_exited():
if dialog.get_ref() == null:
return
if is_a_parent_of(dialog.get_ref()):
call_deferred("remove_child", dialog.get_ref())