Skip to content

Commit

Permalink
per-level skybox
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Oct 18, 2023
1 parent 5991475 commit 96ec58b
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 46 deletions.
2 changes: 1 addition & 1 deletion mods/super_sam_level/.luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ read_globals = {
"VoxelArea", "AreaStore",

-- deps
"super_sam_highscore", "worldedit", "mapsync"
"super_sam_highscore", "super_sam_skybox", "worldedit", "mapsync"
}
3 changes: 3 additions & 0 deletions mods/super_sam_level/end.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mods/super_sam_level/level.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mods/super_sam_level/mod.conf
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions mods/super_sam_level/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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 ¯\_(ツ)_/¯
Expand Down
29 changes: 23 additions & 6 deletions mods/super_sam_level/start_formspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
58 changes: 58 additions & 0 deletions mods/super_sam_skybox/api.lua
Original file line number Diff line number Diff line change
@@ -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

44 changes: 6 additions & 38 deletions mods/super_sam_skybox/init.lua
Original file line number Diff line number Diff line change
@@ -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)
dofile(MP .. "/api.lua")
dofile(MP .. "/register.lua")
dofile(MP .. "/join.lua")
3 changes: 3 additions & 0 deletions mods/super_sam_skybox/join.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minetest.register_on_joinplayer(function(player)
super_sam_skybox.set_skybox("default", player)
end)
16 changes: 16 additions & 0 deletions mods/super_sam_skybox/register.lua
Original file line number Diff line number Diff line change
@@ -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}
})

0 comments on commit 96ec58b

Please sign in to comment.