aboutsummaryrefslogtreecommitdiff
path: root/builtin/mainmenu/gamemgr.lua
blob: b6faa71d9077aa1f49ad7608b4d0ada01640be02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--Minetest
--Copyright (C) 2013 sapier
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

gamemgr = {}

--------------------------------------------------------------------------------
function gamemgr.find_by_gameid(gameid)
	for i=1,#gamemgr.games,1 do
		if gamemgr.games[i].id == gameid then
			return gamemgr.games[i], i
		end
	end
	return nil, nil
end

--------------------------------------------------------------------------------
function gamemgr.get_game_mods(gamespec, retval)
	if gamespec ~= nil and
		gamespec.gamemods_path ~= nil and
		gamespec.gamemods_path ~= "" then
		get_mods(gamespec.gamemods_path, retval)
	end
end

--------------------------------------------------------------------------------
function gamemgr.get_game_modlist(gamespec)
	local retval = ""
	local game_mods = {}
	gamemgr.get_game_mods(gamespec, game_mods)
	for i=1,#game_mods,1 do
		if retval ~= "" then
			retval = retval..","
		end
		retval = retval .. game_mods[i].name
	end
	return retval
end

--------------------------------------------------------------------------------
function gamemgr.get_game(index)
	if index > 0 and index <= #gamemgr.games then
		return gamemgr.games[index]
	end

	return nil
end

--------------------------------------------------------------------------------
function gamemgr.update_gamelist()
	gamemgr.games = core.get_games()
end

--------------------------------------------------------------------------------
function gamemgr.gamelist()
	local retval = ""
	if #gamemgr.games > 0 then
		retval = retval .. gamemgr.games[1].name

		for i=2,#gamemgr.games,1 do
			retval = retval .. "," .. gamemgr.games[i].name
		end
	end
	return retval
end

--------------------------------------------------------------------------------
-- read initial data
--------------------------------------------------------------------------------
gamemgr.update_gamelist()
opt">(const video::SColor &fallback_bg_color){ m_fallback_bg_color = fallback_bg_color; } private: core::aabbox3d<f32> Box; video::SMaterial m_materials[SKY_MATERIAL_COUNT]; // How much sun & moon transition should affect horizon color float m_horizon_blend() { if (!m_sunlight_seen) return 0; float x = m_time_of_day >= 0.5 ? (1 - m_time_of_day) * 2 : m_time_of_day * 2; if (x <= 0.3) return 0; if (x <= 0.4) // when the sun and moon are aligned return (x - 0.3) * 10; if (x <= 0.5) return (0.5 - x) * 10; return 0; } // Mix two colors by a given amount video::SColor m_mix_scolor(video::SColor col1, video::SColor col2, f32 factor) { video::SColor result = video::SColor( col1.getAlpha() * (1 - factor) + col2.getAlpha() * factor, col1.getRed() * (1 - factor) + col2.getRed() * factor, col1.getGreen() * (1 - factor) + col2.getGreen() * factor, col1.getBlue() * (1 - factor) + col2.getBlue() * factor); return result; } video::SColorf m_mix_scolorf(video::SColorf col1, video::SColorf col2, f32 factor) { video::SColorf result = video::SColorf( col1.r * (1 - factor) + col2.r * factor, col1.g * (1 - factor) + col2.g * factor, col1.b * (1 - factor) + col2.b * factor, col1.a * (1 - factor) + col2.a * factor); return result; } bool m_visible; video::SColor m_fallback_bg_color; // Used when m_visible=false bool m_first_update; float m_time_of_day; float m_time_brightness; bool m_sunlight_seen; float m_brightness; float m_cloud_brightness; bool m_clouds_visible; bool m_directional_colored_fog; video::SColorf m_bgcolor_bright_f; video::SColorf m_skycolor_bright_f; video::SColorf m_cloudcolor_bright_f; video::SColor m_bgcolor; video::SColor m_skycolor; video::SColorf m_cloudcolor_f; v3f m_stars[SKY_STAR_COUNT]; video::S3DVertex m_star_vertices[SKY_STAR_COUNT*4]; video::ITexture* m_sun_texture; video::ITexture* m_moon_texture; video::ITexture* m_sun_tonemap; video::ITexture* m_moon_tonemap; }; #endif