Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on May 23, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathValidModeSetupHandler.lua
More file actions
Latest commit
142 lines (134 loc) · 4.81 KB
/
Copy pathValidModeSetupHandler.lua
File metadata and controls
142 lines (134 loc) · 4.81 KB
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
--ValidModeSetupHandler used to check which mode is valid
--the configuration can be found in ValidModeSetup.xml
---@classValidModeSetupHandler
ValidModeSetupHandler=CpObject()
functionValidModeSetupHandler:init()
self:loadFromXml()
end
--load the ValidModeSetup.xml file and create a data table once at start
functionValidModeSetupHandler:loadFromXml()
localmodeSetup= {}
localvalidModeSetupKey="ValidModeSetup"
localfilePath=Utils.getFilename('config/ValidModeSetup.xml', courseplay.path);
self.xmlFile=loadXMLFile('modeSetup', filePath);
ifself.xmlFileandhasXMLProperty(self.xmlFile, validModeSetupKey) then
locali=0
--go through all cp modes
whiletruedo
localmodeKey=string.format("%s.%s(%d)",validModeSetupKey,"Mode",i)
ifnothasXMLProperty(self.xmlFile, modeKey) then
-- courseplay.info(string.format("ValidModeSetupHandler, modeKey not found: %s",modeKey))
break
end
--all the allowedSetups ..
localallowedSetups= {}
self:loadSetupsFromXml(self.xmlFile,modeKey,allowedSetups,"AllowedSetups")
--all the disallowedSetups ..
localdisallowedSetups= {}
self:loadSetupsFromXml(self.xmlFile,modeKey,disallowedSetups,"DisallowedSetups")
localvalidData= {}
if#allowedSetups>0then
validData.allowedSetups=allowedSetups
end
if#disallowedSetups>0then
validData.disallowedSetups=disallowedSetups
end
modeSetup[i+1] =validData
i=i+1
end
self.modeSetup=modeSetup
-- DebugUtil.printTableRecursively(modeSetup, " ", 0, 3)
else
print(string.format("ValidModeSetupHandler, could not load file: %s",filePath))
end
end
--load the Setup for either the allowed or disallowed Setups
functionValidModeSetupHandler:loadSetupsFromXml(xmlFile,baseKey,entry,allowKey)
localkey=string.format("%s.%s",baseKey,allowKey)
locali=0
whiletruedo
localsetupKey=string.format("%s.%s(%d)",key,"Setup",i)
ifnothasXMLProperty(xmlFile, setupKey) then
-- courseplay.info(string.format("ValidModeSetupHandler, %s not found: %s",allowKey,setupKey))
break
end
localspecSetup= {}
self:loadSetupFromXml(xmlFile,setupKey,specSetup,"Specialization")
self:loadSetupFromXml(xmlFile,setupKey,specSetup,"SpecialTool")
if#specSetup>0then
table.insert(entry,specSetup)
end
i=i+1
end
end
--load the Specializations or SpecialTools
functionValidModeSetupHandler:loadSetupFromXml(xmlFile,baseKey,entry,itemKey)
locali=0
whiletruedo
localkey=string.format("%s.%s(%d)",baseKey,itemKey,i)
ifnothasXMLProperty(xmlFile, key) then
-- courseplay.info(string.format("ValidModeSetupHandler, %s not found: %s",itemKey,key))
break
end
localspecName=getXMLString(xmlFile, key.."#name")
table.insert(entry,specName)
i=i+1
end
end
---checks if the "mode" is allowed and not disallowed for the vehicle
---@paramint: cpMode to check
---@paramvehicle: object, implement,vehicle
---@returnboolean, boolean : true = setup allows this mode, true = setup does not disable this mode
functionValidModeSetupHandler:isModeValid(mode,object)
localvalidData=self.modeSetup[mode]
localisAllowedOkay=true
localisDisallowedOkay=true
ifvalidDatathen
ifvalidData.allowedSetupsthen
isAllowedOkay=self:isSetupAllowedValid(validData.allowedSetups,object)
courseplay.debugVehicle(courseplay.DBG_HUD,object,"allowedSetups, mode: %d, isAllowedOkay: %s",mode,tostring(isAllowedOkay))
end
ifvalidData.disallowedSetupsthen
isDisallowedOkay=self:isSetupDisallowedValid(validData.disallowedSetups,object)
courseplay.debugVehicle(courseplay.DBG_HUD,object,"disallowedSetup, mode: %d,, isDisallowedOkay: %s",mode,tostring(isDisallowedOkay))
end
else
courseplay.info("ValidModeSetupHandler, validData==nil !!")
returnfalse
end
returnisAllowedOkay, isDisallowedOkay
end
---checks if one setup combo is allowed for this object
---@paramtable: setups
---@paramvehicle: object, implement,vehicle
---@returnboolean : isAllowedOkay
functionValidModeSetupHandler:isSetupAllowedValid(setups,object)
localallowedSetup=false
for_,specSetupinpairs(setups) do
localfound=true
for_,specinpairs(specSetup) do
ifobject[spec] ==nilandobject.cp.xmlFileName~=specthen
found=false
end
end
allowedSetup=allowedSetuporfound
end
returnallowedSetup
end
---checks if one setup combo is disallowed for this object
---@paramtable: setups
---@paramvehicle: object, implement,vehicle
---@returnboolean : isDisallowedOkay
functionValidModeSetupHandler:isSetupDisallowedValid(setups,object)
localdisallowedSetup=false
for_,specSetupinpairs(setups) do
localfound=false
for_,specinpairs(specSetup) do
ifobject[spec] orobject.cp.xmlFileName==specthen
found=true
end
end
disallowedSetup=disallowedSetuporfound
end
returnnotdisallowedSetup
end