:NAME tutorial1

:GLOBAL int32					state
:GLOBAL float32					timer
:GLOBAL float32					focus_start_time
:GLOBAL float32					focus_start_scale
:GLOBAL c_object*				focus
:GLOBAL c_object*				message

local tutoriallib = require "scripts/tutorial_utils"
local entrylib = require "objects/spawn_entry/spawn_entrylib"

-- ------------ initial delay ------------ 

local state= tutoriallib.add_delay(1.5)

-- ------------ message 1 ------------ 

state= tutoriallib.make_state("message1")
function hand_start()
	local hand_object= object_place("hand")
	if (hand_object) then
		local ws= world_state_get()
		local tween= hand_object.tween_get()
		if (tween) then
			tween.play_animation_after_delay("start", 1)
			tween.play_animation_after_delay("end", 4)
		end
	end
end
function end_when_player_moves()
	local ws= world_state_get()
	local player= ws.primary_player_get()
	if (player) then
		local path= player.path_get()
		if (path.path_active()) then
			return true
		end
	end
	return false
end
state.pause= false
state.start_func= hand_start
state.end_func=end_when_player_moves

-- ------------ delay for hand ------------ 

-- add a delay for the player to play around
tutoriallib.add_delay(1.5)


-- ------------ message 2, focus on painting ------------ 

state= tutoriallib.make_state("message2")
tutoriallib.focus_on(state, "loot_marker", tutoriallib.k_scale_normal)

-- ------------ wait for painting to get picked up ------------ 

state= tutoriallib.add_delay(0)
function player_got_loot()
	local ws= world_state_get()
	local hud= ws.global_script("game_hud")
	if (hud and hud.required_loot_counter == 0) then
		--global.timer= 0.5
		return true
	end
end
state.end_func= player_got_loot

-- ------------ delay ------------ 

state= tutoriallib.add_delay(0.5)

-- ------------ message 3, focus on exit ------------ 

state= tutoriallib.make_state("message3")
tutoriallib.focus_on(state, "exit_marker", 1.2)

-- ------------ spawn guard ------------ 

state= tutoriallib.add_delay(0)
function place_guard()
	local guard= object_place("guard")
	if (guard) then
		local entry= object_get("entry")
		if (entry) then
			entrylib.spawn_entry(guard, entry)
		end
	end
end
state.start_func= place_guard


function global_initialize(g)
	g.state= 0
	g.focus= nil
	g.timer= 0
	g.focus_start_time= 0
	g.focus_start_scale= tutoriallib.k_scale_out	
	
	g.message= nil
	
end

function start()
	local world= world_get()
	local ws= world_state_get()
	global.focus= object_place("focus")
	global.focus.hide(true)
	tutoriallib.start()
end

function update()
	tutoriallib.update(k_states, global)
end

system_register(start, update, nil, nil)
