forked from ZhooL/FS22_EnhancedVehicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFS22_EnhancedVehicle_Loader.lua
114 lines (81 loc) · 3.12 KB
/
FS22_EnhancedVehicle_Loader.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
--
-- Mod: FS22_EnhancedVehicle_Loader
--
-- Author: Majo76
-- email: [email protected]
-- @Date: 22.12.2021
-- @Version: 1.0.0.0
-- #############################################################################
debug = 0 -- 0=0ff, 1=some, 2=everything, 3=madness
local directory = g_currentModDirectory
local modName = g_currentModName
source(Utils.getFilename("FS22_EnhancedVehicle.lua", directory))
source(Utils.getFilename("FS22_EnhancedVehicle_Event.lua", directory))
source(Utils.getFilename("ui/FS22_EnhancedVehicle_UI.lua", directory))
source(Utils.getFilename("ui/FS22_EnhancedVehicle_HUD.lua", directory))
-- include our libUtils
source(Utils.getFilename("libUtils.lua", g_currentModDirectory))
lU = libUtils()
lU:setDebug(0)
-- include our new libConfig XML management
source(Utils.getFilename("libConfig.lua", g_currentModDirectory))
lC = libConfig("FS22_EnhancedVehicle", 1, 0)
lC:setDebug(0)
local EnhancedVehicle
local function isEnabled()
return EnhancedVehicle ~= nil
end
-- #############################################################################
function EV_init()
if debug > 1 then print("EV_init()") end
-- hook into early load
Mission00.load = Utils.prependedFunction(Mission00.load, EV_load)
-- hook into late load
Mission00.loadMission00Finished = Utils.appendedFunction(Mission00.loadMission00Finished, EV_loadedMission)
-- hook into late unload
FSBaseMission.delete = Utils.appendedFunction(FSBaseMission.delete, EV_unload)
-- hook into validateTypes
TypeManager.validateTypes = Utils.prependedFunction(TypeManager.validateTypes, EV_validateTypes)
end
-- #############################################################################
function EV_load(mission)
if debug > 1 then print("EV_load()") end
-- create our EV class
assert(g_EnhancedVehicle == nil)
EnhancedVehicle = FS22_EnhancedVehicle:new(mission, directory, modName, g_i18n, g_gui, g_gui.inputManager, g_messageCenter)
getfenv(0)["g_EnhancedVehicle"] = EnhancedVehicle
mission.EnhancedVehicle = EnhancedVehicle
addModEventListener(EnhancedVehicle);
end
-- #############################################################################
function EV_unload()
if debug > 1 then print("EV_unload()") end
if not isEnabled() then
return
end
removeModEventListener(EnhancedVehicle)
EnhancedVehicle:delete()
EnhancedVehicle = nil
getfenv(0)["g_EnhancedVehicle"] = nil
end
-- #############################################################################
function EV_loadedMission(mission)
if debug > 1 then print("EV_load()") end
if not isEnabled() then
return
end
if mission.cancelLoading then
return
end
EnhancedVehicle:onMissionLoaded(mission)
end
-- #############################################################################
function EV_validateTypes(types)
if debug > 1 then print("EV_validateTypes()") end
-- attach only to vehicles
if (types.typeName == 'vehicle') then
FS22_EnhancedVehicle.installSpecializations(g_vehicleTypeManager, g_specializationManager, directory, modName)
end
end
-- #############################################################################
EV_init()