|
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
|
|
export var initial_dialogic_timeline: String
|
|
|
|
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()
|
|
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())
|
|
|