135 lines
4.7 KiB
Haxe
135 lines
4.7 KiB
Haxe
package funkin.menus.credits;
|
|
|
|
import flixel.text.FlxText;
|
|
import flixel.util.FlxColor;
|
|
import funkin.backend.system.github.GitHub;
|
|
import funkin.backend.system.github.GitHubContributor.CreditsGitHubContributor;
|
|
import funkin.options.PlayerSettings;
|
|
import funkin.options.type.GithubIconOption;
|
|
|
|
using StringTools;
|
|
|
|
class CreditsCodename extends funkin.options.OptionsScreen {
|
|
public var error:Bool = false;
|
|
public var totalContributions:Int = 0;
|
|
public var contribFormats:Array<FlxTextFormatMarkerPair> = [];
|
|
|
|
public override function new()
|
|
{
|
|
super("Codename Engine", "All the contributors of the engine! - Press RESET to update the list (One reset per 2 minutes).");
|
|
tryUpdating(true);
|
|
}
|
|
|
|
// blame the secondary threads if the code has to look this bad - Nex
|
|
private var _canReset:Bool = true;
|
|
private var _downloadingSteps:Int = 0;
|
|
public override function update(elapsed:Float) {
|
|
super.update(elapsed);
|
|
|
|
if (_downloadingSteps == 2) {
|
|
_downloadingSteps = 0;
|
|
_canReset = true;
|
|
displayList();
|
|
} else if (_downloadingSteps == 1) {
|
|
_downloadingSteps = 0;
|
|
_canReset = true;
|
|
updateMenuDesc();
|
|
}
|
|
else if(_canReset && PlayerSettings.solo.controls.RESET) tryUpdating();
|
|
}
|
|
|
|
public function tryUpdating(forceDisplaying:Bool = false) {
|
|
updateMenuDesc("Downloading List...");
|
|
_canReset = false;
|
|
Main.execAsync(function() {
|
|
if(checkUpdate() || forceDisplaying) _downloadingSteps = 2;
|
|
else _downloadingSteps = 1;
|
|
});
|
|
}
|
|
|
|
public override function updateMenuDesc(?txt:String) {
|
|
if(!_canReset) return;
|
|
super.updateMenuDesc(txt);
|
|
updateMarkup();
|
|
}
|
|
|
|
public function updateMarkup() {
|
|
if(parent == null || parent.treeParent == null) return;
|
|
var text:String = parent.treeParent.pathDesc.text;
|
|
parent.treeParent.pathDesc.text = "";
|
|
parent.treeParent.pathDesc.applyMarkup(text, contribFormats = [
|
|
new FlxTextFormatMarkerPair(new FlxTextFormat(Flags.MAIN_DEVS_COLOR), '*'),
|
|
new FlxTextFormatMarkerPair(new FlxTextFormat(FlxColor.interpolate(Flags.MIN_CONTRIBUTIONS_COLOR, Flags.MAIN_DEVS_COLOR, Options.contributors[curSelected].contributions / totalContributions)), '~')
|
|
]);
|
|
}
|
|
|
|
override function close() {
|
|
super.close();
|
|
for (frmt in contribFormats) parent.treeParent.pathDesc.removeFormat(frmt.format);
|
|
}
|
|
|
|
public function checkUpdate():Bool {
|
|
var curTime:Float = Date.now().getTime();
|
|
if(Options.lastUpdated != null && curTime < Options.lastUpdated + 120000) return false; // Fuck you Github rate limits - Nex
|
|
Options.lastUpdated = curTime;
|
|
|
|
error = false;
|
|
var idk = GitHub.getContributors(Flags.REPO_OWNER, Flags.REPO_NAME, function(e) {
|
|
error = true;
|
|
var errMsg:String = 'Error while trying to download contributors list:\n${CoolUtil.removeIP(e.message)}';
|
|
Logs.traceColored([Logs.logText(errMsg.replace('\n', ' '), RED)], ERROR);
|
|
funkin.backend.utils.NativeAPI.showMessageBox("Codename Engine Warning", errMsg, MSG_WARNING);
|
|
});
|
|
if(error) return false;
|
|
if((idk is Array)) {
|
|
var contributors:Array<CreditsGitHubContributor> = [];
|
|
for(e in idk) contributors.push({
|
|
login: e.login,
|
|
avatar_url: e.avatar_url,
|
|
html_url: e.html_url,
|
|
id: e.id,
|
|
contributions: e.contributions
|
|
});
|
|
Options.contributors = contributors;
|
|
}
|
|
Logs.verbose('[CreditsCodename] Contributors list Updated!');
|
|
|
|
var errorOnMain:Bool = false;
|
|
var idk2 = GitHub.getOrganizationMembers(Flags.REPO_OWNER, function(e) {
|
|
errorOnMain = true;
|
|
var errMsg:String = 'Error while trying to download ${Flags.REPO_OWNER} members list:\n${CoolUtil.removeIP(e.message)}';
|
|
Logs.traceColored([Logs.logText(errMsg.replace('\n', ' '), RED)], ERROR);
|
|
funkin.backend.utils.NativeAPI.showMessageBox("Codename Engine Warning", errMsg, MSG_WARNING);
|
|
});
|
|
if(!errorOnMain) {
|
|
Options.mainDevs = [for(m in idk2) m.id];
|
|
Logs.verbose('[CreditsCodename] Main Devs list Updated!');
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function displayList() {
|
|
//if (curSelected > Options.contributors.length - 1) changeSelection(-(curSelected - (Options.contributors.length - 1)));
|
|
if (curSelected > Options.contributors.length - 1) curSelected = Options.contributors.length - 1;
|
|
changeSelection(0, true);
|
|
|
|
while (members.length > 0) {
|
|
members[0].destroy();
|
|
remove(members[0], true);
|
|
}
|
|
|
|
totalContributions = 0;
|
|
for(c in Options.contributors) totalContributions += c.contributions;
|
|
for(c in Options.contributors) {
|
|
var opt:GithubIconOption = new GithubIconOption(c, 'Total Contributions: ~${c.contributions}~ / *${totalContributions}* (~${FlxMath.roundDecimal(c.contributions / totalContributions * 100, 2)}%~) - Select to open GitHub account');
|
|
if(Options.mainDevs.contains(c.id)) {
|
|
opt.desc += " *- Public member of the main Devs!*";
|
|
@:privateAccess opt.__text.color = Flags.MAIN_DEVS_COLOR;
|
|
}
|
|
add(opt);
|
|
}
|
|
|
|
updateMenuDesc();
|
|
}
|
|
} |