This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
forked from KadeArchive/Kade-Engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
project.hxp
647 lines (564 loc) · 20.4 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
638
639
640
641
642
643
644
645
646
647
/*
* GNU General Public License, Version 3.0
*
* Copyright (c) 2021 MasterEric
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* project.hxp
* Provides project configuration in a format mirroring Haxe.
* hey what if project.xml but instead it's code
*/
import hxp.*;
import lime.tools.*;
import sys.FileSystem;
class Project extends HXProject {
static final FEATURE_DISCORD:String = "FEATURE_DISCORD";
static final FEATURE_POLYMOD:String = "FEATURE_POLYMOD";
static final FEATURE_LUAMODCHART:String = "FEATURE_LUAMODCHART";
static final FEATURE_FILESYSTEM:String = "FEATURE_FILESYSTEM";
static final FEATURE_WEBM:String = "FEATURE_WEBM";
static final FEATURE_MULTITHREADING:String = "FEATURE_MULTITHREADING";
static final FEATURE_MODCORE:String = "FEATURE_MODCORE";
static final FEATURE_GAMEJOLT:String = "FEATURE_GAMEJOLT";
public function new () {
super ();
// Display ASCII art.
flair();
// Set the project metadata.
configureApp();
// Apply project feature definitions.
configureFeatureDefines();
// Set the build output folder.
configureOutputDir();
// Configure the Polymod library.
configurePolymod();
// Configure library dependencies.
configureLibraries();
// Configure asset libraries.
configureAssets();
// Configure favicons.
configureIcons();
}
/**
* Configure basic metadata about the project.
*/
function configureApp() {
meta.title = "Enigma Engine";
meta.description = "A moddable game engine for Friday Night Funkin'.";
meta.version = "0.3.0";
meta.packageName = "com.mastereric.enigmaengine";
meta.company = "";
// meta.buildNumber
// meta.companyId
// meta.companyUrl
// The entry point for the application.
app.main = "Main";
// The name of the executable.
app.file = "Enigma";
app.preloader = "flixel.system.FlxPreloader";
// app.path
// app.init
// app.swfVersion
// app.url
// Source directory for the application.
sources.push('source');
}
/**
* Configure feature definitions based on the target platform.
*/
function configureFeatureDefines() {
// Ensure only supported platforms are used.
switch(target) {
case Platform.WINDOWS:
info('Platform: Windows');
case Platform.MAC: // Mac will probably work, but I can't build it right now.
info('Platform: Mac');
case Platform.LINUX:
info('Platform: Linux');
case Platform.ANDROID:
info('Platform: Android');
case Platform.HTML5:
info('Platform: HTML5');
// case Platform.EMSCRITEN: // A WebAssembly build might be interesting...
// case Platform.IOS: // I can't support iOS right now, since I don't have the ability to build.
// case Platform.AIR:
// case Platform.BLACKBERRY:
// case Platform.CONSOLE_PC:
// case Platform.CUSTOM:
// case Platform.FIREFOX:
// case Platform.FLASH:
// case Platform.PS3:
// case Platform.PS4:
// case Platform.TIZEN:
// case Platform.TVOS:
// case Platform.VITA:
// case Platform.WEBOS:
// case Platform.WIIU:
// case Platform.XBOX1:
default:
error('Unsupported platform (got ${target})');
}
for (architecture in architectures) {
// Ensure only supported architectures are used.
switch(architecture) {
case Architecture.X86:
info('Architecture: x86');
case Architecture.X64:
info('Architecture: x64');
case Architecture.ARMV5:
info('Architecture: ARMv5');
case Architecture.ARMV6:
info('Architecture: ARMv6');
case Architecture.ARMV7:
info('Architecture: ARMv7');
case Architecture.ARMV7S:
info('Architecture: ARMv7S');
case Architecture.ARM64:
info('Architecture: ARMx64');
case Architecture.MIPS:
info('Architecture: MIPS');
case Architecture.MIPSEL:
info('Architecture: MIPSEL');
case null:
if (!isWeb())
error('Unsupported architecture (got null on non-web platform)');
default:
error('Unsupported architecture (got ${architecture})');
}
}
if (isDesktop()) {
haxedefs.set(FEATURE_DISCORD, "true");
haxedefs.set(FEATURE_POLYMOD, "true");
haxedefs.set(FEATURE_LUAMODCHART, "true");
haxedefs.set(FEATURE_FILESYSTEM, "true");
haxedefs.set(FEATURE_MULTITHREADING, "true");
haxedefs.set(FEATURE_MODCORE, "true");
haxedefs.set(FEATURE_GAMEJOLT, "true");
}
if (isDesktop() /*|| isWeb()*/) {
haxedefs.set(FEATURE_WEBM, "true");
}
if (isDesktop() && !isWeb()) {
haxedefs.set("FLX_NO_TOUCH", "true");
}
if (isMobile()) {
haxedefs.set("FLX_NO_KEYBOARD", "true");
haxedefs.set("FLX_NO_MOUSE", "true");
}
if (!debug) {
haxedefs.set("FLX_NO_DEBUG", "true");
haxedefs.set("NAPE_RELEASE_BUILD", "true");
}
haxedefs.set("HXCPP_CHECK_POINTER", "true");
haxedefs.set("HXCPP_STACK_LINE", "true");
haxedefs.set("FLX_NO_FOCUS_LOST_SCREEN", "true");
}
function configureOutputDir() {
// Set the output directory. Depends on the target platform and build type.
var architecture = is64Bit() ? "x64" : "x86";
var includeDefaultWeeks = defines.exists("includeDefaultWeeks");
var buildDir = 'export/${debug ? 'debug' : 'release'}/${includeDefaultWeeks ? 'vanilla' : 'base'}/$architecture'; // /$target
info('Output directory: $buildDir');
// setenv('BUILD_DIR', buildDir);
app.path = buildDir;
}
/**
* Configure the Polymod library.
*/
function configurePolymod() {
haxedefs.set("POLYMOD_SCRIPT_EXT", ".hscript");
haxedefs.set("POLYMOD_SCRIPT_LIBRARY", "scripts");
haxedefs.set("POLYMOD_USE_NAMESPACE", "false");
haxedefs.set("POLYMOD_ROOT_PATH", "assets/scripts");
if (debug) {
haxedefs.set("POLYMOD_DEBUG", "true");
}
}
/**
* Configures library dependencies for the project.
*/
function configureLibraries () {
// Primary asset management.
addHaxelib("lime", "7.9.0"); // Explicitly set the version to avoid a warning.
addHaxelib("openfl", "9.1.0");
// The core game engine.
addHaxelib("flixel");
// A set of additional utilities for Flixel.
addHaxelib("flixel-addons");
// A set of user interface controls for Flixel.
addHaxelib("flixel-ui");
// A set of additional functions for working with strings.
addHaxelib("haxe-strings");
// A libary to provide internationalization support.
addHaxelib("firetongue");
// A motion library used by the video handler.
addHaxelib("actuate");
// A library for tolerant JSON parsing. Fewer typo bugs means fewer GitHub issues.
addHaxelib("tjson");
// An FMOD wrapper for Haxe. Includes APIs for sound manipulation.
// addHaxelib("haxefmod");
// A libary which allows for parsing and executing Haxe code. Necessary for mods.
addHaxelib("hscript");
// A library for atomic mod loading and asset replacement.
addHaxelib("polymod");
if (isFeatureEnabled(FEATURE_DISCORD)) {
info('Discord integration is enabled, adding libraries.');
// A library for integration with the Discord API.
addHaxelib("discord_rpc");
}
if (isFeatureEnabled(FEATURE_WEBM) && isDesktop()) {
info('WEBM integration is enabled, adding DESKTOP libraries.');
// A library which allows for loading and parsing of WEBM videos on desktop. Used for cutscenes.
// On web, this library isn't needed, it already supports video.
addHaxelib("extension-webm");
}
if (isFeatureEnabled(FEATURE_LUAMODCHART)) {
info('Lua Modchart integration is enabled, adding libraries.');
// A library for parsing and executing Lua code. Necessary for modcharts.
addHaxelib("linc_luajit");
addHaxelib("hxvm-luajit");
}
}
/**
* Configures the application window.
*/
function configureWindow() {
// Automatically configure FPS.
window.fps = 0;
// Set the window size.
window.width = 1280;
window.height = 720;
// Blank or transparent background.
window.background = null;
window.hardware = true;
window.vsync = false;
if (isWeb()) {
window.resizable = true;
}
if (isDesktop()) {
window.orientation = Orientation.LANDSCAPE;
window.fullscreen = false;
window.resizable = true;
window.vsync = false;
}
if (isMobile()) {
window.orientation = Orientation.LANDSCAPE;
window.fullscreen = false;
window.resizable = false;
window.width = 0;
window.height = 0;
}
// window.allowHighDPI:Bool;
// window.allowShaders:Bool;
// window.alwaysOnTop:Bool;
// window.antialiasing:Int;
// window.borderless:Bool;
// window.colorDepth:Int;
// window.depthBuffer:Bool;
// window.display:Int;
// window.element:js.html.Element;
// window.hidden:Bool;
// window.maximized:Bool;
// window.minimized:Bool;
// window.parameters:String;
// window.requireShaders:Bool;
// window.stencilBuffer:Bool;
// window.title:String;
// window.x:Float;
// window.y:Float;
}
/**
* Configure the asset folders to be used by the project.
*/
function configureAssets() {
var shouldEmbed = defines.exists("embedAssets");
var includeDefaultWeeks = defines.exists("includeDefaultWeeks");
var includeExampleMods = !defines.exists("excludeExampleMods");
// Only use OGG on desktop and MP3 on web.
var excludeExt = isWeb() ? ["*.md", "*.ogg"] : ["*.md", "*.mp3"];
// You can use a define to force assets to be preloaded.
// Github Copilot thought of that part all on its own and that's really scary.
var shouldPreload = !isWeb() || defines.exists("preloadAssets");
if (shouldEmbed) {
info('NOTICE: Embedding assets into executable...');
} else {
info('NOTICE: Including assets alongside executable...');
}
// Put the assets in _includeDefaultWeeks before those in the main folders.
if (includeDefaultWeeks) {
info('NOTICE: Including default weeks...');
addAssetPath("assets/_includeDefaultWeeks", "assets", ["*"], excludeExt, shouldEmbed);
} else {
info('NOTICE: Excluding default weeks...');
addAssetPath("assets/_excludeDefaultWeeks", "assets", ["*"], excludeExt, shouldEmbed);
}
// Add the preloaded main asset path.
addAssetPath("assets/preload", "assets", ["*"], excludeExt, shouldEmbed);
// Add the main libraries.
addAssetLibrary("scripts", true, true); // Scripts should always be embedded.
addAssetLibrary("songs", shouldEmbed, shouldPreload);
addAssetLibrary("shared", shouldEmbed, shouldPreload);
// addAssetLibrary("sm", shouldEmbed, shouldPreload);
// Add the main asset paths (AFTER the libraries).
addAssetPath("assets/core", "assets/core", ["*"], excludeExt, true);
addAssetPath("assets/scripts", "assets/scripts", ["*"], excludeExt, true);
addAssetPath("assets/songs", "assets/songs", ["*"], excludeExt, shouldEmbed);
addAssetPath("assets/shared", "assets/shared", ["*"], excludeExt, shouldEmbed);
// addAssetPath("assets/sm", "sm", ["*"], excludeExt, shouldEmbed);
addAssetPath("assets/core", "assets/core", ["*"], excludeExt, shouldEmbed);
addAssetPath("assets/core", "assets/core", ["*"], excludeExt, shouldEmbed);
// TODO: Deprecate week-specific asset libraries.
if (includeDefaultWeeks) {
// addAssetLibrary("assets/tutorial", shouldEmbed, shouldPreload);
// addAssetLibrary("assets/week1", shouldEmbed, shouldPreload);
// addAssetLibrary("assets/week2", shouldEmbed, shouldPreload);
addAssetLibrary("week3", shouldEmbed, shouldPreload);
addAssetLibrary("week4", shouldEmbed, shouldPreload);
addAssetLibrary("week5", shouldEmbed, shouldPreload);
addAssetLibrary("week6", shouldEmbed, shouldPreload);
// addAssetPath("assets/_includeDefaultWeeks/tutorial", "tutorial", ["*"], excludeExt, shouldEmbed);
// addAssetPath("assets/_includeDefaultWeeks/week1", "week1", ["*"], excludeExt, shouldEmbed);
// addAssetPath("assets/_includeDefaultWeeks/week2", "week2", ["*"], excludeExt, shouldEmbed);
addAssetPath("assets/_includeDefaultWeeks/week3", "assets/week3", ["*"], excludeExt, shouldEmbed);
addAssetPath("assets/_includeDefaultWeeks/week4", "assets/week4", ["*"], excludeExt, shouldEmbed);
addAssetPath("assets/_includeDefaultWeeks/week5", "assets/week5", ["*"], excludeExt, shouldEmbed);
addAssetPath("assets/_includeDefaultWeeks/week6", "assets/week6", ["*"], excludeExt, shouldEmbed);
}
addAsset("art/README.txt", "README.txt", false);
addAsset("LICENSE", "LICENSE.txt", false);
// To font, convert to OTF, then use setFormat on the text with the name of the font.
addAssetPath("assets/fonts", null, ["*"], excludeExt, true);
}
/**
* Configure the favicon for the executable file.
*/
function configureIcons() {
addIcon("art/icon8.png", 8);
addIcon("art/icon16.png", 16);
addIcon("art/icon32.png", 32);
addIcon("art/icon64.png", 64);
addIcon("art/icon128.png", 128);
addIcon("art/icon256.png", 256);
addIcon("art/iconOG.png");
}
/**
* Returns whether a given feature is enabled based on whether a HaxeDef has been provided.
* @param feature The feature to check.
*/
function isFeatureEnabled (feature):Bool {
return haxedefs.exists(feature);
}
/**
* Returns true if the current platform has a 64-bit architecture.
* @return Whether the current platform is 64-bit.
*/
function is64Bit ():Bool {
return architectures.contains(Architecture.X64);
}
/**
* Returns true if the current platform has a 32-bit architecture.
* @return Whether the current platform is 32-bit.
*/
function is32Bit ():Bool {
return architectures.contains(Architecture.X86);
}
/**
* Returns true if the current platform is a desktop platform, such as Windows or Linux.
* @return Whether the current platform is a desktop platform.
*/
function isDesktop():Bool {
return platformType == PlatformType.DESKTOP;
}
/**
* Returns true if the current platform is a mobile platform, such as Android or iOS.
* @return Whether the current platform is a mobile platform.
*/
function isMobile():Bool {
return platformType == PlatformType.MOBILE;
}
/**
* Returns true if the current platform is a web platform, such as HTML5.
* @return Whether the current platform is a web platform.
*/
function isWeb():Bool {
return platformType == PlatformType.WEB;
}
/**
* Returns true if the current platform is a Windows desktop.
* @return Whether the current platform is a Windows desktop.
*/
function isWindows():Bool {
return platformType == PlatformType.DESKTOP && target == Platform.WINDOWS;
}
/**
* Returns true if the current platform is a Linux desktop.
* @return Whether the current platform is a Linux desktop.
*/
function isLinux():Bool {
return platformType == PlatformType.DESKTOP && target == Platform.LINUX;
}
/**
* Returns true if the current platform is a Mac desktop.
* @return Whether the current platform is a Mac desktop.
*/
function isMac():Bool {
return platformType == PlatformType.DESKTOP && target == Platform.MAC;
}
/**
* Returns true if the current platform is an Android mobile device.
* @return Whether the current platform is an Android mobile device.
*/
function isAndroid():Bool {
return platformType == PlatformType.MOBILE && target == Platform.ANDROID;
}
/**
* Returns true if the current platform is an iOS mobile device.
* @return Whether the current platform is an iOS mobile device.
*/
function isIOS():Bool {
return platformType == PlatformType.MOBILE && target == Platform.IOS;
}
/**
* Adds a library to the list of dependencies to be included in the project.
* @param name The name of the library to add.
*/
function addHaxelib(name:String, version:String = ""):Void {
haxelibs.push (new Haxelib (name, version));
}
/**
* Add an icon file of the given size to the project.
* SVG is supported and preferred over bitmap files.
* @param icon The path to the icon file.
* @param size The size of the icon.
*/
function addIcon(icon:String, size:Int = null) {
icons.push(new Icon(icon, size));
}
function addAssetLibrary(name:String, embed:Bool = false, preload:Bool = false) {
var sourcePath = null;
var type = null;
var generate = false;
var prefix = "";
var assetLibrary = new Library(sourcePath, name, type, embed, preload, generate, prefix);
libraries.push(assetLibrary);
}
function addAsset(path:String, rename:String = null, embed:Bool = false) {
assets.push(new Asset(path, rename, null, embed, true));
}
function addAssetPath(path:String, rename:String = null, include:Array<String> = null, exclude:Array<String> = null, embed:Bool = false):Void
{
if (path == "")
return;
if (!FileSystem.exists(path))
{
error("Could not find asset path \"" + path + "\"");
return;
}
if (include == null)
include = ["*"];
if (exclude == null)
exclude = [];
exclude = exclude.concat([".*", "cvs", "thumbs.db", "desktop.ini", "*.hash"]);
var targetPath = "";
if (rename != null)
{
targetPath = rename;
}
else
{
targetPath = path;
}
var files = FileSystem.readDirectory(path);
if (targetPath != "")
targetPath += "/";
for (file in files)
{
if (FileSystem.isDirectory(path + "/" + file))
{
// Recursive file calls.
if (filter(file, ["*"], exclude))
addAssetPath(path + "/" + file, targetPath + file, include, exclude, embed);
}
else
{
if (filter(file, include, exclude)) {
addAsset(path + "/" + file, targetPath + file, embed);
}
}
}
}
function flair() {
info("_____________________________________________");
info("___________________6666666___________________");
info("____________66666__________66666_____________");
info("_________6666___________________666__________");
info("_______666__6____________________6_666_______");
info("_____666_____66_______________666____66______");
info("____66_______66666_________66666______666____");
info("___66_________6___66_____66___66_______666___");
info("__66__________66____6666_____66_________666__");
info("_666___________66__666_66___66___________66__");
info("_66____________6666_______6666___________666_");
info("_66___________6666_________6666__________666_");
info("_66________666_________________666_______666_");
info("_66_____666______66_______66______666____666_");
info("_666__666666666666666666666666666666666__66__");
info("__66_______________6____66______________666__");
info("___66______________66___66_____________666___");
info("____66______________6__66_____________666____");
info("_______666___________666___________666_______");
info("_________6666_________6_________666__________");
info("____________66666_____6____66666_____________");
info("___________________6666666___________________");
info("_____________________________________________");
info("I I");
info("I _____ _ _ _____ _____ ___ ___ ___ I");
info("I | ___| \\ | |_ _| __ \\| \\/ | / _ \\ I");
info("I | |__ | \\| | | | | | \\/| . . |/ /_\\ \\ I");
info("I | __|| . ` | | | | | __ | |\\/| || _ | I");
info("I | |___| |\\ |_| |_| |_\\ \\| | | || | | | I");
info("I \\____/\\_| \\_/\\___/ \\____/\\_| |_/\\_| |_/ I");
info("I _____ _ _ _____ _____ _ _ _____ I");
info("I | ___| \\ | | __ \\_ _| \\ | || ___| I");
info("I | |__ | \\| | | \\/ | | | \\| || |__ I");
info("I | __|| . ` | | __ | | | . ` || __| I");
info("I | |___| |\\ | |_\\ \\_| |_| |\\ || |___ I");
info("I \\____/\\_| \\_/\\____/\\___/\\_| \\_/\\____/ I");
info("I I");
info("I I");
info(" ");
info("Initializing build... ");
}
/**
* Throw an error. This should stop the build process.
* @param message The error message to display.
*/
function error(message:String) {
Log.error(message);
}
/**
* Display an info message. This should not interfere with the build process.
* @param message The message to display.
*/
function info(message:String) {
// Disable info() log calls because of a bug.
// https://github.com/haxelime/lime-vscode-extension/issues/88
Log.info(message);
// trace(message);
// Sys.println(message);
// Sys.stdout().writeString(message);
// Sys.stderr().writeString(message);
}
}