Skip to content

Commit

Permalink
squashed commits
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Jan 22, 2025
1 parent dfe02ec commit c5a3757
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 49 deletions.
7 changes: 7 additions & 0 deletions hmm.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@
"dir": null,
"ref": "bdb191fe7cf745c02a980749906dbf22719e200b",
"url": "https://github.com/fponticelli/thx.semver"
},
{
"name": "HtmlParser",
"type": "git",
"dir": "library",
"ref": "28dad3f2cc40240d0aac8b595b4002b87f5986c3",
"url": "https://github.com/yar3333/haxe-htmlparser"
}
]
}
2 changes: 2 additions & 0 deletions project.hxp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ class Project extends HXProject {
addHaxelib('thx.core'); // General utility library, "the lodash of Haxe"
addHaxelib('thx.semver'); // Version string handling

addHaxelib('HtmlParser');

if (isDebug()) {
addHaxelib('hxcpp-debug-server'); // VSCode debug support
}
Expand Down
7 changes: 5 additions & 2 deletions source/funkin/InitState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import funkin.data.story.level.LevelRegistry;
import funkin.modding.module.ModuleHandler;
import funkin.play.character.CharacterData.CharacterDataParser;
import funkin.play.notes.notekind.NoteKindManager;
import funkin.ui.title.OutdatedState;
import funkin.play.PlayStatePlaylist;
import funkin.ui.debug.charting.ChartEditorState;
import funkin.ui.title.TitleState;
import funkin.ui.transition.LoadingState;
import funkin.modding.module.ModuleHandler;
import funkin.ui.title.OutdatedState;
import funkin.util.CLIUtil;
import funkin.util.CLIUtil.CLIParams;
import funkin.util.macro.MacroUtil;
Expand Down Expand Up @@ -195,7 +198,7 @@ class InitState extends FlxState
/**
* Start the game.
*
* By default, moves to the `TitleState`.
* By default, moves to the `TitleState` or `OutdatedState`.
* But based on compile defines, the game can start immediately on a specific song,
* or immediately in a specific debug menu.
*/
Expand Down Expand Up @@ -286,7 +289,7 @@ class InitState extends FlxState
else
{
FlxG.sound.cache(Paths.music('freakyMenu/freakyMenu'));
FlxG.switchState(() -> new TitleState());
FlxG.switchState(() -> OutdatedState.build());
}
}

Expand Down
145 changes: 145 additions & 0 deletions source/funkin/ui/title/OutdatedState.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package funkin.ui.title;

import haxe.Http;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import funkin.graphics.FunkinSprite;
import funkin.ui.MusicBeatState;
import funkin.util.Constants;
import funkin.util.VersionUtil;
import htmlparser.HtmlDocument;
import htmlparser.HtmlNodeElement;

using StringTools;

/**
* Class that notifies the player that there is an update
*/
class OutdatedState extends MusicBeatState
{
static final URL:String = 'https://ninja-muffin24.itch.io/funkin';

#if windows static final OS_CHECK:String = 'Windows'; #end
#if mac static final OS_CHECK:String = 'macOS'; #end
#if linux static final OS_CHECK:String = 'Linux'; #end

/**
* Whether the game is outdated or not
*/
public static var outdated(get, never):Bool;

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

var leftState:Bool = false;

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

return VersionUtil.validateVersionStr(currentVersion, '<' + newVersion);
}

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

var bg:FunkinSprite = new FunkinSprite().makeSolidColor(FlxG.width, FlxG.height, FlxColor.BLACK);
add(bg);

var txt:FlxText = new FlxText(0, 0, FlxG.width,
'HEY! You\'re running an outdated version of the game!\nCurrent version is '
+ currentVersion
+ ' while the most recent version is '
+ newVersion
+ '!\n Press ACCEPT-Button to go to itch.io, '
+ '\nor BACK-Button 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):Void
{
super.update(elapsed);

if (leftState)
{
return;
}

if (controls.ACCEPT)
{
FlxG.openURL('https://ninja-muffin24.itch.io/funkin');
}

if (controls.BACK)
{
leftState = true;

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

FlxG.switchState(() -> new TitleState());
}
}

static function retrieveVersions():Void
{
// i wanted to use the itch io api
// but i couldnt find a way to get the uploaded files
// so instead im just gonna parse the html

var html:Null<HtmlDocument> = null;

var http:Http = new Http(URL);
http.onData = function(data) {
html = new HtmlDocument(data);
};
http.request(false);

if (html == null)
{
return;
}

var uploadedFiles:Array<HtmlNodeElement> = html.find('.upload');

for (file in uploadedFiles)
{
var os:String = file.find('.download_platforms')[0].children[0].getAttribute('title');
if (!os.endsWith(OS_CHECK))
{
continue;
}

newVersion = file.find('.version_name')[0].innerHTML.replace('Version', '').trim();
}

newVersion = newVersion ?? Constants.VERSION;
currentVersion = Constants.VERSION;
}

/**
* @return `OutdatedState` or `TitleState`
*/
public static function build():MusicBeatState
{
#if debug
return new TitleState();
#else
return outdated ? new OutdatedState() : new TitleState();
#end
}
}
47 changes: 0 additions & 47 deletions source/funkin/ui/title/OutdatedSubState.hx

This file was deleted.

0 comments on commit c5a3757

Please sign in to comment.