beyond-all-reason / beyond-all-reason/RecoilEngine

Spring.GetFactoryCounts returns weird format

Open
#2,571 5 comments 0 reactions 0 assignees View on GitHub
area: Lua API deprecation good first issue refactor
Dominant language
C++
Stars
679
Forks
290
Avg merge
3d 2h
Merged PRs (30d)
40

Description

Here's an example of the output:

```lua
{
[2]={
[260]=20,
},
[3]={
[300]=5,
},
n=3,
}
```

This is very unergonomic and unexpected to work with. Maybe add an argument to not return n for retrocompat concerns, if there are any.

#### Workaround

```lua
-- NOTE: Engine for some reason returns this weird format:
-- ```
-- {
-- [2]={
-- [260]=20,
-- },
-- [3]={
-- [300]=5,
-- },
-- n=3,
-- }
-- ```
-- See: https://github.com/beyond-all-reason/RecoilEngine/issues/2571
local function getNonBrokenEngineReturn(brokenReturn)
if not brokenReturn then
return brokenValue
end

local value = {}
for brokenKey, brokenVal in pairs(brokenReturn) do
if brokenKey ~= "n" then
local actualKey, actualVal = next(brokenVal)

if actualKey then
value[actualKey] = actualVal
end
end
end

return value
end

local notUsableFactoryCounts = Spring.GetFactoryCounts(unitID)
local usableFactoryCounts = getNonBrokenEngineReturn(notUsableFactoryCounts)
```

Contributor guide

Open the contributing guide

Research direction

Start at the Spring.GetFactoryCounts API entry point and compare its returned table with the example and the getNonBrokenEngineReturn workaround in this issue. Resolve whether the existing n field must remain for compatibility or an opt-out is needed; done when the returned factory counts are ergonomic without breaking the required compatibility behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, lua
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.