-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.lua
147 lines (134 loc) · 4.5 KB
/
base.lua
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
return DMod:new("environment_selector", {
name = "Environment selector",
abbr = "ENVSEL",
version = "2.2",
author = "Dr_Newbie, Whurr, _atom",
includes = {
{ "mod_localization", { type = "localization" } },
{ "mod_options", { type = "menu_options" } },
},
hooks = {
{
"OnModuleRegistered",
"OnModuleRegistered_ESCheckDAHMVersion",
function(module)
if D:version() >= "1.16.1.5" then
return
end
module:set_state("disabled")
end,
},
{
"OnModuleLoading",
"override_environment_data",
function(module)
local level_id = tablex.get(Global, "level_data", "level_id")
if not level_id then
return
end
local environment = D:conf("environment_selector_" .. level_id)
if not environment or environment == "default" then
return
end
local environments = {
apartment = "environments/env_apartment/env_apartment",
bank = "environments/env_bank/env_bank",
bridge = "environments/env_bridge2/env_bridge2",
diamond_heist = "environments/env_diamond2/env_diamond2",
heat_street = "environments/env_street/env_street",
hospital = "environments/env_l4d/env_l4d",
secret_stash = "environments/env_undercover/env_undercover",
slaughter_house = "environments/env_slaughterhouse/env_slaughterhouse",
suburbia = "environments/env_suburbia/env_suburbia",
}
local cubemaps = {
apartment = "environments/cubemaps/cubemap_apartment_01",
bank = "environments/cubemaps/cubemap_bank_01",
bridge = "environments/cubemaps/cubemap_bridge_01",
diamond_heist = "environments/cubemaps/cubemap_diamond_01",
heat_street = "environments/cubemaps/cubemap_street_01",
hospital = "environments/cubemaps/cubemap_hospital_01",
secret_stash = "environments/cubemaps/cubemap_secret_stash",
slaughter_house = "environments/cubemaps/cubemap_slaughter_01",
suburbia = "environments/cubemaps/cubemap_suburbia_01",
}
local path = level_id and environments[level_id]
if not path then
return
end
if environment == "random" then
environment = table.random({
"bank",
"pd2_bank_trailer",
"heat_street",
"heat_street_v1",
"apartment",
"apartment_v1",
"bridge",
"diamond_heist",
"slaughter_house",
"suburbia",
"secret_stash",
"hospital",
})
end
if not environment or environment == level_id then
return
end
local script_type = "environment"
DPackageManager:register_processor(module, module:id(), script_type, path, function(_, _, data)
local env_data = loadfile(module:path() .. "environments/" .. environment .. ".lua")
if type(env_data) ~= "function" then
return
end
env_data = env_data(cubemaps[level_id])
-- Not the best way to achieve this but allows us to avoid loading level packages and gives us the possibility of adding custom environments without access to custom assets.
-- Requires DAHM 1.16.1.5 or above.
tablex.deep_merge(data[2], env_data)
end)
end,
},
{
"lib/setups/gamesetup",
function(module)
local GameSetup = module:hook_class("GameSetup")
local package_path = "packages/rain_effect"
module:post_hook(GameSetup, "load_packages", function()
local level_id = tablex.get(Global, "game_settings", "level_id") or "bank"
if next(tweak_data.levels[level_id].environment_effects or {}) then
if not PackageManager:loaded(package_path) then
PackageManager:load(package_path)
end
end
end)
module:post_hook(GameSetup, "unload_packages", function()
if PackageManager:loaded(package_path) then
PackageManager:unload(package_path)
end
end)
end,
},
{
"lib/tweak_data/levelstweakdata",
function(module)
module:post_hook(module:hook_class("LevelsTweakData"), "init", function(self)
for _, level in pairs(self._level_index) do
local heist_effects = {}
local effect_list = {
["rain"] = D:conf("environment_selector_" .. level .. "_rain"),
["raindrop_screen"] = D:conf("environment_selector_" .. level .. "_rain"),
["lightning"] = D:conf("environment_selector_" .. level .. "_lightning"),
}
for effect, enabled in pairs(effect_list) do
if enabled then
table.insert(heist_effects, effect)
end
end
self[level].environment_effects = heist_effects
end
end)
end,
},
},
update = { id = "env_selector", url = "https://raw.githubusercontent.com/mbien1981/dahm-modules/main/version.json" },
})