Implement dynamic cloud sizes, adjust cycle lengths

This commit is contained in:
Till Affeldt
2020-04-13 16:53:32 +02:00
parent 47530bb07e
commit fdc457bd09
9 changed files with 86 additions and 24 deletions

54
ca_effects/clouds.lua Normal file
View File

@ -0,0 +1,54 @@
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)

View File

@ -11,4 +11,4 @@ local function update_effect(player_data)
end
climate_api.register_effect("climate_api:sound", update_effect, "change")
climate_api.set_effect_cycle("climate_api:skybox", climate_api.LONG_CYCLE)
climate_api.set_effect_cycle("climate_api:skybox", climate_api.MEDIUM_CYCLE)