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
- 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
BrandManager
DescriptionThis class handles all registered brandsParent
AbstractManagerFunctions
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 |
75 | function BrandManager:addBrand(name, title, imageFilename, baseDir, isMod, imageShopOverview) |
76 | if name == nil or name == "" then |
77 | print("Warning: Could not register brand. Name is missing or empty!") |
78 | return false |
79 | end |
80 | if title == nil or title == "" then |
81 | print("Warning: Could not register brand. Title is missing or empty!") |
82 | return false |
83 | end |
84 | if imageFilename == nil or imageFilename == "" then |
85 | print("Warning: Could not register brand. Image is missing or empty!") |
86 | return false |
87 | end |
88 | if baseDir == nil then |
89 | print("Warning: Could not register brand. Basedirectory not defined!") |
90 | return false |
91 | end |
92 | if imageShopOverview == nil then |
93 | -- use default image if no specific shop overview icon is available |
94 | imageShopOverview = imageFilename |
95 | end |
96 | |
97 | name = name:upper() |
98 | |
99 | if ClassUtil.getIsValidIndexName(name) then |
100 | if self.nameToIndex[name] == nil then |
101 | self.numOfBrands = self.numOfBrands + 1 |
102 | self.nameToIndex[name] = self.numOfBrands |
103 | |
104 | local brand = {} |
105 | brand.index = self.numOfBrands |
106 | brand.name = name |
107 | brand.image = Utils.getFilename(imageFilename, baseDir) |
108 | brand.imageShopOverview = Utils.getFilename(imageShopOverview, baseDir) |
109 | brand.title = title |
110 | brand.isMod = isMod |
111 | |
112 | self.nameToBrand[name] = brand |
113 | self.indexToBrand[self.numOfBrands] = brand |
114 | |
115 | return brand |
116 | end |
117 | else |
118 | print("Warning: invalid brand name '" .. tostring(name) .. "'! Only capital letters allowed!") |
119 | end |
120 | end |
getBrandByIndex
DescriptionGets brand by indexDefinition
getBrandByIndex(integer brandIndex)Arguments
integer | brandIndex | brand index |
table | brand | the brand object |
126 | function BrandManager:getBrandByIndex(brandIndex) |
127 | if brandIndex ~= nil then |
128 | return self.indexToBrand[brandIndex] |
129 | end |
130 | return nil |
131 | end |
getBrandByName
DescriptionGets brand by nameDefinition
getBrandByName(string brandName)Arguments
string | brandName | brand name |
table | brand | the brand object |
137 | function BrandManager:getBrandByName(brandName) |
138 | if brandName ~= nil then |
139 | return self.nameToBrand[brandName:upper()] |
140 | end |
141 | return nil |
142 | end |
getBrandIndexByName
DescriptionGets brand index by nameDefinition
getBrandIndexByName(string brandName)Arguments
string | brandName | brand name |
integer | brandIndex | the brand index |
148 | function BrandManager:getBrandIndexByName(brandName) |
149 | if brandName ~= nil then |
150 | return self.nameToIndex[brandName:upper()] |
151 | end |
152 | return nil |
153 | 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 | |
54 | if title ~= nil and title:sub(1, 6) == "$l10n_" then |
55 | title = g_i18n:getText(title:sub(7)) |
56 | end |
57 | self:addBrand(name, title, image, "", false, imageShopOverview) |
58 | |
59 | i = i + 1 |
60 | end |
61 | delete(xmlFile) |
62 | |
63 | return true |
64 | 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 |