Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add OutdatedSubState #2633

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 56 additions & 10 deletions source/funkin/ui/title/OutdatedSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,57 @@ import flixel.FlxSprite;
import flixel.FlxSubState;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import funkin.ui.MusicBeatState;
import funkin.graphics.FunkinSprite;
import funkin.ui.MusicBeatSubState;
import lime.app.Application;
import haxe.Http;

#if newgrounds
class OutdatedSubState extends MusicBeatState
class OutdatedSubState extends MusicBeatSubState
{
public static var leftState:Bool = false;

override function create()
static final URL:String = "https://raw.githubusercontent.com/FunkinCrew/Funkin/main/Project.xml";

static var currentVersion:Null<String> = null;
static var newVersion:Null<String> = null;

public static var outdated(get, never):Bool;

static function get_outdated():Bool
{
if (currentVersion == null || newVersion == null)
{
retrieveVersions();
}

return currentVersion != newVersion;
}

override function create():Void
{
super.create();

var bg:FunkinSprite = new FunkinSprite().makeSolidColor(FlxG.width, FlxG.height, FlxColor.BLACK);
add(bg);
var ver = "v" + Application.current.meta.get('version');

var txt:FlxText = new FlxText(0, 0, FlxG.width,
"HEY! You're running an outdated version of the game!\nCurrent version is "
+ ver
+ 'v$currentVersion'
+ " while the most recent version is "
+ NGio.GAME_VER
+ 'v$newVersion'
+ "! Press Space to go to itch.io, or ESCAPE to ignore this!!",
32);
txt.setFormat("VCR OSD Mono", 32, FlxColor.WHITE, CENTER);
txt.screenCenter();
add(txt);

if (FlxG.sound.music != null)
{
FlxG.sound.music.pause();
}
}

override function update(elapsed:Float)
override function update(elapsed:Float):Void
{
if (controls.ACCEPT)
{
Expand All @@ -39,9 +63,31 @@ class OutdatedSubState extends MusicBeatState
if (controls.BACK)
{
leftState = true;
FlxG.switchState(() -> new MainMenuState());

if (FlxG.sound.music != null)
{
FlxG.sound.music.resume();
}

this.close();
}
super.update(elapsed);
}

static function retrieveVersions():Void
{
var http:Http = new Http(URL);

http.onData = function(data:String) {
var xml:Xml = Xml.parse(data);
var project:Xml = xml.elementsNamed("project").next();
var app:Xml = project.elementsNamed("app").next();

newVersion = app.get("version").toString();
};

http.request(false);

currentVersion = Application.current.meta.get('version');
}
}
#end
27 changes: 21 additions & 6 deletions source/funkin/ui/title/TitleState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import openfl.events.AsyncErrorEvent;
import funkin.ui.mainmenu.MainMenuState;
import openfl.events.MouseEvent;
import openfl.events.NetStatusEvent;
import funkin.ui.freeplay.FreeplayState;
import funkin.ui.title.OutdatedSubState;
import openfl.media.Video;
import openfl.net.NetStream;
import funkin.api.newgrounds.NGio;
Expand Down Expand Up @@ -67,11 +67,24 @@ class TitleState extends MusicBeatState
// DEBUG BULLSHIT

// netConnection.addEventListener(MouseEvent.MOUSE_DOWN, overlay_onMouseDown);
if (!initialized) new FlxTimer().start(1, function(tmr:FlxTimer) {
startIntro();
});
if (!initialized)
{
new FlxTimer().start(1, function(tmr:FlxTimer) {
// TODO: maybe add a preprocessor which only enables this check for base version and disables for mods
#if (!web && !debug)
if (OutdatedSubState.outdated && !OutdatedSubState.leftState)
{
this.persistentUpdate = false;
this.openSubState(new OutdatedSubState());
}
#end
startIntro();
});
}
else
{
startIntro();
}
}

function client_onMetaData(metaData:Dynamic)
Expand Down Expand Up @@ -352,9 +365,11 @@ class TitleState extends MusicBeatState
super.update(elapsed);
}

override function draw()
override function closeSubState():Void
{
super.draw();
super.closeSubState();

this.persistentUpdate = true;
}

var cheatArray:Array<Int> = [0x0001, 0x0010, 0x0001, 0x0010, 0x0100, 0x1000, 0x0100, 0x1000];
Expand Down
Loading