Funkin icon indicating copy to clipboard operation
Funkin copied to clipboard

[CHORE] Add null-safety to `PlayState` and `LoadingState`

Open NotHyper-474 opened this issue 8 months ago • 5 comments

A quite large contribution towards #4303.

~This still needs a bit of polishing so I'm making this a draft for the moment.~ I think I'm satisfied with how it turned out.

I've also included LoadingState here as it made sense for me since it's responsible for switching the game to the PlayState.

PlayState might've been the most troublesome class to add null-safety to since it has so many fields and whatnot. It isn't complete null-safety since ~some fields still need to be initialized later in create and also the fact~ the null-safety checker has many oddities. But some notes regarding it:

  • I've made it so currentSong cannot be null at all, so there's gonna be errors thrown in the case something may set it null.

  • I added a new optional parameter to Strumline's constructor, scrollSpeed. This was done because resetScrollSpeed would always get the current scroll value from the PlayState, which doesn't have its instance set until it gets called on create which would cause the scroll speed to always be 1. I could just call resetScrollSpeed in initStrumline but I didn't like that.

  • ~playerStrumline, opponentStrumline, and other fields I've disabled null-safety on would require moving their initialization to new, I felt like the constructor was big enough already with the changes I made to ensure the cameras and the follow point are not nullable but if that is not a problem then I can move them there and remove their init functions. Unfortunately I cannot just move their init functions from create to new as the compiler requires explicitly setting the field in the constructor.~

NotHyper-474 avatar Apr 23 '25 14:04 NotHyper-474

Amazing work! It currently gives me this error when compiling, just another hole to patch up!

image

mfw NO_FEATURE_DISCORD_RPC

NotHyper-474 avatar Apr 25 '25 04:04 NotHyper-474

Will test this later but it makes me really happy to see PlayState get null safety!

AbnormalPoof avatar Apr 25 '25 17:04 AbnormalPoof

Merge conflicts? In null-safe PlayState?

VioletSnowLeopard avatar Apr 28 '25 22:04 VioletSnowLeopard

guuhh thanks to https://github.com/FunkinCrew/Funkin/pull/4318 I had to move some strumline shit to the constructor so I'm re-requesting review just to make sure nothing broke

NotHyper-474 avatar May 03 '25 23:05 NotHyper-474

This is huge.

Hundrec avatar May 14 '25 21:05 Hundrec

NotHyper-474 avatar Aug 04 '25 17:08 NotHyper-474