diff options
author | cheapie <no-email-for-you@example.com> | 2016-08-30 01:25:06 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2016-08-30 01:25:06 -0500 |
commit | 3d026a25307f99d4c7a265cb33ec0f251a06af77 (patch) | |
tree | 2ea510530cc47c3f941c7f4059fe248a0f5e60be | |
download | daynight-3d026a25307f99d4c7a265cb33ec0f251a06af77.tar daynight-3d026a25307f99d4c7a265cb33ec0f251a06af77.tar.gz daynight-3d026a25307f99d4c7a265cb33ec0f251a06af77.tar.bz2 daynight-3d026a25307f99d4c7a265cb33ec0f251a06af77.tar.xz daynight-3d026a25307f99d4c7a265cb33ec0f251a06af77.zip |
-rw-r--r-- | LICENSE | 24 | ||||
-rw-r--r-- | README | 12 | ||||
-rw-r--r-- | depends.txt | 1 | ||||
-rw-r--r-- | init.lua | 96 |
4 files changed, 133 insertions, 0 deletions
@@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to <http://unlicense.org/> @@ -0,0 +1,12 @@ +Day/Night Mode Selector for Minetest +==================================== + +This is a mod for Minetest that adds a simple way to select "automatic" (normal) day/night cycling, always day, or always night. It works per-player, and settings are persistent across restarts. + +Usage (inventory button): Press the button in the inventory to open the menu, then select the desired mode. Use "automatic" to return to normal behavior. + +Usage (chat command): Use the /dayratio command by itself to open the menu, or specify a number from 0 to 1 after it to set a custom value. Custom values set the ratio between day and night - for example, a value of 0.25 will set your lighting to be 1/4 day and 3/4 night. The light level is then unaffected by the time of day. Use a value of "nil" to return to normal behavior. + +Dependencies: unified_inventory + +License: Unlicense, see the "LICENSE" file for full license text. diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..7e882b3 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +unified_inventory diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..1079f93 --- /dev/null +++ b/init.lua @@ -0,0 +1,96 @@ +local prefs = {} + +local path = minetest.get_worldpath()..DIR_DELIM.."daynight.txt" + +local file = io.open(path,"r") + +if file then + local data = file:read("*all") + prefs = minetest.deserialize(data) + file:close() +end + +local function save() + local file = io.open(path,"w") + local data = minetest.serialize(prefs) + file:write(data) + file:close() +end + +local form = "size[6,2.25]".. + "label[2,-0.25;Select a day/night mode:]".. + "image_button_exit[0,0.25;2,2;"..minetest.formspec_escape("[combine:128x128:16,16=ui_moon_icon.png:-16,-16=ui_sun_icon.png")..";normal;]".. + "image_button_exit[2,0.25;2,2;ui_sun_icon.png;day;]".. + "image_button_exit[4,0.25;2,2;ui_moon_icon.png;night;]".. + "label[0.5,2;Automatic]".. + "label[2.5,2;Always Day]".. + "label[4.5,2;Always Night]" + +minetest.register_chatcommand("dayratio", + { + params = "[ratio]", + description = "Sets your day/night ratio to the given value, or opens a GUI if a value is not given", + func = function(name,param) + if param ~= "" and param ~= "nil" then + if not tonumber(param) then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Valid range is 0-1 or nil." + elseif tonumber(param) > 1 then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Value must be nil or <= 1." + elseif tonumber(param) < 0 then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Only positive values are allowed." + end + end + local player = minetest.get_player_by_name(name) + if param == "nil" then + prefs[name] = nil + player:override_day_night_ratio(nil) + return true,minetest.colorize("#00FFFF","Success")..": Day/night ratio override cleared." + elseif tonumber(param) then + prefs[name] = tonumber(param) + player:override_day_night_ratio(tonumber(param)) + return true,minetest.colorize("#00FFFF","Success")..": Day/night ratio set to "..param + else + minetest.show_formspec(name,"daynight:daynight",form) + end + save() + end + } +) + +minetest.register_on_player_receive_fields( + function(player,formname,fields) + local name = player:get_player_name() + if formname ~= "daynight:daynight" then + return false + end + if fields.normal then + prefs[name] = nil + player:override_day_night_ratio(nil) + elseif fields.day then + prefs[name] = 1 + player:override_day_night_ratio(1) + elseif fields.night then + prefs[name] = 0 + player:override_day_night_ratio(0) + end + save() + end +) + +minetest.register_on_joinplayer( + function(player) + local name = player:get_player_name() + player:override_day_night_ratio(prefs[name]) + end +) + +unified_inventory.register_button("daynight", + { + action = function(player) + minetest.show_formspec(player:get_player_name(),"daynight:daynight",form) + end, + tooltip = "Day/Night Options", + type = "image", + image = "[combine:128x128:16,16=ui_moon_icon.png:-16,-16=ui_sun_icon.png" + } +) |