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

Replace obsolete EntityWhitelist IsValid usages #28465

Merged
merged 10 commits into from
Jun 2, 2024

Conversation

Plykiya
Copy link
Contributor

@Plykiya Plykiya commented Jun 1, 2024

About the PR

EntityWhitelist?.IsValid() has a message saying that it's obsolete and to use EntityWhitelistSystem's method instead
So I changed every usage I could find with EntityWhitelistSystem.IsValid()

Why / Balance

Gets rid of some obsolete notifications... I guess?

Technical details

Kinda like how simple the code looked before I did this...

A rough summary of how I approached each case

  1. Add a check for whitelist is not null in some form, kind of can't get around it
  2. == true gets replaced with component.Whitelist == null ? false : _whitelist.IsValid()
  3. == false gets replaced with component.Whitelist == null ? false : !_whitelist.IsValid()
  4. != true gets replaced with component.Whitelist == null ? true : !_whitelist.IsValid()
  5. != false gets replaced with component.Whitelist == null ? true : _whitelist.IsValid()
  6. Null coalescing ?? is replaced like normal

Took me a while to figure out that the null propagating operator gets set to null in the checks which causes different scenarios based on whether it's == or !=, once I figured out that much I properly accounted for what happens when whitelist is null and now everything I tested works pretty much without issue

edit: EmoGarbage requested helper functions so now it's
2. == true gets replaced with _whitelist.IsWhitelistPass()
3. == false gets replaced with _whitelist.IsWhitelistFail()
4. != true gets replaced with _whitelist.IsWhitelistFailOrNull()
5. != false gets replaced with _whitelist.IsWhitelistPassOrNull()
along with similarly named Blacklist functions so you can write things like
_whitelist.IsWhitelistPass() && _whitelist.IsBlacklistFail()

Breaking changes

god I hope not

Changelog

nothing changed for the player experience

@Plykiya Plykiya marked this pull request as ready for review June 1, 2024 05:57
@github-actions github-actions bot added Changes: UI Changes: Might require knowledge of UI design or code. S: Needs Review Status: Requires additional reviews before being fully accepted labels Jun 1, 2024
@EmoGarbage404
Copy link
Member

common pattern that i know exists is nullable whitelists/blacklists that ignore each other so a helper that takes in a nullable whitelist and a nullable blacklist and performs common functions on them would be incredibly useful.

@Plykiya
Copy link
Contributor Author

Plykiya commented Jun 1, 2024

common pattern that i know exists is nullable whitelists/blacklists that ignore each other so a helper that takes in a nullable whitelist and a nullable blacklist and performs common functions on them would be incredibly useful.

where do we store helper functions in the codebase? I'd be up for it
ah, I guess it'd just be in the EntityWhitelistSystem considering the context, okay, sure

@EmoGarbage404
Copy link
Member

EmoGarbage404 commented Jun 1, 2024

image

yeah i feel like basically all of these should have helpers since the replacement is quite unwieldy.

I suggest:
IsWhitelistPass
IsWhitelistFail
IsBlacklistPass
IsBlacklistFail

and then probably two more for combo:
IsWhitelistPass && IsBlacklistFail
IsWhitelistFail || IsBlackListPass

@Plykiya
Copy link
Contributor Author

Plykiya commented Jun 1, 2024

yeah i feel like basically all of these should have helpers since the replacement is quite unwieldy.

I suggest: IsWhitelistPass IsWhitelistFail IsBlacklistPass IsBlacklistFail

and then probably two more for combo: IsWhitelistPass && IsBlacklistFail IsWhitelistFail || IsBlackListPass

ok there you go, it is definitely easier to read that's for sure

@AJCM-git AJCM-git self-requested a review June 1, 2024 13:25
@deltanedas
Copy link
Contributor

common pattern that i know exists is nullable whitelists/blacklists that ignore each other so a helper that takes in a nullable whitelist and a nullable blacklist and performs common functions on them would be incredibly useful.

borg lock pr had this :trollface:

@EmoGarbage404 EmoGarbage404 merged commit d6ba166 into space-wizards:master Jun 2, 2024
11 checks passed
@Plykiya Plykiya deleted the ObsoleteWhitelistFunction branch June 2, 2024 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changes: UI Changes: Might require knowledge of UI design or code. S: Needs Review Status: Requires additional reviews before being fully accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants