diff --git a/mods/super_sam_level/.luacheckrc b/mods/super_sam_level/.luacheckrc index 2c1001d..7b2de1d 100644 --- a/mods/super_sam_level/.luacheckrc +++ b/mods/super_sam_level/.luacheckrc @@ -20,5 +20,5 @@ read_globals = { "VoxelArea", "AreaStore", -- deps - "super_sam_highscore", "worldedit", "mapsync" + "super_sam_highscore", "super_sam_skybox", "worldedit", "mapsync" } diff --git a/mods/super_sam_level/end.lua b/mods/super_sam_level/end.lua index 06fb60a..fd88d7e 100644 --- a/mods/super_sam_level/end.lua +++ b/mods/super_sam_level/end.lua @@ -9,6 +9,9 @@ local function execute_teleport(player, beacon_pos) local pos = vector.add(target_pos, super_sam.player_offset) player:set_pos(pos) + -- reset skybox + super_sam_skybox.reset_skybox(player) + -- save startpos super_sam.set_player_startpos(player, pos) end diff --git a/mods/super_sam_level/level.lua b/mods/super_sam_level/level.lua index 8dee092..ebcb409 100644 --- a/mods/super_sam_level/level.lua +++ b/mods/super_sam_level/level.lua @@ -108,6 +108,7 @@ function super_sam_level.abort_level(player) if super_sam.check_play_mode(player) then super_sam.teleport_player_startpos(player) + super_sam_skybox.reset_skybox(player) super_sam.animation_failed(player) end end diff --git a/mods/super_sam_level/mod.conf b/mods/super_sam_level/mod.conf index 5afaad8..bfb2a6e 100644 --- a/mods/super_sam_level/mod.conf +++ b/mods/super_sam_level/mod.conf @@ -1,3 +1,3 @@ name = super_sam_level -depends = super_sam, super_sam_highscore +depends = super_sam, super_sam_highscore, super_sam_skybox optional_depends = worldedit, mapsync \ No newline at end of file diff --git a/mods/super_sam_level/start.lua b/mods/super_sam_level/start.lua index db98d96..65e3074 100644 --- a/mods/super_sam_level/start.lua +++ b/mods/super_sam_level/start.lua @@ -24,6 +24,7 @@ local function execute_teleport(player, beacon_pos) local playername = player:get_player_name() local meta = minetest.get_meta(beacon_pos) + local skybox = meta:get_string("skybox") local target_pos = { x = meta:get_int("tpx"), y = meta:get_int("tpy"), @@ -39,6 +40,10 @@ local function execute_teleport(player, beacon_pos) -- either the level-requirements are met or the player is in edit-mode player:set_pos(vector.add(target_pos, super_sam.player_offset)) + if skybox ~= "" then + super_sam_skybox.set_skybox(skybox, player) + end + -- capture player, if a beacon is nearby minetest.after(0.1, function() -- because: minetest ¯\_(ツ)_/¯ diff --git a/mods/super_sam_level/start_formspec.lua b/mods/super_sam_level/start_formspec.lua index a48fbbb..06cac88 100644 --- a/mods/super_sam_level/start_formspec.lua +++ b/mods/super_sam_level/start_formspec.lua @@ -7,16 +7,32 @@ function super_sam_level.show_level_start_formspec(pos, playername) end local meta = minetest.get_meta(pos) + local selected_skybox_idx = 1 + + local skybox = meta:get_string("skybox") + if skybox == "" then + skybox = "default" + end + local skybox_items = "" + for i, name in ipairs(super_sam_skybox.get_names()) do + skybox_items = skybox_items .. (i == 1 and "" or ",") .. name + if name == skybox then + selected_skybox_idx = i + end + end local formspec = [[ - size[6,3.5;] - field[0.2,0.5;6,1;required_lvl;Required level;]] .. meta:get_string("required_lvl") .. [[] + size[6,6.5;] + real_coordinates[true] + field[0.5,0.5;5,1;required_lvl;Required level;]] .. meta:get_string("required_lvl") .. [[] + + field[0.5,2;1.5,1;tpx;Teleport;]] .. meta:get_int("tpx") .. [[] + field[2,2;1.5,1;tpy;;]] .. meta:get_int("tpy") .. [[] + field[3.5,2;1.5,1;tpz;;]] .. meta:get_int("tpz") .. [[] - field[0.2,1.5;1,1;tpx;Teleport;]] .. meta:get_int("tpx") .. [[] - field[1.2,1.5;1,1;tpy;;]] .. meta:get_int("tpy") .. [[] - field[2.2,1.5;1,1;tpz;;]] .. meta:get_int("tpz") .. [[] + dropdown[0.5,3.5;5;skybox;]] .. skybox_items .. [[;]] .. selected_skybox_idx .. [[;false] - button_exit[0,2.5;6,1;save;Save] + button_exit[0.5,5;5,1;save;Save] ]] minetest.show_formspec(playername, @@ -44,6 +60,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) meta:set_int("tpx", tonumber(fields.tpx) or 0) meta:set_int("tpy", tonumber(fields.tpy) or 0) meta:set_int("tpz", tonumber(fields.tpz) or 0) + meta:set_string("skybox", fields.skybox) meta:set_string("required_lvl", fields.required_lvl or "") end diff --git a/mods/super_sam_skybox/api.lua b/mods/super_sam_skybox/api.lua new file mode 100644 index 0000000..f4d5924 --- /dev/null +++ b/mods/super_sam_skybox/api.lua @@ -0,0 +1,58 @@ +-- name -> def +local skyboxes = {} + +function super_sam_skybox.register(name, def) + skyboxes[name] = def +end + +function super_sam_skybox.get(name) + return skyboxes[name] +end + +function super_sam_skybox.get_all() + return skyboxes +end + +function super_sam_skybox.get_names() + local names = {} + for name in pairs(skyboxes) do + table.insert(names, name) + end + return names +end + +function super_sam_skybox.reset_skybox(player) + super_sam_skybox.set_skybox("default", player) +end + +function super_sam_skybox.set_skybox(name, player) + local skybox = super_sam_skybox.get(name) + if not skybox then + return false + end + + player:set_clouds({ density=0 }) + + skybox.color = skybox.color or {r=0, g=0, b=0} + + if player.set_sun then + -- new format + player:set_sun({ + visible = false, + sunrise_visible = false + }) + player:set_moon({ + visible = false + }) + player:set_sky({ + base_color = skybox.color, + clouds = false, + type = "skybox", + textures = skybox.textures + }) + else + -- legacy format + player:set_sky(skybox.color, "skybox", skybox.textures) + end +end + diff --git a/mods/super_sam_skybox/init.lua b/mods/super_sam_skybox/init.lua index 72010b8..560b660 100644 --- a/mods/super_sam_skybox/init.lua +++ b/mods/super_sam_skybox/init.lua @@ -1,40 +1,8 @@ +-- namespace +super_sam_skybox = {} -minetest.register_on_joinplayer(function(player) - -- skybox / clouds - player:set_clouds({ density=0 }) +local MP = minetest.get_modpath(minetest.get_current_modname()) - if player.set_sun then - -- new format - player:set_sun({ - visible = false, - sunrise_visible = false - }) - player:set_moon({ - visible = false - }) - player:set_sky({ - base_color = "#000000", - clouds = false, - type = "skybox", - textures = { - "arid2_up.jpg^[transformR270", - "arid2_dn.jpg^[transformR90", - "arid2_ft.jpg", - "arid2_bk.jpg", - "arid2_lf.jpg", - "arid2_rt.jpg" - } - }) - else - -- legacy format - player:set_sky({r=0, g=0, b=0}, "skybox", { - "arid2_up.jpg^[transformR270", - "arid2_dn.jpg^[transformR90", - "arid2_ft.jpg", - "arid2_bk.jpg", - "arid2_lf.jpg", - "arid2_rt.jpg" - }) - end - -end) \ No newline at end of file +dofile(MP .. "/api.lua") +dofile(MP .. "/register.lua") +dofile(MP .. "/join.lua") diff --git a/mods/super_sam_skybox/join.lua b/mods/super_sam_skybox/join.lua new file mode 100644 index 0000000..a20395b --- /dev/null +++ b/mods/super_sam_skybox/join.lua @@ -0,0 +1,3 @@ +minetest.register_on_joinplayer(function(player) + super_sam_skybox.set_skybox("default", player) +end) \ No newline at end of file diff --git a/mods/super_sam_skybox/register.lua b/mods/super_sam_skybox/register.lua new file mode 100644 index 0000000..3c94bc9 --- /dev/null +++ b/mods/super_sam_skybox/register.lua @@ -0,0 +1,16 @@ + +super_sam_skybox.register("default", { + textures = { + "arid2_up.jpg^[transformR270", + "arid2_dn.jpg^[transformR90", + "arid2_ft.jpg", + "arid2_bk.jpg", + "arid2_lf.jpg", + "arid2_rt.jpg" + } +}) + +super_sam_skybox.register("black", { + textures = {}, + color = {r=0, g=0, b=0} +})