local mod = get_mod("Bubblelicious")

mod:io_dofile("Bubblelicious/scripts/mods/Bubblelicious/Bubblelicious_audio")

mod.helper = {}

mod.helper.debug_print_table = function(table, condition)
	for a, b in pairs(table) do
		if condition == nil then
			mod:echo(string.format("%s = %s", a, b))
		elseif condition == true then
			mod.helper.cprint(string.format("%s = %s", a, b), true)
		elseif condition == false then
			mod.helper.cprint(string.format("%s = %s", a, b), false)
		end
	end
end

mod.helper.cprint = function(str, good)
	if good then
		mod:echo(string.format("{#color(089,240,089,255)}%s{#reset()}", str))
	else
		mod:echo(string.format("{#color(255,071,076,255)}%s{#reset()}", str))
	end
end


mod.helper.get_player_class = function(peer_id)
	if not peer_id then
		return Managers.player:local_player(1):profile().archetype.name
	end

	local player = Managers.player:player(peer_id, 1)
	return player:profile().archetype.name, player.player_unit
end

mod.helper.player_is_psyker = function(peer_id)
	if not peer_id then
    	return mod.helper.get_player_class() == "psyker"
	end

	local pclass, punit = mod.helper.get_player_class(peer_id)
	return pclass == "psyker", punit
end


mod.helper.play_shield_failing_voiceline = function(player_unit)
	--Thanks to Norkkom (SanctionedPsyker) for this on-demand audio playback procedure
    local world = Managers.ui:world()
    local wwise_world = Managers.world:wwise_world(world)

    if player_unit then
		local source_id = wwise_world:make_auto_source(player_unit, 1)
		local soundfile = "wwise/externals/" .. mod.voicelines.get_random_voice_line()
		local sfx = "wwise/events/vo/play_sfx_es_player_vo"
		local priority = "es_vo_prio_1"

		wwise_world:trigger_resource_external_event(sfx, priority, soundfile, 4, source_id)
    end
end