LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

GuiProfile

Description
GUI element display profile. Holds GuiElement property data for re-use similar to a HTML/CSS definition.
Functions

getBool

Description
Get a boolean value from this profile (and its ancestors) by name.
Definition
getBool(name Name, default Default)
Arguments
nameNameof attribute value to retrieve
defaultDefaultvalue to use if the attribute is not defined.
Code
131function GuiProfile:getBool(name, default)
132 local value = self:getValue(name)
133 local ret = default
134 if value ~= nil and value ~= "nil" then
135 ret = (value:lower() == "true")
136 end
137
138 return ret
139end

getNumber

Description
Get a number value from this profile (and its ancestors) by name.
Definition
getNumber(name Name, default Default)
Arguments
nameNameof attribute value to retrieve
defaultDefaultvalue to use if the attribute is not defined.
Code
145function GuiProfile:getNumber(name, default)
146 local value = self:getValue(name)
147 local ret = default
148 if value ~= nil and value ~= "nil" then
149 ret = tonumber(value)
150 end
151
152 return ret
153end

getValue

Description
Get a string value from this profile (and its ancestors) by name.
Definition
getValue(name Name, default Default)
Arguments
nameNameof attribute value to retrieve
defaultDefaultvalue to use if the attribute is not defined.
Code
100function GuiProfile:getValue(name, default)
101 local ret = default
102
103 -- Try a special case
104 if self.values[name .. g_baseUIPostfix] ~= nil and self.values[name .. g_baseUIPostfix] ~= "nil" then
105 ret = self.values[name .. g_baseUIPostfix]
106
107 -- Try definition in the profile
108 elseif self.values[name] ~= nil and self.values[name] ~= "nil" then
109 ret = self.values[name]
110
111 -- Try the profile itself
112 else
113 if self.parent ~= nil then
114 if self.profiles[self.parent] ~= nil then
115 if self.profiles[self.parent] ~= "nil" then
116 ret = self.profiles[self.parent]:getValue(name, default)
117 end
118 else
119 print("Warning: Parent-profile '" .. self.parent .. "' not found for profile '" .. self.name .. "'")
120 end
121 end
122 end
123
124 return ret
125end

loadFromXML

Description
Load profile data from XML.
Definition
loadFromXML(xmlFile XML, key Profile, presets Table, isTrait Whether)
Arguments
xmlFileXMLfile handle
keyProfileXML element node path
presetsTableof presets for symbol resolution, {preset name=preset value}
isTraitWhetherthis profile is a trait
Return Values
Trueifprofile values could be loaded, false otherwise.
Code
38function GuiProfile:loadFromXML(xmlFile, key, presets, isTrait)
39 local name = getXMLString(xmlFile, key .. "#name")
40 if name == nil then
41 return false
42 end
43
44 self.name = name
45 self.isTrait = isTrait or false
46 self.parent = getXMLString(xmlFile, key .. "#extends")
47
48 -- If this is not a trait, resolve traits
49 if not isTrait then
50 local traits = getXMLString(xmlFile, key .. "#with")
51 if traits ~= nil then
52 local traitNames = StringUtil.splitString(" ", traits)
53
54 -- Copy all values, overwriting previous ones.
55 -- This is resolving of the traits.
56 for i = #traitNames, 1, -1 do
57 local traitName = traitNames[i]
58 local trait = self.traits[traitName]
59
60 if trait ~= nil then
61 for name, value in pairs(trait.values) do
62 self.values[name] = value
63 end
64 else
65 print("Warning: Trait-profile '" .. traitName .. "' not found for trait '" .. self.name .. "'")
66 end
67 end
68 end
69 end
70
71 local i = 0
72 while true do
73 local k = key .. ".Value(" .. i .. ")"
74 local name = getXMLString(xmlFile, k .. "#name")
75 local value = getXMLString(xmlFile, k .. "#value")
76 if name == nil or value == nil then
77 break
78 end
79
80 if StringUtil.startsWith(value, "$preset_") then
81 local preset = string.gsub(value, "$preset_", "")
82 if presets[preset] ~= nil then
83 value = presets[preset]
84 else
85 print("Warning: Preset '" .. preset .. "' is not defined in GuiProfile!")
86 end
87 end
88
89 self.values[name] = value
90 i = i + 1
91 end
92
93 return true
94end

new

Description
Create a new GuiProfile.
Definition
new(profiles Reference, traits Reference)
Arguments
profilesReferenceto loaded profiles table for inheritance checking.
traitsReferenceto loaded traits table for inheritance checking.
Return Values
NewGuiProfileinstance
Code
19function GuiProfile:new(profiles, traits)
20 local self = setmetatable({}, GuiProfile_mt)
21
22 self.values = {}
23 self.name = ""
24 self.profiles = profiles
25 self.traits = traits
26 self.parent = nil
27
28 return self
29end