Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve merge bp compatibility with removing fields #6637

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

lL1l1
Copy link
Contributor

@lL1l1 lL1l1 commented Jan 26, 2025

Issue

Merge blueprints cannot set fields in the base bp to nil since lua does not allow storing table keys with a value of nil. The alternative to doing that is to set those keys to false, but not all code works well with that.

Description of the proposed changes

Fix errors/bugs I encountered when modding SACUs, so code using blueprints and related to enhancements, enhancement presets, and weapons.

Testing done on the proposed changes

  • Units with enhancement presets that have a false value do not error and the enhancements work properly.
  • Setting a preset to false does not error.
  • Setting weapon buffs to false doesn't break it.

Additional context

An alternative could be to create a special value like "__nil" that table.merged treats as setting a field to nil.

Checklist

  • Changes are annotated, including comments where useful
  • Changes are documented in the changelog for the next game version

lL1l1 added 3 commits January 26, 2025 14:57
The enh name can not exist because a mod modifies the preset by setting the enhancement to `false`, as required for a merge bp to work.
If a merge bp sets an enhancement to `false` then it should not error for presets to work.
It also does not make sense to error and then return `false` afterwards, since the error stops execution.
@lL1l1 lL1l1 added type: bug area: sim Area that is affected by the Simulation of the Game area: ui Anything to do with the User Interface of the Game feature: mod compatibility related to FAF compatibility with mods labels Jan 26, 2025
@lL1l1 lL1l1 added this to the Development Iteration I of 2025 milestone Jan 26, 2025
@lL1l1 lL1l1 marked this pull request as ready for review January 26, 2025 23:01
@lL1l1 lL1l1 changed the title Fix merge bp compatibility with enhancements Improve merge bp compatibility with removing fields Jan 29, 2025
- clear damage table cache only when the buff is successfully enabled (error would stop it anyway though)
- remove irrelevant comments
- remove `ERROR:` since the log will already make it apparent
@lL1l1
Copy link
Contributor Author

lL1l1 commented Jan 30, 2025

Another pain I encountered while modding is the Weapons table, which is an array and index 1 controls the AI. This solution seems okay-ish? At least I'm not using debug functions like I thought of initially, and it still works from inside a .bp file.

local oldModBp = ModBlueprints
---@param all_bps BlueprintsTable
ModBlueprints = function(all_bps)
    local origBp = all_bps.Unit['url0301']--[[@as UnitBlueprint]]
    local origWeapon = origBp.Weapon --[[@as WeaponBlueprint[] ]]
    table.insert(origWeapon, 1, { ... })

    oldModBp(all_bps)
end

@lL1l1
Copy link
Contributor Author

lL1l1 commented Jan 30, 2025

Also there is a bug with reloading merge bps in that the mesh gets deleted due to how mesh bps are extracted and defaulted, ignoring __blueprints when merge = true. The bug causes the unit to not have a mesh and it errors out.

@lL1l1 lL1l1 marked this pull request as draft February 1, 2025 02:37
@lL1l1
Copy link
Contributor Author

lL1l1 commented Feb 2, 2025

local oldModBp = ModBlueprints
---@param all_bps BlueprintsTable
ModBlueprints = function(all_bps)
    local origBp = all_bps.Unit['url0301']--[[@as UnitBlueprint]]
    local origWeapon = origBp.Weapon --[[@as WeaponBlueprint[] ]]
    table.insert(origWeapon, 1, { ... })

    oldModBp(all_bps)
end

Has to be table assignment and not table.insert or else you get infinite copies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: sim Area that is affected by the Simulation of the Game area: ui Anything to do with the User Interface of the Game feature: mod compatibility related to FAF compatibility with mods type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant