mirror of
https://github.com/t-affeldt/climate_api.git
synced 2025-01-03 14:50:34 +01:00
54 lines
1.7 KiB
Lua
54 lines
1.7 KiB
Lua
|
if not climate_mod.settings.skybox then return end
|
||
|
if not minetest.get_modpath("skylayer") then return end
|
||
|
|
||
|
local SKYBOX_NAME = "climate_api:clouds"
|
||
|
|
||
|
local function set_clouds(player, clouds)
|
||
|
sky = { name = SKYBOX_NAME, cloud_data = clouds }
|
||
|
skylayer.add_layer(player:get_player_name(), sky)
|
||
|
end
|
||
|
|
||
|
local function remove_cloud_layer(player)
|
||
|
skylayer.remove_layer(player:get_player_name(), SKYBOX_NAME)
|
||
|
end
|
||
|
|
||
|
local function accumulate(current, incoming, fn)
|
||
|
if type(incoming) ~= "nil" and type(current) == "nil" then
|
||
|
return incoming
|
||
|
elseif type(incoming) ~= "nil" then
|
||
|
return fn(current, incoming)
|
||
|
end
|
||
|
return current
|
||
|
end
|
||
|
|
||
|
local function handle_effect(player_data)
|
||
|
for playername, data in pairs(player_data) do
|
||
|
local player = minetest.get_player_by_name(playername)
|
||
|
|
||
|
local data = player.get_meta()
|
||
|
local current_size = data.get_float("climate_api:cloud_size")
|
||
|
local current_speed_x = data.get_float("climate_api:cloud_speed_x")
|
||
|
local current_speed_z = data.get_float("climate_api:cloud_speed_z")
|
||
|
|
||
|
local clouds = {}
|
||
|
for weather, value in pairs(data) do
|
||
|
clouds.size = accumulate(clouds.size, data.size, function(a, b) return a * b end)
|
||
|
clouds.speed = accumulate(clouds.speed, data.speed, vector.multiply)
|
||
|
if type(data.color) ~= "nil" then
|
||
|
clouds.color = data.color
|
||
|
end
|
||
|
end
|
||
|
set_clouds(player, clouds)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
local function remove_effect(player_data)
|
||
|
for playername, data in ipairs(player_data) do
|
||
|
local player = minetest.get_player_by_name(playername)
|
||
|
remove_cloud_layer(player)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
climate_api.register_effect("climate_api:clouds", handle_effect, "tick")
|
||
|
climate_api.register_effect("climate_api:clouds", remove_effect, "end")
|
||
|
climate_api.set_effect_cycle("climate_api:clouds", climate_api.LONG_CYCLE)
|