LUADOC - Farming Simulator 22

StoreItemUtil

Description
Util for interacting with store items
Functions

addConfigurationItem

Description
Adds a configuration item to the given list
Definition
addConfigurationItem(table configurationItems, string name, string desc, float price, integer dailyUpkeep)
Arguments
tableconfigurationItemsa list of configurationItems
stringnamename of the configuration
stringdescdesc of the configuration
floatpriceprice of the configuration
integerdailyUpkeepdailyUpkeep of the configuration
Return Values
tableconfigobject
Code
254function 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
274end

getBrandIndexFromXML

Description
Gets the storeitem brand index from xml
Definition
getBrandIndexFromXML(integer xmlFile, string storeDataXMLKey)
Arguments
integerxmlFilethe xml handle
stringstoreDataXMLKeypath of the parent xml element
Return Values
integerbrandIndexthe brandindex
Code
340function StoreItemUtil.getBrandIndexFromXML(xmlFile, storeDataXMLKey)
341 local brandName = xmlFile:getValue(storeDataXMLKey..".brand", "")
342 return g_brandManager:getBrandIndexByName(brandName)
343end

getClosestConfigurationSet

Description
Definition
getClosestConfigurationSet()
Code
635function 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
652end

getConfigurationSetsFromXML

Description
Gets predefined configuration sets
Definition
getConfigurationSetsFromXML(table storeItem, integer xmlFile, string key, string baseDir, string customEnvironment, boolean isMod)
Arguments
tablestoreItema storeItem
integerxmlFilethe xml handle
stringkeythe key of the base xml element
stringbaseDirthe base directory
stringcustomEnvironmenta custom environment
booleanisModtrue if the storeitem is a mod, else false
Return Values
tableconfigurationsets
Code
478function 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
538end

getConfigurationsFromXML

Description
Gets the storeitem configurations from xml
Definition
getConfigurationsFromXML(integer xmlFile, string key, string baseDir, string customEnvironment, boolean isMod)
Arguments
integerxmlFilethe xml handle
stringkeythe name of the base xml element
stringbaseDirthe base directory
stringcustomEnvironmenta custom environment
booleanisModtrue if the storeitem is a mod, else false
Return Values
tableconfigurationsa list of configurations
Code
374function 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
467end

getConfigurationsMatchConfigSets

Description
Definition
getConfigurationsMatchConfigSets()
Code
615function 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
631end

getCosts

Description
Get the costs of storeitem
Definition
getCosts(table storeItem, table configurations, string costType)
Arguments
tablestoreItema storeitem object
tableconfigurationslist of configurations
stringcostTypethe cost type
Return Values
integercostof the storeitem
Code
149function 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
172end

getDailyUpkeep

Description
Get the daily upkeep
Definition
getDailyUpkeep(table storeItem, table configurations)
Arguments
tablestoreItema storeitem object
tableconfigurationslist of configurations
Return Values
integerthedaily upkeep
Code
139function StoreItemUtil.getDailyUpkeep(storeItem, configurations)
140 return StoreItemUtil.getCosts(storeItem, configurations, "dailyUpkeep")
141end

getDefaultConfigId

Description
Get the default config id
Definition
getDefaultConfigId(table storeItem, string configurationName)
Arguments
tablestoreItema storeitem object
stringconfigurationNamename of the configuration
Return Values
integerconfigIdthe default config id
Code
96function StoreItemUtil.getDefaultConfigId(storeItem, configurationName)
97 return StoreItemUtil.getDefaultConfigIdFromItems(storeItem.configurations[configurationName])
98end

getDefaultConfigIdFromItems

Description
Get the default config id
Definition
getDefaultConfigIdFromItems(table storeItem, string configurationName)
Arguments
tablestoreItema storeitem object
stringconfigurationNamename of the configuration
Return Values
integerconfigIdthe default config id
Code
105function 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
123end

getDefaultPrice

Description
Get the default price
Definition
getDefaultPrice(table storeItem, table configurations)
Arguments
tablestoreItema storeitem object
tableconfigurationslist of configurations
Return Values
integerthedefault price
Code
130function StoreItemUtil.getDefaultPrice(storeItem, configurations)
131 return StoreItemUtil.getCosts(storeItem, configurations, "price")
132end

getFilteredConfigurationIndex

Description
Definition
getFilteredConfigurationIndex()
Code
587function 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
602end

getFunctionsFromXML

Description
Gets the storeitem functions from xml
Definition
getFunctionsFromXML(integer xmlFile, string storeDataXMLName, string customEnvironment)
Arguments
integerxmlFilethe xml handle
stringstoreDataXMLNamename of the parent xml element
stringcustomEnvironmenta custom environment
Return Values
tablefunctionslist of storeitem functions
Code
282function 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
297end

