Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
ConfigurationUtil
DescriptionVehicle configuration util classFunctions
- addBoughtConfiguration
- applyConfigMaterials
- getColorByConfigId
- getColorFromString
- getConfigColorPostLoad
- getConfigColorSingleItemLoad
- getConfigIdBySaveId
- getConfigMaterialSingleItemLoad
- getConfigurationValue
- getMaterialByConfigId
- getOverwrittenMaterialColors
- getSaveIdByConfigId
- getStoreAdditionalConfigData
- getXMLConfigurationKey
- hasBoughtConfiguration
- isColorMetallic
- loadConfigurationNameFromXML
- registerColorConfigurationXMLPaths
- registerMaterialConfigurationXMLPaths
- 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 |
applyConfigMaterials
DescriptionApply materials defined in the given configDefinition
applyConfigMaterials(table object, table xmlFile, string configName, integer configId)Arguments
table | object | object (vehicle) |
table | xmlFile | xml file object |
string | configName | name of config |
integer | configId | id of config to apply |
138 | function ConfigurationUtil.applyConfigMaterials(object, xmlFile, configName, configId) |
139 | local configuration = g_configurationManager:getConfigurationDescByName(configName) |
140 | local xmlKey = configuration.xmlKey |
141 | if xmlKey ~= nil then |
142 | xmlKey = "."..xmlKey |
143 | else |
144 | xmlKey = "" |
145 | end |
146 | |
147 | local configKey = string.format("vehicle%s.%sConfigurations.%sConfiguration(%d)", xmlKey, configName, configName, configId-1) |
148 | if xmlFile:hasProperty(configKey) then |
149 | xmlFile:iterate(configKey .. ".material", function(_, key) |
150 | local baseMaterialNode = xmlFile:getValue(key.."#node", nil, object.components, object.i3dMappings) |
151 | local refMaterialNode = xmlFile:getValue(key.."#refNode", nil, object.components, object.i3dMappings) |
152 | if baseMaterialNode ~= nil and refMaterialNode ~= nil then |
153 | local oldMaterial = getMaterial(baseMaterialNode, 0) |
154 | local newMaterial = getMaterial(refMaterialNode, 0) |
155 | for _, component in pairs(object.components) do |
156 | ConfigurationUtil.replaceMaterialRec(object, component.node, oldMaterial, newMaterial) |
157 | end |
158 | end |
159 | |
160 | local materialName = xmlFile:getValue(key .. "#name") |
161 | if materialName ~= nil then |
162 | local shaderParameterName = xmlFile:getValue(key .. "#shaderParameter") |
163 | if shaderParameterName ~= nil then |
164 | local color = xmlFile:getValue(key.."#color", nil, true) |
165 | if color ~= nil then |
166 | local materialId = xmlFile:getValue(key.."#materialId") |
167 | if object.setBaseMaterialColor ~= nil then |
168 | object:setBaseMaterialColor(materialName, shaderParameterName, color, materialId) |
169 | end |
170 | end |
171 | end |
172 | end |
173 | end) |
174 | end |
175 | 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 | if configId ~= nil then |
57 | local item = g_storeManager:getItemByXMLFilename(object.configFileName) |
58 | if item.configurations ~= nil then |
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 | end |
66 | |
67 | return nil |
68 | 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) |
422 | function ConfigurationUtil.getColorFromString(colorString) |
423 | if colorString ~= nil then |
424 | local colorVector = g_brandColorManager:getBrandColorByName(colorString) or {colorString:getVector()} |
425 | |
426 | if colorVector == nil or #colorVector < 3 or #colorVector > 4 then |
427 | print("Error: Invalid color string '" .. colorString .. "'") |
428 | return nil |
429 | end |
430 | return colorVector |
431 | end |
432 | return nil |
433 | 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 |
353 | function ConfigurationUtil.getConfigColorPostLoad(xmlFile, baseKey, baseDir, customEnvironment, isMod, configurationItems, storeItem) |
354 | local defaultColorIndex = xmlFile:getValue(baseKey.."#defaultColorIndex") |
355 | |
356 | if xmlFile:getValue(baseKey.."#useDefaultColors", false) then |
357 | local price = xmlFile:getValue(baseKey.."#price", 1000) |
358 | |
359 | for i, color in pairs(g_vehicleColors) do |
360 | local configItem = StoreItemUtil.addConfigurationItem(configurationItems, "", "", price, 0, false) |
361 | if color.r ~= nil and color.g ~= nil and color.b ~= nil then |
362 | configItem.color = {color.r, color.g, color.b, 1} |
363 | elseif color.brandColor ~= nil then |
364 | configItem.color = g_brandColorManager:getBrandColorByName(color.brandColor) |
365 | |
366 | if configItem.color == nil then |
367 | configItem.color = {1, 1, 1, 1} |
368 | Logging.warning("Unable to find brandColor '%s' in g_vehicleColors", color.brandColor) |
369 | end |
370 | end |
371 | |
372 | configItem.name = g_i18n:convertText(color.name) |
373 | |
374 | if i == defaultColorIndex then |
375 | configItem.isDefault = true |
376 | configItem.price = 0 |
377 | end |
378 | end |
379 | end |
380 | |
381 | if defaultColorIndex == nil then |
382 | local defaultIsDefined = false |
383 | for _, item in ipairs(configurationItems) do |
384 | if item.isDefault ~= nil and item.isDefault then |
385 | defaultIsDefined = true |
386 | end |
387 | end |
388 | |
389 | if not defaultIsDefined then |
390 | if #configurationItems > 0 then |
391 | configurationItems[1].isDefault = true |
392 | configurationItems[1].price = 0 |
393 | end |
394 | end |
395 | end |
396 | 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 |
337 | function ConfigurationUtil.getConfigColorSingleItemLoad(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, configItem) |
338 | configItem.color = xmlFile:getValue(baseXMLName.."#color", "1 1 1", true) |
339 | configItem.uiColor = xmlFile:getValue(baseXMLName.."#uiColor", configItem.color, true) |
340 | configItem.material = xmlFile:getValue(baseXMLName.."#material") |
341 | |
342 | configItem.name = ConfigurationUtil.loadConfigurationNameFromXML(xmlFile, baseXMLName, customEnvironment) |
343 | end |
getConfigIdBySaveId
DescriptionReturns config id from given save identifierDefinition
getConfigIdBySaveId(table object, string configName, string saveId)Arguments
table | object | object |
string | configName | name if config |
string | saveId | save identifier |
integer | configId | config id |
97 | function ConfigurationUtil.getConfigIdBySaveId(configFileName, configName, configId) |
98 | local item = g_storeManager:getItemByXMLFilename(configFileName) |
99 | if item.configurations ~= nil then |
100 | local configs = item.configurations[configName] |
101 | if configs ~= nil then |
102 | for j=1, #configs do |
103 | if configs[j].saveId == configId then |
104 | return configs[j].index |
105 | end |
106 | end |
107 | end |
108 | end |
109 | |
110 | return 1 |
111 | end |
getConfigMaterialSingleItemLoad
DescriptionDefinitiongetConfigMaterialSingleItemLoad()Code
401 | function ConfigurationUtil.getConfigMaterialSingleItemLoad(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, configItem) |
402 | configItem.color = xmlFile:getValue(baseXMLName.."#color", "1 1 1", true) |
403 | configItem.material = xmlFile:getValue(baseXMLName.."#material") |
404 | end |
getConfigurationValue
DescriptionGet value of configurationDefinition
getConfigurationValue(integer xmlFile, string key, string subKey, string param, any_type defaultValue, string fallbackConfigKey, string fallbackOldgKey)Arguments
integer | xmlFile | id of xml object |
string | key | key |
string | subKey | sub key |
string | param | parameter |
any_type | defaultValue | default value |
string | fallbackConfigKey | fallback config key |
string | fallbackOldgKey | fallback old key |
any_type | value | value of config |
285 | function ConfigurationUtil.getConfigurationValue(xmlFile, key, subKey, param, defaultValue, fallbackConfigKey, fallbackOldKey) |
286 | if type(subKey) == "table" then |
287 | printCallstack() |
288 | end |
289 | local value = nil |
290 | if key ~= nil then |
291 | value = xmlFile:getValue(key..subKey..param) |
292 | end |
293 | |
294 | if value == nil and fallbackConfigKey ~= nil then |
295 | value = xmlFile:getValue(fallbackConfigKey..subKey..param) -- Check for default configuration (xml index 0) |
296 | end |
297 | if value == nil and fallbackOldKey ~= nil then |
298 | value = xmlFile:getValue(fallbackOldKey..subKey..param) -- Fallback to old xml setup |
299 | end |
300 | return Utils.getNoNil(value, defaultValue) -- using default value |
301 | 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 |
118 | function ConfigurationUtil.getMaterialByConfigId(object, configName, configId) |
119 | if configId ~= nil then |
120 | local item = g_storeManager:getItemByXMLFilename(object.configFileName) |
121 | if item.configurations ~= nil then |
122 | local config = item.configurations[configName][configId] |
123 | if config ~= nil then |
124 | return config.material |
125 | end |
126 | end |
127 | end |
128 | |
129 | return nil |
130 | end |
getOverwrittenMaterialColors
DescriptionSearches in all configurations for defined materials with the given search name and returns the color and materialDefinition
getOverwrittenMaterialColors(table object, table xmlFile, table targetTable)Arguments
table | object | object (vehicle) |
table | xmlFile | xml file object |
table | targetTable | target table with names as indices |
table | color | color |
integer | materialId | material id |
184 | function ConfigurationUtil.getOverwrittenMaterialColors(object, xmlFile, targetTable) |
185 | for configName, configId in pairs(object.configurations) do |
186 | local configuration = g_configurationManager:getConfigurationDescByName(configName) |
187 | local xmlKey = configuration.xmlKey |
188 | if xmlKey ~= nil then |
189 | xmlKey = "."..xmlKey |
190 | else |
191 | xmlKey = "" |
192 | end |
193 | |
194 | local configKey = string.format("vehicle%s.%sConfigurations.%sConfiguration(%d)", xmlKey, configName, configName, configId-1) |
195 | if xmlFile:hasProperty(configKey) then |
196 | xmlFile:iterate(configKey .. ".material", function(_, key) |
197 | local materialName = xmlFile:getValue(key .. "#name") |
198 | if materialName ~= nil then |
199 | for name, _ in pairs(targetTable) do |
200 | if materialName == name then |
201 | local color = xmlFile:getValue(key.."#color", nil, true) |
202 | if color ~= nil and #color > 0 then |
203 | local materialId = xmlFile:getValue(key.."#materialId") |
204 | |
205 | targetTable[name][1] = color[1] |
206 | targetTable[name][2] = color[2] |
207 | targetTable[name][3] = color[3] |
208 | targetTable[name][4] = materialId |
209 | end |
210 | end |
211 | end |
212 | end |
213 | end) |
214 | end |
215 | end |
216 | end |
getSaveIdByConfigId
DescriptionReturns save identifier from given config idDefinition
getSaveIdByConfigId(table object, string configName, Integer configId)Arguments
table | object | object |
string | configName | name if config |
Integer | configId | id of config to get color |
string | saveId | save identifier |
76 | function ConfigurationUtil.getSaveIdByConfigId(configFileName, configName, configId) |
77 | local item = g_storeManager:getItemByXMLFilename(configFileName) |
78 | if item.configurations ~= nil then |
79 | local configs = item.configurations[configName] |
80 | if configs ~= nil then |
81 | local config = configs[configId] |
82 | if config ~= nil then |
83 | return config.saveId |
84 | end |
85 | end |
86 | end |
87 | |
88 | return nil |
89 | end |
getStoreAdditionalConfigData
DescriptionGet store additional config dataDefinition
getStoreAdditionalConfigData(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 |
414 | function ConfigurationUtil.getStoreAdditionalConfigData(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, configItem) |
415 | configItem.vehicleType = xmlFile:getValue(baseXMLName.."#vehicleType") |
416 | 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 |
312 | function ConfigurationUtil.getXMLConfigurationKey(xmlFile, index, key, defaultKey, configurationKey) |
313 | local configIndex = Utils.getNoNil(index, 1) |
314 | local configKey = string.format(key.."(%d)", configIndex-1) |
315 | if index ~= nil and not xmlFile:hasProperty(configKey) then |
316 | print("Warning: Invalid "..configurationKey.." index '"..tostring(index).."' in '"..key.."'. Using default "..configurationKey.." settings instead!") |
317 | end |
318 | |
319 | if not xmlFile:hasProperty(configKey) then |
320 | configKey = key.."(0)" |
321 | end |
322 | if not xmlFile:hasProperty(configKey) then |
323 | configKey = defaultKey |
324 | end |
325 | |
326 | return configKey, configIndex |
327 | 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 |
isColorMetallic
DescriptionGet whether a material is visualized as metallic in UIDefinition
isColorMetallic()Code
487 | function ConfigurationUtil.isColorMetallic(materialId) |
488 | return materialId == 2 |
489 | or materialId == 3 |
490 | or materialId == 19 |
491 | or materialId == 30 |
492 | or materialId == 31 |
493 | or materialId == 35 |
494 | end |
loadConfigurationNameFromXML
DescriptionReturns formatted config name that is loaded from xmlDefinition
loadConfigurationNameFromXML(integer xmlFile, string configKey, string customEnvironment)Arguments
integer | xmlFile | id of xml object |
string | configKey | configuration key |
string | customEnvironment | custom environment |
string | configName | config name |
441 | function ConfigurationUtil.loadConfigurationNameFromXML(xmlFile, configKey, customEnvironment) |
442 | local configName = xmlFile:getValue(configKey.."#name", nil, customEnvironment, false) |
443 | local params = xmlFile:getValue(configKey.."#params") |
444 | if params ~= nil then |
445 | params = params:split("|") |
446 | for i=1, #params do |
447 | params[i] = g_i18n:convertText(params[i]) |
448 | end |
449 | configName = string.format(configName, unpack(params)) |
450 | end |
451 | |
452 | return configName |
453 | end |
registerColorConfigurationXMLPaths
DescriptionRegister color configuration pathsDefinition
registerColorConfigurationXMLPaths()Code
457 | function ConfigurationUtil.registerColorConfigurationXMLPaths(schema, configurationName) |
458 | local baseKey = string.format("vehicle.%sConfigurations", configurationName) |
459 | schema:register(XMLValueType.INT, baseKey .. "#defaultColorIndex", "Default color index on start") |
460 | schema:register(XMLValueType.BOOL, baseKey .. "#useDefaultColors", "Use default colors", false) |
461 | schema:register(XMLValueType.INT, baseKey .. "#price", "Default color price", 1000) |
462 | |
463 | schema:register(XMLValueType.NODE_INDEX, baseKey .. ".colorNode(?)#node", "Color node") |
464 | schema:register(XMLValueType.BOOL, baseKey .. ".colorNode(?)#recursive", "Apply recursively") |
465 | |
466 | local itemKey = string.format("%s.%sConfiguration(?)", baseKey, configurationName) |
467 | schema:register(XMLValueType.COLOR, itemKey .. "#color", "Configuration color", "1 1 1 1") |
468 | schema:register(XMLValueType.COLOR, itemKey .. "#uiColor", "Configuration UI color", "1 1 1 1") |
469 | schema:register(XMLValueType.INT, itemKey .. "#material", "Configuration material") |
470 | schema:register(XMLValueType.L10N_STRING, itemKey .. "#name", "Color name") |
471 | end |
registerMaterialConfigurationXMLPaths
DescriptionRegister material configuration pathsDefinition
registerMaterialConfigurationXMLPaths()Code
475 | function ConfigurationUtil.registerMaterialConfigurationXMLPaths(schema, configurationName) |
476 | schema:register(XMLValueType.NODE_INDEX, configurationName .. ".material(?)#node", "Material node") |
477 | schema:register(XMLValueType.NODE_INDEX, configurationName .. ".material(?)#refNode", "Material reference node") |
478 | |
479 | schema:register(XMLValueType.STRING, configurationName .. ".material(?)#name", "Material name") |
480 | schema:register(XMLValueType.STRING, configurationName .. ".material(?)#shaderParameter", "Material shader parameter name") |
481 | schema:register(XMLValueType.COLOR, configurationName .. ".material(?)#color", "Color") |
482 | schema:register(XMLValueType.INT, configurationName .. ".material(?)#materialId", "Material id") |
483 | 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 |
223 | function ConfigurationUtil.replaceMaterialRec(object, node, oldMaterial, newMaterial) |
224 | if getHasClassId(node, ClassIds.SHAPE) then |
225 | local nodeMaterial = getMaterial(node, 0) |
226 | if nodeMaterial == oldMaterial then |
227 | setMaterial(node, newMaterial, 0) |
228 | end |
229 | end |
230 | |
231 | local numChildren = getNumOfChildren(node) |
232 | if numChildren > 0 then |
233 | for i=0, numChildren-1 do |
234 | ConfigurationUtil.replaceMaterialRec(object, getChildAt(node, i), oldMaterial, newMaterial) |
235 | end |
236 | end |
237 | 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 |
244 | function ConfigurationUtil.setColor(object, xmlFile, configName, configColorId) |
245 | local color = ConfigurationUtil.getColorByConfigId(object, configName, configColorId) |
246 | if color ~= nil then |
247 | local r,g,b,mat = unpack(color) |
248 | local i = 0 |
249 | while true do |
250 | local colorKey = string.format("vehicle.%sConfigurations.colorNode(%d)", configName, i) |
251 | if not xmlFile:hasProperty(colorKey) then |
252 | break |
253 | end |
254 | |
255 | local node = xmlFile:getValue(colorKey .. "#node", nil, object.components, object.i3dMappings) |
256 | if node ~= nil then |
257 | if getHasClassId(node, ClassIds.SHAPE) then |
258 | if mat == nil then |
259 | _,_,_,mat = getShaderParameter(node, "colorScale") |
260 | end |
261 | if xmlFile:getValue(colorKey .. "#recursive", false) then |
262 | I3DUtil.setShaderParameterRec(node, "colorScale", r, g, b, mat) |
263 | else |
264 | setShaderParameter(node, "colorScale", r, g, b, mat, false) |
265 | end |
266 | else |
267 | print("Warning: Could not set vehicle color to '"..getName(node).."' because node is not a shape!") |
268 | end |
269 | end |
270 | i = i + 1 |
271 | end |
272 | end |
273 | 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 |