diff --git a/source/funkin/ui/title/OutdatedSubState.hx b/source/funkin/ui/title/OutdatedSubState.hx index bc938f24a5..b05e0cea5f 100644 --- a/source/funkin/ui/title/OutdatedSubState.hx +++ b/source/funkin/ui/title/OutdatedSubState.hx @@ -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 = null; + static var newVersion:Null = 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) { @@ -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 diff --git a/source/funkin/ui/title/TitleState.hx b/source/funkin/ui/title/TitleState.hx index 8087916cbd..0659295462 100644 --- a/source/funkin/ui/title/TitleState.hx +++ b/source/funkin/ui/title/TitleState.hx @@ -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; @@ -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) @@ -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 = [0x0001, 0x0010, 0x0001, 0x0010, 0x0100, 0x1000, 0x0100, 0x1000];