Skip to content

Convert startbox config to 1-based indexing#5671

Open
MexxPex wants to merge 39 commits intoZeroK-RTS:masterfrom
MexxPex:box-configs
Open

Convert startbox config to 1-based indexing#5671
MexxPex wants to merge 39 commits intoZeroK-RTS:masterfrom
MexxPex:box-configs

Conversation

@MexxPex
Copy link

@MexxPex MexxPex commented Feb 16, 2026

Lua tables are naturally 1‑indexed, and explicit 0‑based keys are mistake‑prone.
This aligns the files with the standards described in issue #5137

@sprunk
Copy link
Member

sprunk commented Feb 16, 2026

Looks like a good starter point but is incomplete, e.g the config for Adansonia v4 has some 0-indexing still. It would also be good if it was split into a bunch of smaller commits because it's difficult to confidently review 300 files at once.

@GoogleFrog
Copy link
Contributor

@sprunk does this not need any code changes? As in can the gadget handle both types already?

@MexxPex
Copy link
Author

MexxPex commented Feb 16, 2026

if we were to change layout[0] to [1] and [1] to [2] it would need to be done for every map and the helpers.lua. I'll try doing that today and making a new commit for that. Edit: I've pushed a new commit that removes the remains of the 0-indexing

I could split the commit into multiple commits if I knew how to do it.

@sprunk
Copy link
Member

sprunk commented Feb 17, 2026

I could split the commit into multiple commits if I knew how to do it.

Generally you use git reset --mixed HEAD^ and then add/commit a few files at a time, google it if needed.

does this not need any code changes? As in can the gadget handle both types already?

It handles both:

--[[ If the boxes start from 1, shift down (allyteams start from 0).
At some point the internals could be rewritten so that configs
starting from 0 would be shifted up instead (since this is how
Lua generally works) but from the PoV of somebody writing map
configs this is transparent so it's just a code neatness thing
that can wait until later. Note that this deprecates 0-indexing,
even though that is how ~all gameside configs still look (that
would be another mechanical task to perform at some point). ]]
if startBoxConfig[1] and not startBoxConfig[0] then
Spring.Echo("1-indexed startbox detected, shifting")
local ret = {}
for boxID, box in pairs(startBoxConfig) do
ret[boxID - 1] = box
end
startBoxConfig = ret
end

@MexxPex
Copy link
Author

MexxPex commented Feb 17, 2026

Is it not a good idea to change that into shifting up now?

ie into:

if startBoxConfig[0] and not startBoxConfig[1] then
		Spring.Echo("0-indexed startbox detected, shifting")

		local ret = {}
		for boxID, box in pairs(startBoxConfig) do
			ret[boxID + 1] = box
		end
		startBoxConfig = ret
	end

	return startBoxConfig
end

@sprunk
Copy link
Member

sprunk commented Feb 18, 2026

Yes, but in a separate PR and also keep in mind that the above snippet is not the only place that would need to be changed (also everywhere the resulting table is used).

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.

3 participants