-- ln_text.lua
-- Tame narration (lewd_noita_tame_text) is default; graphic text is optional.

dofile_once("mods/lewd_noita/files/text/text_data.lua")

local UI_MSG_DEFAULT = "mods/lewd_noita/files/sex_logic/ui_msg.png"

function is_extreme_text_enabled()
	local extreme = ModSettingGet("lewd_noita.extreme_content_enabled")
	if extreme == nil then extreme = true end
	if not extreme then return false end
	local text = ModSettingGet("lewd_noita.extreme_text_enabled")
	if text == nil then text = false end
	return text
end

function ln_text_pick(tame_title, tame_body, extreme_title, extreme_body)
	if is_extreme_text_enabled() then
		return extreme_title, extreme_body
	end
	return tame_title, tame_body
end

function ln_text_string(tame, extreme)
	if is_extreme_text_enabled() then return extreme end
	return tame
end

function ln_print_important(tame_title, tame_body, extreme_title, extreme_body, icon)
	local title, body = ln_text_pick(tame_title, tame_body, extreme_title, extreme_body)
	GamePrintImportant(title, body, icon or UI_MSG_DEFAULT)
end

function ln_print_key(key, icon)
	local entry = LN_TEXT[key]
	if entry == nil then return end
	ln_print_important(entry.tame[1], entry.tame[2], entry.extreme[1], entry.extreme[2], icon)
end

function ln_print_stage(parasite_id, stage, icon)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.stages == nil then return end
	local entry = parasite.stages[stage]
	if entry == nil then return end
	ln_print_important(entry.tame[1], entry.tame[2], entry.extreme[1], entry.extreme[2], icon)
end

function ln_print_infection(parasite_id, result, icon)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.infection == nil then return end
	local entry = parasite.infection[result]
	if entry == nil then return end
	ln_print_important(entry.tame[1], entry.tame[2], entry.extreme[1], entry.extreme[2], icon)
end

function ln_print_cure(parasite_id, icon)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.cure == nil then return end
	ln_print_important(parasite.cure.tame[1], parasite.cure.tame[2], parasite.cure.extreme[1], parasite.cure.extreme[2], icon)
end

function ln_print_monologue(parasite_id, icon)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.monologue == nil then return end
	local title = ln_text_string(parasite.monologue.title.tame, parasite.monologue.title.extreme)
	local bodies = parasite.monologue.bodies
	local pick = bodies[Random(1, #bodies)]
	local body = ln_text_string(pick.tame, pick.extreme)
	GamePrintImportant(title, body, icon or UI_MSG_DEFAULT)
end

function ln_print_compulsion(parasite_id, msg_type, icon)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.compulsion == nil then return end
	local entry = parasite.compulsion[msg_type]
	if entry == nil then return end
	ln_print_important(entry.tame[1], entry.tame[2], entry.extreme[1], entry.extreme[2], icon)
end

function ln_compulsion_during_msg(parasite_id)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.compulsion == nil or parasite.compulsion.during == nil then return nil end
	local during = parasite.compulsion.during
	local list = is_extreme_text_enabled() and during.extreme or during.tame
	if list == nil or #list == 0 then return nil end
	return list[Random(1, #list)]
end

function ln_parasite_icon_desc(parasite_id)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.icon_desc == nil then return "" end
	return ln_text_string(parasite.icon_desc.tame, parasite.icon_desc.extreme)
end

function ln_spawn_pregnancy_desc(parasite_id)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.spawn == nil or parasite.spawn.pregnancy_icon == nil then return "" end
	local entry = parasite.spawn.pregnancy_icon
	return ln_text_string(entry.tame, entry.extreme)
end

function ln_print_spawn(parasite_id, variant, icon)
	local parasite = LN_TEXT[parasite_id]
	if parasite == nil or parasite.spawn == nil then return end
	local entry = parasite.spawn[variant]
	if entry == nil then return end
	ln_print_important(entry.tame[1], entry.tame[2], entry.extreme[1], entry.extreme[2], icon)
end

function ln_print_wolf_bond(stage, icon)
	local wolf = LN_TEXT.wolf_bonding
	if wolf == nil or wolf.bond == nil then return end
	local entry = wolf.bond[stage]
	if entry == nil then return end
	ln_print_important(entry.tame[1], entry.tame[2], entry.extreme[1], entry.extreme[2], icon)
end

function ln_print_wolf_leash(icon)
	local wolf = LN_TEXT.wolf_bonding
	if wolf == nil or wolf.leash == nil then return end
	ln_print_important(wolf.leash.tame[1], wolf.leash.tame[2], wolf.leash.extreme[1], wolf.leash.extreme[2], icon)
end

function ln_print_wolf_release(icon)
	local wolf = LN_TEXT.wolf_bonding
	if wolf == nil or wolf.release == nil then return end
	ln_print_important(wolf.release.tame[1], wolf.release.tame[2], wolf.release.extreme[1], wolf.release.extreme[2], icon)
end

function ln_wolf_icon_desc()
	local wolf = LN_TEXT.wolf_bonding
	if wolf == nil or wolf.icon_desc == nil then return "" end
	return ln_text_string(wolf.icon_desc.tame, wolf.icon_desc.extreme)
end

function ln_print_birth_start(icon)
	local birth = LN_TEXT.birth
	if birth == nil or birth.start == nil then return end
	ln_print_important(birth.start.tame[1], birth.start.tame[2], birth.start.extreme[1], birth.start.extreme[2], icon)
end

function ln_print_text_pair(entry, icon)
	if entry == nil then return end
	ln_print_important(entry.tame[1], entry.tame[2], entry.extreme[1], entry.extreme[2], icon)
end

function ln_pregnancy_description()
	return ln_text_string(
		"Your womb is heavy with alien young. They are ready to be born.",
		"You are about to give birth to something"
	)
end
