Repository navigation
Expand file tree
/
Copy pathproject.hxp
More file actions
372 lines (299 loc) · 9.55 KB
/
Copy pathproject.hxp
File metadata and controls
372 lines (299 loc) · 9.55 KB
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
import hxp.*;
import lime.tools.*;
using StringTools;
class Project extends HXProject
{
static final TITLE:String = "Friday Night Funkin' - Moon Engine";
static final VERSION:String = "0.0.0";
static final EXECUTABLE_NAME:String = "Moon-Engine";
static final PRELOADER:String = "flixel.system.FlxPreloader";
static final SOURCE_DIR:String = "source";
static final PACKAGE_NAME:String = "me.chaoticteam.fnfme";
static final MAIN_CLASS:String = "Main";
static final COMPANY:String = "Chaotic Team";
static final PREBUILD_HX:String = "Prebuild.hx";
static final POSTBUILD_HX:String = "Postbuild.hx";
// feature flags go here
// Rename files that has underscore for html5 builds
static final RENAME_UNDERSCORE:FeatureFlag = "RENAME_UNDERSCORE";
//
// if you want a specific haxedef to be enabled on certain circumstances,
// or one that needs more values,
// you'll have to go to setupHaxedefs() and add it manually there.
static final HAXEDEFS:Array<String> = [
"FLX_NO_HEALTH", "HXCPP_STACK_TRACE", "hscriptPos",
"openfl-enable-handle-error",
"HXCPP_CHECK_POINTER", "HXCPP_STACK_LINE", "HXCPP_STACK_TRACE",
"FLX_NO_FOCUS_LOST_SCREEN", "FLX_NO_SOUND_TRAY", "AP_PREFER_UNENCRYPTED"
];
// same thing I said above applies to libraries.
static final HAXELIBS:Array<String> = [
"lime", "openfl", "flixel", "flixel-addons",
"hscript-iris", "moonchart", "flixel-animate",
"funkin.vis", "flixel-waveform", "flixel-screenshot-plugin",
"haxeui-flixel", "haxeui-core", "hxWebSockets"
];
public function new()
{
super();
info('Initializing Compilation...');
includeAssets("assets");
includeAssets("mods");
setupGame();
setupHaxelibs();
setupHaxedefs();
setupFeatureFlags();
}
function setupGame()
{
this.meta.title = TITLE;
this.meta.version = VERSION;
this.meta.packageName = PACKAGE_NAME;
this.meta.company = COMPANY;
this.app.main = MAIN_CLASS;
this.app.file = EXECUTABLE_NAME;
this.app.preloader = PRELOADER;
this.sources.push(SOURCE_DIR);
info('$TITLE v.$VERSION in ${(isDebug()) ? 'debug' : 'release'}');
// Tell Lime to run some prebuild and postbuild scripts.
this.preBuildCallbacks.push(buildHaxeCLICommand(PREBUILD_HX));
this.postBuildCallbacks.push(buildHaxeCLICommand(POSTBUILD_HX));
//maybe use this, sounds very cool
//this.meta.buildNumber = 0;
this.window.fps = 60;
this.window.width = 1280;
this.window.height = 720;
this.window.background = 0xFF000000;
this.window.hardware = true;
this.window.vsync = false;
this.window.allowHighDPI = true;
if (isDesktop()) {
this.window.orientation = Orientation.LANDSCAPE;
this.window.fullscreen = false;
this.window.resizable = true;
this.window.vsync = false;
}
final buildDir = 'export/${isDebug() ? 'debug' : 'release'}/';
app.path = buildDir;
addIcon("other/icons/icon16.png", 16);
addIcon("other/icons/icon32.png", 32);
addIcon("other/icons/icon64.png", 64);
addIcon("other/icons/iconOG.png");
info('Current Commit: ${getGitCommit()}');
}
function setupHaxelibs()
{
for(lib in HAXELIBS)
addHaxelib(lib);
// ADD HAXELIBS FOR TARGET SPECIFICS BELOW!
if (isDebug())
addHaxelib('hxcpp-debug-server');
if(isDesktop() && !isHashLink())
{
addHaxelib('hxvlc');
addHaxelib('hxdiscord_rpc');
}
}
function setupHaxedefs()
{
for(def in HAXEDEFS)
setHaxedef(def);
if (!isDebug())
setHaxedef("FLX_NO_DEBUG");
setHaxedef("message.reporting", "pretty");
// We set haxeflags here!
addHaxeFlag('-dce no');
}
function setupFeatureFlags()
{
RENAME_UNDERSCORE.apply(this, isWeb());
}
// -- Helper Functions (taken from FNF's Hxp. Thanks funkin crew) -- //
public function error(message:String):Void
Log.error('${message}');
public function info(message:String):Void {
if(command != "display") Log.info('\x1b[36m[INFO] ${message}\x1b[0m');
}
public function getGitCommit():String
{
var process = new sys.io.Process('git', ['rev-parse', 'HEAD']);
if (process.exitCode() != 0)
{
var message = process.stderr.readAll().toString();
error('[ERROR] Could not determine current git commit; is this a proper Git repository?');
}
var commitHash:String = process.stdout.readLine();
var commitHashSplice:String = commitHash.substr(0, 7);
process.close();
return commitHashSplice;
}
public function isWeb():Bool
return this.platformType == PlatformType.WEB;
public function isMobile():Bool
return this.platformType == PlatformType.MOBILE;
public function isDesktop():Bool
return this.platformType == PlatformType.DESKTOP;
public function isConsole():Bool
return this.platformType == PlatformType.CONSOLE;
public function is32Bit():Bool
return this.architectures.contains(Architecture.X86);
public function is64Bit():Bool
return this.architectures.contains(Architecture.X64);
public function isWindows():Bool
return this.target == Platform.WINDOWS;
public function isMac():Bool
return this.target == Platform.MAC;
public function isLinux():Bool
return this.target == Platform.LINUX;
public function isAndroid():Bool
return this.target == Platform.ANDROID;
public function isIOS():Bool
return this.target == Platform.IOS;
public function isHashLink():Bool
return this.targetFlags.exists("hl");
public function isNeko():Bool
return this.targetFlags.exists("neko");
public function isJava():Bool
return this.targetFlags.exists("java");
public function isNodeJS():Bool
return this.targetFlags.exists("nodejs");
public function isCSharp():Bool
return this.targetFlags.exists("cs");
public function isDisplay():Bool
return this.command == "display";
public function isDebug():Bool
return this.debug;
public function isRelease():Bool
return !isDebug();
public function getHaxedef(name:String):Null<Dynamic>
return this.haxedefs.get(name);
public function setHaxedef(name:String, ?value:String):Void
{
if (value == null) value = "";
this.haxedefs.set(name, value);
}
public function unsetHaxedef(name:String):Void {
this.haxedefs.remove(name);
}
public function getDefine(name:String):Null<Dynamic> {
return this.defines.get(name);
}
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.
*/
public function addHaxelib(name:String, version:String = ""):Void {
this.haxelibs.push(new Haxelib(name, version));
}
/**
* Add a `haxeflag` to the project.
*/
public function addHaxeFlag(value:String):Void {
this.haxeflags.push(value);
}
/**
* Call a Haxe build macro.
*/
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.
*/
public function addIcon(icon:String, ?size:Int):Void {
this.icons.push(new Icon(icon, size));
}
/**
* A CLI command to run a command in the shell.
*/
public function buildCLICommand(cmd:String):CLICommand
return CommandHelper.fromSingleString(cmd);
/**
* A CLI command to run a Haxe script via `--interp`.
*/
public function buildHaxeCLICommand(path:String):CLICommand
return CommandHelper.interpretHaxe(path);
}
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)) {
getInverse().disable(project, false);
} else if (getInverse().isEnabled(project)) {
disable(project, false);
} else {
if (enableByDefault) {
enable(project, true);
} else {
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.setHaxedef(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.unsetHaxedef(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;
}
}