From 3e56c332264e35bc6154990962c947f797b35b30 Mon Sep 17 00:00:00 2001 From: Arturas Norkus Date: Sun, 23 Oct 2016 17:22:50 +0300 Subject: [PATCH] structure change - convert to mod; fix for #4, #5 --- README.md | 10 +-- depends.txt | 1 + init.lua | 12 +++ mod.conf | 1 + modpack.txt | 0 rain/rain.lua => rain.lua | 45 ++++------- rain/depends.txt | 1 - rain/init.lua | 3 - skycolor.lua | 71 ++++++++++++++++++ snow/snow.lua => snow.lua | 22 +++++- snow/depends.txt | 1 - snow/init.lua | 3 - {rain/sounds => sounds}/weather_rain.ogg | Bin .../weather_pack_rain_raindrop_1.png | Bin .../weather_pack_rain_raindrop_2.png | Bin .../weather_pack_rain_raindrop_3.png | Bin .../weather_pack_snow_snowflake1.png | Bin .../weather_pack_snow_snowflake2.png | Bin thunder/thunder.lua => thunder.lua | 0 thunder/depends.txt | 3 - thunder/init.lua | 5 -- .../weather_core.lua => weather_core.lua | 0 weather_core/init.lua | 3 - 23 files changed, 125 insertions(+), 56 deletions(-) create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 mod.conf delete mode 100644 modpack.txt rename rain/rain.lua => rain.lua (82%) delete mode 100644 rain/depends.txt delete mode 100644 rain/init.lua create mode 100644 skycolor.lua rename snow/snow.lua => snow.lua (80%) delete mode 100644 snow/depends.txt delete mode 100644 snow/init.lua rename {rain/sounds => sounds}/weather_rain.ogg (100%) rename rain/textures/rain_raindrop_1.png => textures/weather_pack_rain_raindrop_1.png (100%) rename rain/textures/rain_raindrop_2.png => textures/weather_pack_rain_raindrop_2.png (100%) rename rain/textures/rain_raindrop_3.png => textures/weather_pack_rain_raindrop_3.png (100%) rename snow/textures/snow_snowflake1.png => textures/weather_pack_snow_snowflake1.png (100%) rename snow/textures/snow_snowflake2.png => textures/weather_pack_snow_snowflake2.png (100%) rename thunder/thunder.lua => thunder.lua (100%) delete mode 100644 thunder/depends.txt delete mode 100644 thunder/init.lua rename weather_core/weather_core.lua => weather_core.lua (100%) delete mode 100644 weather_core/init.lua diff --git a/README.md b/README.md index 279d757..09d83e3 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,14 @@ Authors of media files: TeddyDesTodes: Snowflakes licensed under CC-BY-SA 3.0 by from weather branch at https://github.com/TeddyDesTodes/minetest/tree/weather - * `snow_snowflake1.png` - CC-BY-SA 3.0 - * `snow_snowflake2.png` - CC-BY-SA 3.0 + * `weather_pack_snow_snowflake1.png` - CC-BY-SA 3.0 + * `weather_pack_snow_snowflake2.png` - CC-BY-SA 3.0 xeranas: - * `rain_raindrop_1.png` - CC-0 - * `rain_raindrop_2.png` - CC-0 - * `rain_raindrop_3.png` - CC-0 + * `weather_pack_rain_raindrop_1.png` - CC-0 + * `weather_pack_rain_raindrop_2.png` - CC-0 + * `weather_pack_rain_raindrop_3.png` - CC-0 inchadney (http://freesound.org/people/inchadney/): diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..b129625 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +lightning? \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..5495896 --- /dev/null +++ b/init.lua @@ -0,0 +1,12 @@ +local modpath = minetest.get_modpath("weather_pack"); +dofile(modpath.."/weather_core.lua") +dofile(modpath.."/snow.lua") +dofile(modpath.."/rain.lua") + +if minetest.get_modpath("lightning") ~= nil then + dofile(modpath.."/thunder.lua") +end + +if minetest.get_modpath("skycolor") == nil then + dofile(modpath.."/skycolor.lua") +end diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..7baa047 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = weather_pack diff --git a/modpack.txt b/modpack.txt deleted file mode 100644 index e69de29..0000000 diff --git a/rain/rain.lua b/rain.lua similarity index 82% rename from rain/rain.lua rename to rain.lua index cc38993..55a2534 100644 --- a/rain/rain.lua +++ b/rain.lua @@ -21,32 +21,16 @@ rain.sound_handler = function(player) }) end --- set skybox based on time (darker if night lighter otherwise) +-- set skybox based on time (uses skycolor api) rain.set_sky_box = function(player) - local current_time = minetest.get_timeofday() - local diff = math.abs(rain.sky_last_update - math.floor(current_time * 10)) - -- don't need update sky if time does not change significantly - if diff < 1 then - return - end - - local color_table = {} - color_table[0] = {r=6, g=8, b=8} - color_table[1] = {r=16, g=23, b=23} - color_table[2] = {r=32, g=46, b=46} - color_table[3] = {r=48, g=69, b=69} - color_table[4] = {r=64, g=92, b=92} - color_table[5] = {r=70, g=100, b=100} - color_table[6] = {r=64, g=92, b=92} - color_table[7] = {r=48, g=69, b=69} - color_table[8] = {r=32, g=46, b=46} - color_table[9] = {r=16, g=23, b=23} - - local timeofday = current_time - local rounded_time = math.floor(timeofday * 10) - - player:set_sky(color_table[rounded_time], "plain", nil) - rain.sky_last_update = rounded_time + skycolor.colors = { + {r=0, g=0, b=0}, + {r=85, g=86, b=98}, + {r=152, g=150, b=159}, + {r=85, g=86, b=98}, + {r=0, g=0, b=0}, + } + skycolor.active = true end -- creating manually parctiles instead of particles spawner because of easier to control @@ -79,11 +63,11 @@ rain.get_texture = function() local texture_name local random_number = math.random() if random_number > 0.33 then - texture_name = "rain_raindrop_1.png" + texture_name = "weather_pack_rain_raindrop_1.png" elseif random_number > 0.66 then - texture_name = "rain_raindrop_2.png" + texture_name = "weather_pack_rain_raindrop_2.png" else - texture_name = "rain_raindrop_3.png" + texture_name = "weather_pack_rain_raindrop_3.png" end return texture_name; end @@ -144,6 +128,9 @@ end rain.clear = function() rain.raining = false rain.sky_last_update = -1 + skycolor.active = false + skycolor.colors = {} + skycolor.set_default_sky() for _, player in ipairs(minetest.get_connected_players()) do rain.remove_sound(player) rain.remove_player(player) @@ -160,12 +147,12 @@ end) rain.make_weather = function() rain.raining = true + rain.set_sky_box() for _, player in ipairs(minetest.get_connected_players()) do if (weather.is_underwater(player)) then return false end rain.add_player(player) - rain.set_sky_box(player) rain.add_rain_particles(player) rain.update_sound(player) end diff --git a/rain/depends.txt b/rain/depends.txt deleted file mode 100644 index 5be7ad4..0000000 --- a/rain/depends.txt +++ /dev/null @@ -1 +0,0 @@ -weather_core \ No newline at end of file diff --git a/rain/init.lua b/rain/init.lua deleted file mode 100644 index 4ae94b9..0000000 --- a/rain/init.lua +++ /dev/null @@ -1,3 +0,0 @@ --- init file for rain -local modpath = minetest.get_modpath("rain"); -dofile(modpath.."/rain.lua") \ No newline at end of file diff --git a/skycolor.lua b/skycolor.lua new file mode 100644 index 0000000..6cec57e --- /dev/null +++ b/skycolor.lua @@ -0,0 +1,71 @@ +skycolor = { + -- Should be activated before do any effect. + active = false, + + -- Update interval. + update_interval = 15, + + -- Main sky colors: starts from midnight to midnight. + colors = {}, + + -- Update sky color. If players not specified update sky for all players. + update_sky_color = function(players) + local timeofday = minetest.get_timeofday() + local rounded_time = math.floor(timeofday * 1000) + local color = skycolor.utils.convert_to_rgb(0, 1000, rounded_time, skycolor.colors) + + if players == nil or #players == 0 then + players = minetest.get_connected_players() + end + for _, player in ipairs(players) do + player:set_sky(color, "plain", nil) + end + + end, + + -- Reset sky color to game default. If players not specified update sky for all players. + set_default_sky = function(players) + if players == nil or #players == 0 then + players = minetest.get_connected_players() + end + for _, player in ipairs(players) do + player:set_sky(nil, "regular", nil) + end + end, + + utils = { + convert_to_rgb = function(minval, maxval, current_val, colors) + local max_index = #colors - 1 + local val = (current_val-minval) / (maxval-minval) * max_index + 1.0 + local index1 = math.floor(val) + local index2 = math.min(math.floor(val)+1, max_index + 1) + local f = val - index1 + local c1 = colors[index1] + local c2 = colors[index2] + return {r=math.floor(c1.r + f*(c2.r - c1.r)), g=math.floor(c1.g + f*(c2.g-c1.g)), b=math.floor(c1.b + f*(c2.b - c1.b))} + end + }, + +} + +local timer = -1 +minetest.register_globalstep(function(dtime) + if skycolor.active ~= true then + return + end + + -- exceptional first time update + if timer <= 0 then + skycolor.update_sky_color() + timer = 0 + return + end + + -- regular updates based on iterval + timer = timer + dtime; + if timer >= skycolor.update_interval then + skycolor.update_sky_color() + timer = 0 + end + +end) \ No newline at end of file diff --git a/snow/snow.lua b/snow.lua similarity index 80% rename from snow/snow.lua rename to snow.lua index dc53bb3..6f73a97 100644 --- a/snow/snow.lua +++ b/snow.lua @@ -26,14 +26,29 @@ snow.add_rain_particles = function(player) end end +snow.set_sky_box = function() + skycolor.colors = { + {r=0, g=0, b=0}, + {r=241, g=244, b=249}, + {r=0, g=0, b=0}, + } + skycolor.active = true +end + +snow.clear = function() + skycolor.active = false + skycolor.colors = {} + skycolor.set_default_sky() +end + -- Simple random texture getter snow.get_texture = function() local texture_name local random_number = math.random() if random_number > 0.5 then - texture_name = "snow_snowflake1.png" + texture_name = "weather_pack_snow_snowflake1.png" else - texture_name = "snow_snowflake2.png" + texture_name = "weather_pack_snow_snowflake2.png" end return texture_name; end @@ -43,6 +58,7 @@ minetest.register_globalstep(function(dtime) return false end + snow.set_sky_box() for _, player in ipairs(minetest.get_connected_players()) do if (weather.is_underwater(player)) then return false @@ -55,6 +71,6 @@ end) if weather.reg_weathers.snow == nil then weather.reg_weathers.snow = { chance = 10, - clear = function() end + clear = snow.clear } end diff --git a/snow/depends.txt b/snow/depends.txt deleted file mode 100644 index 5be7ad4..0000000 --- a/snow/depends.txt +++ /dev/null @@ -1 +0,0 @@ -weather_core \ No newline at end of file diff --git a/snow/init.lua b/snow/init.lua deleted file mode 100644 index 8e5f119..0000000 --- a/snow/init.lua +++ /dev/null @@ -1,3 +0,0 @@ --- init file for snow -local modpath = minetest.get_modpath("snow"); -dofile(modpath.."/snow.lua") \ No newline at end of file diff --git a/rain/sounds/weather_rain.ogg b/sounds/weather_rain.ogg similarity index 100% rename from rain/sounds/weather_rain.ogg rename to sounds/weather_rain.ogg diff --git a/rain/textures/rain_raindrop_1.png b/textures/weather_pack_rain_raindrop_1.png similarity index 100% rename from rain/textures/rain_raindrop_1.png rename to textures/weather_pack_rain_raindrop_1.png diff --git a/rain/textures/rain_raindrop_2.png b/textures/weather_pack_rain_raindrop_2.png similarity index 100% rename from rain/textures/rain_raindrop_2.png rename to textures/weather_pack_rain_raindrop_2.png diff --git a/rain/textures/rain_raindrop_3.png b/textures/weather_pack_rain_raindrop_3.png similarity index 100% rename from rain/textures/rain_raindrop_3.png rename to textures/weather_pack_rain_raindrop_3.png diff --git a/snow/textures/snow_snowflake1.png b/textures/weather_pack_snow_snowflake1.png similarity index 100% rename from snow/textures/snow_snowflake1.png rename to textures/weather_pack_snow_snowflake1.png diff --git a/snow/textures/snow_snowflake2.png b/textures/weather_pack_snow_snowflake2.png similarity index 100% rename from snow/textures/snow_snowflake2.png rename to textures/weather_pack_snow_snowflake2.png diff --git a/thunder/thunder.lua b/thunder.lua similarity index 100% rename from thunder/thunder.lua rename to thunder.lua diff --git a/thunder/depends.txt b/thunder/depends.txt deleted file mode 100644 index e3f1db7..0000000 --- a/thunder/depends.txt +++ /dev/null @@ -1,3 +0,0 @@ -weather_core -rain -lightning? \ No newline at end of file diff --git a/thunder/init.lua b/thunder/init.lua deleted file mode 100644 index 8ccb771..0000000 --- a/thunder/init.lua +++ /dev/null @@ -1,5 +0,0 @@ --- init file for thunder -if minetest.get_modpath("lightning") ~= nil then - local modpath = minetest.get_modpath("thunder"); - dofile(modpath.."/thunder.lua") -end \ No newline at end of file diff --git a/weather_core/weather_core.lua b/weather_core.lua similarity index 100% rename from weather_core/weather_core.lua rename to weather_core.lua diff --git a/weather_core/init.lua b/weather_core/init.lua deleted file mode 100644 index 0f3f59a..0000000 --- a/weather_core/init.lua +++ /dev/null @@ -1,3 +0,0 @@ --- init file for weather_core -local modpath = minetest.get_modpath("weather_core"); -dofile(modpath.."/weather_core.lua") \ No newline at end of file