Skip to content

Commit

Permalink
support for command line arguments
Browse files Browse the repository at this point in the history
for easier modding or laziness? idk
  • Loading branch information
charlesisfeline committed Apr 7, 2024
1 parent 1aec7ea commit bb15635
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 4 deletions.
250 changes: 250 additions & 0 deletions source/debug/Argument.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
#if sys
package debug;

import backend.Difficulty;
import backend.Mods;
import backend.Song;
import backend.WeekData;
import options.OptionsState;
#if ACHIEVEMENTS_ALLOWED import states.AchievementsMenuState; #end
import states.CreditsState;
import states.FreeplayState;
import states.MainMenuState;
import states.ModsMenuState;
import states.PlayState;
import states.StoryMenuState;
import states.editors.CharacterEditorState;
import states.editors.ChartingState;
import states.editors.MasterEditorMenu;

using StringTools;

class Argument
{
public static function parse(args:Array<String>):Bool
{
switch (args[0])
{
default:
return false;

case '-h' | '--help':
{
var exePath:Array<String> = Sys.programPath().split(#if windows '\\' #else '/' #end);
var exeName:String = exePath[exePath.length - 1].replace('.exe', '');

Sys.println('
Usage:
${exeName} (menu | storymode | freeplay | mods ${#if ACHIEVEMENTS_ALLOWED '| awards' #end} | thanks | savefile | credits | options)
${exeName} play "Song Name" ["Mod Folder"] [-s | --story] [-d=<val> | --diff=<val>]
${exeName} chart "Song Name" ["Mod Folder"] [-d=<val> | --diff=<val>]
${exeName} debug ["Mod Folder"]
${exeName} editcharacter <char> ["Mod Folder"]
${exeName} editweek ["Mod Folder"]
${exeName} editcredits ["Mod Folder"]
${exeName} editdialogue ["Mod Folder"]
${exeName} editdialchar ["Mod Folder"]
${exeName} editmenuchar ["Mod Folder"]
${exeName} editsplash ["Mod Folder"]
${exeName} editcredits ["Mod Folder"]
${exeName} -h | --help

Options:
-h --help Show this screen.
-c --charsel Enables selecting a character when going to PlayState.
-s --story Enables story mode when in PlayState.
-d=<val> --diff=<val> Sets the difficulty for the song. [default: ${Difficulty.getDefault().toLowerCase().trim()}]
');

Sys.exit(0);
}

case 'menu':
{
LoadingState.loadAndSwitchState(() -> new MainMenuState());
}

case 'storymode':
{
LoadingState.loadAndSwitchState(() -> new StoryMenuState());
}

case 'freeplay':
{
LoadingState.loadAndSwitchState(() -> new FreeplayState());
}

case 'menu':
{
LoadingState.loadAndSwitchState(() -> new SaveFileState());
}

case 'mods':
{
LoadingState.loadAndSwitchState(() -> new ModsMenuState());
}

case 'thanks':
{
LoadingState.loadAndSwitchState(() -> new ThanksState());
}
case 'thanks':
{
LoadingState.loadAndSwitchState(() -> new ThanksState());
}

#if ACHIEVEMENTS_ALLOWED
case 'awards':
{
LoadingState.loadAndSwitchState(() -> new AchievementsMenuState());
}
#end

case 'credits':
{
LoadingState.loadAndSwitchState(() -> new CreditsState());
}

case 'options':
{
LoadingState.loadAndSwitchState(() -> new OptionsState());
}

case 'play':
{
var modFolder:String = null;
var diff:String = null;
var characterSelect:Bool = false;
for (i in 2...args.length)
{
if (args[i] == '-c' || args[i] == '--charsel')
characterSelect = true;
else if (args[i] == '-s' || args[i] == '--story')
PlayState.isStoryMode = true;
else if (args[i].startsWith('-d=') || args[i].startsWith('--diff='))
diff = (args[i].split('='))[1];
else if (modFolder != null)
modFolder = args[i];
}

setupSong(args[1], modFolder, diff);
if (characterSelect)
LoadingState.loadAndSwitchState(() -> new CharacterSelectionState(), true);
else
LoadingState.loadAndSwitchState(() -> new PlayState(), true);
}

case 'chart':
{
var modFolder:String = null;
var diff:String = null;
for (i in 2...args.length)
{
if (args[i].startsWith('-d') || args[i].startsWith('--diff'))
diff = (args[i].split('='))[1];
else if (modFolder != null)
modFolder = args[i];
}

setupSong(args[1], args[2], diff);
LoadingState.loadAndSwitchState(() -> new ChartingState(), true);
}

case 'debug':
{
if (args[1] != null)
Mods.currentModDirectory = args[1];
LoadingState.loadAndSwitchState(() -> new MasterEditorMenu());
}

case 'editcharacter':
{
if (args[2] != null)
Mods.currentModDirectory = args[2];
LoadingState.loadAndSwitchState(() -> new CharacterEditorState(args[1]));
}

case 'editweek':
{
if (args[1] != null)
Mods.currentModDirectory = args[1];
LoadingState.loadAndSwitchState(() -> new WeekEditorState());
}
case 'editcredits':
{
if (args[1] != null)
Mods.currentModDirectory = args[1];
LoadingState.loadAndSwitchState(() -> new CreditsEditor());
}
case 'editsplash':
{
if (args[1] != null)
Mods.currentModDirectory = args[1];
LoadingState.loadAndSwitchState(() -> new NoteSplashDebugState());
}
case 'editmenuchar':
{
if (args[1] != null)
Mods.currentModDirectory = args[1];
LoadingState.loadAndSwitchState(() -> new MenuCharacterEditorState());
}
case 'editdialogue':
{
if (args[1] != null)
Mods.currentModDirectory = args[1];
LoadingState.loadAndSwitchState(() -> new DialogueEditorState());
}
case 'editdialchar':
{
if (args[1] != null)
Mods.currentModDirectory = args[1];
LoadingState.loadAndSwitchState(() -> new DialogueCharacterEditorState());
}
case 'setupmod':
{
if (args[1] != null)
Mods.currentModDirectory = args[1];
LoadingState.loadAndSwitchState(() -> new ModsSetupState());
}
}

return true;
}

static function setupSong(songName:String, ?modFolder:String, ?diff:String):Void
{
WeekData.reloadWeekFiles(PlayState.isStoryMode);

if (modFolder == null)
{
var songFound:Bool = false;
for (weekData in WeekData.weeksList)
{
if (songFound)
break;

var week:WeekData = WeekData.weeksLoaded.get(weekData);

for (weekSong in week.songs)
{
if (Paths.formatToSongPath(weekSong[0]) == Paths.formatToSongPath(songName))
{
WeekData.setDirectoryFromWeek(week);
Difficulty.loadFromWeek(week);
songFound = true;
break;
}
}
}
}
else
{
Mods.currentModDirectory = modFolder;
}

var defaultDiff:Bool = diff == null || (diff != null && diff.toLowerCase().trim() == Difficulty.getDefault().toLowerCase().trim());
var jsonName:String = songName + (!defaultDiff ? '-${diff}' : '');
PlayState.SONG = Song.loadFromJson(jsonName, songName);
}
}
#end
3 changes: 3 additions & 0 deletions source/psychlua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class FunkinLua {
set('startedCountdown', false);
set('curStage', PlayState.SONG.stage);

set('primaryModifier', Main.modifier_keys[0]); // Control or Command
set('secondaryModifier', Main.modifier_keys[1]); // Alt or Option

set('isStoryMode', PlayState.isStoryMode);
set('difficulty', PlayState.storyDifficulty);

Expand Down
5 changes: 4 additions & 1 deletion source/psychlua/LuaUtils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,12 @@ class LuaUtils

public static function cameraFromString(cam:String):FlxCamera {
switch(cam.toLowerCase()) {
case 'camgame' | 'game': return PlayState.instance.camGame;
case 'camhud' | 'hud': return PlayState.instance.camHUD;
case 'camother' | 'other': return PlayState.instance.camOther;
}
return PlayState.instance.camGame;
var camera:Dynamic = PlayState.instance.variables.get(cam);
if (camera == null || !Std.isOfType(camera, FlxCamera)) camera = PlayState.instance.camGame;
return camera;
}
}
18 changes: 15 additions & 3 deletions source/states/StartingState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import backend.Highscore;
import flixel.input.keyboard.FlxKey;
import flixel.addons.transition.FlxTransitionableState;
import states.StoryMenuState;
import states.TitleState;

#if sys
import debug.Argument;
#end

class StartingState extends MusicBeatState {
public static var muteKeys:Array<FlxKey> = [FlxKey.ZERO];
Expand All @@ -26,13 +31,20 @@ class StartingState extends MusicBeatState {

FlxG.mouse.visible = false;

#if sys
if (!TitleState.initialized && Argument.parse(Sys.args()))
{
TitleState.initialized = true;
FlxG.sound.playMusic(Paths.music('freakyMenu'), 0);
return;
}
#end

if(FlxG.save.data.flashing == null && !FlashingState.leftState) {
FlxTransitionableState.skipNextTransIn = true;
FlxTransitionableState.skipNextTransOut = true;
FlxG.switchState(() -> new FlashingState());
} else {
FlxG.switchState(() -> new TitleState());
}
} else FlxG.switchState(() -> new TitleState());
}

public function _loadShits() {
Expand Down

0 comments on commit bb15635

Please sign in to comment.