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
StoreItemUtil
DescriptionUtil for interacting with store itemsFunctions
- addConfigurationItem
- getBrandIndexFromXML
- getClosestConfigurationSet
- getConfigurationSetsFromXML
- getConfigurationsFromXML
- getConfigurationsMatchConfigSets
- getCosts
- getDailyUpkeep
- getDefaultConfigId
- getDefaultConfigIdFromItems
- getDefaultPrice
- getFilteredConfigurationIndex
- getFunctionsFromXML
- getIsAnimal
- getIsConfigurable
- getIsHandTool
- getIsLeasable
- getIsObject
- getIsPlaceable
- getIsVehicle
- getSizeValues
- getSizeValuesFromXML
- getSizeValuesFromXMLByKey
- getSpecsFromXML
- getSubConfigurationIndex
- getSubConfigurationItems
- getSubConfigurationsFromXML
- getVRamUsageFromXML
- loadSpecsFromXML
- registerConfigurationSetXMLPaths
- renameDuplicatedConfigurationNames
addConfigurationItem
DescriptionAdds a configuration item to the given listDefinition
addConfigurationItem(table configurationItems, string name, string desc, float price, integer dailyUpkeep)Arguments
table | configurationItems | a list of configurationItems |
string | name | name of the configuration |
string | desc | desc of the configuration |
float | price | price of the configuration |
integer | dailyUpkeep | dailyUpkeep of the configuration |
table | config | object |
254 | function StoreItemUtil.addConfigurationItem(configurationItems, name, desc, price, dailyUpkeep, isDefault, overwrittenTitle, saveId, brandIndex, isSelectable, vehicleBrand, vehicleName, vehicleIcon) |
255 | local configItem = {} |
256 | configItem.name = name |
257 | configItem.desc = desc |
258 | configItem.price = price |
259 | configItem.dailyUpkeep = dailyUpkeep |
260 | configItem.isDefault = isDefault |
261 | configItem.isSelectable = isSelectable |
262 | configItem.overwrittenTitle = overwrittenTitle |
263 | table.insert(configurationItems, configItem) |
264 | configItem.index = #configurationItems |
265 | configItem.saveId = saveId or tostring(configItem.index) |
266 | configItem.brandIndex = brandIndex |
267 | configItem.nameCompareParams = {} |
268 | |
269 | configItem.vehicleBrand = vehicleBrand |
270 | configItem.vehicleName = vehicleName |
271 | configItem.vehicleIcon = vehicleIcon |
272 | |
273 | return configItem |
274 | end |
getBrandIndexFromXML
DescriptionGets the storeitem brand index from xmlDefinition
getBrandIndexFromXML(integer xmlFile, string storeDataXMLKey)Arguments
integer | xmlFile | the xml handle |
string | storeDataXMLKey | path of the parent xml element |
integer | brandIndex | the brandindex |
340 | function StoreItemUtil.getBrandIndexFromXML(xmlFile, storeDataXMLKey) |
341 | local brandName = xmlFile:getValue(storeDataXMLKey..".brand", "") |
342 | return g_brandManager:getBrandIndexByName(brandName) |
343 | end |
getClosestConfigurationSet
DescriptionDefinitiongetClosestConfigurationSet()Code
635 | function StoreItemUtil.getClosestConfigurationSet(configurations, configSets) |
636 | local closestSet = nil |
637 | local closestSetMatches = 0 |
638 | for _, configSet in pairs(configSets) do |
639 | local numMatches = 0 |
640 | for configName, index in pairs(configSet.configurations) do |
641 | if configurations[configName] == index then |
642 | numMatches = numMatches + 1 |
643 | end |
644 | end |
645 | if numMatches > closestSetMatches then |
646 | closestSet = configSet |
647 | closestSetMatches = numMatches |
648 | end |
649 | end |
650 | |
651 | return closestSet, closestSetMatches |
652 | end |
getConfigurationSetsFromXML
DescriptionGets predefined configuration setsDefinition
getConfigurationSetsFromXML(table storeItem, integer xmlFile, string key, string baseDir, string customEnvironment, boolean isMod)Arguments
table | storeItem | a storeItem |
integer | xmlFile | the xml handle |
string | key | the key of the base xml element |
string | baseDir | the base directory |
string | customEnvironment | a custom environment |
boolean | isMod | true if the storeitem is a mod, else false |
table | configuration | sets |
478 | function StoreItemUtil.getConfigurationSetsFromXML(storeItem, xmlFile, key, baseDir, customEnvironment, isMod) |
479 | local configurationSetsKey = string.format("%s.configurationSets", key) |
480 | local overwrittenTitle = xmlFile:getValue(configurationSetsKey.."#title", nil, customEnvironment, false) |
481 | |
482 | local configurationsSets = {} |
483 | local i = 0 |
484 | while true do |
485 | local key = string.format("%s.configurationSet(%d)", configurationSetsKey, i) |
486 | if not xmlFile:hasProperty(key) then |
487 | break |
488 | end |
489 | |
490 | local configSet = {} |
491 | configSet.name = xmlFile:getValue(key.."#name", nil, customEnvironment, false) |
492 | |
493 | local params = xmlFile:getValue(key.."#params") |
494 | if params ~= nil then |
495 | params = params:split("|") |
496 | configSet.name = string.format(configSet.name, unpack(params)) |
497 | end |
498 | |
499 | configSet.isDefault = xmlFile:getValue(key.."#isDefault", false) |
500 | |
501 | configSet.overwrittenTitle = overwrittenTitle |
502 | configSet.configurations = {} |
503 | |
504 | local j = 0 |
505 | while true do |
506 | local configKey = string.format("%s.configuration(%d)", key, j) |
507 | if not xmlFile:hasProperty(configKey) then |
508 | break |
509 | end |
510 | |
511 | local name = xmlFile:getValue(configKey.."#name") |
512 | if name ~= nil then |
513 | if storeItem.configurations[name] ~= nil then |
514 | local index = xmlFile:getValue(configKey.."#index") |
515 | if index ~= nil then |
516 | if storeItem.configurations[name][index] ~= nil then |
517 | configSet.configurations[name] = index |
518 | else |
519 | Logging.xmlWarning(xmlFile, "Index '"..index.."' not defined for configuration '"..name.."'!") |
520 | end |
521 | end |
522 | else |
523 | Logging.xmlWarning(xmlFile, "Configuration name '"..name.."' is not defined!") |
524 | end |
525 | else |
526 | Logging.xmlWarning(xmlFile, "Missing name for configuration set item '"..key.."'!") |
527 | end |
528 | |
529 | j = j + 1 |
530 | end |
531 | |
532 | table.insert(configurationsSets, configSet) |
533 | |
534 | i = i + 1 |
535 | end |
536 | |
537 | return configurationsSets |
538 | end |
getConfigurationsFromXML
DescriptionGets the storeitem configurations from xmlDefinition
getConfigurationsFromXML(integer xmlFile, string key, string baseDir, string customEnvironment, boolean isMod)Arguments
integer | xmlFile | the xml handle |
string | key | the name of the base xml element |
string | baseDir | the base directory |
string | customEnvironment | a custom environment |
boolean | isMod | true if the storeitem is a mod, else false |
table | configurations | a list of configurations |
374 | function StoreItemUtil.getConfigurationsFromXML(xmlFile, key, baseDir, customEnvironment, isMod, storeItem) |
375 | |
376 | local configurations = {} |
377 | local defaultConfigurationIds = {} |
378 | local numConfigs = 0 |
379 | -- try to load default configuration values (title (shown in shop), name, desc, price) - additional parameters can be loaded with loadFunc |
380 | local configurationTypes = g_configurationManager:getConfigurationTypes() |
381 | for _, name in pairs(configurationTypes) do |
382 | local configuration = g_configurationManager:getConfigurationDescByName(name) |
383 | local configurationItems = {} |
384 | local i = 0 |
385 | local xmlKey = configuration.xmlKey |
386 | if xmlKey ~= nil then |
387 | xmlKey = "."..xmlKey |
388 | else |
389 | xmlKey = "" |
390 | end |
391 | local baseKey = key..xmlKey.."."..name.."Configurations" |
392 | |
393 | if configuration.preLoadFunc ~= nil then |
394 | configuration.preLoadFunc(xmlFile, baseKey, baseDir, customEnvironment, isMod, configurationItems) |
395 | end |
396 | |
397 | local overwrittenTitle = xmlFile:getValue(baseKey.."#title", nil, customEnvironment, false) |
398 | |
399 | local loadedSaveIds = {} |
400 | |
401 | while true do |
402 | if i > 2 ^ ConfigurationUtil.SEND_NUM_BITS then |
403 | Logging.xmlWarning(xmlFile, "Maximum number of configurations are reached for %s. Only %d configurations per type are allowed!", name, 2 ^ ConfigurationUtil.SEND_NUM_BITS) |
404 | end |
405 | local configKey = string.format(baseKey.."."..name.."Configuration(%d)", i) |
406 | if not xmlFile:hasProperty(configKey) then |
407 | break |
408 | end |
409 | |
410 | local configName = ConfigurationUtil.loadConfigurationNameFromXML(xmlFile, configKey, customEnvironment) |
411 | |
412 | local desc = xmlFile:getValue(configKey.."#desc", nil, customEnvironment, false) |
413 | local price = xmlFile:getValue(configKey.."#price", 0) |
414 | local dailyUpkeep = xmlFile:getValue(configKey.."#dailyUpkeep", 0) |
415 | local isDefault = xmlFile:getValue(configKey.."#isDefault", false) |
416 | local isSelectable = xmlFile:getValue(configKey.."#isSelectable", true) |
417 | local saveId = xmlFile:getValue(configKey.."#saveId") |
418 | |
419 | local vehicleBrandName = xmlFile:getValue(configKey.."#vehicleBrand") |
420 | local vehicleBrand = g_brandManager:getBrandIndexByName(vehicleBrandName) |
421 | |
422 | local vehicleName = xmlFile:getValue(configKey.."#vehicleName") |
423 | local vehicleIcon = xmlFile:getValue(configKey.."#vehicleIcon") |
424 | if vehicleIcon ~= nil then |
425 | vehicleIcon = Utils.getFilename(vehicleIcon, baseDir) |
426 | end |
427 | |
428 | local brandName = xmlFile:getValue(configKey.."#displayBrand") |
429 | local brandIndex = g_brandManager:getBrandIndexByName(brandName) |
430 | |
431 | local configItem = StoreItemUtil.addConfigurationItem(configurationItems, configName, desc, price, dailyUpkeep, isDefault, overwrittenTitle, saveId, brandIndex, isSelectable, vehicleBrand, vehicleName, vehicleIcon) |
432 | |
433 | if saveId ~= nil then |
434 | if loadedSaveIds[saveId] == true then |
435 | Logging.xmlWarning(xmlFile, "Duplicated saveId '%s' in '%s' configurations", saveId, name) |
436 | else |
437 | loadedSaveIds[saveId] = true |
438 | end |
439 | end |
440 | |
441 | if configuration.singleItemLoadFunc ~= nil then |
442 | configuration.singleItemLoadFunc(xmlFile, configKey, baseDir, customEnvironment, isMod, configItem) |
443 | end |
444 | |
445 | StoreItemUtil.renameDuplicatedConfigurationNames(configurationItems, configItem) |
446 | |
447 | i = i + 1 |
448 | end |
449 | |
450 | if configuration.postLoadFunc ~= nil then |
451 | configuration.postLoadFunc(xmlFile, baseKey, baseDir, customEnvironment, isMod, configurationItems, storeItem) |
452 | end |
453 | |
454 | if #configurationItems > 0 then |
455 | defaultConfigurationIds[name] = StoreItemUtil.getDefaultConfigIdFromItems(configurationItems) |
456 | |
457 | configurations[name] = configurationItems |
458 | numConfigs = numConfigs + 1 |
459 | end |
460 | end |
461 | if numConfigs == 0 then |
462 | configurations = nil |
463 | defaultConfigurationIds = nil |
464 | end |
465 | |
466 | return configurations, defaultConfigurationIds |
467 | end |
getConfigurationsMatchConfigSets
DescriptionDefinitiongetConfigurationsMatchConfigSets()Code
615 | function StoreItemUtil.getConfigurationsMatchConfigSets(configurations, configSets) |
616 | for _, configSet in pairs(configSets) do |
617 | local isMatch = true |
618 | for configName, index in pairs(configSet.configurations) do |
619 | if configurations[configName] ~= index then |
620 | isMatch = false |
621 | break |
622 | end |
623 | end |
624 | |
625 | if isMatch then |
626 | return true |
627 | end |
628 | end |
629 | |
630 | return false |
631 | end |
getCosts
DescriptionGet the costs of storeitemDefinition
getCosts(table storeItem, table configurations, string costType)Arguments
table | storeItem | a storeitem object |
table | configurations | list of configurations |
string | costType | the cost type |
integer | cost | of the storeitem |
149 | function StoreItemUtil.getCosts(storeItem, configurations, costType) |
150 | if storeItem ~= nil then |
151 | local costs = storeItem[costType] |
152 | if costs == nil then |
153 | costs = 0 |
154 | end |
155 | if storeItem.configurations ~= nil then |
156 | for name, value in pairs(configurations) do |
157 | local nameConfig = storeItem.configurations[name] |
158 | if nameConfig ~= nil then |
159 | local valueConfig = nameConfig[value] |
160 | if valueConfig ~= nil then |
161 | local costTypeConfig = valueConfig[costType] |
162 | if costTypeConfig ~= nil then |
163 | costs = costs + tonumber(costTypeConfig) |
164 | end |
165 | end |
166 | end |
167 | end |
168 | end |
169 | return costs |
170 | end |
171 | return 0 |
172 | end |
getDailyUpkeep
DescriptionGet the daily upkeepDefinition
getDailyUpkeep(table storeItem, table configurations)Arguments
table | storeItem | a storeitem object |
table | configurations | list of configurations |
integer | the | daily upkeep |
139 | function StoreItemUtil.getDailyUpkeep(storeItem, configurations) |
140 | return StoreItemUtil.getCosts(storeItem, configurations, "dailyUpkeep") |
141 | end |
getDefaultConfigId
DescriptionGet the default config idDefinition
getDefaultConfigId(table storeItem, string configurationName)Arguments
table | storeItem | a storeitem object |
string | configurationName | name of the configuration |
integer | configId | the default config id |
96 | function StoreItemUtil.getDefaultConfigId(storeItem, configurationName) |
97 | return StoreItemUtil.getDefaultConfigIdFromItems(storeItem.configurations[configurationName]) |
98 | end |
getDefaultConfigIdFromItems
DescriptionGet the default config idDefinition
getDefaultConfigIdFromItems(table storeItem, string configurationName)Arguments
table | storeItem | a storeitem object |
string | configurationName | name of the configuration |
integer | configId | the default config id |
105 | function StoreItemUtil.getDefaultConfigIdFromItems(configItems) |
106 | if configItems ~= nil then |
107 | for k, item in pairs(configItems) do |
108 | if item.isDefault then |
109 | if item.isSelectable ~= false then |
110 | return k |
111 | end |
112 | end |
113 | end |
114 | |
115 | for k, item in pairs(configItems) do |
116 | if item.isSelectable ~= false then |
117 | return k |
118 | end |
119 | end |
120 | end |
121 | |
122 | return 1 |
123 | end |
getDefaultPrice
DescriptionGet the default priceDefinition
getDefaultPrice(table storeItem, table configurations)Arguments
table | storeItem | a storeitem object |
table | configurations | list of configurations |
integer | the | default price |
130 | function StoreItemUtil.getDefaultPrice(storeItem, configurations) |
131 | return StoreItemUtil.getCosts(storeItem, configurations, "price") |
132 | end |
getFilteredConfigurationIndex
DescriptionDefinitiongetFilteredConfigurationIndex()Code
587 | function StoreItemUtil.getFilteredConfigurationIndex(storeItem, configName, configIndex) |
588 | local subConfigurations = storeItem.subConfigurations[configName] |
589 | if subConfigurations ~= nil then |
590 | local subConfigValues = subConfigurations.subConfigValues |
591 | for _, identifier in ipairs(subConfigValues) do |
592 | local items = subConfigurations.subConfigItemMapping[identifier] |
593 | for k, item in ipairs(items) do |
594 | if item.index == configIndex then |
595 | return k |
596 | end |
597 | end |
598 | end |
599 | end |
600 | |
601 | return configIndex |
602 | end |
getFunctionsFromXML
DescriptionGets the storeitem functions from xmlDefinition
getFunctionsFromXML(integer xmlFile, string storeDataXMLName, string customEnvironment)Arguments
integer | xmlFile | the xml handle |
string | storeDataXMLName | name of the parent xml element |
string | customEnvironment | a custom environment |
table | functions | list of storeitem functions |
282 | function StoreItemUtil.getFunctionsFromXML(xmlFile, storeDataXMLName, customEnvironment) |
283 | local i=0 |
284 | local functions = {} |
285 | while true do |
286 | local functionKey = string.format(storeDataXMLName..".functions.function(%d)", i) |
287 | if not xmlFile:hasProperty(functionKey) then |
288 | break |
289 | end |
290 | local functionName = xmlFile:getValue(functionKey, nil, customEnvironment, true) |
291 | if functionName ~= nil then |
292 | table.insert(functions, functionName) |
293 | end |
294 | i = i + 1 |
295 | end |
296 | return functions |
297 | end |
getIsAnimal
DescriptionReturns if a store item is an animalDefinition
getIsAnimal(table storeItem)Arguments
table | storeItem | a storeitem object |
boolean | true | if storeitem is an animal, else false |
24 | function StoreItemUtil.getIsAnimal(storeItem) |
25 | return storeItem ~= nil and storeItem.species ~= nil and storeItem.species ~= "" and storeItem.species ~= "placeable" and storeItem.species ~= "object" and storeItem.species ~= "handTool" and storeItem.species ~= "vehicle" |
26 | end |
getIsConfigurable
DescriptionReturns if a store item is configurable. Checks if there are any configurations and also if any of the configurations has more than just one option.Definition
getIsConfigurable(table storeItem)Arguments
table | storeItem | a storeitem object |
boolean | true | if storeitem is configurable, else false |
57 | function StoreItemUtil.getIsConfigurable(storeItem) |
58 | local hasConfigurations = storeItem ~= nil and storeItem.configurations ~= nil |
59 | local hasMoreThanOneOption = false |
60 | if hasConfigurations then |
61 | for _, configItems in pairs(storeItem.configurations) do |
62 | local selectableItems = 0 |
63 | for i=1, #configItems do |
64 | if configItems[i].isSelectable ~= false then |
65 | selectableItems = selectableItems + 1 |
66 | |
67 | if selectableItems > 1 then |
68 | hasMoreThanOneOption = true |
69 | break |
70 | end |
71 | end |
72 | end |
73 | |
74 | if hasMoreThanOneOption then |
75 | break |
76 | end |
77 | end |
78 | end |
79 | |
80 | return hasConfigurations and hasMoreThanOneOption |
81 | end |
getIsHandTool
DescriptionReturns if a store item is a handtoolDefinition
getIsHandTool(table storeItem)Arguments
table | storeItem | a storeitem object |
boolean | true | if storeitem is a handtool, else false |
48 | function StoreItemUtil.getIsHandTool(storeItem) |
49 | return storeItem ~= nil and storeItem.species == "handTool" |
50 | end |
getIsLeasable
DescriptionReturns if a store item is leaseableDefinition
getIsLeasable(table storeItem)Arguments
table | storeItem | a storeitem object |
boolean | true | if storeitem is leaseable, else false |
87 | function StoreItemUtil.getIsLeasable(storeItem) |
88 | return storeItem ~= nil and storeItem.runningLeasingFactor ~= nil and not StoreItemUtil.getIsPlaceable(storeItem) |
89 | end |
getIsObject
DescriptionReturns if a store item is an objectDefinition
getIsObject(table storeItem)Arguments
table | storeItem | a storeitem object |
boolean | true | if storeitem is an object, else false |
40 | function StoreItemUtil.getIsObject(storeItem) |
41 | return storeItem ~= nil and storeItem.species == "object" |
42 | end |
getIsPlaceable
DescriptionReturns if a store item is a placeableDefinition
getIsPlaceable(table storeItem)Arguments
table | storeItem | a storeitem object |
boolean | true | if storeitem is a placeable, else false |
32 | function StoreItemUtil.getIsPlaceable(storeItem) |
33 | return storeItem ~= nil and storeItem.species == "placeable" |
34 | end |
getIsVehicle
DescriptionReturns if a store item is a vehicleDefinition
getIsVehicle(table storeItem)Arguments
table | storeItem | a storeitem object |
boolean | true | if storeitem is a vehicle, else false |
16 | function StoreItemUtil.getIsVehicle(storeItem) |
17 | return storeItem ~= nil and (storeItem.species == nil or storeItem.species == "" or storeItem.species == "vehicle") |
18 | end |
getSizeValues
DescriptionDefinitiongetSizeValues()Code
656 | function StoreItemUtil.getSizeValues(xmlFilename, baseName, rotationOffset, configurations) |
657 | local xmlFile = XMLFile.load("storeItemGetSizeXml", xmlFilename, Vehicle.xmlSchema) |
658 | local size = { |
659 | width = Vehicle.defaultWidth, |
660 | length = Vehicle.defaultLength, |
661 | height = Vehicle.defaultHeight, |
662 | widthOffset = 0, |
663 | lengthOffset = 0, |
664 | heightOffset = 0 |
665 | } |
666 | if xmlFile ~= nil then |
667 | size = StoreItemUtil.getSizeValuesFromXML(xmlFile, baseName, rotationOffset, configurations) |
668 | xmlFile:delete() |
669 | end |
670 | |
671 | return size |
672 | end |
getSizeValuesFromXML
DescriptionDefinitiongetSizeValuesFromXML()Code
676 | function StoreItemUtil.getSizeValuesFromXML(xmlFile, baseName, rotationOffset, configurations) |
677 | return StoreItemUtil.getSizeValuesFromXMLByKey(xmlFile, baseName, "base", "size", "size", rotationOffset, configurations, Vehicle.DEFAULT_SIZE) |
678 | end |
getSizeValuesFromXMLByKey
DescriptionDefinitiongetSizeValuesFromXMLByKey()Code
682 | function StoreItemUtil.getSizeValuesFromXMLByKey(xmlFile, baseName, baseKey, elementKey, configKey, rotationOffset, configurations, defaults) |
683 | local baseSizeKey = string.format("%s.%s.%s", baseName, baseKey, elementKey) |
684 | |
685 | local size = { |
686 | width = xmlFile:getValue(baseSizeKey .. "#width", defaults.width), |
687 | length = xmlFile:getValue(baseSizeKey .. "#length", defaults.length), |
688 | height = xmlFile:getValue(baseSizeKey .. "#height", defaults.height), |
689 | widthOffset = xmlFile:getValue(baseSizeKey .. "#widthOffset", defaults.widthOffset), |
690 | lengthOffset = xmlFile:getValue(baseSizeKey .. "#lengthOffset", defaults.lengthOffset), |
691 | heightOffset = xmlFile:getValue(baseSizeKey .. "#heightOffset", defaults.heightOffset) |
692 | } |
693 | |
694 | -- check configurations for changed size values |
695 | if configurations ~= nil then |
696 | for name, id in pairs(configurations) do |
697 | local specializationKey = g_configurationManager:getConfigurationAttribute(name, "xmlKey") |
698 | if specializationKey ~= nil then |
699 | specializationKey = "." .. specializationKey |
700 | else |
701 | specializationKey = "" |
702 | end |
703 | local key = string.format("%s%s.%sConfigurations.%sConfiguration(%d).%s", baseName, specializationKey, name, name , id - 1, configKey) |
704 | local tempWidth = xmlFile:getValue(key .. "#width") |
705 | local tempLength = xmlFile:getValue(key .. "#length") |
706 | local tempHeight = xmlFile:getValue(key .. "#height") |
707 | local tempWidthOffset = xmlFile:getValue(key .. "#widthOffset") |
708 | local tempLengthOffset = xmlFile:getValue(key .. "#lengthOffset") |
709 | local tempHeightOffset = xmlFile:getValue(key .. "#heightOffset") |
710 | |
711 | if tempWidth ~= nil then |
712 | size.width = math.max(size.width, tempWidth) |
713 | end |
714 | if tempLength ~= nil then |
715 | size.length = math.max(size.length, tempLength) |
716 | end |
717 | if tempHeight ~= nil then |
718 | size.height = math.max(size.height, tempHeight) |
719 | end |
720 | |
721 | if tempWidthOffset ~= nil then |
722 | if size.widthOffset < 0 then |
723 | size.widthOffset = math.min(size.widthOffset, tempWidthOffset) |
724 | else |
725 | size.widthOffset = math.max(size.widthOffset, tempWidthOffset) |
726 | end |
727 | end |
728 | if tempLengthOffset ~= nil then |
729 | if size.lengthOffset < 0 then |
730 | size.lengthOffset = math.min(size.lengthOffset, tempLengthOffset) |
731 | else |
732 | size.lengthOffset = math.max(size.lengthOffset, tempLengthOffset) |
733 | end |
734 | end |
735 | if tempHeightOffset ~= nil then |
736 | if size.heightOffset < 0 then |
737 | size.heightOffset = math.min(size.heightOffset, tempHeightOffset) |
738 | else |
739 | size.heightOffset = math.max(size.heightOffset, tempHeightOffset) |
740 | end |
741 | end |
742 | end |
743 | end |
744 | |
745 | -- limit rotation to 90 deg steps |
746 | rotationOffset = math.floor(rotationOffset / math.rad(90) + 0.5) * math.rad(90) |
747 | rotationOffset = rotationOffset % (2*math.pi) |
748 | if rotationOffset < 0 then |
749 | rotationOffset = rotationOffset + 2*math.pi |
750 | end |
751 | -- switch/invert width/length if rotated |
752 | local rotationIndex = math.floor(rotationOffset / math.rad(90) + 0.5) |
753 | if rotationIndex == 1 then -- 90 deg |
754 | size.width, size.length = size.length, size.width |
755 | size.widthOffset,size.lengthOffset = size.lengthOffset, -size.widthOffset |
756 | elseif rotationIndex == 2 then |
757 | size.widthOffset, size.lengthOffset = -size.widthOffset, -size.lengthOffset |
758 | elseif rotationIndex == 3 then -- 270 def |
759 | size.width, size.length = size.length, size.width |
760 | size.widthOffset, size.lengthOffset = -size.lengthOffset, size.widthOffset |
761 | end |
762 | |
763 | return size |
764 | end |
getSpecsFromXML
DescriptionGets the storeitem specs from xmlDefinition
getSpecsFromXML(table specTypes, integer xmlFile, string customEnvironment)Arguments
table | specTypes | list of spec types |
integer | xmlFile | the xml handle |
string | customEnvironment | a custom environment |
table | specs | list of storeitem specs |
323 | function StoreItemUtil.getSpecsFromXML(specTypes, species, xmlFile, customEnvironment, baseDirectory) |
324 | local specs = {} |
325 | for _, specType in pairs(specTypes) do |
326 | if specType.species == species then |
327 | if specType.loadFunc ~= nil then |
328 | specs[specType.name] = specType.loadFunc(xmlFile, customEnvironment, baseDirectory) |
329 | end |
330 | end |
331 | end |
332 | return specs |
333 | end |
getSubConfigurationIndex
DescriptionDefinitiongetSubConfigurationIndex()Code
569 | function StoreItemUtil.getSubConfigurationIndex(storeItem, configName, configIndex) |
570 | local subConfigurations = storeItem.subConfigurations[configName] |
571 | local subConfigValues = subConfigurations.subConfigValues |
572 | |
573 | for k, identifier in ipairs(subConfigValues) do |
574 | local items = subConfigurations.subConfigItemMapping[identifier] |
575 | for _, item in ipairs(items) do |
576 | if item.index == configIndex then |
577 | return k |
578 | end |
579 | end |
580 | end |
581 | |
582 | return nil |
583 | end |
getSubConfigurationItems
DescriptionDefinitiongetSubConfigurationItems()Code
606 | function StoreItemUtil.getSubConfigurationItems(storeItem, configName, state) |
607 | local subConfigurations = storeItem.subConfigurations[configName] |
608 | local subConfigValues = subConfigurations.subConfigValues |
609 | local identifier = subConfigValues[state] |
610 | return subConfigurations.subConfigItemMapping[identifier] |
611 | end |
getSubConfigurationsFromXML
DescriptionDefinitiongetSubConfigurationsFromXML()Code
542 | function StoreItemUtil.getSubConfigurationsFromXML(configurations) |
543 | local subConfigurations = nil |
544 | |
545 | if configurations ~= nil then |
546 | subConfigurations = {} |
547 | |
548 | for name, items in pairs(configurations) do |
549 | local config = g_configurationManager:getConfigurationDescByName(name) |
550 | if config.hasSubselection then |
551 | local subConfigValues = config.getSubConfigurationValuesFunc(items) |
552 | if #subConfigValues > 1 then |
553 | local subConfigItemMapping = {} |
554 | subConfigurations[name] = {subConfigValues=subConfigValues, subConfigItemMapping=subConfigItemMapping} |
555 | |
556 | for k, value in ipairs(subConfigValues) do |
557 | subConfigItemMapping[value] = config.getItemsBySubConfigurationIdentifierFunc(items, value) |
558 | end |
559 | end |
560 | end |
561 | end |
562 | end |
563 | |
564 | return subConfigurations |
565 | end |
getVRamUsageFromXML
DescriptionGets the storeitem vram usage from xmlDefinition
getVRamUsageFromXML(integer xmlFile, string storeDataXMLName)Arguments
integer | xmlFile | the xml handle |
string | storeDataXMLName | name of the parent xml element |
integer | sharedVramUsage | the shared vram usage |
integer | perInstanceVramUsage | the per instance vram usage |
boolean | ignoreVramUsage | true if vram usage should be ignored else false |
352 | function StoreItemUtil.getVRamUsageFromXML(xmlFile, storeDataXMLName) |
353 | local vertexBufferMemoryUsage = xmlFile:getValue(storeDataXMLName..".vertexBufferMemoryUsage", 0) |
354 | local indexBufferMemoryUsage = xmlFile:getValue(storeDataXMLName..".indexBufferMemoryUsage", 0) |
355 | local textureMemoryUsage = xmlFile:getValue(storeDataXMLName..".textureMemoryUsage", 0) |
356 | local instanceVertexBufferMemoryUsage = xmlFile:getValue(storeDataXMLName..".instanceVertexBufferMemoryUsage", 0) |
357 | local instanceIndexBufferMemoryUsage = xmlFile:getValue(storeDataXMLName..".instanceIndexBufferMemoryUsage", 0) |
358 | local ignoreVramUsage = xmlFile:getValue(storeDataXMLName..".ignoreVramUsage", false) |
359 | |
360 | local perInstanceVramUsage = instanceVertexBufferMemoryUsage + instanceIndexBufferMemoryUsage |
361 | local sharedVramUsage = vertexBufferMemoryUsage + indexBufferMemoryUsage + textureMemoryUsage |
362 | |
363 | return sharedVramUsage, perInstanceVramUsage, ignoreVramUsage |
364 | end |
loadSpecsFromXML
DescriptionLoads the storeitem specs values from xml into the item is only run if specs were not loaded before alreadyDefinition
loadSpecsFromXML()Code
302 | function StoreItemUtil.loadSpecsFromXML(item) |
303 | if item.specs == nil then |
304 | local storeItemXmlFile = XMLFile.load("storeItemXML", item.xmlFilename, item.xmlSchema) |
305 | item.specs = StoreItemUtil.getSpecsFromXML(g_storeManager:getSpecTypes(), item.species, storeItemXmlFile, item.customEnvironment, item.baseDir) |
306 | storeItemXmlFile:delete() |
307 | end |
308 | |
309 | if item.bundleInfo ~= nil then |
310 | local bundleItems = item.bundleInfo.bundleItems |
311 | for i=1, #bundleItems do |
312 | StoreItemUtil.loadSpecsFromXML(bundleItems[i].item) |
313 | end |
314 | end |
315 | end |
registerConfigurationSetXMLPaths
DescriptionRegister configuration set pathsDefinition
registerConfigurationSetXMLPaths()Code
769 | function StoreItemUtil.registerConfigurationSetXMLPaths(schema, baseKey) |
770 | baseKey = baseKey .. ".configurationSets" |
771 | schema:register(XMLValueType.L10N_STRING, baseKey .. "#title", "Title to display in config screen") |
772 | |
773 | local setKey = baseKey .. ".configurationSet(?)" |
774 | schema:register(XMLValueType.L10N_STRING, setKey .. "#name", "Set name") |
775 | schema:register(XMLValueType.STRING, setKey .. "#params", "Parameters to insert into name") |
776 | schema:register(XMLValueType.BOOL, setKey .. "#isDefault", "Is default set") |
777 | schema:register(XMLValueType.STRING, setKey .. ".configuration(?)#name", "Configuration name") |
778 | schema:register(XMLValueType.INT, setKey .. ".configuration(?)#index", "Selected index") |
779 | end |
renameDuplicatedConfigurationNames
DescriptionAdds a '(index)' at the back of the name if it's duplicatedDefinition
renameDuplicatedConfigurationNames(table configurationItems, table configItem)Arguments
table | configurationItems | a list of configurationItems |
table | configItem | config item table |
table | config | object |
212 | function StoreItemUtil.renameDuplicatedConfigurationNames(configurationItems, configItem) |
213 | local name = configItem.name |
214 | if name ~= nil then |
215 | local duplicateFound = true |
216 | local nameIndex = 2 |
217 | while duplicateFound do |
218 | duplicateFound = false |
219 | for i=1, #configurationItems do |
220 | if configurationItems[i] ~= configItem then |
221 | if configurationItems[i].name == name then |
222 | local ignore = false |
223 | for j=1, #configItem.nameCompareParams do |
224 | if configurationItems[i][configItem.nameCompareParams[j]] ~= configItem[configItem.nameCompareParams[j]] then |
225 | ignore = true |
226 | end |
227 | end |
228 | |
229 | if not ignore then |
230 | duplicateFound = true |
231 | end |
232 | end |
233 | end |
234 | end |
235 | |
236 | if duplicateFound then |
237 | name = string.format("%s (%d)", configItem.name, nameIndex) |
238 | nameIndex = nameIndex + 1 |
239 | end |
240 | end |
241 | |
242 | configItem.name = name |
243 | end |
244 | end |