Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- AIVehicleUtil
- ConfigurationManager
- ConfigurationUtil
- SpecializationManager
- SpecializationUtil
- Vehicle
- VehicleCamera
- VehicleCharacter
- VehicleHudUtils
- VehicleMotor
- VehiclePlacementCallback
- VehicleTypeManager
- WheelsUtil
- WorkAreaTypeManager
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
ConfigurationUtil
DescriptionVehicle configuration util classFunctions
- addBoughtConfiguration
- applyDesign
- getColorByConfigId
- getColorFromString
- getConfigColorPostLoad
- getConfigColorSingleItemLoad
- getConfigMaterialSingleItemLoad
- getConfigurationValue
- getMaterialByConfigId
- getStoreAddtionalConfigData
- getXMLConfigurationKey
- hasBoughtConfiguration
- replaceMaterialRec
- setColor
- setConfiguration
addBoughtConfiguration
DescriptionAdd bought configurationDefinition
addBoughtConfiguration(string name, Integer id)Arguments
string | name | of bought configuration type |
Integer | id | id of bought configuration |
20 | function ConfigurationUtil.addBoughtConfiguration(object, name, id) |
21 | if g_configurationManager:getConfigurationIndexByName(name) ~= nil then |
22 | if object.boughtConfigurations[name] == nil then |
23 | object.boughtConfigurations[name] = {} |
24 | end |
25 | object.boughtConfigurations[name][id] = true |
26 | end |
27 | end |
applyDesign
DescriptionApply design configDefinition
applyDesign(integer xmlFile, Integer configDesignId)Arguments
integer | xmlFile | id of xml object |
Integer | configDesignId | id of design to apply |
91 | function ConfigurationUtil.applyDesign(object, xmlFile, configDesignId) |
92 | local designKey = string.format("vehicle.designConfigurations.designConfiguration(%d)", configDesignId-1) |
93 | if not hasXMLProperty(xmlFile, designKey) then |
94 | print("Warning: Invalid design configuration " .. configDesignId); |
95 | return |
96 | end |
97 | local i = 0 |
98 | while true do |
99 | local materialKey = string.format(designKey..".material(%d)", i) |
100 | if not hasXMLProperty(xmlFile, materialKey) then |
101 | break |
102 | end |
103 | local baseMaterialNode = I3DUtil.indexToObject(object.components, getXMLString(xmlFile, materialKey.."#node"), object.i3dMappings); |
104 | local refMaterialNode = I3DUtil.indexToObject(object.components, getXMLString(xmlFile, materialKey.."#refNode"), object.i3dMappings); |
105 | if baseMaterialNode ~= nil and refMaterialNode ~= nil then |
106 | local oldMaterial = getMaterial(baseMaterialNode, 0) |
107 | local newMaterial = getMaterial(refMaterialNode, 0) |
108 | for _, component in pairs(object.components) do |
109 | ConfigurationUtil.replaceMaterialRec(object, component.node, oldMaterial, newMaterial); |
110 | end; |
111 | end |
112 | |
113 | local materialName = getXMLString(xmlFile, materialKey .. "#name") |
114 | if materialName ~= nil then |
115 | local shaderParameterName = getXMLString(xmlFile, materialKey .. "#shaderParameter") |
116 | if shaderParameterName ~= nil then |
117 | local colorStr = getXMLString(xmlFile, materialKey.."#color") |
118 | if colorStr ~= nil then |
119 | local color = g_brandColorManager:getBrandColorByName(colorStr) |
120 | if color == nil then |
121 | color = ConfigurationUtil.getColorFromString(colorStr) |
122 | end |
123 | if color ~= nil then |
124 | local materialId = getXMLInt(xmlFile, materialKey.."#materialId") |
125 | if object.setBaseMaterialColor ~= nil then |
126 | object:setBaseMaterialColor(materialName, shaderParameterName, color, materialId) |
127 | end |
128 | end |
129 | end |
130 | end |
131 | end |
132 | |
133 | i = i + 1 |
134 | end |
135 | ObjectChangeUtil.updateObjectChanges(xmlFile, "vehicle.designConfigurations.designConfiguration", configDesignId, object.components, object); |
136 | end |
getColorByConfigId
DescriptionReturns color of config idDefinition
getColorByConfigId(string configName, Integer configId)Arguments
string | configName | name if config |
Integer | configId | id of config to get color |
table | color | color and material(r, g, b, mat) |
55 | function ConfigurationUtil.getColorByConfigId(object, configName, configId) |
56 | local configId = object.configurations[configName] |
57 | if configId ~= nil then |
58 | local item = g_storeManager:getItemByXMLFilename(object.configFileName) |
59 | local config = item.configurations[configName][configId] |
60 | if config ~= nil then |
61 | local r, g, b = unpack(config.color) |
62 | return {r, g, b, config.material} |
63 | end |
64 | end |
65 | |
66 | return nil |
67 | end |
getColorFromString
DescriptionGet color from stringDefinition
getColorFromString(string colorString)Arguments
string | colorString | color rgba string or brand color identifier |
table | color | color (r, g, b) |
349 | function ConfigurationUtil.getColorFromString(colorString) |
350 | if colorString ~= nil then |
351 | local colorVector = g_brandColorManager:getBrandColorByName(colorString) or {StringUtil.getVectorFromString(colorString)} |
352 | |
353 | if colorVector == nil or #colorVector < 3 or #colorVector > 4 then |
354 | print("Error: Invalid color string '" .. colorString .. "'") |
355 | return nil |
356 | end |
357 | return colorVector; |
358 | end |
359 | return nil; |
360 | end |
getConfigColorPostLoad
DescriptionGet config color post loadDefinition
getConfigColorPostLoad(integer xmlFile, string baseKey, string baseDir, string customEnvironment, boolean isMod, table configurationItems)Arguments
integer | xmlFile | id of xml object |
string | baseKey | base key |
string | baseDir | base directory |
string | customEnvironment | custom environment |
boolean | isMod | is mod |
table | configurationItems | config items |
280 | function ConfigurationUtil.getConfigColorPostLoad(xmlFile, baseKey, baseDir, customEnvironment, isMod, configurationItems, storeItem) |
281 | local defaultColorIndex = getXMLInt(xmlFile, baseKey.."#defaultColorIndex") |
282 | |
283 | if Utils.getNoNil(getXMLBool(xmlFile, baseKey.."#useDefaultColors"), false) then |
284 | local price = Utils.getNoNil(getXMLInt(xmlFile, baseKey.."#price"), 1000); |
285 | |
286 | for i, color in pairs(g_vehicleColors) do |
287 | local configItem = StoreItemUtil.addConfigurationItem(configurationItems, "", "", price, 0, false) |
288 | if color.r ~= nil and color.g ~= nil and color.b ~= nil then |
289 | configItem.color = {color.r, color.g, color.b, 1} |
290 | elseif color.brandColor ~= nil then |
291 | configItem.color = g_brandColorManager:getBrandColorByName(color.brandColor) |
292 | |
293 | if configItem.color == nil then |
294 | configItem.color = {1, 1, 1, 1} |
295 | g_logManager:warning("Unable to find brandColor '%s' in g_vehicleColors", color.brandColor) |
296 | end |
297 | end |
298 | |
299 | configItem.name = g_i18n:convertText(color.name) |
300 | |
301 | if i == defaultColorIndex then |
302 | configItem.isDefault = true |
303 | configItem.price = 0 |
304 | end |
305 | end |
306 | end; |
307 | |
308 | if defaultColorIndex == nil then |
309 | local defaultIsDefined = false |
310 | for _, item in ipairs(configurationItems) do |
311 | if item.isDefault ~= nil and item.isDefault then |
312 | defaultIsDefined = true |
313 | end |
314 | end |
315 | |
316 | if not defaultIsDefined then |
317 | if #configurationItems > 0 then |
318 | configurationItems[1].isDefault = true |
319 | configurationItems[1].price = 0 |
320 | end |
321 | end |
322 | end |
323 | end |
getConfigColorSingleItemLoad
DescriptionGet config color single item loadDefinition
getConfigColorSingleItemLoad(integer xmlFile, string baseXMLName, string baseDir, string customEnvironment, boolean isMod, table configItem)Arguments
integer | xmlFile | id of xml object |
string | baseXMLName | base xml name |
string | baseDir | base directory |
string | customEnvironment | custom environment |
boolean | isMod | is mod |
table | configItem | config item |
258 | function ConfigurationUtil.getConfigColorSingleItemLoad(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, configItem) |
259 | |
260 | local colorStr = Utils.getNoNil(getXMLString(xmlFile, baseXMLName.."#color"), "1 1 1 1") |
261 | local color = g_brandColorManager:getBrandColorByName(colorStr) |
262 | if color == nil then |
263 | color = ConfigurationUtil.getColorFromString(colorStr) |
264 | end |
265 | |
266 | configItem.color = color |
267 | configItem.material = getXMLInt(xmlFile, baseXMLName.."#material") |
268 | |
269 | configItem.name = XMLUtil.getXMLI18NValue(xmlFile, baseXMLName.."#name", getXMLString, "", "", customEnvironment, false) |
270 | end |
getConfigMaterialSingleItemLoad
DescriptionDefinitiongetConfigMaterialSingleItemLoad()Code
328 | function ConfigurationUtil.getConfigMaterialSingleItemLoad(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, configItem) |
329 | configItem.color = ConfigurationUtil.getColorFromString(Utils.getNoNil(getXMLString(xmlFile, baseXMLName.."#color"), "1 1 1 1")); |
330 | configItem.material = getXMLInt(xmlFile, baseXMLName.."#material") |
331 | end |
getConfigurationValue
DescriptionGet value of configurationDefinition
getConfigurationValue(integer xmlFile, string key, string subKey, string param, function xmlFunc, any_type defaultValue, string fallbackConfigKey, string fallbackOldgKey)Arguments
integer | xmlFile | id of xml object |
string | key | key |
string | subKey | sub key |
string | param | parameter |
function | xmlFunc | xml function |
any_type | defaultValue | default value |
string | fallbackConfigKey | fallback config key |
string | fallbackOldgKey | fallback old key |
any_type | value | value of config |
206 | function ConfigurationUtil.getConfigurationValue(xmlFile, key, subKey, param, xmlFunc, defaultValue, fallbackConfigKey, fallbackOldKey) |
207 | if type(subKey) == "table" then |
208 | printCallstack(); |
209 | end |
210 | local value = nil; |
211 | if key ~= nil then |
212 | value = xmlFunc(xmlFile, key..subKey..param); |
213 | end; |
214 | |
215 | if value == nil and fallbackConfigKey ~= nil then |
216 | value = xmlFunc(xmlFile, fallbackConfigKey..subKey..param); -- Check for default configuration (xml index 0) |
217 | end; |
218 | if value == nil and fallbackOldKey ~= nil then |
219 | value = xmlFunc(xmlFile, fallbackOldKey..subKey..param); -- Fallback to old xml setup |
220 | end; |
221 | return Utils.getNoNil(value, defaultValue); -- using default value |
222 | end |
getMaterialByConfigId
DescriptionReturns material of config idDefinition
getMaterialByConfigId(string configName, Integer configId)Arguments
string | configName | name if config |
Integer | configId | id of config to get color |
integer | material | material |
74 | function ConfigurationUtil.getMaterialByConfigId(object, configName, configId) |
75 | local configId = object.configurations[configName] |
76 | if configId ~= nil then |
77 | local item = g_storeManager:getItemByXMLFilename(object.configFileName) |
78 | local config = item.configurations[configName][configId] |
79 | if config ~= nil then |
80 | return config.material |
81 | end |
82 | end |
83 | |
84 | return nil |
85 | end |
getStoreAddtionalConfigData
DescriptionGet store additional config dataDefinition
getStoreAddtionalConfigData(integer xmlFile, string baseXMLName, string baseDir, string customEnvironment, boolean isMod, table configItem)Arguments
integer | xmlFile | id of xml object |
string | baseXMLName | base xml name |
string | baseDir | base directory |
string | customEnvironment | custom environment |
boolean | isMod | is mod |
table | configItem | config item |
341 | function ConfigurationUtil.getStoreAddtionalConfigData(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, configItem) |
342 | configItem.vehicleType = getXMLString(xmlFile, baseXMLName.."#vehicleType") |
343 | end |
getXMLConfigurationKey
DescriptionGet xml configuration keyDefinition
getXMLConfigurationKey(integer xmlFile, Integer index, string key, string defaultKey, string configurationKey)Arguments
integer | xmlFile | id of xml object |
Integer | index | index |
string | key | key |
string | defaultKey | default key |
string | configurationKey | configuration key |
string | configKey | key of configuration |
Integer | configIndex | index of configuration |
233 | function ConfigurationUtil.getXMLConfigurationKey(xmlFile, index, key, defaultKey, configurationKey) |
234 | local configIndex = Utils.getNoNil(index, 1); |
235 | local configKey = string.format(key.."(%d)", configIndex-1); |
236 | if index ~= nil and not hasXMLProperty(xmlFile, configKey) then |
237 | print("Warning: Invalid "..configurationKey.." index '"..tostring(index).."' in '"..key.."'. Using default "..configurationKey.." settings instead!"); |
238 | end; |
239 | |
240 | if not hasXMLProperty(xmlFile, configKey) then |
241 | configKey = key.."(0)"; |
242 | end; |
243 | if not hasXMLProperty(xmlFile, configKey) then |
244 | configKey = defaultKey; |
245 | end; |
246 | |
247 | return configKey, configIndex; |
248 | end |
hasBoughtConfiguration
DescriptionReturns true if configuration has been boughtDefinition
hasBoughtConfiguration(string name, Integer id)Arguments
string | name | of bought configuration type |
Integer | id | id of bought configuration |
boolean | configurationHasBeenBought | configuration has been bought |
34 | function ConfigurationUtil.hasBoughtConfiguration(object, name, id) |
35 | if object.boughtConfigurations[name] ~= nil and object.boughtConfigurations[name][id] then |
36 | return true |
37 | end |
38 | return false |
39 | end |
replaceMaterialRec
DescriptionReplace material of nodeDefinition
replaceMaterialRec(Integer node, Integer oldMaterial, Integer newMaterial)Arguments
Integer | node | id of node |
Integer | oldMaterial | id of old material |
Integer | newMaterial | id of new material |
143 | function ConfigurationUtil.replaceMaterialRec(object, node, oldMaterial, newMaterial) |
144 | if getHasClassId(node, ClassIds.SHAPE) then |
145 | local nodeMaterial = getMaterial(node, 0); |
146 | if nodeMaterial == oldMaterial then |
147 | setMaterial(node, newMaterial, 0) |
148 | end |
149 | end; |
150 | |
151 | local numChildren = getNumOfChildren(node); |
152 | if numChildren > 0 then |
153 | for i=0, numChildren-1 do |
154 | ConfigurationUtil.replaceMaterialRec(object, getChildAt(node, i), oldMaterial, newMaterial) |
155 | end; |
156 | end; |
157 | end |
setColor
DescriptionSets color of vehicleDefinition
setColor(integer xmlFile, string configName, Integer configColorId)Arguments
integer | xmlFile | id of xml object |
string | configName | name of config |
Integer | configColorId | id of config color to use |
164 | function ConfigurationUtil.setColor(object, xmlFile, configName, configColorId) |
165 | local color = ConfigurationUtil.getColorByConfigId(object, configName, configColorId) |
166 | if color ~= nil then |
167 | local r,g,b,mat = unpack(color); |
168 | local i = 0; |
169 | while true do |
170 | local colorKey = string.format("vehicle.%sConfigurations.colorNode(%d)", configName, i) |
171 | if not hasXMLProperty(xmlFile, colorKey) then |
172 | break; |
173 | end |
174 | |
175 | local node = I3DUtil.indexToObject(object.components, getXMLString(xmlFile, colorKey .. "#node"), object.i3dMappings); |
176 | if node ~= nil then |
177 | if getHasClassId(node, ClassIds.SHAPE) then |
178 | if mat == nil then |
179 | _,_,_,mat = getShaderParameter(node, "colorScale") |
180 | end |
181 | if Utils.getNoNil(getXMLBool(xmlFile, colorKey .. "#recursive"), false) then |
182 | I3DUtil.setShaderParameterRec(node, "colorScale", r, g, b, mat); |
183 | else |
184 | setShaderParameter(node, "colorScale", r, g, b, mat, false); |
185 | end |
186 | else |
187 | print("Warning: Could not set vehicle color to '"..getName(node).."' because node is not a shape!") |
188 | end |
189 | end |
190 | i = i + 1; |
191 | end |
192 | end |
193 | end |
setConfiguration
DescriptionSet configuration valueDefinition
setConfiguration(string name, Integer id)Arguments
string | name | name of configuration type |
Integer | id | id of configuration value |
45 | function ConfigurationUtil.setConfiguration(object, name, id) |
46 | object.configurations[name] = id |
47 | end |