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
BrandManager
DescriptionThis class handles all registered brandsParent
AbstractManagerFunctions
- addBrand
- getBrandByIndex
- getBrandByName
- getBrandIconByIndex
- getBrandIndexByName
- initDataStructures
- loadMapData
- new
addBrand
DescriptionAdds a new bandDefinition
addBrand(string name, string title, string imageFilename, string baseDir, boolean isMod, string imageShopOverview)Arguments
string | name | the mapping name .e.g "HORSCH" for accessing a brand using the Brand.HORSCH enumeration |
string | title | the displayed name of the brand in ui |
string | imageFilename | the brand icon |
string | baseDir | the image filename base directory |
boolean | isMod | is a mod brand |
string | imageShopOverview | the brand icon for shop overview |
table | the | brand object or nil of an error occured |
77 | function BrandManager:addBrand(name, title, imageFilename, baseDir, isMod, imageShopOverview, imageOffset) |
78 | if name == nil or name == "" then |
79 | Logging.warning("Could not register brand. Name is missing or empty!") |
80 | return false |
81 | end |
82 | if title == nil or title == "" then |
83 | Logging.warning("Could not register brand '%s'. Title is missing or empty!", name) |
84 | return false |
85 | end |
86 | if imageFilename == nil or imageFilename == "" then |
87 | Logging.warning("Could not register brand '%s'. Image is missing or empty!", name) |
88 | return false |
89 | --#debug else |
90 | --#debug local fullFilename = Utils.getFilename(imageFilename, baseDir) |
91 | --#debug if not fileExists(fullFilename) and not fileExists(fullFilename:gsub(".png", ".dds")) then |
92 | --#debug Logging.devWarning("Defined image file for brand '%s' not found! (%s)", name, fullFilename) |
93 | --#debug end |
94 | end |
95 | if baseDir == nil then |
96 | Logging.warning("Could not register brand '%s'. Base directory not defined!", name) |
97 | return false |
98 | end |
99 | if imageShopOverview == nil then |
100 | -- use default image if no specific shop overview icon is available |
101 | imageShopOverview = imageFilename |
102 | --#debug else |
103 | --#debug local fullFilename = Utils.getFilename(imageShopOverview, baseDir) |
104 | --#debug if not fileExists(fullFilename) and not fileExists(fullFilename:gsub(".png", ".dds")) then |
105 | --#debug Logging.devWarning("Defined shop overview image file for brand '%s' not found! (%s)", name, fullFilename) |
106 | --#debug end |
107 | end |
108 | |
109 | name = name:upper() |
110 | |
111 | if ClassUtil.getIsValidIndexName(name) then |
112 | if self.nameToIndex[name] == nil then |
113 | self.numOfBrands = self.numOfBrands + 1 |
114 | self.nameToIndex[name] = self.numOfBrands |
115 | |
116 | local brand = {} |
117 | brand.index = self.numOfBrands |
118 | brand.name = name |
119 | brand.image = Utils.getFilename(imageFilename, baseDir) |
120 | brand.imageShopOverview = Utils.getFilename(imageShopOverview, baseDir) |
121 | brand.title = title |
122 | brand.isMod = isMod |
123 | brand.imageOffset = imageOffset or 0 |
124 | |
125 | self.nameToBrand[name] = brand |
126 | self.indexToBrand[self.numOfBrands] = brand |
127 | |
128 | return brand |
129 | end |
130 | else |
131 | Logging.warning("Invalid brand name '" .. tostring(name) .. "'! Only capital letters allowed!") |
132 | end |
133 | end |
getBrandByIndex
DescriptionGets brand by indexDefinition
getBrandByIndex(integer brandIndex)Arguments
integer | brandIndex | brand index |
table | brand | the brand object |
139 | function BrandManager:getBrandByIndex(brandIndex) |
140 | if brandIndex ~= nil then |
141 | return self.indexToBrand[brandIndex] |
142 | end |
143 | return nil |
144 | end |
getBrandByName
DescriptionGets brand by nameDefinition
getBrandByName(string brandName)Arguments
string | brandName | brand name |
table | brand | the brand object |
161 | function BrandManager:getBrandByName(brandName) |
162 | if brandName ~= nil then |
163 | return self.nameToBrand[brandName:upper()] |
164 | end |
165 | return nil |
166 | end |
getBrandIconByIndex
DescriptionGets brand icon by indexDefinition
getBrandIconByIndex(integer brandIndex)Arguments
integer | brandIndex | brand index |
string | path | path to brand icon |
150 | function BrandManager:getBrandIconByIndex(brandIndex) |
151 | if brandIndex ~= nil and self.indexToBrand[brandIndex] ~= nil then |
152 | return self.indexToBrand[brandIndex].image |
153 | end |
154 | return nil |
155 | end |
getBrandIndexByName
DescriptionGets brand index by nameDefinition
getBrandIndexByName(string brandName)Arguments
string | brandName | brand name |
integer | brandIndex | the brand index |
172 | function BrandManager:getBrandIndexByName(brandName) |
173 | if brandName ~= nil then |
174 | if ClassUtil.getIsValidIndexName(brandName) then |
175 | local brandIndex = self.nameToIndex[brandName:upper()] |
176 | if brandIndex == nil then |
177 | Logging.warning(brandName.."' is an unknown brand! Using Lizard instead!") |
178 | return Brand.LIZARD |
179 | end |
180 | |
181 | return brandIndex |
182 | else |
183 | Logging.warning("Invalid brand name '" .. brandName .. "'! Only capital letters and underscores allowed. Using Lizard instead.") |
184 | return Brand.LIZARD |
185 | end |
186 | end |
187 | |
188 | return nil |
189 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
25 | function BrandManager:initDataStructures() |
26 | self.numOfBrands = 0 |
27 | self.nameToIndex = {} |
28 | self.nameToBrand = {} |
29 | self.indexToBrand = {} |
30 | |
31 | Brand = self.nameToIndex |
32 | end |
loadMapData
DescriptionLoad data on map loadDefinition
loadMapData()Return Values
boolean | true | if loading was successful else false |
37 | function BrandManager:loadMapData(missionInfo) |
38 | BrandManager:superClass().loadMapData(self) |
39 | |
40 | local xmlFile = loadXMLFile("brandsXML", "dataS/brands.xml") |
41 | |
42 | local i = 0 |
43 | while true do |
44 | local baseXMLName = string.format("brands.brand(%d)", i) |
45 | |
46 | if not hasXMLProperty(xmlFile, baseXMLName) then |
47 | break |
48 | end |
49 | local name = getXMLString(xmlFile, baseXMLName .. "#name") |
50 | local title = getXMLString(xmlFile, baseXMLName .. "#title") |
51 | local image = getXMLString(xmlFile, baseXMLName .. "#image") |
52 | local imageShopOverview = getXMLString(xmlFile, baseXMLName .. "#imageShopOverview") |
53 | local imageOffset = getXMLFloat(xmlFile, baseXMLName .. "#imageOffset") |
54 | |
55 | if title ~= nil and title:sub(1, 6) == "$l10n_" then |
56 | title = g_i18n:getText(title:sub(7)) |
57 | end |
58 | self:addBrand(name, title, image, "", false, imageShopOverview, imageOffset) |
59 | |
60 | i = i + 1 |
61 | end |
62 | |
63 | delete(xmlFile) |
64 | |
65 | return true |
66 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
17 | function BrandManager.new(customMt) |
18 | local self = AbstractManager.new(customMt or BrandManager_mt) |
19 | |
20 | return self |
21 | end |