mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-14 19:25:16 -05:00
wtf am i doing
This commit is contained in:
parent
fb3ed180e1
commit
99f6ad9d50
4 changed files with 255 additions and 139 deletions
|
@ -48,7 +48,7 @@ haxelib git polymod https://github.com/larsiusprime/polymod.git
|
|||
### Ignored files
|
||||
|
||||
I gitignore the API keys for the game, so that no one can nab them and post fake highscores on the leaderboards. But because of that the game
|
||||
doesn't compile without it.
|
||||
doesn't compile without it. Below is a version of APIStuff that points at a debug NG project for the game.
|
||||
|
||||
Just make a file in `/source` and call it `APIStuff.hx`, and copy paste this into it
|
||||
|
||||
|
@ -57,8 +57,9 @@ package;
|
|||
|
||||
class APIStuff
|
||||
{
|
||||
public static var API:String = "";
|
||||
public static var EncKey:String = "";
|
||||
inline public static var API:String = "51348:TtzK0rZ8";
|
||||
inline public static var EncKey:String = "5NqKsSVSNKHbF9fPgZPqPg==";
|
||||
inline public static var SESSION:String = null;
|
||||
}
|
||||
|
||||
```
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package;
|
||||
|
||||
import flixel.util.FlxTimer;
|
||||
import flixel.FlxState;
|
||||
import cpp.abi.Abi;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxObject;
|
||||
import flixel.FlxSprite;
|
||||
|
@ -14,19 +17,13 @@ import flixel.util.FlxColor;
|
|||
import io.newgrounds.NG;
|
||||
import lime.app.Application;
|
||||
|
||||
import ui.MenuItemList;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class MainMenuState extends MusicBeatState
|
||||
{
|
||||
var curSelected:Int = 0;
|
||||
|
||||
var menuItems:FlxTypedGroup<FlxSprite>;
|
||||
|
||||
#if !switch
|
||||
var optionShit:Array<String> = ['story mode', 'freeplay', 'donate'];
|
||||
#else
|
||||
var optionShit:Array<String> = ['story mode', 'freeplay'];
|
||||
#end
|
||||
var menuItems:MenuItemList;
|
||||
|
||||
var magenta:FlxSprite;
|
||||
var camFollow:FlxObject;
|
||||
|
@ -67,23 +64,38 @@ class MainMenuState extends MusicBeatState
|
|||
add(magenta);
|
||||
// magenta.scrollFactor.set();
|
||||
|
||||
menuItems = new FlxTypedGroup<FlxSprite>();
|
||||
menuItems = new MenuItemList('FNF_main_menu_assets');
|
||||
add(menuItems);
|
||||
|
||||
var tex = Paths.getSparrowAtlas('FNF_main_menu_assets');
|
||||
|
||||
for (i in 0...optionShit.length)
|
||||
menuItems.onChange.add(onMenuItemChange);
|
||||
menuItems.onAcceptPress.add(function(_)
|
||||
{
|
||||
var menuItem:FlxSprite = new FlxSprite(0, 60 + (i * 160));
|
||||
menuItem.frames = tex;
|
||||
menuItem.animation.addByPrefix('idle', optionShit[i] + " basic", 24);
|
||||
menuItem.animation.addByPrefix('selected', optionShit[i] + " white", 24);
|
||||
menuItem.animation.play('idle');
|
||||
menuItem.ID = i;
|
||||
menuItem.screenCenter(X);
|
||||
menuItems.add(menuItem);
|
||||
menuItem.scrollFactor.set();
|
||||
menuItem.antialiasing = true;
|
||||
FlxFlicker.flicker(magenta, 1.1, 0.15, false, true);
|
||||
});
|
||||
|
||||
|
||||
var hasPopupBlocker = #if web true #else false #end;
|
||||
|
||||
menuItems.addItem('story mode', function () startExitState(new StoryMenuState()));
|
||||
menuItems.addItem('freeplay', function () startExitState(new FreeplayState()));
|
||||
// addMenuItem('options', function () startExitState(new OptionMenu()));
|
||||
#if (!switch)
|
||||
menuItems.addItem('donate', selectDonate, hasPopupBlocker);
|
||||
#end
|
||||
#if newgrounds
|
||||
if (NG.core.loggedIn)
|
||||
menuItems.addItem("logout", selectLogout);
|
||||
else
|
||||
menuItems.addItem("login", selectLogin, hasPopupBlocker);
|
||||
#end
|
||||
|
||||
// center vertically
|
||||
var spacing = 160;
|
||||
var top = (FlxG.height - (spacing * (menuItems.length - 1))) / 2;
|
||||
for (i in 0...menuItems.length)
|
||||
{
|
||||
var menuItem = menuItems.members[i];
|
||||
menuItem.x = FlxG.width / 2;
|
||||
menuItem.y = top + spacing * i;
|
||||
}
|
||||
|
||||
FlxG.camera.follow(camFollow, null, 0.06);
|
||||
|
@ -95,12 +107,48 @@ class MainMenuState extends MusicBeatState
|
|||
|
||||
// NG.core.calls.event.logEvent('swag').send();
|
||||
|
||||
changeItem();
|
||||
|
||||
super.create();
|
||||
}
|
||||
|
||||
var selectedSomethin:Bool = false;
|
||||
function onMenuItemChange(selected:MenuItem)
|
||||
{
|
||||
camFollow.setPosition(selected.getGraphicMidpoint().x, selected.getGraphicMidpoint().y);
|
||||
}
|
||||
|
||||
function selectDonate()
|
||||
{
|
||||
#if linux
|
||||
Sys.command('/usr/bin/xdg-open', ["https://ninja-muffin24.itch.io/funkin", "&"]);
|
||||
#else
|
||||
FlxG.openURL('https://ninja-muffin24.itch.io/funkin');
|
||||
#end
|
||||
}
|
||||
|
||||
function selectLogin()
|
||||
{
|
||||
}
|
||||
|
||||
function selectLogout()
|
||||
{
|
||||
}
|
||||
|
||||
function startExitState(state:FlxState)
|
||||
{
|
||||
var duration = 0.4;
|
||||
menuItems.forEach(function(item)
|
||||
{
|
||||
if (menuItems.selectedIndex != item.ID)
|
||||
{
|
||||
FlxTween.tween(item, {alpha: 0}, duration, { ease: FlxEase.quadOut });
|
||||
}
|
||||
else
|
||||
{
|
||||
item.visible = false;
|
||||
}
|
||||
});
|
||||
|
||||
new FlxTimer().start(duration, function(_) FlxG.switchState(state));
|
||||
}
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
|
@ -109,108 +157,9 @@ class MainMenuState extends MusicBeatState
|
|||
FlxG.sound.music.volume += 0.5 * FlxG.elapsed;
|
||||
}
|
||||
|
||||
if (!selectedSomethin)
|
||||
{
|
||||
if (controls.UP_P)
|
||||
{
|
||||
FlxG.sound.play(Paths.sound('scrollMenu'));
|
||||
changeItem(-1);
|
||||
}
|
||||
|
||||
if (controls.DOWN_P)
|
||||
{
|
||||
FlxG.sound.play(Paths.sound('scrollMenu'));
|
||||
changeItem(1);
|
||||
}
|
||||
|
||||
if (controls.BACK)
|
||||
{
|
||||
if (menuItems.active && controls.BACK)
|
||||
FlxG.switchState(new TitleState());
|
||||
}
|
||||
|
||||
if (controls.ACCEPT)
|
||||
{
|
||||
if (optionShit[curSelected] == 'donate')
|
||||
{
|
||||
#if linux
|
||||
Sys.command('/usr/bin/xdg-open', ["https://ninja-muffin24.itch.io/funkin", "&"]);
|
||||
#else
|
||||
FlxG.openURL('https://ninja-muffin24.itch.io/funkin');
|
||||
#end
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedSomethin = true;
|
||||
FlxG.sound.play(Paths.sound('confirmMenu'));
|
||||
|
||||
FlxFlicker.flicker(magenta, 1.1, 0.15, false);
|
||||
|
||||
menuItems.forEach(function(spr:FlxSprite)
|
||||
{
|
||||
if (curSelected != spr.ID)
|
||||
{
|
||||
FlxTween.tween(spr, {alpha: 0}, 0.4, {
|
||||
ease: FlxEase.quadOut,
|
||||
onComplete: function(twn:FlxTween)
|
||||
{
|
||||
spr.kill();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
FlxFlicker.flicker(spr, 1, 0.06, false, false, function(flick:FlxFlicker)
|
||||
{
|
||||
var daChoice:String = optionShit[curSelected];
|
||||
|
||||
switch (daChoice)
|
||||
{
|
||||
case 'story mode':
|
||||
FlxG.switchState(new StoryMenuState());
|
||||
trace("Story Menu Selected");
|
||||
case 'freeplay':
|
||||
FlxG.switchState(new FreeplayState());
|
||||
|
||||
trace("Freeplay Menu Selected");
|
||||
|
||||
case 'options':
|
||||
FlxG.switchState(new OptionsMenu());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.update(elapsed);
|
||||
|
||||
menuItems.forEach(function(spr:FlxSprite)
|
||||
{
|
||||
spr.screenCenter(X);
|
||||
});
|
||||
}
|
||||
|
||||
function changeItem(huh:Int = 0)
|
||||
{
|
||||
curSelected += huh;
|
||||
|
||||
if (curSelected >= menuItems.length)
|
||||
curSelected = 0;
|
||||
if (curSelected < 0)
|
||||
curSelected = menuItems.length - 1;
|
||||
|
||||
menuItems.forEach(function(spr:FlxSprite)
|
||||
{
|
||||
spr.animation.play('idle');
|
||||
|
||||
if (spr.ID == curSelected)
|
||||
{
|
||||
spr.animation.play('selected');
|
||||
camFollow.setPosition(spr.getGraphicMidpoint().x, spr.getGraphicMidpoint().y);
|
||||
}
|
||||
|
||||
spr.updateHitbox();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import flixel.FlxG;
|
|||
import flixel.util.FlxSignal;
|
||||
import flixel.util.FlxTimer;
|
||||
import io.newgrounds.NG;
|
||||
import io.newgrounds.NGLite;
|
||||
import io.newgrounds.components.ScoreBoardComponent.Period;
|
||||
import io.newgrounds.objects.Medal;
|
||||
import io.newgrounds.objects.Score;
|
||||
|
@ -43,7 +44,7 @@ class NGio
|
|||
{
|
||||
var call = NG.core.calls.app.getCurrentVersion(GAME_VER).addDataHandler(function(response:Response<GetCurrentVersionResult>)
|
||||
{
|
||||
GAME_VER = response.result.data.current_version;
|
||||
GAME_VER = response.result.data.currentVersion;
|
||||
trace('CURRENT NG VERSION: ' + GAME_VER);
|
||||
gotOnlineVer = true;
|
||||
});
|
||||
|
@ -53,18 +54,28 @@ class NGio
|
|||
}
|
||||
}
|
||||
|
||||
public function new(api:String, encKey:String, ?sessionId:String)
|
||||
public function new(api:String, encKey:String)
|
||||
{
|
||||
trace("connecting to newgrounds");
|
||||
|
||||
NG.createAndCheckSession(api, sessionId);
|
||||
var sessionId:String = NGLite.getSessionId();
|
||||
if (sessionId != null)
|
||||
trace("found web session id");
|
||||
|
||||
#if (debug)
|
||||
if (sessionId == null && APIStuff.SESSION != null)
|
||||
{
|
||||
sessionId = APIStuff.SESSION;
|
||||
trace("using debug session id");
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
NG.create(api, sessionId);
|
||||
NG.core.verbose = true;
|
||||
// Set the encryption cipher/format to RC4/Base64. AES128 and Hex are not implemented yet
|
||||
NG.core.initEncryption(encKey); // Found in you NG project view
|
||||
|
||||
trace(NG.core.attemptingLogin);
|
||||
|
||||
if (NG.core.attemptingLogin)
|
||||
{
|
||||
/* a session_id was found in the loadervars, this means the user is playing on newgrounds.com
|
||||
|
@ -73,6 +84,7 @@ class NGio
|
|||
trace("attempting login");
|
||||
NG.core.onLogin.add(onNGLogin);
|
||||
}
|
||||
//GK: taking out auto login, adding a login button to the main menu
|
||||
else
|
||||
{
|
||||
/* They are NOT playing on newgrounds.com, no session id was found. We must start one manually, if we want to.
|
||||
|
|
154
source/ui/MenuItemList.hx
Normal file
154
source/ui/MenuItemList.hx
Normal file
|
@ -0,0 +1,154 @@
|
|||
package ui;
|
||||
|
||||
import flixel.util.typeLimit.OneOfTwo;
|
||||
import flixel.math.FlxPoint;
|
||||
import flixel.FlxG;
|
||||
import flixel.effects.FlxFlicker;
|
||||
import flixel.graphics.frames.FlxAtlasFrames;
|
||||
import flixel.group.FlxGroup;
|
||||
import flixel.tweens.FlxEase;
|
||||
import flixel.tweens.FlxTween;
|
||||
import flixel.util.FlxSignal;
|
||||
|
||||
typedef ItemAsset = OneOfTwo<String, FlxAtlasFrames>
|
||||
|
||||
class MenuItemList extends MenuTypedItemList<MenuItem>
|
||||
{
|
||||
public function addItem(x = 0.0, y = 0.0, name, callback, fireInstantly = false)
|
||||
{
|
||||
var i = length;
|
||||
var menuItem = new MenuItem(name, tex, callback, x, y);
|
||||
menuItem.fireInstantly = fireInstantly;
|
||||
menuItem.ID = i;
|
||||
add(menuItem);
|
||||
|
||||
if (i == selectedIndex)
|
||||
menuItem.select();
|
||||
|
||||
return menuItem;
|
||||
}
|
||||
}
|
||||
|
||||
class MenuTypedItemList<T:MenuItem> extends FlxTypedGroup<T>
|
||||
{
|
||||
public var tex:FlxAtlasFrames;
|
||||
public var selectedIndex = 0;
|
||||
public var onChange(default, null) = new FlxTypedSignal<T->Void>();
|
||||
public var onAcceptPress(default, null) = new FlxTypedSignal<T->Void>();
|
||||
|
||||
public function new (asset:ItemAsset)
|
||||
{
|
||||
super();
|
||||
|
||||
if (Std.is(asset, String))
|
||||
tex = Paths.getSparrowAtlas(cast asset);
|
||||
else
|
||||
tex = cast asset;
|
||||
}
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
super.update(elapsed);
|
||||
|
||||
var controls = PlayerSettings.player1.controls;
|
||||
|
||||
if (controls.UP_P)
|
||||
prev();
|
||||
|
||||
if (controls.DOWN_P)
|
||||
next();
|
||||
|
||||
if (controls.ACCEPT)
|
||||
accept();
|
||||
}
|
||||
|
||||
public function accept()
|
||||
{
|
||||
var selected = members[selectedIndex];
|
||||
if (selected.fireInstantly)
|
||||
selected.callback();
|
||||
else
|
||||
{
|
||||
active = false;
|
||||
FlxG.sound.play(Paths.sound('confirmMenu'));
|
||||
FlxFlicker.flicker(selected, 1, 0.06, true, false, function(_)
|
||||
{
|
||||
selected.callback();
|
||||
active = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
inline function prev() changeItem(-1);
|
||||
inline function next() changeItem(1);
|
||||
|
||||
function changeItem(amount:Int)
|
||||
{
|
||||
FlxG.sound.play(Paths.sound('scrollMenu'));
|
||||
members[selectedIndex].idle();
|
||||
|
||||
selectedIndex += amount;
|
||||
|
||||
if (selectedIndex >= length)
|
||||
selectedIndex = 0;
|
||||
else if (selectedIndex < 0)
|
||||
selectedIndex = length - 1;
|
||||
|
||||
var selected = members[selectedIndex];
|
||||
selected.select();
|
||||
onChange.dispatch(selected);
|
||||
}
|
||||
|
||||
override function destroy()
|
||||
{
|
||||
super.destroy();
|
||||
tex = null;
|
||||
}
|
||||
}
|
||||
|
||||
class MenuItem extends flixel.FlxSprite
|
||||
{
|
||||
public var callback:Void->Void;
|
||||
/**
|
||||
* Set to true for things like opening URLs otherwise, it may it get blocked.
|
||||
*/
|
||||
public var fireInstantly = false;
|
||||
|
||||
public function new (name, tex, callback, x = 0.0, y = 0.0)
|
||||
{
|
||||
super(x, y);
|
||||
|
||||
frames = tex;
|
||||
setItem(name, callback);
|
||||
}
|
||||
|
||||
public function setItem(name:String, callback:Void->Void)
|
||||
{
|
||||
this.callback = callback;
|
||||
|
||||
animation.addByPrefix('idle', '$name basic', 24);
|
||||
animation.addByPrefix('selected', '$name white', 24);
|
||||
idle();
|
||||
scrollFactor.set();
|
||||
antialiasing = true;
|
||||
}
|
||||
|
||||
function updateSize()
|
||||
{
|
||||
updateHitbox();
|
||||
centerOrigin();
|
||||
offset.copyFrom(origin);
|
||||
}
|
||||
|
||||
public function idle()
|
||||
{
|
||||
animation.play('idle');
|
||||
updateSize();
|
||||
}
|
||||
|
||||
public function select()
|
||||
{
|
||||
animation.play('selected');
|
||||
updateSize();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue