diff --git a/Project.xml b/Project.xml
index bb9ef84de..174fbf25b 100644
--- a/Project.xml
+++ b/Project.xml
@@ -113,7 +113,7 @@
-
+
@@ -167,11 +167,17 @@
-
-
-
-
-
-
+
+
+
diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx
index b39ebc973..872e44d27 100644
--- a/source/FreeplayState.hx
+++ b/source/FreeplayState.hx
@@ -211,9 +211,7 @@ class FreeplayState extends MusicBeatState
if (curDifficulty > 2)
curDifficulty = 0;
- #if !switch
intendedScore = Highscore.getScore(songs[curSelected], curDifficulty);
- #end
switch (curDifficulty)
{
@@ -228,9 +226,7 @@ class FreeplayState extends MusicBeatState
function changeSelection(change:Int = 0)
{
- #if !switch
NGio.logEvent('Fresh');
- #end
// NGio.logEvent('Fresh');
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
@@ -244,10 +240,8 @@ class FreeplayState extends MusicBeatState
// selector.y = (70 * curSelected) + 30;
- #if !switch
intendedScore = Highscore.getScore(songs[curSelected], curDifficulty);
// lerpScore = 0;
- #end
#if PRELOAD_ALL
FlxG.sound.playMusic(Paths.inst(songs[curSelected]), 0);
diff --git a/source/Highscore.hx b/source/Highscore.hx
index 5fbc73298..2fee324fd 100644
--- a/source/Highscore.hx
+++ b/source/Highscore.hx
@@ -13,51 +13,55 @@ class Highscore
public static function saveScore(song:String, score:Int = 0, ?diff:Int = 0):Void
{
- var daSong:String = formatSong(song, diff);
+ var formattedSong:String = formatSong(song, diff);
-
- #if !switch
+ #if newgrounds
NGio.postScore(score, song);
#end
-
- if (songScores.exists(daSong))
+ if (songScores.exists(formattedSong))
{
- if (songScores.get(daSong) < score)
- setScore(daSong, score);
+ if (songScores.get(formattedSong) < score)
+ setScore(formattedSong, score);
}
else
- setScore(daSong, score);
+ setScore(formattedSong, score);
}
public static function saveWeekScore(week:Int = 1, score:Int = 0, ?diff:Int = 0):Void
{
-
- #if !switch
+ #if newgrounds
NGio.postScore(score, "Week " + week);
#end
+ var formattedSong:String = formatSong('week' + week, diff);
- var daWeek:String = formatSong('week' + week, diff);
-
- if (songScores.exists(daWeek))
+ if (songScores.exists(formattedSong))
{
- if (songScores.get(daWeek) < score)
- setScore(daWeek, score);
+ if (songScores.get(formattedSong) < score)
+ setScore(formattedSong, score);
}
else
- setScore(daWeek, score);
+ setScore(formattedSong, score);
}
/**
* YOU SHOULD FORMAT SONG WITH formatSong() BEFORE TOSSING IN SONG VARIABLE
*/
- static function setScore(song:String, score:Int):Void
+ static function setScore(formattedSong:String, score:Int):Void
{
+ /** GeoKureli
+ * References to Highscore were wrapped in `#if !switch` blocks. I wasn't sure if this
+ * is because switch doesn't use NGio, or because switch has a different saving method.
+ * I moved the compiler flag here, rather than using it everywhere else.
+ */
+ #if !switch
+
// Reminder that I don't need to format this song, it should come formatted!
- songScores.set(song, score);
+ songScores.set(formattedSong, score);
FlxG.save.data.songScores = songScores;
FlxG.save.flush();
+ #end
}
public static function formatSong(song:String, diff:Int):String
diff --git a/source/MainMenuState.hx b/source/MainMenuState.hx
index db00ce94d..b207f97e5 100644
--- a/source/MainMenuState.hx
+++ b/source/MainMenuState.hx
@@ -15,7 +15,6 @@ import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
-import io.newgrounds.NG;
import lime.app.Application;
import ui.MenuItemList;
@@ -81,11 +80,11 @@ class MainMenuState extends MusicBeatState
menuItems.createItem('story mode', function () startExitState(new StoryMenuState()));
menuItems.createItem('freeplay', function () startExitState(new FreeplayState()));
// addMenuItem('options', function () startExitState(new OptionMenu()));
- #if (!switch)
+ #if CAN_OPEN_LINKS
menuItems.createItem('donate', selectDonate, hasPopupBlocker);
#end
#if newgrounds
- if (NG.core.loggedIn)
+ if (NGio.isLoggedIn)
menuItems.createItem("logout", selectLogout);
else
menuItems.createItem("login", selectLogin);
@@ -119,8 +118,10 @@ class MainMenuState extends MusicBeatState
menuItems.enabled = true;
+ #if newgrounds
if (NGio.savedSessionFailed)
showSavedSessionFailed();
+ #end
}
function onMenuItemChange(selected:MenuItem)
@@ -150,32 +151,37 @@ class MainMenuState extends MusicBeatState
function showNgPrompt(fromUi:Bool)
{
- menuItems.enabled = false;
-
- var prompt = new Prompt("prompt-ng_login", "Talking to server...", None);
- prompt.closeCallback = function() menuItems.enabled = true;
+ var prompt = createNGPrompt("Talking to server...", None);
openSubState(prompt);
function onLoginComplete(result:ConnectionResult)
{
switch (result)
{
case Success:
+ {
menuItems.resetItem("login", "logout", selectLogout);
prompt.setText("Login Successful");
prompt.setButtons(Ok);
prompt.onYes = prompt.close;
+ }
case Fail(msg):
+ {
trace("Login Error:" + msg);
prompt.setText("Login failed");
prompt.setButtons(Ok);
prompt.onYes = prompt.close;
+ }
case Cancelled:
+ {
if (prompt != null)
{
prompt.setText("Login cancelled by user");
prompt.setButtons(Ok);
prompt.onYes = prompt.close;
}
+ else
+ trace("Login cancelled via prompt");
+ }
}
}
@@ -196,7 +202,7 @@ class MainMenuState extends MusicBeatState
#end
prompt.onYes = function()
{
- prompt.setText("Connecting...");
+ prompt.setText("Connecting..." #if web + "\n(check your popup blocker)" #end);
prompt.setButtons(None);
openPassportUrl();
};
@@ -204,7 +210,7 @@ class MainMenuState extends MusicBeatState
{
prompt.close();
prompt = null;
- NG.core.cancelLoginRequest();
+ NGio.cancelLogin();
};
}
else
@@ -219,9 +225,8 @@ class MainMenuState extends MusicBeatState
function selectLogout()
{
- menuItems.enabled = false;
- var prompt = new Prompt("prompt-ng_login", "Log out of " + NG.core.user.name + "?", Yes_No);
- prompt.closeCallback = function () menuItems.enabled = true;
+ var user = io.newgrounds.NG.core.user.name;
+ var prompt = createNGPrompt('Log out of $user?', Yes_No);
prompt.onYes = function()
{
NGio.logout();
@@ -231,6 +236,22 @@ class MainMenuState extends MusicBeatState
prompt.onNo = prompt.close;
openSubState(prompt);
}
+
+ public function createNGPrompt(text:String, style:ButtonStyle = Yes_No)
+ {
+ var oldAutoPause = FlxG.autoPause;
+ FlxG.autoPause = false;
+ menuItems.enabled = false;
+
+ var prompt = new Prompt("prompt-ng_login", text, style);
+ prompt.closeCallback = function ()
+ {
+ menuItems.enabled = true;
+ FlxG.autoPause = oldAutoPause;
+ }
+
+ return prompt;
+ }
#end
function startExitState(state:FlxState)
diff --git a/source/NGio.hx b/source/NGio.hx
index b05b7e8aa..f82323e4b 100644
--- a/source/NGio.hx
+++ b/source/NGio.hx
@@ -1,4 +1,5 @@
package;
+#if newgrounds
import flixel.FlxG;
import flixel.util.FlxSignal;
@@ -17,19 +18,24 @@ import lime.app.Application;
import openfl.display.Stage;
using StringTools;
-
+#end
/**
* MADE BY GEOKURELI THE LEGENED GOD HERO MVP
*/
class NGio
{
+ #if newgrounds
/**
* True, if the saved sessionId was used in the initial login, and failed to connect.
* Used in MainMenuState to show a popup to establish a new connection
*/
public static var savedSessionFailed(default, null):Bool = false;
- public static var isLoggedIn:Bool = false;
public static var scoreboardsLoaded:Bool = false;
+ public static var isLoggedIn(get, never):Bool;
+ inline static function get_isLoggedIn()
+ {
+ return NG.core != null && NG.core.loggedIn;
+ }
public static var scoreboardArray:Array = [];
@@ -38,7 +44,6 @@ class NGio
public static var GAME_VER:String = "";
-
static public function checkVersion(callback:String->Void)
{
trace('checking NG.io version');
@@ -54,7 +59,7 @@ class NGio
.send();
}
- static public function init(api:String, encKey:String)
+ static public function init()
{
var api = APIStuff.API;
if (api == null || api.length == 0)
@@ -149,11 +154,15 @@ class NGio
NG.core.requestLogin(onSuccess, onPending, onFail, onCancel);
}
+
+ inline static public function cancelLogin():Void
+ {
+ NG.core.cancelLoginRequest();
+ }
static function onNGLogin():Void
{
trace('logged in! user:${NG.core.user.name}');
- isLoggedIn = true;
FlxG.save.data.sessionId = NG.core.sessionId;
FlxG.save.flush();
// Load medals then call onNGMedalFetch()
@@ -216,24 +225,6 @@ class NGio
// more info on scores --- http://www.newgrounds.io/help/components/#scoreboard-getscores
}
- inline static public function postScore(score:Int = 0, song:String)
- {
- if (isLoggedIn)
- {
- for (id in NG.core.scoreBoards.keys())
- {
- var board = NG.core.scoreBoards.get(id);
-
- if (song == board.name)
- {
- board.postScore(score, "Uhh meow?");
- }
-
- // trace('loaded scoreboard id:$id, name:${board.name}');
- }
- }
- }
-
static function onNGScoresFetch():Void
{
scoreboardsLoaded = true;
@@ -252,21 +243,52 @@ class NGio
// NGio.scoreboardArray = NG.core.scoreBoards.get(8004).scores;
}
+ #end
- inline static public function logEvent(event:String)
+ static public function logEvent(event:String)
{
+ #if newgrounds
NG.core.calls.event.logEvent(event).send();
trace('should have logged: ' + event);
+ #else
+ #if debug trace('event:$event - not logged, missing NG.io lib'); #end
+ #end
}
- inline static public function unlockMedal(id:Int)
+ static public function unlockMedal(id:Int)
{
+ #if newgrounds
if (isLoggedIn)
{
var medal = NG.core.medals.get(id);
if (!medal.unlocked)
medal.sendUnlock();
}
+ #else
+ #if debug trace('medal:$id - not unlocked, missing NG.io lib'); #end
+ #end
+ }
+
+ static public function postScore(score:Int = 0, song:String)
+ {
+ #if newgrounds
+ if (isLoggedIn)
+ {
+ for (id in NG.core.scoreBoards.keys())
+ {
+ var board = NG.core.scoreBoards.get(id);
+
+ if (song == board.name)
+ {
+ board.postScore(score, "Uhh meow?");
+ }
+
+ // trace('loaded scoreboard id:$id, name:${board.name}');
+ }
+ }
+ #else
+ #if debug trace('Song:$song, Score:$score - not posted, missing NG.io lib'); #end
+ #end
}
}
diff --git a/source/OptionsMenu.hx b/source/OptionsMenu.hx
index bf36c83d5..a938495db 100644
--- a/source/OptionsMenu.hx
+++ b/source/OptionsMenu.hx
@@ -93,9 +93,7 @@ class OptionsMenu extends MusicBeatState
function changeSelection(change:Int = 0)
{
- #if !switch
NGio.logEvent('Fresh');
- #end
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
diff --git a/source/PlayState.hx b/source/PlayState.hx
index 647357157..3366edf0a 100644
--- a/source/PlayState.hx
+++ b/source/PlayState.hx
@@ -1604,9 +1604,7 @@ class PlayState extends MusicBeatState
vocals.volume = 0;
if (SONG.validScore)
{
- #if !switch
Highscore.saveScore(SONG.song, songScore, storyDifficulty);
- #end
}
if (isStoryMode)
diff --git a/source/StoryMenuState.hx b/source/StoryMenuState.hx
index adb9d6cb3..b985369b8 100644
--- a/source/StoryMenuState.hx
+++ b/source/StoryMenuState.hx
@@ -352,10 +352,6 @@ class StoryMenuState extends MusicBeatState
sprDifficulty.y = leftArrow.y - 15;
intendedScore = Highscore.getWeekScore(curWeek, curDifficulty);
- #if !switch
- intendedScore = Highscore.getWeekScore(curWeek, curDifficulty);
- #end
-
FlxTween.tween(sprDifficulty, {y: leftArrow.y + 15, alpha: 1}, 0.07);
}
@@ -431,8 +427,6 @@ class StoryMenuState extends MusicBeatState
txtTracklist.screenCenter(X);
txtTracklist.x -= FlxG.width * 0.35;
- #if !switch
intendedScore = Highscore.getWeekScore(curWeek, curDifficulty);
- #end
}
}
diff --git a/source/TitleState.hx b/source/TitleState.hx
index ffc691947..2c3e2a43d 100644
--- a/source/TitleState.hx
+++ b/source/TitleState.hx
@@ -20,7 +20,6 @@ import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
-import io.newgrounds.NG;
import lime.app.Application;
import openfl.Assets;
@@ -56,9 +55,11 @@ class TitleState extends MusicBeatState
FlxG.save.bind('funkin', 'ninjamuffin99');
Highscore.load();
-
- NGio.init(APIStuff.API, APIStuff.EncKey);
-
+
+ #if newgrounds
+ NGio.init();
+ #end
+
if (FlxG.save.data.weekUnlocked != null)
{
// FIX LATER!!!
@@ -242,13 +243,11 @@ class TitleState extends MusicBeatState
if (pressedEnter && !transitioning && skippedIntro)
{
- #if !switch
NGio.unlockMedal(60960);
// If it's Friday according to da clock
if (Date.now().getDay() == 5)
NGio.unlockMedal(61034);
- #end
titleText.animation.play('press');
@@ -258,6 +257,7 @@ class TitleState extends MusicBeatState
transitioning = true;
// FlxG.sound.music.stop();
+ #if newgrounds
if (!OutdatedSubState.leftState)
{
NGio.checkVersion(function(version)
@@ -278,6 +278,9 @@ class TitleState extends MusicBeatState
}
});
}
+ #else
+ FlxG.switchState(new MainMenuState());
+ #end
// FlxG.sound.play(Paths.music('titleShoot'), 0.7);
}
diff --git a/source/ui/MenuItemList.hx b/source/ui/MenuItemList.hx
index a79ca1f2b..4991c9b2a 100644
--- a/source/ui/MenuItemList.hx
+++ b/source/ui/MenuItemList.hx
@@ -114,7 +114,8 @@ class MenuTypedItemList extends FlxTypedGroup
if (controls.RIGHT_P || controls.DOWN_P) next();
}
}
-
+
+ //Todo: bypass popup blocker on firefox
if (controls.ACCEPT)
accept();
}