print("hello!")

ecs.behavior_tree.register_node("luaHello", function(entity_id, params)
    local message = params.message or "Hello!"
    print("Entity " .. entity_id .. " says: " .. message)
    return "success"
end)

ecs.action_db.add_action("lua_hello_action", 1,
    {},  -- no preconditions
    {},  -- no effects
    {    -- behavior tree
        type = "sequence",
        children = {
            ecs.behavior_tree.create_node("luaHello", "message=Welcome to the game!"),
            ecs.behavior_tree.create_node("setAnimationState", "main/action"),
            ecs.behavior_tree.create_node("setAnimationState", "action/sitting-ground"),
	    ecs.behavior_tree.create_node("delay", "dly", "9.0"),
	    ecs.behavior_tree.create_node("setAnimationState", "main/locomotion"),
	    ecs.behavior_tree.create_node("setAnimationState", "locomotion/idle"),
        }
    }
)

ecs.subscribe_event("game_start", function(event, params)
	print("Event: " .. event)
	-- ecs.debug_crash("game_start triggered")
	ecs.subscribe_event("new_game", function(event, params)
		-- ecs.debug_crash("new_game triggered")
		local tsub = ecs.subscribe_event("scene_ready", function(event, params)
			-- ecs.unsubscribe_event(tsub)
			-- ecs.debug_crash("scene_ready triggered")
		end)
	end)
end)

