From 9bb9a6cecbe8c2f113581c88f20a8bdb2696c036 Mon Sep 17 00:00:00 2001 From: Arturas Norkus Date: Sun, 14 Jul 2019 13:11:14 +0300 Subject: [PATCH] refactor: moved weather files to separate dir --- init.lua | 16 ++++---- ...ather_api.lua => lib_happy_weather_api.lua | 0 ...sky_layer_api.lua => lib_sky_layer_api.lua | 0 heavy_rain.lua => weathers/heavy_rain.lua | 0 light_rain.lua => weathers/light_rain.lua | 0 rain.lua => weathers/rain.lua | 0 snow.lua => weathers/snow.lua | 0 snowstorm.lua => weathers/snowstorm.lua | 39 +++++++++++-------- thunder.lua => weathers/thunder.lua | 0 9 files changed, 30 insertions(+), 25 deletions(-) rename embedded_happy_weather_api.lua => lib_happy_weather_api.lua (100%) rename embedded_sky_layer_api.lua => lib_sky_layer_api.lua (100%) rename heavy_rain.lua => weathers/heavy_rain.lua (100%) rename light_rain.lua => weathers/light_rain.lua (100%) rename rain.lua => weathers/rain.lua (100%) rename snow.lua => weathers/snow.lua (100%) rename snowstorm.lua => weathers/snowstorm.lua (86%) rename thunder.lua => weathers/thunder.lua (100%) diff --git a/init.lua b/init.lua index 535e1ec..37bd223 100644 --- a/init.lua +++ b/init.lua @@ -2,26 +2,26 @@ local modpath = minetest.get_modpath("weather_pack"); -- If skylayer mod not located then embeded version will be loaded. if minetest.get_modpath("skylayer") == nil then - dofile(modpath.."/embedded_sky_layer_api.lua") + dofile(modpath.."/lib_sky_layer_api.lua") end -- If happy_weather_api mod not located then embeded version will be loaded. if minetest.get_modpath("happy_weather_api") == nil then - dofile(modpath.."/embedded_happy_weather_api.lua") + dofile(modpath.."/lib_happy_weather_api.lua") dofile(modpath.."/commands.lua") end -- Happy Weather utilities dofile(modpath.."/utils.lua") -dofile(modpath.."/light_rain.lua") -dofile(modpath.."/rain.lua") -dofile(modpath.."/heavy_rain.lua") -dofile(modpath.."/snow.lua") -dofile(modpath.."/snowstorm.lua") +dofile(modpath.."/weathers/light_rain.lua") +dofile(modpath.."/weathers/rain.lua") +dofile(modpath.."/weathers/heavy_rain.lua") +dofile(modpath.."/weathers/snow.lua") +dofile(modpath.."/weathers/snowstorm.lua") if minetest.get_modpath("lightning") ~= nil then - dofile(modpath.."/thunder.lua") + dofile(modpath.."/weathers/thunder.lua") -- Turn off lightning mod 'auto mode' lightning.auto = false diff --git a/embedded_happy_weather_api.lua b/lib_happy_weather_api.lua similarity index 100% rename from embedded_happy_weather_api.lua rename to lib_happy_weather_api.lua diff --git a/embedded_sky_layer_api.lua b/lib_sky_layer_api.lua similarity index 100% rename from embedded_sky_layer_api.lua rename to lib_sky_layer_api.lua diff --git a/heavy_rain.lua b/weathers/heavy_rain.lua similarity index 100% rename from heavy_rain.lua rename to weathers/heavy_rain.lua diff --git a/light_rain.lua b/weathers/light_rain.lua similarity index 100% rename from light_rain.lua rename to weathers/light_rain.lua diff --git a/rain.lua b/weathers/rain.lua similarity index 100% rename from rain.lua rename to weathers/rain.lua diff --git a/snow.lua b/weathers/snow.lua similarity index 100% rename from snow.lua rename to weathers/snow.lua diff --git a/snowstorm.lua b/weathers/snowstorm.lua similarity index 86% rename from snowstorm.lua rename to weathers/snowstorm.lua index ad9125f..7526dad 100644 --- a/snowstorm.lua +++ b/weathers/snowstorm.lua @@ -10,9 +10,9 @@ local snowstorm = {} -- Weather identification code snowstorm.code = "snowstorm" -snow.last_check = 0 -snow.check_interval = 400 -snow.chance = 0.04 +snowstorm.last_check = 0 +snowstorm.check_interval = 5 +snowstorm.chance = 1 -- Keeps sound handler references local sound_handlers = {} @@ -41,6 +41,13 @@ local remove_weather_sound = function(player) end snowstorm.is_starting = function(dtime, position) + if snowstorm.last_check + snowstorm.check_interval < os.time() then + snowstorm.last_check = os.time() + if math.random() < snowstorm.chance then + return true + end + end + if manual_trigger_start then manual_trigger_start = false return true @@ -65,26 +72,24 @@ local set_sky_box = function(player_name) sl.sky_data = { gradient_colors = { {r=0, g=0, b=0}, - {r=70, g=70, b=85}, - {r=120, g=120, b=125}, - {r=70, g=70, b=85}, + {r=231, g=234, b=239}, {r=0, g=0, b=0} } } - sl.clouds_data = { - gradient_colors = { - {r=10, g=10, b=10}, - {r=65, g=66, b=78}, - {r=112, g=110, b=119}, - {r=65, g=66, b=78}, - {r=10, g=10, b=10} - }, - speed = {z = 30, y = -80}, - density = 0.6 - } skylayer.add_layer(player_name, sl) end +snowstorm.in_area = function(position) + if hw_utils.is_biome_frozen(position) == false then + return false + end + + if position.y > 30 and position.y < 140 then + return true + end + return false +end + snowstorm.add_player = function(player) sound_handlers[player:get_player_name()] = set_weather_sound(player) set_sky_box(player:get_player_name()) diff --git a/thunder.lua b/weathers/thunder.lua similarity index 100% rename from thunder.lua rename to weathers/thunder.lua