editor_util_editorElementHelper¶
File: lua/ge/extensions/editor/util/editorElementHelper.lua · VM: Game Engine (GE) · 1563 lines · BeamNG.drive 0.40.5 (buildbot 302427 on GitLab)
Access: require("extensions/editor/util/editorElementHelper") (file under extensions/ but not a regular extension)
Editor helper that builds imgui forms driven by declared "elements" (numeric, text, boolean, 3D transform, vehicle model/config, file, race, sites, ranking, dropdown, vehicle filter, zone selector, decorations...). Used mostly by the mission/quest/test editor: a derived class declares its elements in init(), then you call setContainer(c) to load the values, draw() to display/edit, getNewData() to get the default values and checkContainer() to detect missing or mistyped fields. The module returns a constructor: require('/lua/ge/extensions/editor/util/editorElementHelper')(derivedClass, mode); the keys of derivedClass are copied into the object.
Example¶
local helper = require('/lua/ge/extensions/editor/util/editorElementHelper')({
init = function(self)
self:addNumeric('Durée', 'duration', 60)
self:addBool('Actif', 'enabled', true)
end
}, 'mission')
helper:setContainer(mission) -- reads mission.missionTypeData
helper:draw()
Notes¶
- The mode determines the container's data field: 'quest' -> questTypeData, 'test' -> test, otherwise missionTypeData.
- Each element gets a unique _id (module counter); displayOptions.associatedStars as a string is converted to a table {key = true}.
- Transform: writes three fields
Pos, Rot, Scl (vec3/quat converted to tables). Model/config: Model, Config, ConfigPath. Ranking: Count, BestResult, MediumResult, WorstResult. Zone selector: _initialZones and _destinationZones. - addFile warns if the .prefab extension is used instead of .prefab.json.
- Code bugs: in newDataFunctions, reward and simpleLapConfig equal the nonexistent variable
defaultValue(nil), so these elements produce no default data; defaultColors.default/orange/red use ImVec4 with 5 arguments (1,0.6,0,8,0.75) instead of 4; elementIdSetContainer reads ctd.value instead of ctd[e.fieldName]; checkContainerFunctions.elementId points to elementIdSetContainer. - editingAnyTransform also consults extensions.editor_missionEditor.getStartTriggerWindow(), which ties this helper to the mission editor.
Class C¶
Instance of the element helper (with elements, autoAdditionalAttributes, mode, typeDataFieldName, container).
The module returns a constructor: local obj = require("editor_util_editorElementHelper")(options).
| Method | Description | Line |
|---|---|---|
C:addBigDecoHeader(text, color) |
Decoration: large title (color by name: default, orange, red, green, blue, white, black). | 240 |
C:addBool(label, fieldName, defaultValue, hideElementList, displayOptions) |
Checkbox, default false. With hideElementList, those elements are moved right after it and hidden (hidden) while the box is unchecked. | 35 |
C:addContainerId(label, fieldName, idType, defaultValue, displayOptions) |
Reference to another element of the container by identifier, default "(none)"; idType is ignored by the code. | 212 |
C:addCustomElement(label, getNewFunction, setContainerFunction, drawFunction) |
Custom element: getNewFunction(e) returns a list {fieldName, value}, setContainerFunction(e, data) loads the values, drawFunction draws. All three are nop by default. | 22 |
C:addDecoDummy(height) |
Decoration: vertical space of given height (default 1). | 245 |
C:addDecoHeader(text, color) |
Decoration: colored section title. | 241 |
C:addDecoSeparator() |
Decoration: separator. | 243 |
C:addDecoSpacer() |
Decoration: vertical space of 4. | 244 |
C:addDecoText(text, tooltip) |
Decoration: plain text with optional tooltip. | 242 |
C:addDropdown(label, fieldName, values, defaultValue, valueTooltips) |
Dropdown; if values is empty, it contains "issues Values!". Default: first value. | 177 |
C:addElement(element) |
Adds an already built element to the list: gives it a unique _id, normalizes displayOptions and returns it. | 246 |
C:addFile(label, fieldName, defaultValue, allowedExtensions, displayOptions) |
File selector (1024-character string); allowedExtensions is a list of {description, pattern} pairs. | 107 |
C:addFixedFile(label, filepathsInfolder, displayOptions) |
Expected file(s) at a fixed location in the folder; a string or a list (only one of the files is required). | 120 |
C:addLeaderboard(label, fieldName, defaultCount, defaultBest, defaultMedium, defaultWorst) |
Ranking: number of entries and best, medium, worst times/results. Defaults: 10, 80, 120, 200. | 152 |
C:addModelConfig(label, fieldName, defaultModel, defaultConfig, displayOptions) |
Vehicle model and configuration selector; default sbr / TT_RWD_S_M. | 96 |
C:addNumeric(label, fieldName, defaultValue, displayOptions) |
Numeric field (FloatPtr), default 0. | 25 |
C:addRace(label, fieldName, defaultValue, ...) |
Path file (*.path.json), element of type 'race'. | 136 |
C:addReward(label, fieldName, defaultValue) |
Numeric field of type 'reward'. | 172 |
C:addSimpleLapConfig(label, fieldName, displayOptions) |
Simple lap configuration (lapConfigUtil), default {}. | 141 |
C:addSites(label, fieldName, defaultValue) |
Sites file (*.sites.json), element of type 'sites'. | 147 |
C:addString(label, fieldName, defaultValue, len, displayOptions) |
Text field (ArrayChar), length 1024 by default, default empty. | 29 |
C:addTransform(label, fieldName, valueOptions, displayOptions) |
Editable 3D transform (position, rotation, scale) with gizmo (transformUtil). valueOptions: defaultPos, defaultRot, defaultScl, hasPos, hasRot, hasScl, oneDimScale; displayOptions: drawMode ('sphere' by default, 'vehicle', 'sphereDir', 'halfBox', 'fullBox'), drawColor (default {1,0.25,0,0.5}). | 58 |
C:addVehicleFilter(label, fieldName, displayOptions) |
Vehicle filter (vehicleFilterUtil): base filter, probability settings, manual additions/removals, maxVehicles (0 = all), popAttribute ("Population"), auxiliary vehicles and loaded trailers. | 187 |
C:addZoneSelector(label, fieldName, globalInfoFolderFieldName, displayOptions) |
Selector of initial and destination zones (zoneSelectorUtil), read from the sites file of the folder given by globalInfoFolderFieldName. | 217 |
C:checkContainer(c, fix, tags) |
Checks a container: missing fields, types different from those expected, nonexistent models/configs, missing files, etc. Returns a list of problems {label, severity, fixable, data}. The fix parameter allows repairing fixable problems (inferred from code). | 496 |
C:clear() |
Empties the list of elements. | 259 |
C:draw(filterOptions) |
Draws the form (visible elements) and handles transform editing by click in the 3D view (in objectSelect mode, hovering a transform = "Click to Edit"). | 1287 |
C:drawAxisBox(corner, x, y, z, clr) |
Draws an axis-aligned box (corner, x, y, z vectors, color) with debugDrawer. | 1420 |
C:drawTransformAsSphereDir(e) |
Draws a transform as a sphere with direction (debugDrawer). | 1327 |
C:drawTransformAsVehicle(e) |
Draws a transform as a vehicle footprint (debugDrawer). | 1346 |
C:editingAnyTransform() |
True if a transform of the helper (or the start trigger transform of the mission editor) is being edited. | 1271 |
C:getAllFieldNames() |
List of the managed field names with their type, all elements combined. | 1519 |
C:getNewData() |
Gathers the default values of all elements into a fieldName -> value table (new container). | 327 |
C:setAutoAdditionalAttributes(key, auto) |
Enables (default true) or disables the automatic handling of additional attributes for the given key. | 1529 |
C:setContainer(c) |
Remembers the container and loads into each element the values of c[typeDataFieldName]; calls valueChangedCallback of the elements concerned. C.setContainerBaseFunction is an alias. | 380 |
C:updateMouseInfo(container) |
Updates mouseInfo: camera position, mouse ray, ray hit (forest collision disabled for the duration of the shot), button down/held state and closest hovered transform. | 1203 |
Calls into the engine (C++)¶
FS:fileExists,findFilesSim.getUniqueNamedebugDrawer:drawLine,drawSphere,drawSquarePrism,drawTextAdvanced,drawTriSolid
tim19Atlas (Tim0219800) — derived from BeamNG GmbH Lua code (bCDDL 1.1, see LICENSE). Source: lua/ge/extensions/editor/util/editorElementHelper.lua.