Update screen (using a temp repo)
This commit is contained in:
+7
-1
@@ -95,6 +95,9 @@
|
||||
|
||||
<!-- _________________________________ Engine Settings _______________________________ -->
|
||||
|
||||
<!-- Comment this out to disable updates !-->
|
||||
<define name="UPDATE_CHECKING" />
|
||||
|
||||
<!-- Comment this out to disable titlescreen.xml !-->
|
||||
<haxedef name="TITLESCREEN_XML" />
|
||||
|
||||
@@ -117,9 +120,10 @@
|
||||
<define name="VIDEO_CUTSCENES" unless="web" />
|
||||
|
||||
|
||||
<haxedef name="VIDEO_CUTSCENES" if="VIDEO_CUTSCENES" />
|
||||
<haxedef name="UPDATE_CHECKING" if="UPDATE_CHECKING" />
|
||||
<!-- _______________________________ Libraries ______________________________ -->
|
||||
|
||||
<haxedef name="VIDEO_CUTSCENES" if="VIDEO_CUTSCENES" />
|
||||
|
||||
<haxelib name="hxCodec" if="VIDEO_CUTSCENES" />
|
||||
<haxelib name="away3d" />
|
||||
@@ -129,6 +133,8 @@
|
||||
|
||||
<haxelib name="hscript-improved" />
|
||||
<haxelib name="linc_discord-rpc" if="desktop"/>
|
||||
|
||||
<haxelib name="markdown" if="UPDATE_CHECKING" />
|
||||
|
||||
<!-- <haxelib name="hxcpp-debug-server" if="desktop"/> -->
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1474
|
||||
1507
|
||||
@@ -1,6 +1,5 @@
|
||||
package funkin.menus;
|
||||
|
||||
import funkin.system.UpdateUtil;
|
||||
import funkin.github.GitHub;
|
||||
import funkin.system.MusicBeatGroup;
|
||||
import funkin.system.XMLUtil;
|
||||
@@ -176,12 +175,12 @@ class TitleState extends MusicBeatState
|
||||
|
||||
new FlxTimer().start(2, function(tmr:FlxTimer)
|
||||
{
|
||||
/*
|
||||
UpdateUtil.checkForUpdates(function(newUpdate) {
|
||||
|
||||
});
|
||||
*/
|
||||
FlxG.switchState(new MainMenuState());
|
||||
var report = funkin.updating.UpdateUtil.checkForUpdates();
|
||||
if (report.newUpdate) {
|
||||
FlxG.switchState(new funkin.updating.UpdateScreen(report));
|
||||
} else {
|
||||
FlxG.switchState(new MainMenuState());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package funkin.updating;
|
||||
|
||||
import funkin.menus.MainMenuState;
|
||||
import flixel.math.FlxPoint;
|
||||
import flixel.math.FlxMath;
|
||||
import flixel.FlxSprite;
|
||||
import funkin.updating.UpdateUtil.UpdateCheckCallback;
|
||||
import funkin.ui.FunkinText;
|
||||
import flixel.text.FlxText;
|
||||
import flixel.tweens.FlxEase;
|
||||
import funkin.ui.Alphabet;
|
||||
import flixel.addons.transition.FlxTransitionableState;
|
||||
import flixel.tweens.FlxTween;
|
||||
import flixel.FlxG;
|
||||
|
||||
class UpdateAvailableScreen extends MusicBeatState {
|
||||
public var bg:FlxSprite;
|
||||
|
||||
public var versionCheckBG:FlxSprite;
|
||||
public var title:Alphabet;
|
||||
public var versionDifferenceLabel:FunkinText;
|
||||
public var changeLogText:FunkinText;
|
||||
public var check:UpdateCheckCallback;
|
||||
|
||||
public var optionsBG:FlxSprite;
|
||||
public var installButton:FunkinText;
|
||||
public var skipButton:FunkinText;
|
||||
|
||||
public var installSelected:Bool = true;
|
||||
|
||||
public function new(check:UpdateCheckCallback) {
|
||||
super();
|
||||
this.check = check;
|
||||
}
|
||||
|
||||
public override function create() {
|
||||
super.create();
|
||||
FlxTransitionableState.skipNextTransIn = true;
|
||||
FlxG.mouse.visible = true;
|
||||
|
||||
FlxG.camera.flash(0xFF000000, 0.25);
|
||||
|
||||
bg = new FlxSprite().loadAnimatedGraphic(Paths.image("menus/menuDesat"));
|
||||
bg.color = 0xFF181818;
|
||||
bg.antialiasing = true;
|
||||
bg.scrollFactor.set();
|
||||
bg.screenCenter();
|
||||
add(bg);
|
||||
|
||||
title = new Alphabet(0, 10, "NEW UPDATE", true);
|
||||
title.screenCenter(X);
|
||||
title.scrollFactor.set();
|
||||
|
||||
versionDifferenceLabel = new FunkinText(0, title.y + title.height + 10, FlxG.width, '${check.currentVersionTag} < ${check.newVersionTag}', 28, false);
|
||||
versionDifferenceLabel.color = 0xFFFFFFFF;
|
||||
versionDifferenceLabel.alignment = CENTER;
|
||||
versionDifferenceLabel.scrollFactor.set();
|
||||
|
||||
versionCheckBG = new FlxSprite(-1, -1).makeGraphic(1, 1, 0xFFFFFFFF);
|
||||
versionCheckBG.alpha = 0.75;
|
||||
versionCheckBG.color = 0xFF000000;
|
||||
versionCheckBG.scale.set(FlxG.width + 2, versionDifferenceLabel.y + versionDifferenceLabel.height + 14);
|
||||
versionCheckBG.updateHitbox();
|
||||
versionCheckBG.scrollFactor.set();
|
||||
|
||||
changeLogText = new FunkinText(0, versionCheckBG.y + versionCheckBG.height + 10, FlxG.width, "", 20, false);
|
||||
changeLogText.textField.htmlText = Markdown.markdownToHtml(check.updates.last().body.replace("\t", " "));
|
||||
changeLogText.applyMarkup(
|
||||
UpdateUtil.parseWarnings(changeLogText.textField.text),
|
||||
[
|
||||
new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFFFF00, false, true), "<o>"),
|
||||
new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFF0000, false, true), "<r>"),
|
||||
new FlxTextFormatMarkerPair(new FlxTextFormat(0xFF00FF08, false, true), "<g>"),
|
||||
new FlxTextFormatMarkerPair(new FlxTextFormat(0xFF7D7D7D, false, true), "<gray>"),
|
||||
]
|
||||
);
|
||||
|
||||
installButton = new FunkinText(0, FlxG.height - 25, Std.int(FlxG.width / 2), "> INSTALL <", 32);
|
||||
skipButton = new FunkinText(Std.int(FlxG.width / 2), FlxG.height - 25, Std.int(FlxG.width / 2), "SKIP", 32);
|
||||
|
||||
skipButton.y -= skipButton.height;
|
||||
installButton.y -= installButton.height;
|
||||
|
||||
installButton.alignment = skipButton.alignment = CENTER;
|
||||
|
||||
optionsBG = new FlxSprite(-1, installButton.y - 25).makeGraphic(1, 1, 0xFFFFFFFF);
|
||||
optionsBG.alpha = 0.75;
|
||||
optionsBG.color = 0xFF000000;
|
||||
optionsBG.scale.set(FlxG.width + 2, Std.int(FlxG.height - optionsBG.y));
|
||||
optionsBG.updateHitbox();
|
||||
|
||||
installButton.scrollFactor.set();
|
||||
skipButton.scrollFactor.set();
|
||||
optionsBG.scrollFactor.set();
|
||||
|
||||
add(changeLogText);
|
||||
|
||||
add(versionCheckBG);
|
||||
add(title);
|
||||
add(versionDifferenceLabel);
|
||||
|
||||
add(optionsBG);
|
||||
add(installButton);
|
||||
add(skipButton);
|
||||
|
||||
oldPos = FlxG.mouse.getScreenPosition();
|
||||
}
|
||||
|
||||
var destY:Float = 0;
|
||||
var oldPos:FlxPoint;
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
|
||||
destY = FlxMath.bound(destY - (FlxG.mouse.wheel * 40), 0, Math.max(0, changeLogText.height - FlxG.height + versionCheckBG.height + 20 + optionsBG.height));
|
||||
FlxG.camera.scroll.y = lerp(FlxG.camera.scroll.y, destY, 1/3);
|
||||
|
||||
if (controls.LEFT_P || controls.RIGHT_P) {
|
||||
installSelected = !installSelected;
|
||||
changeSelection();
|
||||
}
|
||||
|
||||
var newPos = FlxG.mouse.getScreenPosition();
|
||||
if (oldPos.x != newPos.x || oldPos.y != newPos.y) {
|
||||
if (newPos.y >= optionsBG.y) {
|
||||
if (installSelected != (installSelected = (newPos.x < (FlxG.width / 2)))) {
|
||||
changeSelection();
|
||||
}
|
||||
}
|
||||
oldPos = newPos;
|
||||
}
|
||||
|
||||
if (controls.ACCEPT || (newPos.y >= optionsBG.y && FlxG.mouse.justPressed))
|
||||
select();
|
||||
}
|
||||
|
||||
public function select() {
|
||||
if (installSelected) {
|
||||
CoolUtil.playMenuSFX(1);
|
||||
FlxG.switchState(new UpdateScreen(check));
|
||||
} else {
|
||||
CoolUtil.playMenuSFX(2);
|
||||
FlxG.switchState(new MainMenuState());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function changeSelection() {
|
||||
CoolUtil.playMenuSFX();
|
||||
if (installSelected) {
|
||||
installButton.text = "> INSTALL <";
|
||||
skipButton.text = "SKIP";
|
||||
} else {
|
||||
installButton.text = "INSTALL";
|
||||
skipButton.text = "> SKIP <";
|
||||
}
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
super.destroy();
|
||||
FlxG.mouse.visible = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package funkin.updating;
|
||||
|
||||
import funkin.updating.UpdateUtil.UpdateCheckCallback;
|
||||
|
||||
class UpdateScreen extends MusicBeatState {
|
||||
public var updater:Updater;
|
||||
|
||||
public function new(check:UpdateCheckCallback) {
|
||||
super(false);
|
||||
updater = new AsyncUpdater(check);
|
||||
}
|
||||
|
||||
public override function create() {
|
||||
super.create();
|
||||
Main.execAsync(installUpdates);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package funkin.updating;
|
||||
|
||||
import funkin.github.GitHubRelease;
|
||||
import funkin.github.GitHub;
|
||||
import lime.app.Application;
|
||||
|
||||
using funkin.github.GitHub;
|
||||
|
||||
class UpdateUtil {
|
||||
public static function checkForUpdates():UpdateCheckCallback {
|
||||
var curTag = 'v${Application.current.meta.get('version')}';
|
||||
trace(curTag);
|
||||
|
||||
var error = false;
|
||||
|
||||
// TODO: replace "CodenameTestRepo" by "CodenameEngine" once done.
|
||||
|
||||
var newUpdates = __doReleaseFiltering(GitHub.getReleases("YoshiCrafter29", "CodenameTestRepo", function(e) {
|
||||
error = true;
|
||||
}), curTag);
|
||||
|
||||
if (error) return {
|
||||
success: false,
|
||||
newUpdate: false
|
||||
};
|
||||
|
||||
if (newUpdates.length <= 0) {
|
||||
return {
|
||||
success: true,
|
||||
newUpdate: false
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
newUpdate: true,
|
||||
currentVersionTag: curTag,
|
||||
newVersionTag: newUpdates.last().tag_name,
|
||||
updates: newUpdates
|
||||
};
|
||||
}
|
||||
|
||||
static var __curVersionPos = 0;
|
||||
static function __doReleaseFiltering(releases:Array<GitHubRelease>, currentVersionTag:String) {
|
||||
releases = releases.filterReleases(false, false);
|
||||
if (releases.length <= 0)
|
||||
return releases;
|
||||
|
||||
var newArray:Array<GitHubRelease> = [];
|
||||
|
||||
for(index in 0...releases.length) {
|
||||
var i = releases.length - 1 - index;
|
||||
|
||||
var release = releases[i];
|
||||
if (release.tag_name == currentVersionTag) {
|
||||
__curVersionPos = index;
|
||||
}
|
||||
newArray.push(release);
|
||||
}
|
||||
|
||||
return newArray.length <= 0 ? newArray : newArray.splice(__curVersionPos+1, newArray.length-(__curVersionPos+1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all `⚠ TEXT` into `<o>/!\ TEXT</o>`
|
||||
* @param text
|
||||
*/
|
||||
public static function parseWarnings(text:String) {
|
||||
text = parseEmote(text, "⚠", "<o>(!)", "<o>");
|
||||
text = parseEmote(text, "❌", "<r>(X)", "<r>");
|
||||
text = parseEmote(text, "✔", "<g>(+)", "<g>");
|
||||
text = parseEmote(text, "\n> ", "\n<gray>| ", "<gray>");
|
||||
return text;
|
||||
}
|
||||
|
||||
public static function parseEmote(text:String, emote:String, beginning:String, end:String) {
|
||||
var index:Int;
|
||||
while((index = text.indexOf(emote)) >= 0) {
|
||||
var nextIndex = text.indexOf("\n", index + emote.length);
|
||||
if (nextIndex < 0)
|
||||
nextIndex = text.length;
|
||||
text = text.substr(0, index) + beginning + text.substring(index + emote.length, nextIndex) + end + text.substring(nextIndex);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
typedef UpdateCheckCallback = {
|
||||
var success:Bool;
|
||||
|
||||
var newUpdate:Bool;
|
||||
|
||||
@:optional var currentVersionTag:String;
|
||||
|
||||
@:optional var newVersionTag:String;
|
||||
|
||||
@:optional var updates:Array<GitHubRelease>;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package funkin.updating;
|
||||
|
||||
import sys.FileSystem;
|
||||
import funkin.github.GitHubRelease;
|
||||
|
||||
class AsyncUpdater {
|
||||
// NON ASYNC STUFF
|
||||
#if REGION
|
||||
public function new(releases:Array<GitHubRelease>) {
|
||||
this.releases = releases;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
Main.execAsync(installUpdates);
|
||||
}
|
||||
#end
|
||||
|
||||
public var releases:Array<GitHubRelease>;
|
||||
public var progress:UpdaterProgress = new UpdaterProgress();
|
||||
public var path:String;
|
||||
|
||||
public function installUpdates() {
|
||||
prepareInstallationEnvironment();
|
||||
|
||||
}
|
||||
|
||||
public function prepareInstallationEnvironment() {
|
||||
progress.step = PREPARING;
|
||||
|
||||
#if windows
|
||||
path = '${Sys.getEnv("TEMP")}\\Codename Engine\\Updater\\';
|
||||
#else
|
||||
path = '.\\.temp\\';
|
||||
#end
|
||||
|
||||
FileSystem.createDirectory(path);
|
||||
}
|
||||
}
|
||||
|
||||
class UpdaterProgress {
|
||||
public var step:UpdaterStep = PREPARING;
|
||||
|
||||
public function new() {}
|
||||
}
|
||||
|
||||
@:enum
|
||||
abstract UpdaterStep(Int) {
|
||||
var PREPARING = 0;
|
||||
var DOWNLOADING_ASSETS = 1;
|
||||
var DOWNLOADING_EXECUTABLE = 2;
|
||||
var INSTALLING = 3;
|
||||
}
|
||||
+2
-1
@@ -2,4 +2,5 @@ haxelib git linc_discord-rpc https://github.com/Aidan63/linc_discord-rpc
|
||||
haxelib git flixel-yc29 https://www.github.com/YoshiCrafter29/flixel
|
||||
haxelib git hscript-improved https://www.github.com/YoshiCrafter29/hscript-improved
|
||||
haxelib install away3d
|
||||
haxelib install hxCodec
|
||||
haxelib install hxCodec
|
||||
haxelib install markdown
|
||||
Reference in New Issue
Block a user