1 -- main tables of environement & general editor functions
7 ------------------------------------------------------------------------------------------------------------
8 -- Helper : eval a property in an instance of a class :
9 -- if the property is a value, then that value is returned
10 -- if the property is a function, then the 'this' parameter is passed to the function and the result is returned
11 -- if the property is nil, then the defualt value is returned
12 function r2
:evalProp(prop
, this
, defaultValue
)
13 if type(prop
) == "function" then return prop(this
) -- could have been this:prop(), too...
14 elseif prop
~= nil then return prop
15 else return defaultValue
19 -------------------------------------------------------------------------------------
20 -- get translation id for a property, followed by a boolean (false if not found)
21 function r2
:getPropertyTranslationId(prop
)
24 if prop
.Translation
~= nil then
25 translationId
= prop
.Translation
26 elseif i18n
.hasTranslation('uiR2EDProp_' .. prop
.Name
) then
27 translationId
= 'uiR2EDProp_' .. prop
.Name
28 elseif i18n
.hasTranslation('uiR2ED' .. prop
.Name
) then
29 translationId
= 'uiR2ED' .. prop
.Name
31 translationId
= prop
.Name
34 return translationId
, found
37 -------------------------------------------------------------------------------------
38 -- get translation id for a property, as an ucstring
39 function r2
:getPropertyTranslation(prop
)
40 local translationId
= r2
:getPropertyTranslationId(prop
)
41 if (i18n
.hasTranslation(translationId
)) then
42 return i18n
.get(translationId
)
44 return ucstring(translationId
)
49 ------------------------------------------------------------------------------------------------------------
50 -- return the left quota for the current scenario (called by C++)
51 function r2
:getLeftQuota()
52 return r2
.ScenarioWindow
:getLeftQuota()
56 ------------------------------------------------------------------------------------------------------------
57 -- retrieve class description of an instance (in the r2.Classes table)
58 function r2
:getClass(instance
)
59 if instance
== nil or instance
.isNil
then
60 debugInfo("Calling r2:getClass on nil instance")
61 debugInfo(debug
.traceback())
64 if instance
.Class
== nil then
65 debugInfo("Calling r2:getClass on class with no 'Class' field")
66 debugInfo(debug
.traceback())
69 return r2
.Classes
[instance
.Class
]
72 ------------------------------------------------------------------------------------------------------------
73 -- get parent instance of an object in the editor (that is an object with an InstanceId)
74 function r2
:getParentInstance(object
)
75 debugInfo(debug
.traceback())
76 assert(nil) -- deprecated : use special member 'ParentInstance' instead
77 --if object == nil then return nil end
78 --local parent = object.Parent
79 --while parent ~= nil do
80 -- if parent.InstanceId ~= nil then
83 -- parent = parent.Parent
88 ------------------------------------------------------------------------------------------------------------
89 -- get max number of acts in a scenario
90 function r2
:getMaxNumberOfAdditionnalActs()
91 return getDefine("r2ed_max_num_additionnal_acts")
94 ------------------------------------------------------------------------------------------------------------
95 -- Explore a tree of instance, each instance that has a sheet id is append to the list
96 function r2
:exploreInstanceTree(obj
, destTable
)
97 if obj
.InstanceId
~= nil then
98 table.insert(destTable
, obj
)
100 for k
, v
in specPairs(obj
) do
101 if type(v
) == "userdata" and v
.Size
~= nil then
102 -- this is a sub array
103 r2
:exploreInstanceTree(v
, destTable
)
109 -- test from a sheet id if an object is a bot object
110 function r2
:isBotObject(sheetClient
)
111 return getCharacterSheetSkel(sheetClient
, false) == ""
112 or string.match(sheetClient
, "object_[%w_]*%.creature") -- patch for bot objects (with skeletons -> wind turbine)
115 -- helper function for pasting : relocate the 'Position' field of 'dest' for proper pasting
116 function r2
:relocatePos(dest
)
117 local x
, y
, z
= r2
:findEmptyPlace(dest
.Position
.x
, dest
.Position
.y
)
125 -- Get a new position were to paste an object
126 function r2
:getPastePosition()
127 local x
, y
, z
= r2
:getUserEntityPosition()
128 local fx
, fy
= r2
:getUserEntityFront()
131 x
= x
+ 3 * math
.random(-100, 100) / 100
132 y
= y
+ 3 * math
.random(-100, 100) / 100
133 local nx
, ny
= r2
:findEmptyPlace(x
, y
)
137 return r2
:getUserEntityPosition() -- no empty place found, paste on user
142 ------------------------------------------------------------------------------------------------------------------
147 --debugInfo("Initializing main tables")
149 r2
= {} -- for vianney's tests (is initialized by the caller otherwise)
156 r2
.ScratchUCStr
= ucstring() -- scratch ucstring, useful to do call from utf8 without to create a new object
158 ---------------------
159 -- EDITION GLOBALS --
160 ---------------------
164 -- define in r2_features.lua
167 -- define in r2_basic_bricks.lua
170 -- define in r2_palette.lua
173 -- definition of all R2 classes (contains both basic components and components of features)
176 -- current content of the clipboard after the selection has been copied
178 r2
.ClipBoardSrcInstanceId
= nil
179 r2
.ClipBoardDisplayName
= nil
182 -----------------------
183 -- ANIMATION GLOBALS --
184 -----------------------
186 -- contains var related to animation
189 Acts
= nil, -- set to nil until received by server, contains
190 -- the list of acts accessible at runtime by the animator
191 UserTriggers
= nil, -- set to nil until received by server, contains
192 -- the list of triggers that an animator can fire at runtime
194 -------------------------------------------------------------------------------------
195 reset
= function(this
)
197 this
.UserTriggers
= nil