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

feat: Add Lua bindings to toggle mutations on/off #5762

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

karxi
Copy link
Contributor

@karxi karxi commented Nov 25, 2024

Checklist

Required

Purpose of change

Current Lua bindings for Creature objects are somewhat incomplete. In particular, there is no way to cleanly disable a mutation, or enable one at all.

Describe the solution

Added a couple of lines in src/catalua_bindings_creature.cpp. Now we can do this:

muti = MutationBranchId.new("WEB_WEAVER")       -- pick a disruptive example
gapi.get_avatar():set_mutation(muti)            -- force it onto the player
gapi.get_avatar():activate_mutation(muti)       -- weave a tangled web
gapi.get_avatar():deactivate_mutation(muti)     -- free the player from themselves

I also added a few lines in src/mutation.cpp. Its corresponding activate/deactivate_mutation functions now check if the player has the necessary target—i.e., they have the mutation and it is (in)active.

Describe alternatives you've considered

The alternative looks roughly like this:

muti = MutationBranchId.new("WEB_WEAVER")   -- pick a disruptive example
gapi.get_avatar():set_mutation(muti)        -- force it onto the player
-- Close console, open mutations menu, activate Web Weaver per example
gapi.get_avatar():unset_mutation(muti)      -- unceremoniously remove mutation
gapi.get_avatar():set_mutation(muti)        -- give mutation back, now off by default

It is exactly as awful as it seems.

Testing

See "Describe the solution", but also:

gapi.get_avatar():deactivate_mutation(MutationBranchId.new("BIOLUM1"))
gapi.get_avatar():activate_mutation(MutationBranchId.new("BIOLUM2"))

These should no longer error on a character without the specified mutations.

Additional context

If there's any code that needed to activate mutations multiple times without de-'power'-ing them...sorry! I don't know of anything else this could possibly break.

@github-actions github-actions bot added the src changes related to source code. label Nov 25, 2024
Copy link
Collaborator

@RoyalFox2140 RoyalFox2140 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be easily or effectively tested because our maintainer base doesn't script in lua. It looks like all the other lua hooks though. Given that it looks fine and it's primarily a mod problem this should be safe.

@RoyalFox2140
Copy link
Collaborator

Weep at this black magic with me, Chaos.

@chaosvolt
Copy link
Member

I cri. Currently still out on laptop, I'll see if I can get home soon and compile-test but I have fuck-all idea how to fiddle with LUA currently. :D

@RoyalFox2140
Copy link
Collaborator

I cri. Currently still out on laptop, I'll see if I can get home soon and compile-test but I have fuck-all idea how to fiddle with LUA currently. :D

Scarf says we can run in the lua console that we apparently have built into the game, and the testing code is commands we can run.

Copy link
Member

@chaosvolt chaosvolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Compiled and load-tested.
  2. Tried the first LUA command suggested, it correctly does nothing when used on a character without Weak Photophore.
  3. Gave myself that trait and tried again. No weird errors on trying to deactivate an inactive mutation, does (silently) deactivate the mutation if you turn it on first.

Minor oddity: Deactivating an active mutation with the LUA doesn't print the normal deactivation message.

@scarf005 scarf005 merged commit a661ed3 into cataclysmbnteam:main Nov 26, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants