2022-03-08 03:13:53 -05:00
|
|
|
package funkin;
|
2021-09-07 17:09:34 -04:00
|
|
|
|
|
|
|
import flixel.addons.transition.FlxTransitionableState;
|
2023-06-16 17:37:56 -04:00
|
|
|
import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond;
|
2021-09-07 17:09:34 -04:00
|
|
|
import flixel.addons.transition.TransitionData;
|
|
|
|
import flixel.graphics.FlxGraphic;
|
|
|
|
import flixel.math.FlxPoint;
|
|
|
|
import flixel.math.FlxRect;
|
2023-06-26 20:39:47 -04:00
|
|
|
import flixel.FlxSprite;
|
2023-01-06 03:21:54 -05:00
|
|
|
import flixel.system.debug.log.LogStyle;
|
2021-09-07 17:09:34 -04:00
|
|
|
import flixel.util.FlxColor;
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.ui.PreferencesMenu;
|
2023-01-06 03:21:54 -05:00
|
|
|
import funkin.util.macro.MacroUtil;
|
2023-06-16 17:37:56 -04:00
|
|
|
import funkin.util.WindowUtil;
|
2023-06-26 20:39:47 -04:00
|
|
|
import funkin.play.PlayStatePlaylist;
|
2022-03-25 17:56:47 -04:00
|
|
|
import openfl.display.BitmapData;
|
2023-07-13 20:26:56 -04:00
|
|
|
import funkin.data.level.LevelRegistry;
|
|
|
|
import funkin.data.notestyle.NoteStyleRegistry;
|
|
|
|
import funkin.play.event.SongEventData.SongEventParser;
|
|
|
|
import funkin.play.cutscene.dialogue.ConversationDataParser;
|
|
|
|
import funkin.play.cutscene.dialogue.DialogueBoxDataParser;
|
|
|
|
import funkin.play.cutscene.dialogue.SpeakerDataParser;
|
|
|
|
import funkin.play.song.SongData.SongDataParser;
|
|
|
|
import funkin.play.stage.StageData.StageDataParser;
|
|
|
|
import funkin.play.character.CharacterData.CharacterDataParser;
|
|
|
|
import funkin.modding.module.ModuleHandler;
|
2023-08-08 15:41:25 -04:00
|
|
|
import funkin.ui.title.TitleState;
|
2021-09-07 17:09:34 -04:00
|
|
|
#if discord_rpc
|
|
|
|
import Discord.DiscordClient;
|
|
|
|
#end
|
|
|
|
|
2022-02-23 16:49:54 -05:00
|
|
|
/**
|
2023-06-26 20:39:47 -04:00
|
|
|
* The initialization state has several functions:
|
|
|
|
* - Calls code to set up the game, including loading saves and parsing game data.
|
|
|
|
* - Chooses whether to start via debug or via launching normally.
|
2022-02-23 16:49:54 -05:00
|
|
|
*/
|
2021-09-07 17:09:34 -04:00
|
|
|
class InitState extends FlxTransitionableState
|
|
|
|
{
|
2023-06-26 20:39:47 -04:00
|
|
|
/**
|
|
|
|
* Perform a bunch of game setup, then immediately transition to the title screen.
|
|
|
|
*/
|
|
|
|
public override function create():Void
|
|
|
|
{
|
|
|
|
setupShit();
|
|
|
|
|
|
|
|
loadSaveData();
|
|
|
|
|
|
|
|
startGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup a bunch of important Flixel stuff.
|
|
|
|
*/
|
|
|
|
function setupShit()
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-06-25 12:36:00 -04:00
|
|
|
//
|
2023-06-26 20:39:47 -04:00
|
|
|
// GAME SETUP
|
2023-06-25 12:36:00 -04:00
|
|
|
//
|
2023-06-26 20:39:47 -04:00
|
|
|
|
|
|
|
// Setup window events (like callbacks for onWindowClose)
|
|
|
|
WindowUtil.initWindowEvents();
|
|
|
|
// Disable the thing on Windows where it tries to send a bug report to Microsoft because why do they care?
|
|
|
|
WindowUtil.disableCrashHandler();
|
|
|
|
|
2023-06-25 12:36:00 -04:00
|
|
|
// This ain't a pixel art game! (most of the time)
|
|
|
|
FlxSprite.defaultAntialiasing = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
// Disable default keybinds for volume (we manually control volume in MusicBeatState with custom binds)
|
|
|
|
FlxG.sound.volumeUpKeys = [];
|
|
|
|
FlxG.sound.volumeDownKeys = [];
|
|
|
|
FlxG.sound.muteKeys = [];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
// TODO: Make sure volume still saves/loads properly.
|
|
|
|
// if (FlxG.save.data.volume != null) FlxG.sound.volume = FlxG.save.data.volume;
|
|
|
|
// if (FlxG.save.data.mute != null) FlxG.sound.muted = FlxG.save.data.mute;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
// Set the game to a lower frame rate while it is in the background.
|
|
|
|
FlxG.game.focusLostFramerate = 30;
|
|
|
|
|
|
|
|
//
|
|
|
|
// FLIXEL DEBUG SETUP
|
|
|
|
//
|
|
|
|
#if debug
|
|
|
|
// Disable using ~ to open the console (we use that for the Editor menu)
|
|
|
|
FlxG.debugger.toggleKeys = [F2];
|
|
|
|
|
|
|
|
// Adds an additional Close Debugger button.
|
2023-01-22 19:55:30 -05:00
|
|
|
// This big obnoxious white button is for MOBILE, so that you can press it
|
|
|
|
// easily with your finger when debug bullshit pops up during testing lol!
|
2023-01-22 22:25:45 -05:00
|
|
|
FlxG.debugger.addButton(LEFT, new BitmapData(200, 200), function() {
|
2023-01-22 19:55:30 -05:00
|
|
|
FlxG.debugger.visible = false;
|
|
|
|
});
|
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
// Adds a red button to the debugger.
|
|
|
|
// This pauses the game AND the music! This ensures the Conductor stops.
|
2023-01-22 22:25:45 -05:00
|
|
|
FlxG.debugger.addButton(CENTER, new BitmapData(20, 20, true, 0xFFCC2233), function() {
|
2023-01-22 20:03:08 -05:00
|
|
|
if (FlxG.vcr.paused)
|
|
|
|
{
|
|
|
|
FlxG.vcr.resume();
|
|
|
|
|
|
|
|
for (snd in FlxG.sound.list)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-01-22 20:03:08 -05:00
|
|
|
snd.resume();
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2023-01-22 20:03:08 -05:00
|
|
|
|
|
|
|
FlxG.sound.music.resume();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxG.vcr.pause();
|
|
|
|
|
|
|
|
for (snd in FlxG.sound.list)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-01-22 20:03:08 -05:00
|
|
|
snd.pause();
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2023-01-22 20:03:08 -05:00
|
|
|
|
|
|
|
FlxG.sound.music.pause();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
// Adds a blue button to the debugger.
|
|
|
|
// This skips forward in the song.
|
2023-01-22 22:25:45 -05:00
|
|
|
FlxG.debugger.addButton(CENTER, new BitmapData(20, 20, true, 0xFF2222CC), function() {
|
2023-01-22 20:03:08 -05:00
|
|
|
FlxG.game.debugger.vcr.onStep();
|
|
|
|
|
|
|
|
for (snd in FlxG.sound.list)
|
|
|
|
{
|
|
|
|
snd.pause();
|
|
|
|
snd.time += FlxG.elapsed * 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
FlxG.sound.music.pause();
|
|
|
|
FlxG.sound.music.time += FlxG.elapsed * 1000;
|
|
|
|
});
|
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
// Make errors and warnings less annoying.
|
|
|
|
// TODO: Disable this so we know to fix warnings.
|
|
|
|
if (false)
|
|
|
|
{
|
|
|
|
LogStyle.ERROR.openConsole = false;
|
|
|
|
LogStyle.ERROR.errorSound = null;
|
|
|
|
LogStyle.WARNING.openConsole = false;
|
|
|
|
LogStyle.WARNING.errorSound = null;
|
|
|
|
}
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
//
|
|
|
|
// FLIXEL TRANSITIONS
|
|
|
|
//
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
// Diamond Transition
|
2023-01-22 19:55:30 -05:00
|
|
|
var diamond:FlxGraphic = FlxGraphic.fromClass(GraphicTransTileDiamond);
|
|
|
|
diamond.persist = true;
|
|
|
|
diamond.destroyOnNoUse = false;
|
|
|
|
|
2023-06-27 21:29:58 -04:00
|
|
|
// NOTE: tileData is ignored if TransitionData.type is FADE instead of TILES.
|
|
|
|
var tileData:TransitionTileData = {asset: diamond, width: 32, height: 32};
|
|
|
|
|
2023-07-04 16:38:10 -04:00
|
|
|
FlxTransitionableState.defaultTransIn = new TransitionData(FADE, FlxColor.BLACK, 1, new FlxPoint(0, -1), tileData,
|
2023-06-27 21:29:58 -04:00
|
|
|
new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
|
2023-07-04 16:38:10 -04:00
|
|
|
FlxTransitionableState.defaultTransOut = new TransitionData(FADE, FlxColor.BLACK, 0.7, new FlxPoint(0, 1), tileData,
|
2023-06-27 21:29:58 -04:00
|
|
|
new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
|
2023-06-26 20:39:47 -04:00
|
|
|
// Don't play transition in when entering the title state.
|
|
|
|
FlxTransitionableState.skipNextTransIn = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
//
|
|
|
|
// NEWGROUNDS API SETUP
|
|
|
|
//
|
|
|
|
#if newgrounds
|
|
|
|
NGio.init();
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
//
|
|
|
|
// DISCORD API SETUP
|
|
|
|
//
|
|
|
|
#if discord_rpc
|
|
|
|
DiscordClient.initialize();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
Application.current.onExit.add(function(exitCode) {
|
|
|
|
DiscordClient.shutdown();
|
|
|
|
});
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
//
|
|
|
|
// ANDROID SETUP
|
|
|
|
//
|
|
|
|
#if android
|
|
|
|
FlxG.android.preventDefaultKeys = [flixel.input.android.FlxAndroidKey.BACK];
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
//
|
|
|
|
// GAME DATA PARSING
|
|
|
|
//
|
2023-07-13 20:26:56 -04:00
|
|
|
|
|
|
|
// NOTE: Registries and data parsers must be imported and not referenced with fully qualified names,
|
|
|
|
// to ensure build macros work properly.
|
|
|
|
LevelRegistry.instance.loadEntries();
|
|
|
|
NoteStyleRegistry.instance.loadEntries();
|
|
|
|
SongEventParser.loadEventCache();
|
|
|
|
ConversationDataParser.loadConversationCache();
|
|
|
|
DialogueBoxDataParser.loadDialogueBoxCache();
|
|
|
|
SpeakerDataParser.loadSpeakerCache();
|
|
|
|
SongDataParser.loadSongCache();
|
|
|
|
StageDataParser.loadStageCache();
|
|
|
|
CharacterDataParser.loadCharacterCache();
|
|
|
|
ModuleHandler.buildModuleCallbacks();
|
|
|
|
ModuleHandler.loadModuleCache();
|
|
|
|
|
|
|
|
ModuleHandler.callOnCreate();
|
2023-06-26 20:39:47 -04:00
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
/**
|
|
|
|
* Retrive and parse data from the user's save.
|
|
|
|
*/
|
|
|
|
function loadSaveData()
|
|
|
|
{
|
|
|
|
// Bind save data.
|
|
|
|
// TODO: Migrate save data to a better format.
|
|
|
|
FlxG.save.bind('funkin', 'ninjamuffin99');
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
// Load player options from save data.
|
2023-01-22 19:55:30 -05:00
|
|
|
PreferencesMenu.initPrefs();
|
2023-06-26 20:39:47 -04:00
|
|
|
// Load controls from save data.
|
2023-01-22 19:55:30 -05:00
|
|
|
PlayerSettings.init();
|
2023-06-26 20:39:47 -04:00
|
|
|
// Load highscores from save data.
|
2023-01-22 19:55:30 -05:00
|
|
|
Highscore.load();
|
2023-06-26 20:39:47 -04:00
|
|
|
// TODO: Load level/character/cosmetic unlocks from save data.
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
/**
|
|
|
|
* Start the game.
|
|
|
|
*
|
|
|
|
* By default, moves to the `TitleState`.
|
|
|
|
* But based on compile defines, the game can start immediately on a specific song,
|
|
|
|
* or immediately in a specific debug menu.
|
|
|
|
*/
|
|
|
|
function startGame():Void
|
|
|
|
{
|
|
|
|
#if SONG // -DSONG=bopeebo
|
|
|
|
startSong(defineSong(), defineDifficulty());
|
|
|
|
#elseif LEVEL // -DLEVEL=week1 -DDIFFICULTY=hard
|
|
|
|
startLevel(defineLevel(), defineDifficulty());
|
|
|
|
#elseif FREEPLAY // -DFREEPLAY
|
|
|
|
FlxG.switchState(new FreeplayState());
|
|
|
|
#elseif ANIMATE // -DANIMATE
|
|
|
|
FlxG.switchState(new funkin.ui.animDebugShit.FlxAnimateTest());
|
|
|
|
#elseif CHARTING // -DCHARTING
|
|
|
|
FlxG.switchState(new funkin.ui.debug.charting.ChartEditorState());
|
|
|
|
#elseif STAGEBUILD // -DSTAGEBUILD
|
|
|
|
FlxG.switchState(new funkin.ui.stageBullshit.StageBuilderState());
|
|
|
|
#elseif ANIMDEBUG // -DANIMDEBUG
|
|
|
|
FlxG.switchState(new funkin.ui.animDebugShit.DebugBoundingState());
|
|
|
|
#elseif LATENCY // -DLATENCY
|
|
|
|
FlxG.switchState(new funkin.LatencyState());
|
|
|
|
#else
|
|
|
|
startGameNormally();
|
|
|
|
#end
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
/**
|
|
|
|
* Start the game by moving to the title state and play the game as normal.
|
|
|
|
*/
|
|
|
|
function startGameNormally():Void
|
|
|
|
{
|
2023-07-22 20:16:43 -04:00
|
|
|
FlxG.sound.cache(Paths.music('freakyMenu/freakyMenu'));
|
2023-06-26 20:39:47 -04:00
|
|
|
FlxG.switchState(new TitleState());
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
/**
|
|
|
|
* Start the game by directly loading into a specific song.
|
|
|
|
* @param songId
|
|
|
|
* @param difficultyId
|
|
|
|
*/
|
|
|
|
function startSong(songId:String, difficultyId:String = 'normal'):Void
|
|
|
|
{
|
|
|
|
var songData:funkin.play.song.Song = funkin.play.song.SongData.SongDataParser.fetchSong(songId);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
if (songData == null)
|
|
|
|
{
|
|
|
|
startGameNormally();
|
|
|
|
return;
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
LoadingState.loadAndSwitchState(new funkin.play.PlayState(
|
|
|
|
{
|
|
|
|
targetSong: songData,
|
|
|
|
targetDifficulty: difficultyId,
|
|
|
|
}));
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
/**
|
|
|
|
* Start the game by directly loading into a specific story mode level.
|
|
|
|
* @param levelId
|
|
|
|
* @param difficultyId
|
|
|
|
*/
|
|
|
|
function startLevel(levelId:String, difficultyId:String = 'normal'):Void
|
|
|
|
{
|
|
|
|
var currentLevel:funkin.ui.story.Level = funkin.data.level.LevelRegistry.instance.fetchEntry(levelId);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
if (currentLevel == null)
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-06-26 20:39:47 -04:00
|
|
|
startGameNormally();
|
|
|
|
return;
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
PlayStatePlaylist.playlistSongIds = currentLevel.getSongs();
|
|
|
|
PlayStatePlaylist.isStoryMode = true;
|
|
|
|
PlayStatePlaylist.campaignScore = 0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
var targetSongId:String = PlayStatePlaylist.playlistSongIds.shift();
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
var targetSong:funkin.play.song.Song = funkin.play.song.SongData.SongDataParser.fetchSong(targetSongId);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
LoadingState.loadAndSwitchState(new funkin.play.PlayState(
|
|
|
|
{
|
|
|
|
targetSong: targetSong,
|
|
|
|
targetDifficulty: difficultyId,
|
|
|
|
}));
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
function defineSong():String
|
|
|
|
{
|
|
|
|
return MacroUtil.getDefine('SONG');
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
function defineLevel():String
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-06-26 20:39:47 -04:00
|
|
|
return MacroUtil.getDefine('LEVEL');
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-06-26 20:39:47 -04:00
|
|
|
function defineDifficulty():String
|
|
|
|
{
|
|
|
|
return MacroUtil.getDefine('DIFFICULTY');
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
2022-02-09 20:24:33 -05:00
|
|
|
}
|