Skip to content

core_licensePlateDesign

File: lua/ge/extensions/core/licensePlateDesign.lua · VM: Game Engine (GE) · 307 lines · BeamNG.drive 0.40.5 (buildbot 302427 on GitLab)

Access: extension core_licensePlateDesign: extensions.load("core_licensePlateDesign"), then the global core_licensePlateDesign

GE extension core_licensePlateDesign: loads the definition of a license plate design and converts it to the current format (version 3, type 'licenseplate', *.sktemplate.json files). It also translates the old JSON formats (versions 0 to 2, with diffuse/bump/text/characterLayout fields and printf-type patterns %d %c %l) into text trees with variables {plate}, {line1}, {seg1}... A modder uses it to read a plate design, whether old or new.

Example

local design = core_licensePlateDesign.loadDesign('/vehicles/common/licenseplate-default.json')
if design then dump(design.format) end

Notes

  • The module has only one public function, loadDesign; everything else is local. The default format of old single-format designs is the key '30-15' (FORMAT_US).
  • loadDesign first looks for the matching *.sktemplate.json file (the .json path is turned into .sktemplate.json). If it has a format field, the missing formats are completed from the old .json of the same name (mergeLegacyFormats). Otherwise it reads the old file and translates it.
  • The legacy patterns %d, %c, %l become {d}, {c}, {c} (the 'l' charset is converted to 'c'). Default charsets: d = 0-9, c = A-Z, D = 1-9. The maximum plate text length is 32.
  • Default plate dimensions: 512 x 256 pixels; default line height 80; default finish { roughness 1.0, metallic 0.0, fgRoughness 0.7, fgMetallic 0.0 }.
  • The built-in fonts are 'plate', 'plateIT' (layout path containing 'italy' or '_it') and 'plateFE' (containing 'fe' or 'europe'). A mod font (.otf, .ttf, or .json layout with atlas) is used as is if the files exist. Nearly white colors (luminance >= 224) are forced to black with a built-in font.
  • Probable bug in resolveTextColor: parseColor(color:gsub('%s+', '')) also passes the 2nd return of gsub (number of replacements) as an argument; harmless, parseColor ignores the 2nd argument.
  • The local functions translateLegacyFormat / translateV2ToV3 do not check the input types: a malformed JSON file can cause a Lua error.

Functions

Function Description Line
core_licensePlateDesign.loadDesign(path) Loads a plate design from a JSON file (old or *.sktemplate.json) and returns a table in version 3 format: { name, version = 3, type = 'licenseplate', format = { [key] = { size, background, emboss, finish, root, segments/limit/limit2, normal } }, vars = { plate = {...} } }. The old formats are converted, the new ones are completed with the formats of the old file if it exists. 279

Parameter details

core_licensePlateDesign.loadDesign(path)

Loads a plate design from a JSON file (old or *.sktemplate.json) and returns a table in version 3 format: { name, version = 3, type = 'licenseplate', format = { [key] = { size, background, emboss, finish, root, segments/limit/limit2, normal } }, vars = { plate = {...} } }. The old formats are converted, the new ones are completed with the formats of the old file if it exists.

  • path (string|nil) : Virtual path of the design file; nil or empty string returns nil.
  • returns: table|nil Version 3 design, or nil if the file is not found or unreadable (warning in the log).

Calls into the engine (C++)

  • FS: fileExists

tim19Atlas (Tim0219800) — derived from BeamNG GmbH Lua code (bCDDL 1.1, see LICENSE). Source: lua/ge/extensions/core/licensePlateDesign.lua.