Vehicle Editor - JBeam Beautifier
Reformats JBeam files by aligning table columns within selected sections (nodes, beams, triangles, etc.) using AST-level manipulation, with optional number rounding.
Reformats JBeam files by aligning table columns within selected sections (nodes, beams, triangles, etc.) using AST-level manipulation, with optional number rounding.
Module Exports
| Export | Type | Description |
|---|---|---|
M.menuEntry | string | "JBeam Beautifier" - menu label |
M.open | function | Opens the beautifier window |
M.onUpdate | hook | Renders ImGui controls |
M.onSerialize | hook | Persists window state |
M.onDeserialized | hook | Restores window state |
Key Internals
| Variable | Type | Purpose |
|---|---|---|
windowOpen | BoolPtr | Window visibility |
sectionsToBeautifyTblPtr | table | Checkboxes for which sections to format |
alignHeaderEnabledPtr | BoolPtr | Whether to align header rows too |
roundingEnabledPtr | BoolPtr | Enable number rounding |
decimalPlacesPtr | IntPtr | Number of decimal places for rounding |
directoryToBeautifyPtr | ArrayChar | Path to file or folder to beautify |
How It Works
Phase 1: Column Width Analysis (getSectionsWidthPerColumn)
- Parses the JBeam file into an AST via
jsonAST.parse() - For each selected section in each part, measures per-column text widths
- Tracks maximum width per column across all rows
- Handles inline arrays/objects as single columns
- Optionally rounds numbers to specified decimal places
Phase 2: Column Alignment (beautifySections)
- Walks the AST nodes for each section row
- Removes existing spacing (spaces, tabs) between columns
- Inserts new array delimiters and calculated spacing
- Maintains AST offset tracking for node index stability
Phase 3: Write (beautifyJBeamFile)
- Reads original file, validates JSON, parses AST
- Runs column analysis and alignment
- Stringifies the modified AST back to text
- Writes the result to the file
Lua Code Example
-- Open beautifier
extensions.editor_vehicleEditor_staticEditor_veJBeamBeautifier.open()
-- Sections available for beautification:
-- beams, nodes, quads, slots, slots2, triangles
-- Each has a checkbox; nodes and triangles are enabled by default
-- Settings:
-- "Align JBeam Header Row" - also aligns the first row (column names)
-- "Round Numbers" + "Decimal Places" - rounds numeric values
-- File/folder selection via file dialog:
-- editor_fileDialog.openFile(callback, {{"JBeam files", ".jbeam"}}, isFolder, "/vehicles/")
-- Core beautification pipeline:
-- local astData = jsonAST.parse(origJBeamStr, true)
-- local widths, maxWidths = getSectionsWidthPerColumn(astData)
-- beautifySections(astData, widths, maxWidths)
-- local newJBeamStr = jsonAST.stringify(astData.ast)
-- writeFile(filePath, newJBeamStr)
-- Column width calculation per element:
-- For numbers: width adjusted by -1 for negative sign
-- For inline objects/arrays: entire subtree stringified as one column
-- Maximum width tracked per column index across all rows
-- Verification (optional, commented out):
-- local res = test(origJBeamStr, newJBeamStr)
-- Uses deepcompare() to verify data integrity after formatting
-- Batch processing:
-- beautifyJBeamFiles(path) processes all .jbeam files in a directory
-- Results logged per file: "Successfully beautified: path" or "Failed to beautify: path"See Also
- Vehicle Editor - JBeam Modifier Leaking Visualizer - Related reference
- Vehicle Editor - JBeam Spellchecker - Related reference
- Vehicle Editor - JBeam Table Visualizer - Related reference
- World Editor Guide - Guide
Vehicle Editor - Scene View
Creates and manages multiple auxiliary scene views (render views) attached to the vehicle, supporting orthographic projections (left/right/front/back/top/bottom) and free 3D camera mode.
Vehicle Editor - JBeam Modifier Leaking Visualizer
Analyzes and visualizes JBeam modifier leaking - when a modifier set in one part affects rows in a different part due to the cascading nature of JBeam table modifiers.