getIsAnimal

Description
Returns if a store item is an animal
Definition
getIsAnimal(table storeItem)
Arguments
tablestoreItema storeitem object
Return Values
booleantrueif storeitem is an animal, else false
Code
24function 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"
26end

getIsConfigurable

Description
Returns 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
tablestoreItema storeitem object
Return Values
booleantrueif storeitem is configurable, else false
Code
57function 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
81end

getIsHandTool

Description
Returns if a store item is a handtool
Definition
getIsHandTool(table storeItem)
Arguments
tablestoreItema storeitem object
Return Values
booleantrueif storeitem is a handtool, else false
Code
48function StoreItemUtil.getIsHandTool(storeItem)
49 return storeItem ~= nil and storeItem.species == "handTool"
50end

getIsLeasable

Description
Returns if a store item is leaseable
Definition
getIsLeasable(table storeItem)
Arguments
tablestoreItema storeitem object
Return Values
booleantrueif storeitem is leaseable, else false
Code
87function StoreItemUtil.getIsLeasable(storeItem)
88 return storeItem ~= nil and storeItem.runningLeasingFactor ~= nil and not StoreItemUtil.getIsPlaceable(storeItem)
89end

getIsObject

Description
Returns if a store item is an object
Definition
getIsObject(table storeItem)
Arguments
tablestoreItema storeitem object
Return Values
booleantrueif storeitem is an object, else false
Code
40function StoreItemUtil.getIsObject(storeItem)
41 return storeItem ~= nil and storeItem.species == "object"
42end

getIsPlaceable

Description
Returns if a store item is a placeable
Definition
getIsPlaceable(table storeItem)
Arguments
tablestoreItema storeitem object
Return Values
booleantrueif storeitem is a placeable, else false
Code
32function StoreItemUtil.getIsPlaceable(storeItem)
33 return storeItem ~= nil and storeItem.species == "placeable"
34end

getIsVehicle

Description
Returns if a store item is a vehicle
Definition
getIsVehicle(table storeItem)
Arguments
tablestoreItema storeitem object
Return Values
booleantrueif storeitem is a vehicle, else false
Code
16function StoreItemUtil.getIsVehicle(storeItem)
17 return storeItem ~= nil and (storeItem.species == nil or storeItem.species == "" or storeItem.species == "vehicle")
18end

getSizeValues

Description
Definition
getSizeValues()
Code
656function 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
672end

getSizeValuesFromXML

Description
Definition
getSizeValuesFromXML()
Code
676function StoreItemUtil.getSizeValuesFromXML(xmlFile, baseName, rotationOffset, configurations)
677 return StoreItemUtil.getSizeValuesFromXMLByKey(xmlFile, baseName, "base", "size", "size", rotationOffset, configurations, Vehicle.DEFAULT_SIZE)
678end

getSizeValuesFromXMLByKey

Description
Definition
getSizeValuesFromXMLByKey()
Code
682function 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
764end

getSpecsFromXML

Description
Gets the storeitem specs from xml
Definition
getSpecsFromXML(table specTypes, integer xmlFile, string customEnvironment)
Arguments
tablespecTypeslist of spec types
integerxmlFilethe xml handle
stringcustomEnvironmenta custom environment
Return Values
tablespecslist of storeitem specs
Code
323function 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
333end

getSubConfigurationIndex

Description
Definition
getSubConfigurationIndex()
Code
569function 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
583end

getSubConfigurationItems

Description
Definition
getSubConfigurationItems()
Code
606function 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]
611end

getSubConfigurationsFromXML

Description
Definition
getSubConfigurationsFromXML()
Code
542function 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
565end

getVRamUsageFromXML

Description
Gets the storeitem vram usage from xml
Definition
getVRamUsageFromXML(integer xmlFile, string storeDataXMLName)
Arguments
integerxmlFilethe xml handle
stringstoreDataXMLNamename of the parent xml element
Return Values
integersharedVramUsagethe shared vram usage
integerperInstanceVramUsagethe per instance vram usage
booleanignoreVramUsagetrue if vram usage should be ignored else false
Code
352function 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
364end

loadSpecsFromXML

Description
Loads the storeitem specs values from xml into the item is only run if specs were not loaded before already
Definition
loadSpecsFromXML()
Code
302function 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
315end

registerConfigurationSetXMLPaths

Description
Register configuration set paths
Definition
registerConfigurationSetXMLPaths()
Code
769function 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")
779end

renameDuplicatedConfigurationNames

Description
Adds a '(index)' at the back of the name if it's duplicated
Definition
renameDuplicatedConfigurationNames(table configurationItems, table configItem)
Arguments
tableconfigurationItemsa list of configurationItems
tableconfigItemconfig item table
Return Values
tableconfigobject
Code
212function 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
244end