1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-05 06:14:36 +00:00
Funkin/source/funkin/InitState.hx

228 lines
6.3 KiB
Haxe
Raw Normal View History

package funkin;
import flixel.system.debug.log.LogStyle;
import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond;
import flixel.addons.transition.FlxTransitionableState;
import flixel.addons.transition.TransitionData;
import flixel.graphics.FlxGraphic;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
import flixel.util.FlxColor;
import funkin.modding.module.ModuleHandler;
2022-03-25 21:56:47 +00:00
import funkin.play.PlayState;
import funkin.play.character.CharacterData.CharacterDataParser;
2022-09-24 19:02:10 +00:00
import funkin.play.event.SongEvent.SongEventHandler;
2022-09-13 05:09:30 +00:00
import funkin.play.song.SongData.SongDataParser;
import funkin.play.stage.StageData;
import funkin.ui.PreferencesMenu;
import funkin.util.macro.MacroUtil;
import funkin.util.WindowUtil;
2022-03-25 21:56:47 +00:00
import openfl.display.BitmapData;
#if colyseus
import io.colyseus.Client;
import io.colyseus.Room;
#end
#if discord_rpc
import Discord.DiscordClient;
#end
2022-02-23 21:49:54 +00:00
/**
* Initializes the game state using custom defines.
* Only used in Debug builds.
*/
class InitState extends FlxTransitionableState
{
override public function create():Void
{
2022-02-23 21:49:54 +00:00
trace('This is a debug build, loading InitState...');
#if android
2022-02-26 14:06:49 +00:00
FlxG.android.preventDefaultKeys = [flixel.input.android.FlxAndroidKey.BACK];
#end
#if newgrounds
NGio.init();
#end
#if discord_rpc
DiscordClient.initialize();
2021-09-10 14:07:55 +00:00
Application.current.onExit.add(function(exitCode)
{
DiscordClient.shutdown();
});
#end
// ==== flixel shit ==== //
2021-09-10 14:07:55 +00: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!
FlxG.debugger.addButton(LEFT, new BitmapData(200, 200), function()
{
FlxG.debugger.visible = false;
});
FlxG.sound.muteKeys = [ZERO];
FlxG.game.focusLostFramerate = 60;
// FlxG.stage.window.borderless = true;
// FlxG.stage.window.mouseLock = true;
var diamond:FlxGraphic = FlxGraphic.fromClass(GraphicTransTileDiamond);
diamond.persist = true;
diamond.destroyOnNoUse = false;
FlxTransitionableState.defaultTransIn = new TransitionData(FADE, FlxColor.BLACK, 1, new FlxPoint(0, -1), {asset: diamond, width: 32, height: 32},
new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
2021-09-10 14:07:55 +00:00
FlxTransitionableState.defaultTransOut = new TransitionData(FADE, FlxColor.BLACK, 0.7, new FlxPoint(0, 1), {asset: diamond, width: 32, height: 32},
new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
// ===== save shit ===== //
FlxG.save.bind('funkin', 'ninjamuffin99');
// https://github.com/HaxeFlixel/flixel/pull/2396
// IF/WHEN MY PR GOES THRU AND IT GETS INTO MAIN FLIXEL, DELETE THIS CHUNKOF CODE, AND THEN UNCOMMENT THE LINE BELOW
// FlxG.sound.loadSavedPrefs();
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;
// Make errors and warnings less annoying.
LogStyle.ERROR.openConsole = false;
LogStyle.ERROR.errorSound = null;
LogStyle.WARNING.openConsole = false;
LogStyle.WARNING.errorSound = null;
// FlxG.save.close();
// FlxG.sound.loadSavedPrefs();
WindowUtil.initWindowEvents();
PreferencesMenu.initPrefs();
PlayerSettings.init();
Highscore.load();
if (FlxG.save.data.weekUnlocked != null)
{
// FIX LATER!!!
// WEEK UNLOCK PROGRESSION!!
// StoryMenuState.weekUnlocked = FlxG.save.data.weekUnlocked;
if (StoryMenuState.weekUnlocked.length < 4)
StoryMenuState.weekUnlocked.insert(0, true);
// QUICK PATCH OOPS!
if (!StoryMenuState.weekUnlocked[0])
StoryMenuState.weekUnlocked[0] = true;
}
if (FlxG.save.data.seenVideo != null)
VideoState.seenVideo = FlxG.save.data.seenVideo;
// ===== fuck outta here ===== //
// FlxTransitionableState.skipNextTransOut = true;
FlxTransitionableState.skipNextTransIn = true;
2022-02-11 19:21:42 +00:00
2022-09-24 19:02:10 +00:00
SongEventHandler.registerBaseEventCallbacks();
// TODO: Register custom event callbacks here
2022-09-13 05:09:30 +00:00
SongDataParser.loadSongCache();
2022-02-23 21:49:54 +00:00
StageDataParser.loadStageCache();
CharacterDataParser.loadCharacterCache();
ModuleHandler.buildModuleCallbacks();
ModuleHandler.loadModuleCache();
FlxG.debugger.toggleKeys = [F2];
2022-02-10 01:24:33 +00:00
#if song
2022-02-11 19:21:42 +00:00
var song = getSong();
var weeks = [
['bopeebo', 'fresh', 'dadbattle'],
['spookeez', 'south', 'monster'],
['spooky', 'spooky', 'monster'],
['pico', 'philly', 'blammed'],
['satin-panties', 'high', 'milf'],
['cocoa', 'eggnog', 'winter-horrorland'],
['senpai', 'roses', 'thorns'],
['ugh', 'guns', 'stress']
];
var week = 0;
for (i in 0...weeks.length)
{
if (weeks[i].contains(song))
2022-02-10 01:24:33 +00:00
{
2022-02-11 19:21:42 +00:00
week = i + 1;
break;
2022-02-10 01:24:33 +00:00
}
2022-02-11 19:21:42 +00:00
}
if (week == 0)
throw 'Invalid -D song=$song';
startSong(week, song, false);
2022-02-10 01:24:33 +00:00
#elseif week
2022-02-11 19:21:42 +00:00
var week = getWeek();
var songs = [
'bopeebo', 'spookeez', 'spooky', 'pico',
'satin-panties', 'cocoa', 'senpai', 'ugh'
];
if (week <= 0 || week >= songs.length)
throw "invalid -D week=" + week;
startSong(week, songs[week - 1], true);
2022-02-10 01:24:33 +00:00
#elseif FREEPLAY
FlxG.switchState(new FreeplayState());
#elseif ANIMATE
FlxG.switchState(new funkin.animate.dotstuff.DotStuffTestStage());
#elseif CHARTING
FlxG.switchState(new ChartingState());
#elseif STAGEBUILD
FlxG.switchState(new StageBuilderState());
#elseif FIGHT
FlxG.switchState(new PicoFight());
#elseif ANIMDEBUG
2022-03-23 05:18:23 +00:00
FlxG.switchState(new funkin.ui.animDebugShit.DebugBoundingState());
2022-07-05 18:24:02 +00:00
#elseif LATENCY
FlxG.switchState(new LatencyState());
#elseif NETTEST
FlxG.switchState(new netTest.NetTest());
#else
FlxG.sound.cache(Paths.music('freakyMenu'));
FlxG.switchState(new TitleState());
#end
}
2022-02-11 19:21:42 +00:00
2022-02-10 01:24:33 +00:00
function startSong(week, song, isStoryMode)
{
var dif = getDif();
2022-02-11 19:21:42 +00:00
PlayState.currentSong = SongLoad.loadFromJson(song, song);
2022-09-22 10:34:03 +00:00
PlayState.currentSong_NEW = SongDataParser.fetchSong(song);
2022-02-10 01:24:33 +00:00
PlayState.isStoryMode = isStoryMode;
PlayState.storyDifficulty = dif;
PlayState.storyDifficulty_NEW = switch (dif)
2022-02-10 01:24:33 +00:00
{
case 0: 'easy';
case 1: 'normal';
case 2: 'hard';
default: 'normal';
};
SongLoad.curDiff = PlayState.storyDifficulty_NEW;
2022-02-10 01:24:33 +00:00
PlayState.storyWeek = week;
LoadingState.loadAndSwitchState(new PlayState());
}
}
2022-02-11 19:21:42 +00:00
function getWeek()
2022-02-23 21:49:54 +00:00
return Std.parseInt(MacroUtil.getDefine("week"));
2022-02-11 19:21:42 +00:00
function getSong()
2022-02-23 21:49:54 +00:00
return MacroUtil.getDefine("song");
2022-02-11 19:21:42 +00:00
function getDif()
2022-02-23 21:49:54 +00:00
return Std.parseInt(MacroUtil.getDefine("dif", "1"));