-- @ Version: SCREEN SPACE SHADERS - UPDATE 17
-- @ Description: Rain script
-- @ Author: https://www.moddb.com/members/ascii1457
-- @ Mod: https://www.moddb.com/mods/stalker-anomaly/addons/screen-space-shaders

-- Settings
local ssfx_rain_quality = 0

local ssfx_rain_alpha = 0
local ssfx_rain_brightness = 0
local ssfx_rain_refraction = 0
local ssfx_rain_reflection = 0

local ssfx_rain_len = 0
local ssfx_rain_width = 0
local ssfx_rain_speed = 0

local ssfx_rain_splash_alpha = 0
local ssfx_rain_splash_refraction = 0

-- Internal vars
module_installed = true

local function apply_interactive_grass_settings()

	-- Apply command
	get_console():execute("ssfx_rain_1 (" .. ssfx_rain_len .. "," .. ssfx_rain_width .. "," .. ssfx_rain_speed .. "," .. ssfx_rain_quality .. ")")
	get_console():execute("ssfx_rain_2 (" .. ssfx_rain_alpha .. "," .. ssfx_rain_brightness .. "," .. ssfx_rain_refraction .."," .. ssfx_rain_reflection .. ")")
	get_console():execute("ssfx_rain_3 (" .. ssfx_rain_splash_alpha .. "," .. ssfx_rain_splash_refraction .. ",0,0)")

end

local function update_settings()
	
	-- Get settings
	module_id = "ssfx_rain_module/ssfx_rain_main"
	ssfx_rain_quality = ssfx_001_mcm.ssfx_get_setting(module_id, "quality", ssfx_rain_settings)

	ssfx_rain_alpha = ssfx_001_mcm.ssfx_get_setting(module_id, "alpha", ssfx_rain_settings)
	ssfx_rain_brightness = ssfx_001_mcm.ssfx_get_setting(module_id, "brightness", ssfx_rain_settings)
	ssfx_rain_refraction = ssfx_001_mcm.ssfx_get_setting(module_id, "refraction", ssfx_rain_settings)
	ssfx_rain_reflection = ssfx_001_mcm.ssfx_get_setting(module_id, "reflection", ssfx_rain_settings)

	ssfx_rain_len = ssfx_001_mcm.ssfx_get_setting(module_id, "len", ssfx_rain_settings)
	ssfx_rain_width = ssfx_001_mcm.ssfx_get_setting(module_id, "width", ssfx_rain_settings)
	ssfx_rain_speed = ssfx_001_mcm.ssfx_get_setting(module_id, "speed", ssfx_rain_settings)

	ssfx_rain_splash_alpha = ssfx_001_mcm.ssfx_get_setting(module_id, "splash_alpha", ssfx_rain_settings)
	ssfx_rain_splash_refraction = ssfx_001_mcm.ssfx_get_setting(module_id, "splash_refraction", ssfx_rain_settings)

	-- Apply settings
	apply_interactive_grass_settings()

end

function on_game_start()

	-- General Functions
	RegisterScriptCallback("on_option_change", update_settings)

	-- Read and apply settigns
	update_settings()
end