-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.hxp
637 lines (560 loc) · 19.2 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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
import haxe.io.Path;
import sys.FileSystem;
import sys.io.Process;
import hxp.*;
import lime.tools.*;
using StringTools;
class EngineAsset {
/**
* The key name of the item should be the final path!
*/
public static var mapping:Map<String, EngineAsset> = new Map<String, EngineAsset>();
public var path:String;
public var rename:String;
public var library:String;
public var embed:Bool;
public function new(path:String, ?rename:String, ?library:String, embed:Bool = false) {
this.path = path;
this.rename = rename;
this.library = library;
this.embed = embed;
}
}
/**
* This project instead used a hxp file instead of a xml!
* This makes it easier to organize everything imo.
*
* Note: Based from base games hxp file.
*/
@:nullSafety class Project extends HXProject {
// Basic variables.
/**
* The current engine version.
* Remember to update this when a new engine version releases.
*/
static final engineVersion:String = '0.0.0';
/**
* The starting windowTitle.
* Although slightly mananaged by the `FlxWindow` class I'm still having this here.
*/
static final windowTitle:String = 'Friday Night Funkin\': Imaginative Engine';
/**
* The name of the executable file when the game complies.
*/
static final exeFileName:String = 'Imaginative';
/**
* The directory path to the source code.
*/
static final sourceCodeDirectory:String = 'engine/source';
/**
* The class path to the preloader class.
*/
static final preloaderClassPath:String = 'imaginative.backend.system.Preloader';
/**
* The package name.
*/
static final packageName:String = 'imaginative.engine.dev';
/**
* The class path to the main class.
*/
static final mainClassPath:String = 'imaginative.backend.system.Main';
/**
* The company name.
*/
static final companyName:String = 'Funkin-Imaginative';
// Compiler flags.
/**
* States if the engine has a version ID.
*/
static final knowsVersionID:CompilerFlag = 'KNOWS_VERSION_ID';
/**
* States if the engine can tell when a new version is available.
*/
static final checkForUpdates:CompilerFlag = 'CHECK_FOR_UPDATES';
/**
* States if the engine has modding support.
*/
static final modSupport:CompilerFlag = 'MOD_SUPPORT';
/**
* States if the engine has scripting support.
*/
static final scriptSupport:CompilerFlag = 'SCRIPT_SUPPORT';
/**
* States if the engine has haxe scripting support.
*/
static final canHaxeScript:CompilerFlag = 'CAN_HAXE_SCRIPT';
/**
* States if the engine has lua scripting support.
*/
static final canLuaScript:CompilerFlag = 'CAN_LUA_SCRIPT';
/**
* States if the engine can do scripted states.
*/
static final scriptedStates:CompilerFlag = 'SCRIPTED_STATES';
/**
* States if haxe scripting can do custom classes.
*/
static final customClasses:CompilerFlag = 'CUSTOM_CLASSES';
/**
* States if dead code elimination will be disabled.
*/
static final disableDCE:CompilerFlag = 'DISABLE_DCE';
/**
* States if the engine allows shaders at all.
*/
static final allowShaders:CompilerFlag = 'ALLOW_SHADERS';
/**
* States if the engine can connect with discord's rich presence system.
*/
static final discordRPC:CompilerFlag = 'DISCORD_RICH_PRESENCE';
/**
* States if the engine allows videos at all.
*/
static final allowVideos:CompilerFlag = 'ALLOW_VIDEOS';
/**
* States the console print should be fancy.
*/
static final consoleFancyPrint:CompilerFlag = 'CONSOLE_FANCY_PRINT';
override public function new() {
super();
CompilerFlag.init(this);
if (FileSystem.exists('compile/platform.txt')) {
if (sys.io.File.getContent('compile/platform.txt').trim() == 'cpp') {
Sys.println('...');
Sys.sleep(2);
Sys.println('Thought you could get away with it huh?');
Sys.sleep(2);
Sys.println('WELL NO.');
Sys.sleep(1);
Sys.println('PEANUT BUTTER & CHEESE');
Sys.exit(1);
}
}
if (hasDefine('web') || hasDefine('html5')) {
error('None of that thank you! I don\'t want people using the engine for web ports. If you don\'t remember, there used to be so many that base game wasn\'t first in search results!');
return;
} else if (isDesktop() || isMobile()) {
if (isMac()) { // fix for compiling on mac
setDefine('mac');
setDefine('macos');
}
} else {
error('Hey this engine only works on desktop and android devices!');
return;
}
setDefine('official'); // idk how I'm gonna handle this atm
addIcon('extras/art/logo.png');
/* Define Setup */
knowsVersionID.enable();
if ((isRelease() && knowsVersionID.exists()) && !isDebug())
checkForUpdates.enable();
modSupport.enable();
scriptSupport.enable();
// script related
if (scriptSupport.exists()) {
canHaxeScript.enable();
canLuaScript.enable();
disableDCE.enable();
scriptedStates.enable();
if (canHaxeScript.exists())
customClasses.enable();
info('Scripting was enabled.');
}
if (hasDefine('cpp')) {
if (isDesktop()) discordRPC.enable();
if (isDesktop() || isMobile())
allowVideos.enable();
}
if (discordRPC.exists())
setHaxedef('DISCORD_DISABLE_IO_THREAD');
allowShaders.enable();
consoleFancyPrint.softEnable();
/* Define Setup */
/* App Setup */
this.meta.title = windowTitle;
this.meta.version = engineVersion;
this.meta.packageName = packageName;
this.meta.company = companyName;
this.app.main = mainClassPath;
this.app.file = exeFileName;
this.app.preloader = preloaderClassPath;
/* App Setup */
/* Window Settings */
this.window.fps = 60;
this.window.width = 1280;
this.window.height = 720;
this.window.background = 0xFF000000;
this.window.hardware = this.window.resizable = true;
this.window.vsync = this.window.fullscreen = false;
this.window.allowShaders = allowShaders.exists();
this.window.orientation = Orientation.LANDSCAPE;
if (isMobile()) {
this.window.fullscreen = true;
this.window.resizable = false;
}
/* Window Settings */
/* Path Settings */
if (isDesktop())
addAsset('extras/alsoft.txt', '${isMac() ? 'Resources/' : ''}plugins/alsoft.${isWindows() ? 'ini' : 'conf'}');
var buildFolder:String = 'build';
if (!isRelease() && isDebug()) buildFolder = 'debug';
else if (isRelease() && !isDebug()) buildFolder = 'release';
else if (isRelease() && isDebug()) buildFolder = 'test';
this.app.path = 'export/$buildFolder${is32Bit() ? '-32bit' : ''}';
setDefine('GeneralAssetFolder', modSupport.exists() ? 'funkin' : 'assets');
var finalPath:String = '${modSupport.exists() ? 'solo/' : ''}${getDefine('GeneralAssetFolder')}';
this.sources.push(sourceCodeDirectory);
inline function mergeArrays<T>(one:Array<T>, two:Array<T>):Array<T> {
var result:Array<T> = [];
for (a in [one, two])
for (v in a)
result.push(v);
return result;
}
var repoItems:Array<String> = ['.git*', '.prettier*', '.editorconfig', 'checkstyle.json', '.vscode']; // Should certain things stay?
var excludeList:Array<String> = ['*.md']; // Should readme's be removed?
addAssetPath('engine/', '', ['*'], mergeArrays(excludeList, ['assets', 'modding', 'source', 'readme.md']));
addAssetPath('engine/assets', finalPath, ['*'], mergeArrays(excludeList, repoItems));
if (modSupport.exists()) {
addAssetPath('engine/modding/upfront', 'solo', ['*'], mergeArrays(excludeList, repoItems));
addAssetPath('engine/modding/lowerend', 'mods', ['*'], mergeArrays(excludeList, repoItems));
}
if (isDebug())
addAssetPath('extras/debug/', finalPath, true, ['*'], mergeArrays(excludeList, repoItems));
info('The ${modSupport.exists() ? 'main mod' : 'asset folder'} is "$finalPath".');
/* Path Settings */
/* Libraries */
addHaxelib('hxp');
// required for flixel, don't put below flixel, causes wierd issues
addHaxelib('openfl');
addHaxelib('lime');
// the game engine
addHaxelib('flixel', 'git');
addHaxelib('flixel-addons', 'git');
// json parsing
addHaxelib('json2object', 'git');
addHaxelib('checkstyle'); // pretty export
// debugging
if (isDesktop() && isDebug())
addHaxelib('hxcpp-debug-server');
// chart converter
addHaxelib('moonchart', 'git');
if ( canHaxeScript.exists()) addHaxelib('hscript-improved', 'git');
if ( canLuaScript .exists()) addHaxelib('linc_luajit', 'git');
if ( discordRPC .exists()) addHaxelib('hxdiscord_rpc');
if (allowVideos .exists()) addHaxelib('hxvlc', 'git');
if (knowsVersionID.exists()) addHaxelib('thx.semver');
/* Libraries */
if (!isDebug())
setHaxedef('FLX_NO_DEBUG');
// may add one
setHaxedef('FLX_NO_FOCUS_LOST_SCREEN');
if (disableDCE.exists())
addHaxeFlag('-dce no');
setHaxedef('no-deprecation-warnings'); // May remove?
setHaxedef('message.reporting', 'pretty');
setHaxedef('message.log-format', 'pretty');
if (allowVideos.exists())
setHaxedef('HXVLC_NO_SHARE_DIRECTORY');
if (canHaxeScript.exists())
setHaxedef('hscriptPos');
if (isRelease() && !isDebug())
setHaxedef('analyzer-optimize');
// related to flixel cne fork
setHaxedef('EXPERIMENTAL_FLXGRAPHIC_DESTROY_FIX');
// truly push assets
var defineEmbed:Bool = false;
for (setAsset in EngineAsset.mapping) {
var willEmbed:Bool = /* isDebug() ? false : */ setAsset.embed;
if (willEmbed)
defineEmbed = true;
var asset = new Asset(setAsset.path ?? '', setAsset.rename ?? '', null, willEmbed);
@:nullSafety(Off) asset.library = setAsset.library ?? 'default';
this.assets.push(asset);
}
if (defineEmbed) // save memory on compiled build... probably
setHaxedef('CONTAINS_EMBEDDED_FILES');
}
/**
* If true, your compiling on desktop.
*/
inline public function isDesktop():Bool
return hasDefine('desktop');
/**
* If true, your compiling on mobile.
*/
inline public function isMobile():Bool
return hasDefine('mobile');
/**
* If true, your compiling on a 32 bit system.
*/
inline public function is32Bit():Bool
return this.architectures.contains(Architecture.X86);
/**
* If true, your compiling on a 64 bit system.
*/
inline public function is64Bit():Bool
return this.architectures.contains(Architecture.X64);
/**
* If true, your compiling on windows.
*/
inline public function isWindows():Bool
return hasDefine('windows');
/**
* If true, your compiling on mac.
*/
inline public function isMac():Bool
return hasDefine('mac') || hasDefine('macos');
/**
* If true, your compiling on linux.
*/
inline public function isLinux():Bool
return hasDefine('linux');
/**
* If true, your compiling on android.
*/
inline public function isAndroid():Bool
return this.targetFlags.exists('android');
/**
* If true, your compiling on ios.
*/
inline public function isIOS():Bool
return this.targetFlags.exists('ios');
/**
* If true, your compiling on a release build.
*/
inline public function isRelease():Bool
return hasDefine('release');
/**
* If true, your compiling on a debug build.
*/
inline public function isDebug():Bool
return hasDefine('debug');
/**
* Set's a haxedef.
* @param name The haxedef key.
* @param value The value of the haxedef.
*/
inline public function setHaxedef(name:String, value:String = ''):Void {
info('Set haxedef "$name"${value == null ? '' : ' value of "$value"'}.');
this.haxedefs.set(name, value);
}
/**
* Get's information from a haxedef.
* @param name The haxedef key.
* @return The value of the haxedef.
*/
inline public function getHaxedef(name:String):Null<Dynamic>
return this.haxedefs.get(name);
/**
* Unset's a haxedef.
* @param name The haxedef key.
*/
inline public function unsetHaxedef(name:String):Void
if (hasHaxedef(name)) {
info('Unset haxedef "$name".');
this.haxedefs.remove(name);
}
/**
* Check's if a haxedef exists.
* @param name The haxedef key.
* @return If true, the define exists.
*/
inline public function hasHaxedef(name:String):Bool
return this.haxedefs.exists(name);
/**
* Set's a define.
* @param name The define key.
* @param value The value of the define.
*/
inline public function setDefine(name:String, value:String = ''):Void {
info('Set define "$name"${value == null ? '' : ' value of "$value"'}.');
this.defines.set(name, value);
this.haxedefs.set(name, value);
this.environment.set(name, value);
}
/**
* Get's information from a define.
* @param name The define key.
* @return The value of the define.
*/
inline public function getDefine(name:String):Null<Dynamic>
return this.defines.get(name);
/**
* Unset's a define.
* @param name The define key.
*/
inline public function unsetDefine(name:String):Void
if (hasDefine(name)) {
info('Unset define "$name".');
this.defines.remove(name);
this.haxedefs.remove(name);
this.environment.remove(name);
}
/**
* Check's if a define exists.
* @param name The define key.
* @return If true, the define exists.
*/
inline public function hasDefine(name:String):Bool
return this.defines.exists(name);
/**
* Add a library to the list of dependencies for the project.
* @param name The name of the library to add.
* @param version The version of the library to add. Optional.
*/
inline public function addHaxelib(name:String, version:String = ''):Void
this.haxelibs.push(new Haxelib(name, version));
/**
* Add a `haxeflag` to the project.
* @param value The flag.
*/
inline public function addHaxeFlag(value:String):Void
this.haxeflags.push(value);
/**
* Call a Haxe build macro.
* @param value The macro.
*/
inline public function addHaxeMacro(value:String):Void
addHaxeFlag('--macro $value');
/**
* Add an icon to the project.
* @param icon The path to the icon.
* @param size The size of the icon, optional.
*/
inline public function addIcon(icon:String, ?size:Int):Void
this.icons.push(new Icon(icon, size));
/**
* Add an asset to the game build.
* @param path The path the asset is located at.
* @param rename The path the asset should be placed.
* @param force If true, if the game find that the file already exists then it will replace that file.
* @param library The asset library to add the asset to. `null` = "default"
* @param embed Whether to embed the asset in the executable.
*/
inline public function addAsset(path:String, ?rename:String, force:Bool = false, ?library:String, embed:Bool = false):Void
if (!EngineAsset.mapping.exists(rename ?? path) || force)
EngineAsset.mapping.set(rename ?? path, new EngineAsset(Path.normalize(path), @:nullSafety(Off) Path.normalize(rename), library, embed));
/**
* Add an entire path of assets to the game build.
* @param path The path the assets are located at.
* @param rename The path the assets should be placed.
* @param force If true, if the game find that the file already exists then it will replace that file.
* @param library The asset library to add the assets to. `null` = "default"
* @param include An optional array to include specific asset names.
* @param exclude An optional array to exclude specific asset names.
* @param embed Whether to embed the assets in the executable.
*/
public function addAssetPath(path:String, ?rename:String, force:Bool = false, ?library:String, ?include:Array<String>, ?exclude:Array<String>, embed:Bool = false):Void {
// Argument parsing.
if (path == '')
return;
if (include == null)
include = [];
if (exclude == null)
exclude = [];
var targetPath:String = Path.normalize(rename ?? path);
// Validate path.
if (!FileSystem.exists(path)) {
error('Could not find asset path "$path".');
return;
} else if (!FileSystem.isDirectory(path)) {
error('Could not parse asset path "$path", expected a directory.');
return;
} /* else
info('Found asset path "$path".'); */
if (FileSystem.isDirectory(path) || FileSystem.exists(path))
for (file in FileSystem.readDirectory(path)) {
if (FileSystem.isDirectory('$path/$file')) {
// Attempt to recursively add all assets in the directory.
if (this.filter(file, ['*'], exclude)) {
var renamedFolder:String = file;
var willEmbed:Bool = file == 'embed';
if (willEmbed)
renamedFolder = '';
else if (file == '!embed')
renamedFolder = 'embed';
if (embed)
willEmbed = embed;
addAssetPath('$path/$file', '${Path.addTrailingSlash(targetPath)}$renamedFolder', force, library, include, exclude, willEmbed);
}
} else if (FileSystem.exists('$path/$file'))
if (this.filter(file, include, exclude)) {
var folderEmbedded:Bool = false;
var renamedFile:String = file;
var willEmbed:Bool = Path.extension(Path.withoutExtension(file)) == 'embed';
if (willEmbed) {
folderEmbedded = path.split('/').contains('embed');
renamedFile = '${Path.withoutExtension(Path.withoutExtension(file))}.${Path.extension(file)}';
} else if (Path.extension(Path.withoutExtension(file)) == '!embed')
renamedFile = '${Path.withoutExtension(Path.withoutExtension(file))}.embed.${Path.extension(file)}';
if (embed)
willEmbed = embed;
if (folderEmbedded) info('File "$path/$file" is already in an "embed" folder. Embedding denied.');
else addAsset('$path/$file', '${Path.addTrailingSlash(targetPath)}$renamedFile', force, willEmbed);
}
}
}
/**
* Add an asset library to the game build.
* @param name The name of the library.
* @param embed
* @param preload
*/
inline public function addAssetLibrary(name:String, embed:Bool = false, preload:Bool = false):Void
this.libraries.push(new Library('', name, null, embed, preload, false, ''));
/**
* Display an error message. This should stop the build process.
*/
inline public function error(message:String):Void
Log.error('$message');
/**
* Display an info message. This should not interfere with the build process.
*/
inline public function info(message:String):Void {
// CURSED: We have to disable info() log calls because of a bug.
// https://github.com/haxelime/lime-vscode-extension/issues/88
// The bug they talk about is a thing, but unlike them it doesn't effect compiling for me lmfao.
// Log.info('[INFO] $message');
}
}
/**
* An object representing a feature flag, which can be enabled or disabled.
* Includes features such as automatic generation of compile defines and inversion.
*/
abstract CompilerFlag(String) {
static var parentProject(default, null):Project;
public static function init(project:Project):Void
parentProject = project;
inline public function new(input:String)
this = input;
@:from inline public static function fromString(input:String):CompilerFlag
return new CompilerFlag(input);
/**
* Enable this feature flag by setting the appropriate compile define.
* @param value The flag value.
*/
inline public function enable(value:String = ''):Void
if (!exists())
parentProject.setDefine(this, value);
/**
* Enable this feature flag by setting the appropriate compile define.
* @param value The flag value.
*/
inline public function softEnable(value:String = ''):Void
if (!exists())
parentProject.setHaxedef(this, value);
/**
* Disable this feature flag by removing the appropriate compile define.
*/
inline public function disable():Void
if (exists())
parentProject.unsetDefine(this);
else if (parentProject.hasHaxedef(this))
parentProject.unsetHaxedef(this);
/**
* Query if this feature flag is enabled.
*/
inline public function exists():Bool
return parentProject.hasHaxedef(this);
}