Skip to content

Commit 2500eb6

Browse files
committed
Move contributor percentages to a macro.
This commit: - Refactors the way that the engine pulls `git` related things inside `Project.hxp`. - Added `GitContributorMacro`, a way of getting contributor percentages at compile time. (Fixes #19) - Added `FunkinMacroCache`. - Does some general cleanup. Signed-off-by: TechnikTil <techniktil@tilnotdrip.org>
1 parent 056b599 commit 2500eb6

File tree

14 files changed

+361
-105
lines changed

14 files changed

+361
-105
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ RECOVER_*.fla
1313

1414
docs/dox/
1515
dump/
16-
export/
16+
export/
17+
.macrocache

Project.hxp

Lines changed: 86 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package;
22

3+
import haxe.Exception;
34
import hxp.*;
45
import lime.tools.*;
56
import sys.io.Process;
@@ -18,7 +19,7 @@ class Project extends HXProject
1819
*/
1920
public final TECHNOTDRIP_VERSION:String = '0.1.0';
2021

21-
/**
22+
/**
2223
* `-DFUNKIN_DISCORD_RPC`
2324
* Whether the game should have Discord RPC.
2425
* Developers can set this by checking the flag above.
@@ -46,12 +47,6 @@ class Project extends HXProject
4647
*/
4748
public final FUNKIN_ASSETS_FORWARDING:FeatureFlag = 'FUNKIN_ASSETS_FORWARDING';
4849

49-
public var GIT_HASH:String = null;
50-
51-
public var GIT_BRANCH:String = null;
52-
53-
public var GIT_MODIFIED:Null<Bool> = null;
54-
5550
public function new()
5651
{
5752
super();
@@ -133,7 +128,7 @@ class Project extends HXProject
133128
// The second parameter is the default value unless overridden!
134129
FUNKIN_DISCORD_RPC.apply(this, platformType == DESKTOP && haxedefs.get('cpp')); // Will be enabled if its on desktop (windows, linux, mac)!
135130
FUNKIN_DOX_GENERATION.apply(this, false); // Will always be false unless you wanna make a documentation website.
136-
FUNKIN_GIT_DETAILS.apply(this, !['stable', 'main', 'master', null].contains(getGitBranch().toLowerCase())); // Will show if it isn't the main branch!
131+
FUNKIN_GIT_DETAILS.apply(this, isGitInitialized()); // Only show details when this is a git repository.
137132
FUNKIN_ASSETS_FORWARDING.apply(this, platformType == DESKTOP && debug);
138133
}
139134

@@ -166,11 +161,15 @@ class Project extends HXProject
166161
addHaxeDefine('FLX_NO_TOUCH', platformType != MOBILE);
167162
addHaxeDefine('message.reporting', 'pretty');
168163
addHaxeDefine('NAPE_RELEASE_BUILD', !debug);
169-
addHaxeDefine('TND_GIT_HASH', getGitHash(false));
170-
addHaxeDefine('TND_GIT_BRANCH', getGitBranch());
171-
addHaxeDefine('TND_GIT_MODIFIED', getGitModified());
172164

173-
if(haxedefs.get('android'))
165+
if (FUNKIN_GIT_DETAILS.isEnabled(this))
166+
{
167+
addHaxeDefine('TND_GIT_HASH', getGitHash());
168+
addHaxeDefine('TND_GIT_BRANCH', getGitBranch());
169+
addHaxeDefine('TND_GIT_MODIFIED', getGitModified());
170+
}
171+
172+
if (haxedefs.get('android'))
174173
{
175174
config.set("android.gradle-version", '7.4.2');
176175
config.set("android.gradle-plugin", "7.3.1");
@@ -219,93 +218,84 @@ class Project extends HXProject
219218
icons.push(new Icon(path, size));
220219
}
221220

222-
function getGitHash(splice:Bool = false):String
221+
function isGitInitialized():Bool
223222
{
224-
if (GIT_HASH == null)
225-
{
226-
var gitProcess:Process = new Process('git', ['rev-parse', 'HEAD']);
223+
var gitProcess:Process = new Process('git', ['status']);
227224

228-
if (gitProcess.exitCode() != 0)
229-
{
230-
trace('[WARNING]: Unable to get current git repository hash.');
231-
return null;
232-
}
233-
else
234-
{
235-
GIT_HASH = gitProcess.stdout.readLine().trim();
236-
}
225+
var exitCode:Int = gitProcess.exitCode();
226+
gitProcess.close();
237227

238-
gitProcess.close();
228+
return exitCode == 0;
229+
}
230+
231+
function getGitHash():String
232+
{
233+
var gitProcess:Process = new Process('git', ['rev-parse', 'HEAD']);
234+
235+
var gitHash:String = gitProcess.stdout.readLine().trim();
236+
var exitCode:Int = gitProcess.exitCode();
237+
gitProcess.close();
238+
239+
if (exitCode != 0)
240+
{
241+
trace('[WARNING] Unable to get current git repository hash.');
242+
return null;
239243
}
240244

241-
return GIT_HASH;
245+
return gitHash;
242246
}
243247

244248
function getGitBranch():String
245249
{
246-
if (GIT_BRANCH == null)
247-
{
248-
var gitProcess:Process = new Process('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
250+
var gitProcess:Process = new Process('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
249251

250-
if (gitProcess.exitCode() != 0)
251-
{
252-
trace('[WARNING]: Unable to get current git repository branch.');
253-
return null;
254-
}
255-
else
256-
{
257-
GIT_BRANCH = gitProcess.stdout.readLine().trim();
258-
}
252+
var gitBranch:String = gitProcess.stdout.readLine().trim();
253+
var exitCode:Int = gitProcess.exitCode();
254+
gitProcess.close();
259255

260-
gitProcess.close();
256+
if (exitCode != 0)
257+
{
258+
trace('[WARNING] Unable to get current git repository branch.');
259+
return null;
261260
}
262261

263-
return GIT_BRANCH;
262+
return gitBranch;
264263
}
265264

266265
function getGitModified():Bool
267266
{
268-
if (GIT_MODIFIED == null)
269-
{
270-
var gitProcess:Process = new Process('git', ['status', '--porcelain']);
267+
var gitProcess:Process = new Process('git', ['status', '--porcelain']);
271268

272-
if (gitProcess.exitCode() != 0)
273-
{
274-
trace('[WARNING]: Unable to get current git repository branch.');
275-
return null;
276-
}
277-
else
278-
{
279-
try
280-
{
281-
GIT_MODIFIED = gitProcess.stdout.readLine().trim().length > 0;
282-
}
283-
catch(e)
284-
{
285-
return false; // idk it breaks sometimes
286-
}
287-
}
269+
var gitModifiedFiles:String = gitProcess.stdout.readLine().trim();
270+
var exitCode:Int = gitProcess.exitCode();
271+
gitProcess.close();
288272

289-
gitProcess.close();
273+
if (exitCode != 0)
274+
{
275+
trace('[WARNING] Unable to get current git repository status.');
276+
return false;
290277
}
291278

292-
return GIT_MODIFIED;
279+
return gitModifiedFiles.length > 0;
293280
}
294281
}
295282

296283
/**
297284
* An object representing a feature flag, which can be enabled or disabled.
298285
* Includes features such as automatic generation of compile defines and inversion.
299286
*/
300-
abstract FeatureFlag(String) {
287+
abstract FeatureFlag(String)
288+
{
301289
static final INVERSE_PREFIX:String = "NO_";
302290

303-
public function new(input:String) {
291+
public function new(input:String)
292+
{
304293
this = input;
305294
}
306295

307296
@:from
308-
public static function fromString(input:String):FeatureFlag {
297+
public static function fromString(input:String):FeatureFlag
298+
{
309299
return new FeatureFlag(input);
310300
}
311301

@@ -314,20 +304,29 @@ abstract FeatureFlag(String) {
314304
* Doesn't override a feature flag that was set explicitly.
315305
* @param enableByDefault Whether to enable this feature flag if it is unset.
316306
*/
317-
public function apply(project:Project, enableByDefault:Bool = false):Void {
307+
public function apply(project:Project, enableByDefault:Bool = false):Void
308+
{
318309
// TODO: Name this function better?
319310

320-
if (isEnabled(project)) {
311+
if (isEnabled(project))
312+
{
321313
// If this flag was already enabled, disable the inverse.
322314
getInverse().disable(project, false);
323-
} else if (getInverse().isEnabled(project)) {
315+
}
316+
else if (getInverse().isEnabled(project))
317+
{
324318
// If the inverse flag was already enabled, disable this flag.
325319
disable(project, false);
326-
} else {
327-
if (enableByDefault) {
320+
}
321+
else
322+
{
323+
if (enableByDefault)
324+
{
328325
// Enable this flag if it was unset, and disable the inverse.
329326
enable(project, true);
330-
} else {
327+
}
328+
else
329+
{
331330
// Disable this flag if it was unset, and enable the inverse.
332331
disable(project, true);
333332
}
@@ -340,9 +339,11 @@ abstract FeatureFlag(String) {
340339
* @param project The project to modify.
341340
* @param andInverse Also disable the feature flag's inverse.
342341
*/
343-
public function enable(project:Project, andInverse:Bool = true) {
342+
public function enable(project:Project, andInverse:Bool = true)
343+
{
344344
project.haxedefs.set(this, "");
345-
if (andInverse) {
345+
if (andInverse)
346+
{
346347
getInverse().disable(project, false);
347348
}
348349
}
@@ -353,9 +354,11 @@ abstract FeatureFlag(String) {
353354
* @param project The project to modify.
354355
* @param andInverse Also enable the feature flag's inverse.
355356
*/
356-
public function disable(project:Project, andInverse:Bool = true) {
357+
public function disable(project:Project, andInverse:Bool = true)
358+
{
357359
project.haxedefs.remove(this);
358-
if (andInverse) {
360+
if (andInverse)
361+
{
359362
getInverse().enable(project, false);
360363
}
361364
}
@@ -364,24 +367,28 @@ abstract FeatureFlag(String) {
364367
* Query if this feature flag is enabled.
365368
* @param project The project to query.
366369
*/
367-
public function isEnabled(project:Project):Bool {
370+
public function isEnabled(project:Project):Bool
371+
{
368372
// Check both Haxedefs and Defines for this flag.
369373
return project.haxedefs.exists(this) || project.defines.exists(this);
370374
}
371375

372376
/**
373377
* Query if this feature flag's inverse is enabled.
374378
*/
375-
public function isDisabled(project:Project):Bool {
379+
public function isDisabled(project:Project):Bool
380+
{
376381
return getInverse().isEnabled(project);
377382
}
378383

379384
/**
380385
* Return the inverse of this feature flag.
381386
* @return A new feature flag that is the inverse of this one.
382387
*/
383-
public function getInverse():FeatureFlag {
384-
if (this.startsWith(INVERSE_PREFIX)) {
388+
public function getInverse():FeatureFlag
389+
{
390+
if (this.startsWith(INVERSE_PREFIX))
391+
{
385392
return this.substring(INVERSE_PREFIX.length);
386393
}
387394
return INVERSE_PREFIX + this;

src/funkin/api/DiscordRPC.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,17 @@ class DiscordRPC
294294

295295
updatePresence();
296296

297-
trace('[INFO]: Discord RPC Successfully connected! Connected to ${request[0].globalName} (${request[0].username}$displayDiscrim)');
297+
trace('[INFO] Discord RPC Successfully connected! Connected to ${request[0].globalName} (${request[0].username}$displayDiscrim)');
298298
}
299299

300300
static function onDisconnected(errorCode:Int, message:cpp.ConstCharStar):Void
301301
{
302-
trace('[INFO]: Discord RPC Disconnected! $message ($errorCode)');
302+
trace('[INFO] Discord RPC Disconnected! $message ($errorCode)');
303303
}
304304

305305
static function onError(errorCode:Int, message:cpp.ConstCharStar):Void
306306
{
307-
trace('[ERROR]: Discord RPC Error! $message ($errorCode)');
307+
trace('[ERROR] Discord RPC Error! $message ($errorCode)');
308308
}
309309

310310
// Setting Discord RPC Variables

src/funkin/data/save/SaveMigrator.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SaveMigrator
1515
}
1616
catch (e:Exception)
1717
{
18-
trace('[ERROR]: Migrating save data has an invalid version.');
18+
trace('[ERROR] Migrating save data has an invalid version.');
1919
version = null;
2020
}
2121

@@ -31,7 +31,7 @@ class SaveMigrator
3131

3232
if (version != Save.SAVE_VERSION && version.satisfies(Save.SAVE_VERSION_RULE))
3333
{
34-
trace('[INFO]: Old/New version ($version) compatible with new/old (${Save.SAVE_VERSION})');
34+
trace('[INFO] Old/New version ($version) compatible with new/old (${Save.SAVE_VERSION})');
3535
var defaultData:Dynamic = Save.getDefault();
3636

3737
saveData = ReflectUtil.deepMerge(defaultData, saveData, false);

0 commit comments

Comments
 (0)