Implement classic texture style and allow users to choose

This commit is contained in:
Till Affeldt 2020-04-12 01:45:37 +02:00
parent b81669c9da
commit e2220440ec
19 changed files with 44 additions and 17 deletions

View File

@ -28,4 +28,22 @@ minetest.register_chatcommand("set_moonphase", {
end
end
end
})
minetest.register_chatcommand("set_moonstyle", {
params = "<style>",
description = "Set your moon's texture style to the given preset",
func = function(playername, param)
if param == nil or param == "" then
minetest.chat_send_player(playername, "Provide a texture style. Possible styles are classic or realistic")
else
local player = minetest.get_player_by_name(playername)
local change = moon_phases.set_style(player, param)
if change then
minetest.chat_send_player(playername, "Moon texture changed successfully")
else
minetest.chat_send_player(playername, "Invalid argument. Provide a valid preset.")
end
end
end
})

View File

@ -16,22 +16,19 @@ if not state:contains("day") then
})
end
-- retrieve and parse mod configuration
local function get_cycle_config()
local config = minetest.settings:get("moon_phases_cycle") or DEFAULT_LENGTH
config = math.floor(tonumber(config))
if (not config) or config < 0 then
minetest.log("warning", "[Moon Phases] Invalid cycle configuration")
return DEFAULT_LENGTH
end
return config
end
-- retrieve mod configuration
local PHASE_LENGTH = minetest.settings:get("moon_phases_cycle") or DEFAULT_LENGTH
local TEXTURE_STYLE = minetest.settings:get("moon_phases_style") or DEFAULT_STYLE
local PHASE_LENGTH = get_cycle_config()
-- set the moon texture of a player to the given texture
local function set_texture(player, texture)
-- set the moon texture of a player to the given phase
local function set_texture(player, phase)
local sl = {}
local meta_data = player:get_meta()
local style = meta_data:get_string("moon_phases:texture_style")
if style ~= "classic" and style ~= "realistic" then
style = TEXTURE_STYLE
end
local texture = "moon_" .. phase .. "_" .. style .. ".png"
sl.name = "moon_phases:custom"
sl.moon_data = {
visible = true,
@ -49,7 +46,7 @@ end
local function update_textures()
local phase = state:get_int("phase")
for _, player in ipairs(minetest.get_connected_players()) do
set_texture(player, "moon_" .. phase .. ".png")
set_texture(player, phase)
end
end
@ -89,12 +86,23 @@ function moon_phases.set_phase(phase)
return true
end
-- set the moon's texture style for the given player
function moon_phases.set_style(player, style)
if style ~= "classic" and style ~= "realistic" then
return false
end
local meta_data = player:get_meta()
meta_data:set_string("moon_phases:texture_style", style)
set_texture(player, state:get_int("phase"))
return true
end
-- set the moon texture of newly joined player
minetest.register_on_joinplayer(function(player)
local phase = state:get_int("phase")
-- phase might not have been set at server start
if phase < 1 then phase = 1 end
set_texture(player, "moon_" .. phase .. ".png")
set_texture(player, phase)
end)
-- check for day changes and call handlers

View File

@ -1 +1,2 @@
moon_phases_cycle (Change moon phase every X days) int 4
moon_phases_cycle (Change moon phase every X days) int 4
moon_phases_style (Choose a default texture style) enum classic classic,realistic

BIN
textures/moon_1_classic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

BIN
textures/moon_2_classic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

View File

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

BIN
textures/moon_3_classic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

View File

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

BIN
textures/moon_4_classic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

View File

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 93 KiB

BIN
textures/moon_5_classic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

View File

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 80 KiB

BIN
textures/moon_6_classic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 602 B

View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

BIN
textures/moon_7_classic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

View File

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

BIN
textures/moon_8_classic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 B

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB