-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.hxp
377 lines (320 loc) · 9.88 KB
/
Project.hxp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
package;
import hxp.*;
import lime.tools.*;
import sys.io.Process;
using StringTools;
/**
* This is the main project file for TechNotDrip Engine.
*
* This works exactly like an Project.xml but in Haxe Syntax.
*/
class Project extends HXProject
{
/**
* The version of TechNotDrip Engine.
*/
public final TECHNOTDRIP_VERSION:String = '0.1.0';
/**
* `-DFUNKIN_DISCORD_RPC`
* Whether the game should have Discord RPC.
* Developers can set this by checking the flag above.
*/
public final FUNKIN_DISCORD_RPC:FeatureFlag = 'FUNKIN_DISCORD_RPC';
/**
* `-DFUNKIN_DOX_GENERATION`
* Whether the game should be compiled into dox instead.
* Developers can set this by checking the flag above.
*/
public final FUNKIN_DOX_GENERATION:FeatureFlag = 'FUNKIN_DOX_GENERATION';
/**
* `-DFUNKIN_GIT_DETAILS`
* Whether the git hashes/branches should be shown in MenuState.
* Developers can set this by checking the flag above.
*/
public final FUNKIN_GIT_DETAILS:FeatureFlag = 'FUNKIN_GIT_DETAILS';
public var GIT_HASH:String = null;
public var GIT_BRANCH:String = null;
public var GIT_MODIFIED:Null<Bool> = null;
public function new()
{
super();
setenv('HAXEPATH', './'); // Fixes an issue for haxelibs that use native C++ files until Haxe 5 releases.
setupApplicationSettings();
setupWindowSettings();
setupPathSettings();
setupFeatureFlags();
setupHaxelibs();
setupHaxeDefines();
setupHaxeFlags();
}
public function setupApplicationSettings():Void
{
meta.title = 'Friday Night Funkin\': TechNotDrip Engine';
meta.version = TECHNOTDRIP_VERSION;
meta.packageName = 'ca.technotdrip.tilnotdrip';
meta.company = 'TilNotDrip';
app.file = 'TechNotDrip';
app.main = 'Main';
app.preloader = 'flixel.system.FlxPreloader';
}
public function setupWindowSettings():Void
{
window.width = 1280;
window.height = 720;
window.background = 0;
window.hardware = true;
window.vsync = false;
if (platformType == WEB)
{
window.resizable = true;
}
if (platformType == DESKTOP)
{
window.orientation = LANDSCAPE;
window.fullscreen = false;
window.resizable = true;
}
if (platformType == MOBILE)
{
window.orientation = LANDSCAPE;
window.fullscreen = false;
window.resizable = false;
window.allowShaders = true;
window.requireShaders = true;
window.allowHighDPI = true;
}
}
public function setupPathSettings():Void
{
app.path = 'export/' + ((debug) ? 'debug' : 'release');
var excludeList:Array<String> = [];
excludeList.push((platformType == WEB) ? 'ogg' : 'mp3');
// TODO: Maybe scan the entire assets folder instead like base fnf.
includeAssets("assets", "assets", ['*'], excludeList);
addIcon('extras/appicons/icon16.png', 16);
addIcon('extras/appicons/icon32.png', 32);
addIcon('extras/appicons/icon64.png', 64);
addIcon('extras/appicons/icon.png');
sources.push('src');
}
public function setupFeatureFlags():Void
{
// The second parameter is the default value unless overridden!
FUNKIN_DISCORD_RPC.apply(this, platformType == DESKTOP && haxedefs.get('cpp')); // Will be enabled if its on desktop (windows, linux, mac)!
FUNKIN_DOX_GENERATION.apply(this, false); // Will always be false unless you wanna make a documentation website.
FUNKIN_GIT_DETAILS.apply(this, !['stable', 'main', 'master', null].contains(getGitBranch().toLowerCase())); // Will show if it isn't the main branch!
}
public function setupHaxelibs():Void
{
addHaxelib('lime', '8.2.2');
addHaxelib('openfl', '9.4.1');
addHaxelib('flixel', '6.0.0');
addHaxelib('flixel-addons', 'git');
addHaxelib('flxanimate', 'git');
addHaxelib('extension-androidtools', '2.1.1', platformType == MOBILE && haxedefs.get('android'));
addHaxelib('hxcpp-debug-server', '1.2.4', debug);
addHaxelib('hxdiscord_rpc', '1.3.0', FUNKIN_DISCORD_RPC.isEnabled(this));
addHaxelib('thx.core', '0.44.0');
addHaxelib('thx.semver', '0.2.2');
}
public function setupHaxeDefines():Void
{
addHaxeDefine('doc-gen', FUNKIN_DOX_GENERATION.isEnabled(this));
addHaxeDefine('FLX_CUSTOM_ASSETS_DIRECTORY', 'assets', debug);
addHaxeDefine('FLX_NO_DEBUG', !debug);
addHaxeDefine('FLX_NO_FOCUS_LOST_SCREEN');
addHaxeDefine('FLX_NO_HEALTH');
addHaxeDefine('FLX_NO_KEYBOARD', platformType == MOBILE);
addHaxeDefine('FLX_NO_MOUSE', platformType == MOBILE);
addHaxeDefine('FLX_NO_TOUCH', platformType != MOBILE);
addHaxeDefine('message.reporting', 'pretty');
addHaxeDefine('NAPE_RELEASE_BUILD', !debug);
addHaxeDefine('TND_GIT_HASH', getGitHash(false));
addHaxeDefine('TND_GIT_BRANCH', getGitBranch());
addHaxeDefine('TND_GIT_MODIFIED', getGitModified());
if(haxedefs.get('android'))
{
config.set("android.gradle-version", '7.4.2');
config.set("android.gradle-plugin", "7.3.1");
config.set('android.minimum-sdk-version', 16);
config.set('android.target-sdk-version', 29);
}
}
public function setupHaxeFlags():Void
{
addHaxeFlag('-dce no');
addHaxeFlag("--macro include('funkin')");
addHaxeFlag("--macro include('flixel', true, ['flixel.addons.editors.spine.*', 'flixel.addons.nape.*', 'flixel.system.macros.*', 'flixel.addons.tile.FlxRayCastTilemap'])");
addHaxeFlag("--macro addMetadata('@:build(funkin.macros.ZProperty.build())', 'flixel.FlxBasic')");
addHaxeFlag('--no-output', FUNKIN_DOX_GENERATION.isEnabled(this));
addHaxeFlag('-xml docs/dox/' + Std.string(target).toLowerCase() + '.xml', FUNKIN_DOX_GENERATION.isEnabled(this));
}
public function addHaxelib(name:String, version:String = '', conditions:Bool = true):Void
{
if (!conditions)
return;
haxelibs.push(new Haxelib(name, version));
}
public function addHaxeDefine(name:String, value:String = '', conditions:Bool = true):Void
{
if (!conditions)
return;
haxedefs.set(name, value);
}
public function addHaxeFlag(name:String, conditions:Bool = true):Void
{
if (!conditions)
return;
haxeflags.push(name);
}
public function addIcon(path:String, ?size:Int):Void
{
icons.push(new Icon(path, size));
}
function getGitHash(splice:Bool = false):String
{
if (GIT_HASH == null)
{
var gitProcess:Process = new Process('git', ['rev-parse', 'HEAD']);
if (gitProcess.exitCode() != 0)
{
trace('[WARNING]: Unable to get current git repository hash.');
return null;
}
else
{
GIT_HASH = gitProcess.stdout.readLine().trim();
}
gitProcess.close();
}
return GIT_HASH;
}
function getGitBranch():String
{
if (GIT_BRANCH == null)
{
var gitProcess:Process = new Process('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
if (gitProcess.exitCode() != 0)
{
trace('[WARNING]: Unable to get current git repository branch.');
return null;
}
else
{
GIT_BRANCH = gitProcess.stdout.readLine().trim();
}
gitProcess.close();
}
return GIT_BRANCH;
}
function getGitModified():Bool
{
if (GIT_MODIFIED == null)
{
var gitProcess:Process = new Process('git', ['status', '--porcelain']);
if (gitProcess.exitCode() != 0)
{
trace('[WARNING]: Unable to get current git repository branch.');
return null;
}
else
{
try
{
GIT_MODIFIED = gitProcess.stdout.readLine().trim().length > 0;
}
catch(e)
{
return false; // idk it breaks sometimes
}
}
gitProcess.close();
}
return GIT_MODIFIED;
}
}
/**
* An object representing a feature flag, which can be enabled or disabled.
* Includes features such as automatic generation of compile defines and inversion.
*/
abstract FeatureFlag(String) {
static final INVERSE_PREFIX:String = "NO_";
public function new(input:String) {
this = input;
}
@:from
public static function fromString(input:String):FeatureFlag {
return new FeatureFlag(input);
}
/**
* Enable/disable a feature flag if it is unset, and handle the inverse flag.
* Doesn't override a feature flag that was set explicitly.
* @param enableByDefault Whether to enable this feature flag if it is unset.
*/
public function apply(project:Project, enableByDefault:Bool = false):Void {
// TODO: Name this function better?
if (isEnabled(project)) {
// If this flag was already enabled, disable the inverse.
getInverse().disable(project, false);
} else if (getInverse().isEnabled(project)) {
// If the inverse flag was already enabled, disable this flag.
disable(project, false);
} else {
if (enableByDefault) {
// Enable this flag if it was unset, and disable the inverse.
enable(project, true);
} else {
// Disable this flag if it was unset, and enable the inverse.
disable(project, true);
}
}
}
/**
* Enable this feature flag by setting the appropriate compile define.
*
* @param project The project to modify.
* @param andInverse Also disable the feature flag's inverse.
*/
public function enable(project:Project, andInverse:Bool = true) {
project.haxedefs.set(this, "");
if (andInverse) {
getInverse().disable(project, false);
}
}
/**
* Disable this feature flag by removing the appropriate compile define.
*
* @param project The project to modify.
* @param andInverse Also enable the feature flag's inverse.
*/
public function disable(project:Project, andInverse:Bool = true) {
project.haxedefs.remove(this);
if (andInverse) {
getInverse().enable(project, false);
}
}
/**
* Query if this feature flag is enabled.
* @param project The project to query.
*/
public function isEnabled(project:Project):Bool {
// Check both Haxedefs and Defines for this flag.
return project.haxedefs.exists(this) || project.defines.exists(this);
}
/**
* Query if this feature flag's inverse is enabled.
*/
public function isDisabled(project:Project):Bool {
return getInverse().isEnabled(project);
}
/**
* Return the inverse of this feature flag.
* @return A new feature flag that is the inverse of this one.
*/
public function getInverse():FeatureFlag {
if (this.startsWith(INVERSE_PREFIX)) {
return this.substring(INVERSE_PREFIX.length);
}
return INVERSE_PREFIX + this;
}
}