:NAME tutorial5

: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 state= nil

-- ------------ initial delay and message 1 ------------

tutoriallib.add_delay(.7)

state= tutoriallib.make_state("message1")
tutoriallib.focus_on(state, "loot", tutoriallib.k_scale_normal)

-- ------------ wait for loot to be collected ------------

state= tutoriallib.add_delay(0)
function player_picked_up_loot()
	local ws= world_state_get()
	local hud= ws.global_script("game_hud")
	if (hud and hud.loot_count > 0) then
		return true
	end
end
state.end_func= player_picked_up_loot

-- ------------ delay and remove message 1 ------------

state= tutoriallib.add_delay(.5)
function remove_message_1()
	tutoriallib.remove_bubble("message1")
end
state.start_func= remove_message_1

-- ------------ message 2 ------------

tutoriallib.make_state("message2")

-- ------------ wait until game is won ------------

state= tutoriallib.add_delay(.5)
function game_is_won()
	local ws= world_state_get()
	local hud= ws.global_script("game_hud")
	if (hud and hud.win_screen_on) then
		return true
	end
end
state.end_func= game_is_won

-- ------------ delay, then place the post_win_tutorial plate ------------

tutoriallib.add_delay(1)
state= tutoriallib.add_delay(0)
function place_post_win_tutorial()
	local w= world_get()
	local ws= world_state_get()
	local plate= w.get_plate("post_win_tutorial")
	if (plate) then
		ws.place_plate(plate);
	end
end
state.start_func= place_post_win_tutorial

-- ------------ wait until we dismiss the win screen ------------

state= tutoriallib.add_delay(0)
function win_screen_dismissed()
	local ws= world_state_get()
	local hud= ws.global_script("game_hud")
	if (hud and (not hud.win_screen_display)) then
		-- call "fadeout" animation on all the tutorial elements
		local w= world_get()
		local plate= w.get_plate("post_win_tutorial")
		if (plate) then
			local plate_state= plate.plate_state_get()
			local object= plate_state.objects
			while true do
				if (object) then
					object.tween_animation_play("fadeout")
					object= object.plate_object_next
				else
					break
				end
			end
		end
	
		return true
	end	
end
state.end_func= win_screen_dismissed




-- ------------ init and update ------------

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)
