Skip to content

Replace all C++ sector numbering with Lua API in scripts/api#2872

Open
oznogon wants to merge 1 commit into
daid:masterfrom
oznogon:move-sector-naming-to-lua
Open

Replace all C++ sector numbering with Lua API in scripts/api#2872
oznogon wants to merge 1 commit into
daid:masterfrom
oznogon:move-sector-naming-to-lua

Conversation

@oznogon
Copy link
Copy Markdown
Contributor

@oznogon oznogon commented May 31, 2026

Move sector naming from C++ to the Lua scripting API, allowing scenarios to customize the functions. Move the global functions getSectorName(x,y) and sectorToXY(name) to a Sector. pseudonamespace to retain entity functions with the same names, and add global wrappers at the old function names for backward scenario compatibility.

All radars should now show sector names as defined in the Lua API. This allows each scenario to define custom sector naming behaviors by overriding Sector.getSectorName() and Sector.sectorToXY(). This also allows redefining the default behavior by overriding or replacing the API functions.

This should not change any default behaviors. The Lua API implementation attempts to reproduce EE's existing C++ implementation, quirks and all.

Override example

Tested against the Edge-of-Space scenario, which had already switched from hardcoded sector names in comms scripts to global functions, and set overriding sector naming functions in the scenario. The scenario seamlessly used the overrides.

At origin coords 0,0:

image

Scenario code:

Sector.getSectorName = function(x, y)
    return string.format("%d,%d", math.floor(x / 20000), math.floor(y / 20000))
end

Sector.sectorToXY = function(name)
    local x, y = name:match("(-?%d+),(-?%d+)")
    if not x then return 0, 0, false end
    return tonumber(x) * 20000, tonumber(y) * 20000, true
end

Comms reporting sector names in stock scenario_06_edgeofspace.lua, with the only change being to add the above custom sector naming functions to the scenario:

image

Move sector naming from C++ to the Lua scripting API, allowing
scenarios to customize the functions. Move the global functions
getSectorName(x,y) and sectorToXY(name) to a `Sector.` pseudonamespace
to retain entity functions with the same names, and add global wrappers
at the old function names for backward scenario compatibility.

All radars should now show sector names as defined in the Lua API.
This allows each scenario to define custom sector naming behaviors by
overriding Sector.getSectorName() and Sector.sectorToXY(). This also
allows redefining the default behavior by overriding or replacing the
API functions.

Tested against the Edge-of-Space scenario, which had already switched
from hardcoded sector names in comms scripts to global functions, and
set overriding sector naming functions in the scenario. The scenario
seamlessly used the overrides.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant