File tree 7 files changed +56
-10
lines changed
7 files changed +56
-10
lines changed Original file line number Diff line number Diff line change 16
16
"option" : " versionDisplay" ,
17
17
"value" : true
18
18
},
19
+ {
20
+ "option" : " showCommitHash" ,
21
+ "value" : true
22
+ },
19
23
{
20
24
"option" : " uiSkin" ,
21
25
"value" : " default"
Original file line number Diff line number Diff line change @@ -107,6 +107,10 @@ class Main extends Sprite {
107
107
display .infoDisplayed [3 ] = logsEnabled ;
108
108
}
109
109
110
+ public static inline function toggleCommitHash (commitHashEnabled : Bool ): Void {
111
+ display .infoDisplayed [4 ] = commitHashEnabled ;
112
+ }
113
+
110
114
public static inline function changeFont (font : String ): Void {
111
115
display .defaultTextFormat = new TextFormat (font , (font == " _sans" ? 12 : 14 ), display .textColor );
112
116
}
Original file line number Diff line number Diff line change
1
+ package macros ;
2
+
3
+ import haxe .macro .Context ;
4
+ import haxe .macro .Expr ;
5
+ import sys .io .Process ;
6
+
7
+ /**
8
+ * Macro class for getting the current git commit hash.
9
+ * @see https://code.haxe.org/category/macros/add-git-commit-hash-in-build.html
10
+ */
11
+ class GithubCommitHash {
12
+ public static macro function getGitCommitHash (): ExprOf <String > {
13
+ #if !display
14
+ var process : Process = new Process (' git' , [' rev-parse' , ' HEAD' ]);
15
+ if (process .exitCode () != 0 ) {
16
+ var message : String = process .stderr .readAll ().toString ();
17
+ var pos : Position = Context .currentPos ();
18
+ Context .error (" Cannot execute `git rev-parse HEAD`. " + message , pos );
19
+ }
20
+
21
+ // read the output of the process
22
+ var commitHash : String = process .stdout .readLine ();
23
+
24
+ // Generates a string expression
25
+ return macro $v {commitHash };
26
+ #else
27
+ // `#if display` is used for code completion. In this case returning an
28
+ // empty string is good enough; We don't want to call git on every hint.
29
+ var commitHash : String = " " ;
30
+ return macro $v {commitHash };
31
+ #end
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -96,7 +96,8 @@ class OptionsMenu extends MusicBeatState {
96
96
" infoDisplayFont" ),
97
97
new BoolOption (" FPS Counter" , " fpsCounter" ),
98
98
new BoolOption (" Memory Counter" , " memoryCounter" ),
99
- new BoolOption (" Version Display" , " versionDisplay" )
99
+ new BoolOption (" Version Display" , " versionDisplay" ),
100
+ new BoolOption (" Commit Hash" , " showCommitHash" )
100
101
],
101
102
" Judgements" => [
102
103
new PageOption (" Back" , " Gameplay" ),
Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ class TitleState extends MusicBeatState {
170
170
Main .toggleVers (Options .getData (" versionDisplay" ));
171
171
Main .toggleLogs (Options .getData (" developer" ));
172
172
Main .changeFont (Options .getData (" infoDisplayFont" ));
173
+ Main .toggleCommitHash (Options .getData (" showCommitHash" ));
173
174
174
175
call (" startIntroPost" );
175
176
}
@@ -307,8 +308,6 @@ class TitleState extends MusicBeatState {
307
308
var http : Http = new Http (" https://raw.githubusercontent.com/Vortex2Oblivion/LeatherEngine/main/version.txt" );
308
309
http .onData = (data : String ) -> {
309
310
data = ' v' + data ;
310
- trace (data );
311
-
312
311
if (CoolUtil .getCurrentVersion () != data ) {
313
312
trace (' Outdated Version Detected! ' + data .trim () + ' != ' + CoolUtil .getCurrentVersion (), WARNING );
314
313
Main .display .version + = ' - UPDATE AVALIABLE ( ${data .trim ()})' ;
Original file line number Diff line number Diff line change @@ -101,6 +101,8 @@ class BoolOption extends Option {
101
101
Main .toggleVers (optionChecked );
102
102
case " developer" :
103
103
Main .toggleLogs (optionChecked );
104
+ case " showCommitHash" :
105
+ Main .toggleCommitHash (optionChecked );
104
106
}
105
107
}
106
108
}
Original file line number Diff line number Diff line change 1
1
package ui ;
2
2
3
+ import macros .GithubCommitHash ;
3
4
import flixel .util .FlxStringUtil ;
4
5
import flixel .FlxG ;
5
6
import openfl .utils .Assets ;
6
7
import openfl .text .TextField ;
7
8
import openfl .text .TextFormat ;
8
9
import external .memory .Memory ;
10
+ import macros .GithubCommitHash ;
11
+ import haxe .macro .Compiler ;
9
12
10
13
/**
11
14
* Shows basic info about the game.
@@ -35,7 +38,7 @@ class SimpleInfoDisplay extends TextField {
35
38
height = FlxG .height ;
36
39
}
37
40
38
- private function update (): Void {
41
+ public function update (): Void {
39
42
framerateTimer + = FlxG .elapsed ;
40
43
41
44
if (framerateTimer >= 1 ) {
@@ -59,16 +62,16 @@ class SimpleInfoDisplay extends TextField {
59
62
60
63
switch (i ) {
61
64
case 0 : // FPS
62
- text + = ' ${framerate }fps' ;
65
+ text + = ' ${framerate }fps \n ' ;
63
66
case 1 : // Memory
64
- text + = ' ${FlxStringUtil .formatBytes (Memory .getCurrentUsage ())} / ${FlxStringUtil .formatBytes (Memory .getPeakUsage ())}' ;
67
+ text + = ' ${FlxStringUtil .formatBytes (Memory .getCurrentUsage ())} / ${FlxStringUtil .formatBytes (Memory .getPeakUsage ())}\n ' ;
65
68
case 2 : // Version
66
- text + = version ;
69
+ text + = ' $ version \n ' ;
67
70
case 3 : // Console
68
- text + = ' ${Main .logsOverlay .logs .length } traced lines. F3 to view.' ;
71
+ text + = Main .logsOverlay .logs .length > 0 ? ' ${Main .logsOverlay .logs .length } traced lines. F3 to view. \n ' : ' ' ;
72
+ case 4 :
73
+ text + = ' Commit ${GithubCommitHash .getGitCommitHash ().substring (0 , 7 )}' ;
69
74
}
70
-
71
- text + = ' \n ' ;
72
75
}
73
76
}
74
77
}
You can’t perform that action at this time.
0 commit comments