funkin null safe

This commit is contained in:
Lasercar
2025-06-23 13:49:32 -04:00
committed by Eric
parent c1d4bba813
commit 3ac2a02291
5 changed files with 34 additions and 13 deletions
+1
View File
@@ -3,6 +3,7 @@ package funkin;
/** /**
* A core class which handles tracking score and combo for the current song. * A core class which handles tracking score and combo for the current song.
*/ */
@:nullSafety
class Highscore class Highscore
{ {
/** /**
+19 -7
View File
@@ -52,6 +52,7 @@ import funkin.api.newgrounds.NewgroundsClient;
* *
* It should not contain any sprites or rendering. * It should not contain any sprites or rendering.
*/ */
@:nullSafety
class InitState extends FlxState class InitState extends FlxState
{ {
/** /**
@@ -383,7 +384,7 @@ class InitState extends FlxState
*/ */
function startSong(songId:String, difficultyId:String = 'normal'):Void 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) if (songData == null)
{ {
@@ -420,6 +421,7 @@ class InitState extends FlxState
PlayStatePlaylist.campaignId = 'weekend1'; PlayStatePlaylist.campaignId = 'weekend1';
} }
@:nullSafety(Off) // Cannot unify?
LoadingState.loadPlayState( LoadingState.loadPlayState(
{ {
targetSong: songData, targetSong: songData,
@@ -434,7 +436,7 @@ class InitState extends FlxState
*/ */
function startLevel(levelId:String, difficultyId:String = 'normal'):Void 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) if (currentLevel == null)
{ {
@@ -450,10 +452,19 @@ class InitState extends FlxState
PlayStatePlaylist.isStoryMode = true; PlayStatePlaylist.isStoryMode = true;
PlayStatePlaylist.campaignScore = 0; 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( LoadingState.loadPlayState(
{ {
targetSong: targetSong, targetSong: targetSong,
@@ -461,6 +472,7 @@ class InitState extends FlxState
}); });
} }
@:nullSafety(Off) // Meh, remove when flixel.system.debug.log.LogStyle is null safe
function setupFlixelDebug():Void function setupFlixelDebug():Void
{ {
// //
@@ -540,17 +552,17 @@ class InitState extends FlxState
#end #end
} }
function defineSong():String function defineSong():Null<String>
{ {
return MacroUtil.getDefine('SONG'); return MacroUtil.getDefine('SONG');
} }
function defineLevel():String function defineLevel():Null<String>
{ {
return MacroUtil.getDefine('LEVEL'); return MacroUtil.getDefine('LEVEL');
} }
function defineDifficulty():String function defineDifficulty():Null<String>
{ {
return MacroUtil.getDefine('DIFFICULTY'); return MacroUtil.getDefine('DIFFICULTY');
} }
+2 -1
View File
@@ -6,6 +6,7 @@ import openfl.utils.AssetType;
/** /**
* A core class which handles determining asset paths. * A core class which handles determining asset paths.
*/ */
@:nullSafety
class Paths class Paths
{ {
static var currentLevel:Null<String> = null; static var currentLevel:Null<String> = null;
@@ -136,7 +137,7 @@ class Paths
* @param withExtension if it should return with the audio file extension `.mp3` or `.ogg`. * @param withExtension if it should return with the audio file extension `.mp3` or `.ogg`.
* @return String * @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}' : ''; var ext:String = withExtension ? '.${Constants.EXT_SOUND}' : '';
return 'songs:assets/songs/${song.toLowerCase()}/Inst$suffix$ext'; return 'songs:assets/songs/${song.toLowerCase()}/Inst$suffix$ext';
+6
View File
@@ -9,12 +9,17 @@ import flixel.util.FlxSignal.FlxTypedSignal;
/** /**
* A core class which represents the current player(s) and their controls and other configuration. * A core class which represents the current player(s) and their controls and other configuration.
*/ */
@:nullSafety
class PlayerSettings class PlayerSettings
{ {
// TODO: Finish implementation of second player. // TODO: Finish implementation of second player.
public static var numPlayers(default, null) = 0; public static var numPlayers(default, null) = 0;
public static var numAvatars(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; public static var player1(default, null):PlayerSettings;
@:nullSafety(Off)
public static var player2(default, null):PlayerSettings; public static var player2(default, null):PlayerSettings;
public static var onAvatarAdd(default, null) = new FlxTypedSignal<PlayerSettings->Void>(); public static var onAvatarAdd(default, null) = new FlxTypedSignal<PlayerSettings->Void>();
@@ -70,6 +75,7 @@ class PlayerSettings
/** /**
* Forcibly destroy the PlayerSettings singletons for each player. * Forcibly destroy the PlayerSettings singletons for each player.
*/ */
@:nullSafety(Off)
public static function reset():Void public static function reset():Void
{ {
player1 = null; player1 = null;
+6 -5
View File
@@ -10,6 +10,7 @@ import funkin.util.HapticUtil.HapticsMode;
/** /**
* A core class which provides a store of user-configurable, globally relevant values. * A core class which provides a store of user-configurable, globally relevant values.
*/ */
@:nullSafety
class Preferences class Preferences
{ {
/** /**
@@ -59,7 +60,7 @@ class Preferences
#if NO_FEATURE_NAUGHTYNESS #if NO_FEATURE_NAUGHTYNESS
return false; return false;
#else #else
return Save?.instance?.options?.naughtyness; return Save?.instance?.options?.naughtyness ?? true;
#end #end
} }
@@ -83,7 +84,7 @@ class Preferences
static function get_downscroll():Bool static function get_downscroll():Bool
{ {
return Save?.instance?.options?.downscroll #if mobile ?? true #end; return Save?.instance?.options?.downscroll #if mobile ?? true #else ?? false #end;
} }
static function set_downscroll(value:Bool):Bool static function set_downscroll(value:Bool):Bool
@@ -121,7 +122,7 @@ class Preferences
static function get_zoomCamera():Bool static function get_zoomCamera():Bool
{ {
return Save?.instance?.options?.zoomCamera; return Save?.instance?.options?.zoomCamera ?? true;
} }
static function set_zoomCamera(value:Bool):Bool static function set_zoomCamera(value:Bool):Bool
@@ -144,7 +145,7 @@ class Preferences
#if mobile #if mobile
return false; return false;
#end #end
return Save?.instance?.options?.debugDisplay; return Save?.instance?.options?.debugDisplay ?? false;
} }
static function set_debugDisplay(value:Bool):Bool static function set_debugDisplay(value:Bool):Bool
@@ -296,7 +297,7 @@ class Preferences
static function get_unlockedFramerate():Bool static function get_unlockedFramerate():Bool
{ {
return Save?.instance?.options?.unlockedFramerate; return Save?.instance?.options?.unlockedFramerate ?? false;
} }
static function set_unlockedFramerate(value:Bool):Bool static function set_unlockedFramerate(value:Bool):Bool