Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarcleint committed Feb 5, 2024
2 parents f72a768 + 3875b91 commit 08075f3
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 100 deletions.
14 changes: 6 additions & 8 deletions source/funkin/backend/assets/AssetsLibraryList.hx
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,21 @@ class AssetsLibraryList extends AssetLibrary {

public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH, ?avoidRoot:Bool = false):Dynamic {
try {
var fileFromAssets:Bool = id.startsWith("assets/");

if (!fileFromAssets) {
if (!id.startsWith("assets/")) {
var ass = getSpecificAsset('assets/$id', type, source);
if (ass != null)
return ass;
}

if (fileFromAssets) {
} else {
for (lib in assetsLibs) {
if (shouldSkipLib(libraries.indexOf(lib), source)) continue;

var asset = lib.getAsset(id, type);
if (asset != null)
return asset;
}
} else if (!avoidRoot) {
}

if (!avoidRoot) {
for (lib in rootLibs) {
if (shouldSkipLib(libraries.indexOf(lib), source)) continue;

Expand Down Expand Up @@ -182,7 +180,7 @@ class AssetsLibraryList extends AssetLibrary {

if (finalLib is IModsAssetLibrary)
assetsLibs.insert(0, finalLib);
else
else
rootLibs.insert(0, finalLib);
return lib;
}
Expand Down
161 changes: 78 additions & 83 deletions source/funkin/backend/system/github/GitHub.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,123 @@ package funkin.backend.system.github;
import haxe.Json;
import haxe.Exception;
import haxe.Http;
#end

// 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 The user/group that owns the repository
* @param user The user/organization that owns the repository
* @param repository The repository name
* @param onError Error Callback
* @return Releases
*/
public static function getReleases(user:String, repository:String, ?onError:Exception->Void):Array<GitHubRelease> {
#if GITHUB_API
try {
var url = 'https://api.github.com/repos/${user}/${repository}/releases';

var data = Json.parse(__requestOnGitHubServers(url));
var data = Json.parse(__requestOnGitHubServers('https://api.github.com/repos/${user}/${repository}/releases'));
if (!(data is Array))
throw __parseGitHubException(data);

return data;
} catch(e) {
if (onError != null)
onError(e);
}
#end
return [];
}

/**
* Gets the contributors list from a specific GitHub repository using the GitHub API.
* @param user The user/group that owns the repository
* @param user The user/organization that owns the repository
* @param repository The repository name
* @param onError Error Callback
* @return Contributors List
*/
public static function getContributors(user:String, repository:String, ?onError:Exception->Void):Array<GitHubContributor> {
#if GITHUB_API
try {
var url = 'https://api.github.com/repos/${user}/${repository}/contributors';

var data = Json.parse(__requestOnGitHubServers(url));
var data = Json.parse(__requestOnGitHubServers('https://api.github.com/repos/${user}/${repository}/contributors'));
if (!(data is Array))
throw __parseGitHubException(data);

return data;
} catch(e) {
if (onError != null)
onError(e);
}
#end
return [];
}

/**
* Gets a specific GitHub user/group using the GitHub API.
* @param user The user/group to get
* @return User/Group
* Gets a specific GitHub organization using the GitHub API.
* @param org The organization to get
* @param onError Error Callback
* @return Organization
*/
public static function getOrganization(org:String, ?onError:Exception->Void):GitHubOrganization {
#if GITHUB_API
try {
var data = Json.parse(__requestOnGitHubServers('https://api.github.com/orgs/$org'));
if (Reflect.hasField(data, "documentation_url"))
throw __parseGitHubException(data);

return data;
} catch(e) {
if (onError != null)
onError(e);
}
#end
return null;
}

/**
* Gets the members list from a specific GitHub organization using the GitHub API.
* NOTE: Members use Contributors' structure!
* @param org The organization to get the members from
* @param onError Error Callback
* @return Members List
*/
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
public static function getOrganizationMembers(org:String, ?onError:Exception->Void):Array<GitHubContributor> {
#if GITHUB_API
try {
var data = Json.parse(__requestOnGitHubServers('https://api.github.com/orgs/$org/members'));
if (Reflect.hasField(data, "documentation_url"))
throw __parseGitHubException(data);

return data;
} catch(e) {
if (onError != null)
onError(e);
}
#end
return [];
}

/**
* Gets a specific GitHub user/organization using the GitHub API.
* NOTE: If organization, it will be returned with the structure of a normal user; use `getOrganization` if you specifically want an organization!
* @param user The user/organization to get
* @param onError Error Callback
* @return User/Organization
*/
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
#if GITHUB_API
try {
var url = 'https://api.github.com/users/$user';

var data = Json.parse(__requestOnGitHubServers(url));
if (Reflect.hasField(data, "documentation_url"))
throw __parseGitHubException(data);

return data;
} catch(e) {
if (onError != null)
onError(e);
}
#end
return null;
}

Expand All @@ -80,13 +132,14 @@ class GitHub {
* @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];
return #if GITHUB_API [for(release in releases) if (release != null && (!release.prerelease || (release.prerelease && keepPrereleases)) && (!release.draft || (release.draft && keepDrafts))) release] #else releases #end;

public static function __requestOnGitHubServers(url:String) {
var r = null;
#if GITHUB_API
var h = new Http(url);
h.setHeader("User-Agent", "request");

var r = null;
h.onStatus = function(s) {
if(isRedirect(s))
r = __requestOnGitHubServers(h.responseHeaders.get("Location"));
Expand All @@ -100,13 +153,15 @@ class GitHub {
}

h.request(false);
#end
return r;
}
public static function __requestBytesOnGitHubServers(url:String) {
var r = null;
#if GITHUB_API
var h = new Http(url);
h.setHeader("User-Agent", "request");

var r = null;
h.onStatus = function(s) {
if(isRedirect(s))
r = __requestBytesOnGitHubServers(h.responseHeaders.get("Location"));
Expand All @@ -120,6 +175,7 @@ class GitHub {
}

h.request(false);
#end
return r;
}
private static function isRedirect(status:Int):Bool {
Expand All @@ -132,77 +188,16 @@ class GitHub {
return false;
}
private static function __parseGitHubException(obj:Dynamic):GitHubException {
#if GITHUB_API
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);
}
}

#else
import haxe.Json;
import haxe.Exception;

class GitHub {
/**
* Gets all the releases from a specific GitHub repository using the GitHub API.
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Releases
*/
public static function getReleases(user:String, repository:String, ?onError:Exception->Void):Array<GitHubRelease> {
return [];
}

/**
* Gets the contributors list from a specific GitHub repository using the GitHub API.
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Contributors List
*/
public static function getContributors(user:String, repository:String, ?onError:Exception->Void):Array<GitHubContributor> {
return [];
}

/**
* Gets a specific GitHub user/group using the GitHub API.
* @param user The user/group to get
* @return User/Group
*/
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
return null;
}

/**
* 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 releases;

public static function __requestOnGitHubServers(url:String) {
return null;
}
public static function __requestBytesOnGitHubServers(url:String) {
#else
return null;
#end
}
private static function __parseGitHubException(obj:Dynamic):GitHubException {
return null;
}
private static function isRedirect(status:Int):Bool {
switch (status) {
// 301: Moved Permanently, 302: Found (Moved Temporarily), 307: Temporary Redirect, 308: Permanent Redirect - Nex
case 301 | 302 | 307 | 308 :
trace("Redirected with status code: " + status);
return true;
}
return false;
}
}
#end
}
1 change: 1 addition & 0 deletions source/funkin/backend/system/github/GitHubContributor.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package funkin.backend.system.github;

// Also used by Organizations for members!
typedef GitHubContributor = {
var login:String;
var id:Int;
Expand Down
36 changes: 36 additions & 0 deletions source/funkin/backend/system/github/GitHubOrganization.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package funkin.backend.system.github;

import funkin.backend.system.github.GitHubUser.GitHubUserType;

typedef GitHubOrganization = {
var login:String;
var id:Int;
var node_id:String;
var url:String;
var repos_url:String;
var events_url:String;
var hooks_url:String;
var issues_url:String;
var members_url:String;
var public_members_url:String;
var avatar_url:String;
var description:String;
var name:String;
var company:String;
var blog:String;
var location:String;
var email:String;
var twitter_username:String;
var is_verified:Bool;
var has_organization_projects:Bool;
var has_repository_projects:Bool;
var public_repos:Int;
var public_gists:Int;
var followers:Int;
var following:Int;
var html_url:String;
var created_at:String;
var updated_at:String;
var archived_at:String;
var type:GitHubUserType;
}
2 changes: 1 addition & 1 deletion source/funkin/menus/BetaWarningState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BetaWarningState extends MusicBeatState {

disclaimer = new FunkinText(16, titleAlphabet.y + titleAlphabet.height + 10, FlxG.width - 32, "", 32);
disclaimer.alignment = CENTER;
disclaimer.applyMarkup("This engine is still in a alpha state. That means *majority of the features* are either *buggy* or *non finished*. If you find any bugs, please report them to the Codename Engine GitHub.\n\nPress ENTER to continue",
disclaimer.applyMarkup("This engine is still in a beta state. That means *majority of the features* are either *buggy* or *non finished*. If you find any bugs, please report them to the Codename Engine GitHub.\n\nPress ENTER to continue",
[
new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFF4444), "*")
]
Expand Down
Loading

0 comments on commit 08075f3

Please sign in to comment.