-
Notifications
You must be signed in to change notification settings - Fork 1
/
addSpecialization.lua
136 lines (113 loc) · 3.84 KB
/
addSpecialization.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
--
-- add specialization to all mods.
--
--
-- @author: Xentro ([email protected])
-- @website: www.Xentro.se
-- @history: v1.53 - 2014-11-11 - Improvement
-- v1.52 - 2013-10-29 -
--
addSpecialization = {};
addSpecialization.isLoaded = true;
addSpecialization.g_currentModDirectory = g_currentModDirectory;
if SpecializationUtil.specializations["LightAddon"] == nil then
SpecializationUtil.registerSpecialization("LightAddon", "LightAddon", g_currentModDirectory .. "LightAddon.lua")
addSpecialization.isLoaded = false;
end;
addModEventListener(addSpecialization);
function addSpecialization:loadMap(name)
self.addLAdebugger = GrisuDebug:create("addSpecialization ( LightAddon )")
self.addLAdebugger:setLogLvl(GrisuDebug.DEBUG)
if not g_currentMission.lightModLoaded then
if not addSpecialization.isLoaded then
addSpecialization:add();
addSpecialization.isLoaded = true;
end;
g_currentMission.lightModLoaded = true;
else
self.addLAdebugger:print(GrisuDebug.ERROR, "The LightAddon mod have been loaded already! remove one of the copy's")
--print("LightAddon - Error: The LightAddon mod have been loaded already! remove one of the copy's");
end;
end;
function addSpecialization:deleteMap()
g_currentMission.lightModLoaded = nil;
end;
function addSpecialization:mouseEvent(posX, posY, isDown, isUp, button)
end;
function addSpecialization:keyEvent(unicode, sym, modifier, isDown)
end;
function addSpecialization:update(dt)
end;
function addSpecialization:draw()
end;
function addSpecialization:add()
local searchWords = {"LightAddon"};
local searchSpecializations = {{"LightAddon", false}, {"lights", true}}; -- only globally accessible scripts. (steerable, fillable etc.)
for k, vehicle in pairs(VehicleTypeUtil.vehicleTypes) do
local locationAllowed, specialization;
for _, s in ipairs(searchSpecializations) do s[3] = false; end;
for _, vs in ipairs(vehicle.specializations) do
for _, s in ipairs(searchSpecializations) do
if vs == SpecializationUtil.getSpecialization(s[1]) then
if s[2] then
locationAllowed = "allowed";
s[3] = true;
else
locationAllowed = "has";
specialization = s[1];
break;
end;
end;
end;
if locationAllowed ~= nil and locationAllowed ~= "allowed" then
break;
end;
end;
if locationAllowed == nil then
locationAllowed = "allowed";
end;
for _, s in ipairs(searchSpecializations) do
if s[2] then
if s[3] ~= true then
locationAllowed = "missing";
specialization = s[1];
break;
end;
end;
end;
if locationAllowed == "allowed" then
local addSpec;
local modName = Utils.splitString(".", k);
local spec = {};
for name in pairs(SpecializationUtil.specializations) do
if string.find(name, modName[1]) ~= nil then
local parts = Utils.splitString(".", name);
if table.getn(parts) > 1 then
table.insert(spec, parts);
end;
end;
end;
for _, s in ipairs(spec) do
for _, search in ipairs(searchWords) do
if string.find(string.lower(s[2]), string.lower(search)) ~= nil then
addSpec = s[2];
break;
end;
end;
if addSpec ~= nil then
break;
end;
end;
if addSpec == nil then
table.insert(vehicle.specializations, SpecializationUtil.getSpecialization("LightAddon"));
self.addLAdebugger:print(GrisuDebug.TRACE, "LightAddon: Inserted on " .. k);
else
self.addLAdebugger:print(GrisuDebug.INFO, "Failed inserting on " .. k .. " as it has the specialization (" .. addSpec .. ")");
end;
elseif locationAllowed == "has" then
self.addLAdebugger:print(GrisuDebug.INFO,"Failed inserting on " .. k .. " as it has the specialization (" .. specialization .. ")");
else
self.addLAdebugger:print(GrisuDebug.INFO,"Failed inserting on " .. k .. " as its missing specialization " .. specialization);
end;
end;
end;