forked from CaptainKirb49/Forever-Engine-Reboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hx
351 lines (293 loc) · 10.9 KB
/
Main.hx
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
package;
import flixel.FlxBasic;
import flixel.FlxG;
import flixel.FlxGame;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.addons.transition.FlxTransitionableState;
import flixel.util.FlxColor;
import haxe.CallStack.StackItem;
import haxe.CallStack;
import haxe.io.Path;
import lime.app.Application;
import meta.*;
import meta.data.PlayerSettings;
import meta.data.dependency.Discord;
import meta.data.dependency.FNFTransition;
import meta.data.dependency.FNFUIState;
import openfl.Assets;
import openfl.Lib;
import openfl.display.FPS;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.events.UncaughtErrorEvent;
import sys.FileSystem;
import sys.io.File;
import sys.io.Process;
// Here we actually import the states and metadata, and just the metadata.
// It's nice to have modularity so that we don't have ALL elements loaded at the same time.
// at least that's how I think it works. I could be stupid!
class Main extends Sprite
{
/*
This is the main class of the project, it basically connects everything together.
If you know what you're doing, go ahead and shoot! if you're looking for something more specific, however,
try accessing some game objects or meta files, meta files control the information (say what's playing on screen)
and game objects are like the boyfriend, girlfriend and the oppontent.
Thanks for using my little modular project! I really appreciate it.
If you've got any suggestions let me know at "!SIG7Ivan#2449" on Discord or create a ticket on the github.
Forever Engine is hard to use, shoutouts to Alex for being a better programmer than I.
yeah this is a problem I have
it has to be perfect or else it isn't presentable
I'm sure I'll write this down on the GitHub, but this is a fork of an open source Friday Night Funkin' Modding engine
which is completely open for anyone to modify. I have a couple of requests and prerequisites however, and that is
that you, number one, in no way claim this, the modifications to the engine, or the sprites as your own. If you're going to
make an open source modification to the engine you should run a pull request or fork and not create a new standalone repo
for it.
If you're actually going to mod the game however, lease, by all means, create your own repository for it instead as it
would be your project then. I also request the engine is credited somewhere in the project. (in the gamebanana page,
wherever you'd like/is most convenient for you!) if you don't wanna credit me that's fine, I just ask for the project
to be in the credits somewhere.
If you use the Fanmastered sprites and/or code, then it would be great if you could at least give credits.
I have no idea how licenses work so pretend I'm professional or something AAAA
thank you for using this engine it means a lot to me :)
if you have any questions like I said, shoot me a message or something, I'm totally cool with it even if it's just help with programming or something
> fair warning I'm not a very good programmer
*/
// class action variables
public static var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
public static var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
public static var mainClassState:Class<FlxState> = Init; // Determine the main class state of the game
public static var framerate:Int = 120; // How many frames per second the game should run at.
public static var gameVersion:String = '0.3';
public static var modVersion:String = '0.1';
var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
var skipSplash:Bool = false; // Whether to skip the flixel splash screen that appears in release mode.
var infoCounter:InfoHud; // initialize the heads up display that shows information before creating it.
// heres gameweeks set up!
/**
Small bit of documentation here, gameweeks are what control everything in my engine
this system will eventually be overhauled in favor of using actual week folders within the
assets.
Enough of that, here's how it works
[ [songs to use], [characters in songs], [color of week], name of week ]
**/
public static var gameWeeks:Array<Dynamic> = [
[['Tutorial'], ['gf'], [FlxColor.fromRGB(129, 100, 223)], 'Funky Beginnings'],
[
['Bopeebo', 'Fresh', 'Dadbattle'],
['dad', 'dad', 'dad'],
[FlxColor.fromRGB(129, 100, 223)],
'DADDY DEAREST'
],
[
['Spookeez', 'South', 'Monster'],
['spooky', 'spooky', 'monster'],
[FlxColor.fromRGB(30, 45, 60)],
'Spooky Month'
],
[
['Pico', 'Philly-Nice', 'Blammed'],
['pico'],
[FlxColor.fromRGB(111, 19, 60)],
'Pico'
],
[
['Satin-Panties', 'High', 'Milf'],
['mom'],
[FlxColor.fromRGB(203, 113, 170)],
'MOMMY MUST MURDER'
],
[
['Cocoa', 'Eggnog', 'Winter-Horrorland'],
['parents-christmas', 'parents-christmas', 'monster-christmas'],
[FlxColor.fromRGB(141, 165, 206)],
'RED SNOW'
],
[
['Senpai', 'Roses', 'Thorns'],
['senpai', 'senpai', 'spirit'],
[FlxColor.fromRGB(206, 106, 169)],
"hating simulator ft. moawling"
],
//Week 7, properly ported from 0.2.8
[
['Ugh', 'Guns', 'Stress'],
['tankman', 'tankman', 'tankman'],
[FlxColor.fromRGB(246, 182, 4)],
"Tankman"
],
//Custom weeks.
[
['dunk', 'ram', 'hello-world', 'glitcher'],
['hex', 'hex', 'hex', 'hex'],
[FlxColor.fromRGB(206, 106, 169)],
"A New Face"
],
[
['hex', 'hex'],
['cooling', 'detected'],
[FlxColor.fromRGB(206, 106, 169)],
"YOUR NEW WEEK"
],
[
['Lo-Fight', 'Overhead', 'Ballistic'],
['whitty', 'whitty', 'angor'],
[FlxColor.fromRGB(175, 20, 0)],
"Back Alley Blitz"
],
[
['Underground'],
['white'],
[FlxColor.fromRGB(175, 20, 0)],
"Just like Old Times."
],
];
// most of these variables are just from the base game!
// be sure to mess around with these if you'd like.
public static function main():Void
{
Lib.current.addChild(new Main());
}
// calls a function to set the game up
public function new()
{
super();
/**
ok so, haxe html5 CANNOT do 120 fps. it just cannot.
so here i just set the framerate to 60 if its complied in html5.
reason why we dont just keep it because the game will act as if its 120 fps, and cause
note studders and shit its weird.
**/
Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onCrash);
#if html5
framerate = 60;
#end
// simply said, a state is like the 'surface' area of the window where everything is drawn.
// if you've used gamemaker you'll probably understand the term surface better
// this defines the surface bounds
var stageWidth:Int = Lib.current.stage.stageWidth;
var stageHeight:Int = Lib.current.stage.stageHeight;
if (zoom == -1)
{
var ratioX:Float = stageWidth / gameWidth;
var ratioY:Float = stageHeight / gameHeight;
zoom = Math.min(ratioX, ratioY);
gameWidth = Math.ceil(stageWidth / zoom);
gameHeight = Math.ceil(stageHeight / zoom);
// this just kind of sets up the camera zoom in accordance to the surface width and camera zoom.
// if set to negative one, it is done so automatically, which is the default.
}
FlxTransitionableState.skipNextTransIn = true;
////
////
////
////
// here we set up the base game
var gameCreate:FlxGame;
gameCreate = new FlxGame(gameWidth, gameHeight, mainClassState, #if (flixel < "5.0.0") zoom, #end framerate, framerate, skipSplash);
addChild(gameCreate); // and create it afterwards
flixel.FlxG.plugins.add(new screenshotplugin.ScreenShotPlugin());
//https://github.com/sayofthelor/flixel-screenshot-plugin
//When does FlxGame get initialized? I'm guessing here but it didn't work last time.
////
////
////
////
// default game FPS settings, I'll probably comment over them later.
// addChild(new FPS(10, 3, 0xFFFFFF));
// begin the discord rich presence
#if !html5
Discord.initializeRPC();
Discord.changePresence('');
#end
// test initialising the player settings
PlayerSettings.init();
// if you're reading this in the future I've added my own FPS counter below! hopefully...
// yeah dw I'm getting started on it fffff
infoCounter = new InfoHud(10, 3, 0xFFFFFF, true);
addChild(infoCounter);
}
public static function framerateAdjust(input:Float)
{
return input * (60 / FlxG.drawFramerate);
}
/* This is used to switch "rooms," to put it basically. Imagine you are in the main menu, and press the freeplay button.
That would change the game's main class to freeplay, as it is the active class at the moment.
*/
public static var lastState:FlxState;
public static function switchState(curState:FlxState, target:FlxState)
{
// Custom made Trans in
mainClassState = Type.getClass(target);
if (!FlxTransitionableState.skipNextTransIn)
{
curState.openSubState(new FNFTransition(0.35, false));
FNFTransition.finishCallback = function() {
FlxG.switchState(target);
};
return trace('changed state');
}
FlxTransitionableState.skipNextTransIn = false;
// load the state
FlxG.switchState(target);
}
public static function updateFramerate(newFramerate:Int)
{
// flixel will literally throw errors at me if I dont separate the orders
if (newFramerate > FlxG.updateFramerate)
{
FlxG.updateFramerate = newFramerate;
FlxG.drawFramerate = newFramerate;
}
else
{
FlxG.drawFramerate = newFramerate;
FlxG.updateFramerate = newFramerate;
}
}
function onCrash(e:UncaughtErrorEvent):Void
{
var errMsg:String = "";
var path:String;
var callStack:Array<StackItem> = CallStack.exceptionStack(true);
var dateNow:String = Date.now().toString();
dateNow = StringTools.replace(dateNow, " ", "_");
dateNow = StringTools.replace(dateNow, ":", "'");
path = "./crash/" + "FE_" + dateNow + ".txt";
for (stackItem in callStack)
{
switch (stackItem)
{
case FilePos(s, file, line, column):
errMsg += file + " (line " + line + ")\n";
default:
Sys.println(stackItem);
}
}
errMsg += "\nUncaught Error: " + e.error + "\nPlease report this error to the GitHub page: https://github.com/SIG7Pro/FunkinFanmasters";
if (!FileSystem.exists("./crash/"))
FileSystem.createDirectory("./crash/");
File.saveContent(path, errMsg + "\n");
Sys.println(errMsg);
Sys.println("Crash dump saved in " + Path.normalize(path));
var crashDialoguePath:String = "FE-CrashDialog";
#if windows
crashDialoguePath += ".exe";
#end
if (FileSystem.exists("./" + crashDialoguePath))
{
Sys.println("Found crash dialog: " + crashDialoguePath);
#if linux
crashDialoguePath = "./" + crashDialoguePath;
#end
new Process(crashDialoguePath, [path]);
}
else
{
Sys.println("No crash dialog found! Making a simple alert instead...");
Application.current.window.alert(errMsg, "Error!");
}
Sys.exit(1);
}
}