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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pride pin reskinning #82920

Merged
merged 9 commits into from May 8, 2024
Merged

Fix pride pin reskinning #82920

merged 9 commits into from May 8, 2024

Conversation

00-Steven
Copy link
Contributor

@00-Steven 00-Steven commented Apr 27, 2024

About The Pull Request

Edit: Since writing, this pr has been updated to address failing CI based on code-general suggestions, invalidating the previous descriptions. The previous descriptions has been included as spoilers for posterity

Right, so, this has gone from just a simple pride pin fix to realizing CI fails with it to doing a more complex lasting fix based on suggestions.

Recap time. Objects get reskinning set up if they have unique_reskin set when Initialize(...) runs.

if(unique_reskin)
RegisterSignal(src, COMSIG_CLICK_ALT, PROC_REF(on_click_alt_reskin))
register_context()

Because pride pins use a global list, we set it in Initialize(...)... After we call the parent.
/obj/item/clothing/accessory/pride/Initialize(mapload)
. = ..()
unique_reskin = GLOB.pride_pin_reskins

Obviously this fails.

However, moving this before Initialize(...), while fixing the issue, causes CI to fail due to calling register_context() twice.
Why? Well, it's simple. We automatically call register_context() if we have unique_reskin set, as seen above, but we also call it on accessory Initialize(...) due to it having its own context.

/obj/item/clothing/accessory/Initialize(mapload)
. = ..()
register_context()

This causes it to try register the same thing twice, which doesn't break things, but it sure as hell isn't clean.

So talking about this with San in code general, we decided to try go with the following:
We add two new procs, setup_reskinning() and check_setup_reskinning(), and handle all this fuckery within those.
This lets subtypes override them with their own new checks or differences in setup.
Then we override setup_reskinning() for /obj/item/clothing/under and /obj/item/clothing/accessory to not register context again, and do the same for /obj/item/clothing/accessory/pride but while also setting unique_reskin.

This fixes it.

Previous implementation for posterity

Back from my short code break, time to fix some of the things I've been annoyed by.

Firstly, I noticed pride pins could no longer be reskinned since the alt-click refactor.
Looking into it, this seems to be because we now only register this on Initialize(...) if unique_reskin has been set:

if(unique_reskin)
RegisterSignal(src, COMSIG_CLICK_ALT, PROC_REF(on_click_alt_reskin))
register_context()

While due to using a global list we don't set this in the item definition, but in Initialize(...) :
/obj/item/clothing/accessory/pride/Initialize(mapload)
. = ..()
unique_reskin = GLOB.pride_pin_reskins

Where we call the parent proc before setting unique_reskin, and thus not registering our ability to reskin.

So all we do is set this to our global list before we call the parent proc.

/obj/item/clothing/accessory/pride/Initialize(mapload)
	unique_reskin = GLOB.pride_pin_reskins // Set before parent proc checks for it.
	. = ..()

This fixes it.

Why It's Good For The Game

Fixes pride pin reskinning.
Theoretically makes it easier to avoid this happening in the future, and allows setup_reskinning() to be manually called in the case of values being edited post-initialize.

Previous pitch for posterity

Fixes pride pin reskinning.

Changelog

馃啈
fix: Pride pins can be reskinned again with alt-click.
/:cl:

@tgstation-server tgstation-server added the Fix Rewrites a bug so it appears in different circumstances label Apr 27, 2024
@san7890
Copy link
Member

san7890 commented Apr 27, 2024

There is a better way to fix this that makes it more extendable for future coders:

Do the following in [tgstation/code/game/objects/items.dm] Lines 267 to 269 in [9145ecb] Initialize() that runs the code if either one of the obj_flags is set (in addition to unique_reskin). This is just leveraging the existing framework as the pins already have this flag set.

if(unique_reskin || (obj_flags & (UNIQUE_RENAME | INFINITE_RESKIN)))
 RegisterSignal(src, COMSIG_CLICK_ALT, PROC_REF(on_click_alt_reskin)) 
 register_context()

Much better.

@san7890
Copy link
Member

san7890 commented Apr 27, 2024

Also you're failing CI doing it the way it is presently so just do my suggestion

@00-Steven
Copy link
Contributor Author

As mentioned on the discord, the failing CI is a matter of oops double register due to accessory+reskin.
Anyhow, drafting.

@00-Steven 00-Steven marked this pull request as draft April 27, 2024 22:36
Copy link
Contributor

github-actions bot commented May 5, 2024

This PR has been inactive for long enough to be automatically marked as stale. This means it is at risk of being auto closed in ~ 7 days, please address any outstanding review items and ensure your PR is finished, if these are all true and you are auto-staled anyway, you need to actively ask maintainers if your PR will be merged. Once you have done any of the previous actions then you should request a maintainer remove the stale label on your PR, to reset the stale timer. If you feel no maintainer will respond in that time, you may wish to close this PR youself, while you seek maintainer comment, as you will then be able to reopen the PR yourself

@github-actions github-actions bot added the Stale Even the uncaring universe rejects you, why even go on label May 5, 2024
@00-Steven
Copy link
Contributor Author

funny how the commits I forgot to push show up as being before the stale label post

@00-Steven
Copy link
Contributor Author

Now just need to update the main pr body

@00-Steven
Copy link
Contributor Author

writeup's good enough:tm:, undrafting once checks're done

@00-Steven 00-Steven marked this pull request as ready for review May 6, 2024 22:07
@github-actions github-actions bot removed the Stale Even the uncaring universe rejects you, why even go on label May 7, 2024
@Jacquerel Jacquerel merged commit aa5eddb into tgstation:master May 8, 2024
21 checks passed
comfyorange added a commit that referenced this pull request May 8, 2024
github-actions bot added a commit that referenced this pull request May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Rewrites a bug so it appears in different circumstances
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants