extends AIScriptModule


# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
var root
var skel
var hair_skel

var garments = ["male-panties1", "male-shirt1"]
var garments_head = []
var basedir = "res://scenes/clothes/"
var material = preload("res://scenes/clothes/clothes-male.material")
func init(tick):
	root = get_character(tick)
	assert(root.has_meta("skeleton"))

	call_deferred("setup_markers")
	call_deferred("setup_garments")
func setup_markers():
	var cmdq = []
	if root.has_meta("cmdqueue"):
		cmdq = root.get_meta("cmdqueue")
#	cmdq.push_back(["hide_marker", "head/marker_talk"])
#	cmdq.push_back(["hide_marker", "head/marker_hips_action"])
#	cmdq.push_back(["register_marker", self, "hips/marker_dagger_sacrifice",
#		{
#			"method": "dagger_sacrifice"
#		}
#	])
#	cmdq.push_back(["hide_marker", "hips/marker_dagger_sacrifice"])
	cmdq.push_back(["anim_state", "locomotion"])
	root.set_meta("cmdqueue", cmdq)
func setup_garments():
	skel = root.get_meta("skeleton")
	hair_skel = root.get_meta("hair_skeleton")
	
	print("garments for player")
	for g in garments:
		var m: MeshInstance = MeshInstance.new()
		m.name = g
		var geo: ArrayMesh = load(basedir + g + ".mesh")
		print(g, " mesh: ", geo, "mat: ", material)
		geo.surface_set_material(0, material)
		m.mesh = geo
#		m.skeleton = m.get_path_to(root.get_meta("skeleton"))
#		 = root.get_meta("skeleton")
		skel.add_child(m)
		m.transform = Transform()
	for g in garments_head:
		var m: MeshInstance = MeshInstance.new()
		m.name = g
		var geo: ArrayMesh = load(basedir + g + ".mesh")
		print("mesh: ", geo, "mat: ", material)
		geo.surface_set_material(0, material)
		m.mesh = geo
#		m.skeleton = m.get_path_to(root.get_meta("skeleton"))
#		 = root.get_meta("skeleton")
		hair_skel.add_child(m)
		m.transform = Transform()
#func _process(delta):
#	if !skel:
#		skel = root.get_meta("skeleton")
#	var sacrifice_marker = skel.get_node("hips/marker_dagger_sacrifice")
#	if sacrifice_marker.visible && !inventory.items.s_dagger:
#		sacrifice_marker.hide()
#	elif !sacrifice_marker.visible && inventory.items.s_dagger:
#		sacrifice_marker.show()

#func dagger_sacrifice(data):
#	print("dagger sacrifice")
#	var cmdq = []
#	var other = group_manager.player
#	if other.has_meta("cmdqueue"):
#		cmdq = other.get_meta("cmdqueue")
#	cmdq.push_back(["anim_param", "blade_right/blend_amount", 1.0])
#	cmdq.push_back(["equip", "wrist_r/weapon_right", "s_dagger"])
#	other.set_meta("cmdqueue", cmdq)
#	group_manager.submit_player_npc_event_arot(root, "sacrificed-a", root, "sacrificed", root)
func update_physics(tick, delta):
	return ERR_BUSY
func update(tick, delta):
	return ERR_BUSY

