Skip to content

[CHORE] Null safety for 5 more classes #4751

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/funkin/Highscore.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package funkin;
/**
* A core class which handles tracking score and combo for the current song.
*/
@:nullSafety
class Highscore
{
/**
Expand Down
26 changes: 19 additions & 7 deletions source/funkin/InitState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import funkin.api.newgrounds.NewgroundsClient;
*
* It should not contain any sprites or rendering.
*/
@:nullSafety
class InitState extends FlxState
{
/**
Expand Down Expand Up @@ -306,7 +307,7 @@ class InitState extends FlxState
*/
function startSong(songId:String, difficultyId:String = 'normal'):Void
{
var songData:funkin.play.song.Song = funkin.data.song.SongRegistry.instance.fetchEntry(songId);
var songData:Null<funkin.play.song.Song> = funkin.data.song.SongRegistry.instance.fetchEntry(songId);

if (songData == null)
{
Expand Down Expand Up @@ -343,6 +344,7 @@ class InitState extends FlxState
PlayStatePlaylist.campaignId = 'weekend1';
}

@:nullSafety(Off) // Cannot unify?
LoadingState.loadPlayState(
{
targetSong: songData,
Expand All @@ -357,7 +359,7 @@ class InitState extends FlxState
*/
function startLevel(levelId:String, difficultyId:String = 'normal'):Void
{
var currentLevel:funkin.ui.story.Level = funkin.data.story.level.LevelRegistry.instance.fetchEntry(levelId);
var currentLevel:Null<funkin.ui.story.Level> = funkin.data.story.level.LevelRegistry.instance.fetchEntry(levelId);

if (currentLevel == null)
{
Expand All @@ -373,17 +375,27 @@ class InitState extends FlxState
PlayStatePlaylist.isStoryMode = true;
PlayStatePlaylist.campaignScore = 0;

var targetSongId:String = PlayStatePlaylist.playlistSongIds.shift();
var targetSongId:Null<String> = PlayStatePlaylist.playlistSongIds.shift();

var targetSong:funkin.play.song.Song = SongRegistry.instance.fetchEntry(targetSongId);
var targetSong:Null<funkin.play.song.Song> = null;

if (targetSongId != null) targetSong = SongRegistry.instance.fetchEntry(targetSongId);

if (targetSongId == null)
{
startGameNormally();
return;
}

@:nullSafety(Off)
LoadingState.loadPlayState(
{
targetSong: targetSong,
targetDifficulty: difficultyId,
});
}

@:nullSafety(Off) // Meh, remove when flixel.system.debug.log.LogStyle is null safe
function setupFlixelDebug():Void
{
//
Expand Down Expand Up @@ -463,17 +475,17 @@ class InitState extends FlxState
#end
}

function defineSong():String
function defineSong():Null<String>
{
return MacroUtil.getDefine('SONG');
}

function defineLevel():String
function defineLevel():Null<String>
{
return MacroUtil.getDefine('LEVEL');
}

function defineDifficulty():String
function defineDifficulty():Null<String>
{
return MacroUtil.getDefine('DIFFICULTY');
}
Expand Down
3 changes: 2 additions & 1 deletion source/funkin/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import openfl.utils.AssetType;
/**
* A core class which handles determining asset paths.
*/
@:nullSafety
class Paths
{
static var currentLevel:Null<String> = null;
Expand Down Expand Up @@ -136,7 +137,7 @@ class Paths
* @param withExtension if it should return with the audio file extension `.mp3` or `.ogg`.
* @return String
*/
public static function inst(song:String, ?suffix:String = '', ?withExtension:Bool = true):String
public static function inst(song:String, ?suffix:String = '', withExtension:Bool = true):String
{
var ext:String = withExtension ? '.${Constants.EXT_SOUND}' : '';
return 'songs:assets/songs/${song.toLowerCase()}/Inst$suffix$ext';
Expand Down
6 changes: 6 additions & 0 deletions source/funkin/PlayerSettings.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import flixel.util.FlxSignal.FlxTypedSignal;
/**
* A core class which represents the current player(s) and their controls and other configuration.
*/
@:nullSafety
class PlayerSettings
{
// TODO: Finish implementation of second player.
public static var numPlayers(default, null) = 0;
public static var numAvatars(default, null) = 0;
// TODO: Making both of these null makes a lot of errors with the controls.
// That'd explain why unplugging input devices can cause the game to crash?
@:nullSafety(Off)
public static var player1(default, null):PlayerSettings;
@:nullSafety(Off)
public static var player2(default, null):PlayerSettings;

public static var onAvatarAdd(default, null) = new FlxTypedSignal<PlayerSettings->Void>();
Expand Down Expand Up @@ -70,6 +75,7 @@ class PlayerSettings
/**
* Forcibly destroy the PlayerSettings singletons for each player.
*/
@:nullSafety(Off)
public static function reset():Void
{
player1 = null;
Expand Down
11 changes: 6 additions & 5 deletions source/funkin/Preferences.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import funkin.save.Save;
/**
* A core class which provides a store of user-configurable, globally relevant values.
*/
@:nullSafety
class Preferences
{
/**
Expand Down Expand Up @@ -44,7 +45,7 @@ class Preferences

static function get_naughtyness():Bool
{
return Save?.instance?.options?.naughtyness;
return Save?.instance?.options?.naughtyness ?? true;
}

static function set_naughtyness(value:Bool):Bool
Expand All @@ -63,7 +64,7 @@ class Preferences

static function get_downscroll():Bool
{
return Save?.instance?.options?.downscroll;
return Save?.instance?.options?.downscroll ?? false;
}

static function set_downscroll(value:Bool):Bool
Expand Down Expand Up @@ -101,7 +102,7 @@ class Preferences

static function get_zoomCamera():Bool
{
return Save?.instance?.options?.zoomCamera;
return Save?.instance?.options?.zoomCamera ?? true;
}

static function set_zoomCamera(value:Bool):Bool
Expand All @@ -120,7 +121,7 @@ class Preferences

static function get_debugDisplay():Bool
{
return Save?.instance?.options?.debugDisplay;
return Save?.instance?.options?.debugDisplay ?? false;
}

static function set_debugDisplay(value:Bool):Bool
Expand Down Expand Up @@ -180,7 +181,7 @@ class Preferences

static function get_unlockedFramerate():Bool
{
return Save?.instance?.options?.unlockedFramerate;
return Save?.instance?.options?.unlockedFramerate ?? false;
}

static function set_unlockedFramerate(value:Bool):Bool
Expand Down
Loading