working on update checking

This commit is contained in:
Yoshman29
2022-12-16 13:31:16 +01:00
parent 4a6bf6a08d
commit cd73a0a123
10 changed files with 356 additions and 15 deletions
+3 -1
View File
@@ -114,11 +114,13 @@
<haxedef name="USE_ADAPTED_ASSETS" />
<!-- Comment this out to disable video cutscene support, in case of compilation errors. !-->
<haxedef name="VIDEO_CUTSCENES" unless="web" />
<define name="VIDEO_CUTSCENES" unless="web" />
<!-- _______________________________ Libraries ______________________________ -->
<haxedef name="VIDEO_CUTSCENES" if="VIDEO_CUTSCENES" />
<haxelib name="hxCodec" if="VIDEO_CUTSCENES" />
<haxelib name="away3d" />
+1 -1
View File
@@ -1 +1 @@
1472
1474
+59 -1
View File
@@ -1,5 +1,63 @@
package funkin.github;
class GitHub {
import haxe.Json;
import haxe.Exception;
import haxe.Http;
// TODO: Document further and perhaps make this a Haxelib.
class GitHub {
/**
* Gets all the releases from a specific GitHub repository using the GitHub API.
* @param user
* @param repository
* @return Releases
*/
public static function getReleases(user:String, repository:String, ?onError:Exception->Void):Array<GitHubRelease> {
try {
var url = 'https://api.github.com/repos/${user}/${repository}/releases';
var data = Json.parse(__requestOnGitHubServers(url));
if (!(data is Array))
throw __parseGitHubException(data);
return data;
} catch(e) {
if (onError != null)
onError(e);
}
return [];
}
/**
* Filters all releases gotten by `getReleases`
* @param releases Releases
* @param keepPrereleases Whenever to keep Pre-Releases.
* @param keepDrafts Whenever to keep Drafts.
* @return Filtered releases.
*/
public static inline function filterReleases(releases:Array<GitHubRelease>, keepPrereleases:Bool = true, keepDrafts:Bool = false)
return [for(release in releases) if (release != null && (!release.prerelease || (release.prerelease && keepPrereleases)) && (!release.draft || (release.draft && keepDrafts))) release];
private static function __requestOnGitHubServers(url:String) {
var h = new Http(url);
h.setHeader("User-Agent", "request");
var r = null;
h.onData = function(d) {
r = d;
}
h.onError = function(e) {
throw e;
}
h.request(false);
return r;
}
private static function __parseGitHubException(obj:Dynamic):GitHubException {
var msg:String = "(No message)";
var url:String = "(No API url)";
if (Reflect.hasField(obj, "message"))
msg = Reflect.field(obj, "message");
if (Reflect.hasField(obj, "documentation_url"))
url = Reflect.field(obj, "documentation_url");
return new GitHubException(msg, url);
}
}
+19
View File
@@ -0,0 +1,19 @@
package funkin.github;
import funkin.github.GitHubUser;
typedef GitHubAsset = {
var url:String;
var id:Int;
var node_id:String;
var name:String;
var label:String;
var uploader:GitHubUser;
var content_type:String;
var state:String;
var size:UInt;
var download_count:Int;
var created_at:String;
var updated_at:String;
var browser_download_url:String;
}
+15
View File
@@ -0,0 +1,15 @@
package funkin.github;
import haxe.Exception;
class GitHubException extends Exception {
public var apiMessage:String;
public var documentationUrl:String;
public function new(apiMessage:String, documentationUrl:String) {
super('[GitHubException] ${apiMessage} (Check ${documentationUrl})');
this.apiMessage = apiMessage;
this.documentationUrl = documentationUrl;
}
}
+13
View File
@@ -0,0 +1,13 @@
package funkin.github;
typedef GitHubReactions = {
var url:String;
var total_count:Int;
// +1 and -1 cant be added, you need to use Reflect.field
var laugh:Int;
var hooray:Int;
var confused:Int;
var heart:Int;
var rocket:Int;
var eyes:Int;
}
+62
View File
@@ -0,0 +1,62 @@
package funkin.github;
typedef GitHubRelease = {
/**
* Body of the GitHub request (Markdown)
*/
var body:String;
/**
* Url of the release (GitHub API)
*/
var url:String;
/**
* Url for the assets JSON. Also accessible via `GitHubRelease.assets`
*/
var assets_url:String;
/**
* Template URL for asset download link.
*/
var upload_url:String;
/**
* Link to the release on the GitHub website.
*/
var html_url:String;
/**
* ID of the release.
*/
var id:Int;
/**
* Author of the release
*/
var author:GitHubUser;
var node_id:String;
var tag_name:String;
var target_commitish:String;
var name:String;
var draft:Bool;
var prerelease:Bool;
var created_at:String;
var published_at:String;
var assets:Array<GitHubAsset>;
var tarball_url:String;
var zipball_url:String;
var reactions:GitHubReactions;
}
+132
View File
@@ -0,0 +1,132 @@
package funkin.github;
typedef GitHubUser = {
/**
* Username of the user.
*/
var login:String;
/**
* ID of the user.
*/
var id:Int;
/**
* ID of the current node on the GitHub database.
*/
var node_id:String;
/**
* Link to the avatar (profile picture).
*/
var avatar_url:String;
/**
* Unknown
*/
var gravatar_id:String;
/**
* URL to the user on GitHub's servers.
*/
var url:String;
/**
* URL to the user on GitHub's website.
*/
var html_url:String;
/**
* URL on GitHub's API to access this user's followers.
*/
var followers_url:String;
/**
* URL on GitHub's API to access the accounts this user is following.
*/
var following_url:String;
/**
* URL on GitHub's API to access this user's gists.
*/
var gists_url:String;
/**
* URL on GitHub's API to access this user's starred repositories.
*/
var starred_url:String;
// NOT COMPLETE: MISSING repos_url, organizations_url, subscriptions_url, events_url, received_events_url.
/**
* Type of the user.
*/
var type:GitHubUserType;
/**
* Whenever the user is a GitHub administrator.
*/
var site_admin:Bool;
/**
* Name of the user.
*/
var name:String;
/**
* The company this user belongs to. Can be `null`.
*/
var company:String;
var blog:String;
var location:String;
var email:String;
var hireable:Null<Bool>;
var bio:String;
/**
* Twitter username of the user. Can be null.
*/
var twitter_username:String;
/**
* Number of public repos this user own.
*/
var public_repos:Int;
/**
* Number of public gists this user own.
*/
var public_gists:Int;
/**
* Number of followers this user have
*/
var followers:Int;
/**
* Number of accounts this user follows.
*/
var following:Int;
/**
* Date of creation of the account
*/
var created_at:String;
/**
* Date of last account update.
*/
var updated_at:String;
}
@:enum
abstract GitHubUserType(String) {
var USER = "User";
var ORGANIZATION = "Organization";
}
+23 -12
View File
@@ -1,5 +1,7 @@
package funkin.menus;
import funkin.system.UpdateUtil;
import funkin.github.GitHub;
import funkin.system.MusicBeatGroup;
import funkin.system.XMLUtil;
import flixel.util.typeLimit.OneOfThree;
@@ -154,18 +156,7 @@ class TitleState extends MusicBeatState
if (pressedEnter && !transitioning && skippedIntro)
{
titleText.animation.play('press');
FlxG.camera.flash(FlxColor.WHITE, 1);
CoolUtil.playMenuSFX(1, 0.7);
transitioning = true;
// FlxG.sound.music.stop();
new FlxTimer().start(2, function(tmr:FlxTimer)
{
FlxG.switchState(new MainMenuState());
});
pressEnter();
}
if (pressedEnter && !skippedIntro)
@@ -174,6 +165,26 @@ class TitleState extends MusicBeatState
super.update(elapsed);
}
public function pressEnter() {
titleText.animation.play('press');
FlxG.camera.flash(FlxColor.WHITE, 1);
CoolUtil.playMenuSFX(1, 0.7);
transitioning = true;
// FlxG.sound.music.stop();
new FlxTimer().start(2, function(tmr:FlxTimer)
{
/*
UpdateUtil.checkForUpdates(function(newUpdate) {
});
*/
FlxG.switchState(new MainMenuState());
});
}
public function createCoolText(textArray:Array<String>)
{
for (i=>text in textArray)
+29
View File
@@ -0,0 +1,29 @@
package funkin.system;
import funkin.github.GitHub;
import lime.app.Application;
class UpdateUtil {
function checkForUpdates(callback:Bool->Void) {
var curTag = 'v${Application.current.meta.get('version')}';
trace(curTag);
var error = false;
var releases = GitHub.getReleases("YoshiCrafter29", "YoshiCrafterEngine", function(e) {
error = true;
callback(false);
});
if (error) return;
}
}
typedef UpdateCheckCallback = {
var success:Bool;
var newUpdate:Bool;
var currentVersion:String;
var newVersion:String;
}