mirror of
https://github.com/t-affeldt/climate_api.git
synced 2025-07-03 00:40:36 +02:00
Add hud overlay effect, increase global tick cycle, improve skybox and sound effects
This commit is contained in:
@ -1,48 +0,0 @@
|
||||
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)
|
||||
local 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 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, "stop")
|
||||
climate_api.set_effect_cycle("climate_api:clouds", climate_api.LONG_CYCLE)
|
68
ca_effects/hud_overlay.lua
Normal file
68
ca_effects/hud_overlay.lua
Normal file
@ -0,0 +1,68 @@
|
||||
if not climate_mod.settings.sound then return end
|
||||
|
||||
local EFFECT_NAME = "climate_api:hud_overlay"
|
||||
|
||||
local handles = {}
|
||||
local function apply_hud(pname, weather, hud)
|
||||
if handles[pname] == nil then handles[pname] = {} end
|
||||
if handles[pname][weather] ~= nil then return end
|
||||
local player = minetest.get_player_by_name(pname)
|
||||
local handle = player:hud_add({
|
||||
name = weather,
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 0},
|
||||
alignment = {x = 1, y = 1},
|
||||
scale = { x = -100, y = -100},
|
||||
z_index = hud.z_index,
|
||||
text = hud.file,
|
||||
offset = {x = 0, y = 0}
|
||||
})
|
||||
handles[pname][weather] = handle
|
||||
end
|
||||
|
||||
local function remove_hud(pname, weather, hud)
|
||||
if handles[pname] == nil or handles[pname][weather] == nil then return end
|
||||
local handle = handles[pname][weather]
|
||||
local player = minetest.get_player_by_name(pname)
|
||||
player:hud_remove(handle)
|
||||
handles[pname][weather] = nil
|
||||
end
|
||||
|
||||
local function start_effect(player_data)
|
||||
for playername, data in pairs(player_data) do
|
||||
for weather, value in pairs(data) do
|
||||
apply_hud(playername, weather, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function handle_effect(player_data, prev_data)
|
||||
for playername, data in pairs(player_data) do
|
||||
for weather, value in pairs(data) do
|
||||
if prev_data[playername][weather] == nil then
|
||||
apply_hud(playername, weather, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for playername, data in pairs(prev_data) do
|
||||
for weather, value in pairs(data) do
|
||||
if player_data[playername][weather] == nil then
|
||||
remove_hud(playername, weather, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function stop_effect(prev_data)
|
||||
for playername, data in pairs(prev_data) do
|
||||
for weather, value in pairs(data) do
|
||||
remove_hud(playername, weather, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
climate_api.register_effect(EFFECT_NAME, start_effect, "start")
|
||||
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
|
||||
climate_api.register_effect(EFFECT_NAME, stop_effect, "stop")
|
||||
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.MEDIUM_CYCLE)
|
@ -1,5 +1,7 @@
|
||||
if not climate_mod.settings.particles then return end
|
||||
|
||||
local EFFECT_NAME = "climate_api:particles"
|
||||
|
||||
local function get_particle_texture(particles)
|
||||
if type(particles.textures) == "nil" or next(particles.textures) == nil then
|
||||
return particles.texture
|
||||
@ -61,5 +63,5 @@ local function handle_effect(player_data)
|
||||
end
|
||||
end
|
||||
|
||||
climate_api.register_effect("climate_api:particles", handle_effect, "tick")
|
||||
climate_api.set_effect_cycle("climate_api:particles", climate_api.SHORT_CYCLE)
|
||||
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
|
||||
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.SHORT_CYCLE)
|
@ -1,15 +1,27 @@
|
||||
if not climate_mod.settings.skybox then return end
|
||||
if not minetest.get_modpath("skylayer") then return end
|
||||
|
||||
local SKYBOX_NAME = "climate_api:skybox"
|
||||
local EFFECT_NAME = "climate_api:skybox"
|
||||
|
||||
local function set_skybox(player, sky)
|
||||
sky.name = SKYBOX_NAME
|
||||
skylayer.add_layer(player:get_player_name(), sky)
|
||||
if sky.sky_data ~= nil then
|
||||
player:set_sky(sky.sky_data)
|
||||
end
|
||||
if sky.cloud_data ~= nil then
|
||||
player:set_clouds(sky.cloud_data)
|
||||
end
|
||||
if sky.moon_data ~= nil then
|
||||
player:set_moon(sky.moon_data)
|
||||
end
|
||||
if sky.sun_data ~= nil then
|
||||
player:set_sun(sky.sun_data)
|
||||
end
|
||||
if sky.stars_data ~= nil then
|
||||
player:set_sun(sky.stars_data)
|
||||
end
|
||||
end
|
||||
|
||||
local function remove_skybox(player)
|
||||
skylayer.remove_layer(player:get_player_name(), SKYBOX_NAME)
|
||||
player:set_sky({ type = "regular", clouds = true})
|
||||
end
|
||||
|
||||
local function handle_effect(player_data)
|
||||
@ -24,12 +36,12 @@ local function handle_effect(player_data)
|
||||
end
|
||||
|
||||
local function remove_effect(player_data)
|
||||
for playername, data in ipairs(player_data) do
|
||||
for playername, data in pairs(player_data) do
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
remove_skybox(player)
|
||||
end
|
||||
end
|
||||
|
||||
climate_api.register_effect("climate_api:skybox", handle_effect, "tick")
|
||||
climate_api.register_effect("climate_api:skybox", remove_effect, "stop")
|
||||
climate_api.set_effect_cycle("climate_api:skybox", climate_api.LONG_CYCLE)
|
||||
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
|
||||
climate_api.register_effect(EFFECT_NAME, remove_effect, "stop")
|
||||
--climate_api.set_effect_cycle("climate_api:skybox", climate_api.LONG_CYCLE)
|
@ -1,5 +1,7 @@
|
||||
if not climate_mod.settings.sound then return end
|
||||
|
||||
local EFFECT_NAME = "climate_api:sound"
|
||||
|
||||
local handles = {}
|
||||
local function start_sound(pname, weather, sound)
|
||||
if handles[pname] == nil then handles[pname] = {} end
|
||||
@ -30,7 +32,7 @@ local function handle_effect(player_data, prev_data)
|
||||
for playername, data in pairs(player_data) do
|
||||
for weather, value in pairs(data) do
|
||||
if prev_data[playername][weather] == nil then
|
||||
start_sound(playername, weather, sound)
|
||||
start_sound(playername, weather, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -38,7 +40,7 @@ local function handle_effect(player_data, prev_data)
|
||||
for playername, data in pairs(prev_data) do
|
||||
for weather, value in pairs(data) do
|
||||
if player_data[playername][weather] == nil then
|
||||
stop_sound(playername, weather, sound)
|
||||
stop_sound(playername, weather, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -53,7 +55,7 @@ local function stop_effect(prev_data)
|
||||
end
|
||||
end
|
||||
|
||||
climate_api.register_effect("climate_api:sound", start_effect, "start")
|
||||
climate_api.register_effect("climate_api:sound", handle_effect, "tick")
|
||||
climate_api.register_effect("climate_api:sound", stop_effect, "stop")
|
||||
climate_api.set_effect_cycle("climate_api:sound", 0)
|
||||
climate_api.register_effect(EFFECT_NAME, start_effect, "start")
|
||||
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
|
||||
climate_api.register_effect(EFFECT_NAME, stop_effect, "stop")
|
||||
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.LONG_CYCLE)
|
Reference in New Issue
Block a user