Skip to content

Commit 93116d7

Browse files
imaviemoxie-coder
authored andcommitted
dngu
1 parent e51c1c5 commit 93116d7

File tree

3 files changed

+111
-8
lines changed

3 files changed

+111
-8
lines changed

project.hxp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ class Project extends HXProject
7979
static final COMPANY:String = "JordanSantiago";
8080

8181
/**
82-
* Path to the Haxe script run before building the game.
83-
*/
84-
static final PREBUILD_HX:String = "art/Prebuild.hx";
85-
86-
/**
87-
* Path to the Haxe script run after building the game.
88-
*/
89-
static final POSTBUILD_HX:String = "art/Postbuild.hx";
82+
* Path to the Haxe script run before building the game.
83+
*/
84+
static final PREBUILD_HX:String = "source/Prebuild.hx";
85+
86+
/**
87+
* Path to the Haxe script run after building the game.
88+
*/
89+
static final POSTBUILD_HX:String = "source/Postbuild.hx";
9090

9191
/**
9292
* Asset path globs to always exclude from asset libraries.

source/Postbuild.hx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package source; // Yeah, I know...
2+
3+
import sys.FileSystem;
4+
import sys.io.File;
5+
6+
using StringTools;
7+
8+
/**
9+
* A script which executes after the game is built.
10+
*/
11+
class Postbuild
12+
{
13+
static inline final BUILD_TIME_FILE:String = '.build_time';
14+
15+
static function main():Void
16+
{
17+
printBuildTime();
18+
}
19+
20+
static function printBuildTime():Void
21+
{
22+
// get buildEnd before fs operations since they are blocking
23+
var end:Float = Sys.time();
24+
if (FileSystem.exists(BUILD_TIME_FILE))
25+
{
26+
var fi:sys.io.FileInput = File.read(BUILD_TIME_FILE);
27+
var start:Float = fi.readDouble();
28+
fi.close();
29+
30+
sys.FileSystem.deleteFile(BUILD_TIME_FILE);
31+
32+
Sys.println('[INFO] Build took: ${format(end - start)}');
33+
}
34+
}
35+
36+
static function format(time:Float, decimals:Int = 1):String
37+
{
38+
var units = [
39+
{name: "day", secs: 86400},
40+
{name: "hour", secs: 3600},
41+
{name: "minute", secs: 60},
42+
{name: "second", secs: 1}
43+
];
44+
45+
var parts:Array<String> = [];
46+
var remaining:Float = time;
47+
48+
for (unit in units)
49+
{
50+
var value:Float;
51+
if (unit.name == "second")
52+
{
53+
// handle seconds with decimals
54+
value = Math.round(remaining * Math.pow(10, decimals)) / Math.pow(10, decimals);
55+
}
56+
else
57+
{
58+
value = Math.floor(remaining / unit.secs);
59+
remaining %= unit.secs;
60+
}
61+
62+
//
63+
if (value > 0 || (unit.name == "second" && parts.length == 0))
64+
{
65+
parts.push('${value} ${unit.name}${value == 1 ? "" : "s"}');
66+
}
67+
}
68+
69+
return parts.join(" ");
70+
}
71+
}

source/Prebuild.hx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package source; // Yeah, I know...
2+
3+
import sys.io.File;
4+
5+
/**
6+
* A script which executes before the game is built.
7+
*/
8+
class Prebuild
9+
{
10+
static inline final BUILD_TIME_FILE:String = '.build_time';
11+
12+
static function main():Void
13+
{
14+
var start:Float = Sys.time();
15+
// Sys.println('[INFO] Performing pre-build tasks...');
16+
17+
saveBuildTime();
18+
19+
var end:Float = Sys.time();
20+
var duration:Float = end - start;
21+
// Sys.println('[INFO] Finished pre-build tasks in $duration seconds.');
22+
}
23+
24+
static function saveBuildTime():Void
25+
{
26+
// PostBuild.hx reads this file and computes the total build duration.
27+
var fo:sys.io.FileOutput = File.write(BUILD_TIME_FILE);
28+
var now:Float = Sys.time();
29+
fo.writeDouble(now);
30+
fo.close();
31+
}
32+
}

0 commit comments

Comments
 (0)