mirror of
https://github.com/t-affeldt/climate_api.git
synced 2024-11-17 16:08:21 +01:00
Add hud overlay effect, increase global tick cycle, improve skybox and sound effects
This commit is contained in:
parent
f42f8481da
commit
7f8f1a77f2
1
TODO.md
1
TODO.md
@ -3,7 +3,6 @@
|
||||
## Required for MVP
|
||||
- Find good values for weather conditions
|
||||
- Make sure all weather presets are working
|
||||
- Add light level to possible conditions
|
||||
|
||||
## Required for Beta
|
||||
- Implement fallback for sky changes without skylayer
|
||||
|
@ -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)
|
2
init.lua
2
init.lua
@ -53,7 +53,7 @@ dofile(modpath.."/lib/main.lua")
|
||||
dofile(modpath.."/lib/commands.lua")
|
||||
|
||||
-- import predefined environment effects
|
||||
dofile(modpath .. "/ca_effects/clouds.lua")
|
||||
dofile(modpath .. "/ca_effects/hud_overlay.lua")
|
||||
dofile(modpath .. "/ca_effects/particles.lua")
|
||||
dofile(modpath .. "/ca_effects/skybox.lua")
|
||||
dofile(modpath .. "/ca_effects/sound.lua")
|
||||
|
@ -129,4 +129,4 @@ minetest.register_chatcommand("weather_status", {
|
||||
minetest.chat_send_player(playername, dump2(status, weather))
|
||||
end
|
||||
end
|
||||
})
|
||||
})
|
||||
|
11
lib/main.lua
11
lib/main.lua
@ -1,5 +1,5 @@
|
||||
local GSCYCLE = 0.01
|
||||
local WORLD_CYCLE = 0.5
|
||||
local GSCYCLE = 0.03
|
||||
local WORLD_CYCLE = 2
|
||||
|
||||
local gs_timer = 0
|
||||
local world_timer = 0
|
||||
@ -16,13 +16,14 @@ minetest.register_globalstep(function(dtime)
|
||||
climate_mod.world.update_status(noise_timer)
|
||||
end
|
||||
|
||||
local previous_effects = climate_mod.current_effects
|
||||
climate_mod.current_effects = climate_mod.trigger.get_active_effects()
|
||||
local previous_effects = table.copy(climate_mod.current_effects)
|
||||
local current_effects = climate_mod.trigger.get_active_effects()
|
||||
|
||||
for name, effect in pairs(climate_mod.effects) do
|
||||
if climate_mod.cycles[name].timespan < climate_mod.cycles[name].timer + dtime then
|
||||
climate_mod.cycles[name].timer = 0
|
||||
climate_mod.trigger.call_handlers(name, climate_mod.current_effects[name], previous_effects[name])
|
||||
climate_mod.current_effects[name] = current_effects[name]
|
||||
climate_mod.trigger.call_handlers(name, current_effects[name], previous_effects[name])
|
||||
else
|
||||
climate_mod.cycles[name].timer = climate_mod.cycles[name].timer + dtime
|
||||
end
|
||||
|
@ -15,6 +15,7 @@ function trigger.get_player_environment(player)
|
||||
env.humidity = climate_api.environment.get_humidity(ppos)
|
||||
env.time = minetest.get_timeofday()
|
||||
env.date = minetest.get_day_count()
|
||||
env.light = minetest.get_node_light(vector.add(ppos, vector.new({x=0,y=1.5,z=0})), 0.5)
|
||||
return env
|
||||
end
|
||||
|
||||
|
BIN
textures/climate_hud.png
Normal file
BIN
textures/climate_hud.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 MiB |
Loading…
Reference in New Issue
Block a user