Skip to content

Commit

Permalink
oh my god bro
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesisfeline committed Jun 25, 2024
1 parent dc68468 commit 3bcfd49
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 42 deletions.
11 changes: 8 additions & 3 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ xsi:schemaLocation="http://lime.openfl.org/project/1.0.4 http://lime.openfl.org/
</section>

<!-- Run a script before and after building. -->
<prebuild haxe="source/Prebuild.hx"/> -->
<postbuild haxe="source/Postbuild.hx"/> -->
<prebuild haxe="source/Prebuild.hx"/>
<postbuild haxe="source/Postbuild.hx"/>

<!-- Enable this on platforms which do not support dropping files onto the window. -->
<haxedef name="FILE_DROP_UNSUPPORTED" if="mac" />
Expand All @@ -246,7 +246,9 @@ xsi:schemaLocation="http://lime.openfl.org/project/1.0.4 http://lime.openfl.org/
<!-- Turns on additional debug logging. -->
<haxedef name="POLYMOD_DEBUG" value="true" if="debug" />
<!-- The file extension to use for script files. -->
<haxedef name="POLYMOD_SCRIPT_EXT" value=".hscript" />
<haxedef name="POLYMOD_SCRIPT_EXT" value=".hxs" />
<!-- The file extension to use for scripted classes. -->
<haxedef name="POLYMOD_SCRIPT_CLASS_EXT" value=".hx" />
<!-- Which asset library to use for scripts. -->
<haxedef name="POLYMOD_SCRIPT_LIBRARY" value="scripts" />
<!-- The base path from which scripts should be accessed. -->
Expand All @@ -260,4 +262,7 @@ xsi:schemaLocation="http://lime.openfl.org/project/1.0.4 http://lime.openfl.org/
<!-- Determines the file in the mod folder used for the icon. -->
<haxedef name="POLYMOD_MOD_ICON_FILE" value="_polymod_icon.png" />
</section>

<!-- Fix compiling issues -->
<setenv name="HAXEPATH" value="./"/>
</project>
16 changes: 16 additions & 0 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,17 @@ class Main extends Sprite

function setupGame():Void
{
#if windows
@:functionCode("
#include <windows.h>
setProcessDPIAware() // allows for more crisp visuals
")
#end

initHaxeUI();

flixel.system.FlxAssets.FONT_DEFAULT = "VCR OSD Mono";

// addChild gets called by the user settings code.
fpsCounter = new FPS(10, 3, 0xFFFFFF);

Expand All @@ -108,6 +117,9 @@ class Main extends Sprite
Save.load();
var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, Preferences.framerate, Preferences.framerate, skipSplash, startFullscreen);

openfl.Lib.current.stage.align = "tl";
openfl.Lib.current.stage.scaleMode = openfl.display.StageScaleMode.NO_SCALE;

// FlxG.game._customSoundTray wants just the class, it calls new from
// create() in there, which gets called when it's added to stage
// which is why it needs to be added before addChild(game) here
Expand All @@ -116,6 +128,10 @@ class Main extends Sprite

addChild(game);

#if !mobile
applicationScreen.stage.scaleMode = openfl.display.StageScaleMode.NO_SCALE;
#end

#if debug
game.debugger.interaction.addTool(new funkin.util.TrackerToolButtonUtil());
#end
Expand Down
9 changes: 7 additions & 2 deletions source/funkin/InitState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,21 @@ class InitState extends FlxState
WindowUtil.disableCrashHandler();

// This ain't a pixel art game! (most of the time)
FlxSprite.defaultAntialiasing = true;
FlxSprite.defaultAntialiasing = true; // TODO: Add antialising option.

// Disable default keybinds for volume (we manually control volume in MusicBeatState with custom binds)
FlxG.sound.volumeUpKeys = [];
FlxG.sound.volumeDownKeys = [];
FlxG.sound.muteKeys = [];

FlxG.fixedTimestep = false;

// Set the game to a lower frame rate while it is in the background.
FlxG.game.focusLostFramerate = 30;

@:privateAccess
FlxG.game.getTimer = () -> openfl.Lib.getTimer();

setupFlixelDebug();

//
Expand All @@ -115,7 +120,7 @@ class InitState extends FlxState
#if windows
funkin.util.tools.Windows.setDarkMode(true);
#end

//
// NEWGROUNDS API SETUP
//
Expand Down
2 changes: 2 additions & 0 deletions source/funkin/audio/FunkinSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>

// split the path and get only after first :
// we are bypassing the openfl/lime asset library fuss
#if web
path = Paths.stripLibrary(path);
#end

var soundRequest = FlxPartialSound.partialLoadFromFile(path, start, end);

Expand Down
72 changes: 56 additions & 16 deletions source/funkin/modding/PolymodHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -228,44 +228,83 @@ class PolymodHandler
{
// Add default imports for common classes.

Polymod.addDefaultImport(Std);
Polymod.addDefaultImport(Math);
Polymod.addDefaultImport(flixel.FlxG);
Polymod.addDefaultImport(flixel.FlxG);
Polymod.addDefaultImport(funkin.modding.module.Module);
Polymod.addDefaultImport(funkin.modding.module.ModuleHandler);
Polymod.addDefaultImport(funkin.play.PlayState);
Polymod.addDefaultImport(funkin.Paths);
Polymod.addDefaultImport(funkin.Preferences);

Polymod.addDefaultImport(haxe.Json);
Polymod.addDefaultImport(openfl.utils.Assets);
Polymod.addDefaultImport(lime.app.Application);
// Polymod.addDefaultImport(lime.app.Application.current.window);
Polymod.addDefaultImport(flixel.FlxSprite);
Polymod.addDefaultImport(funkin.graphics.FunkinSprite);
Polymod.addDefaultImport(flixel.FlxBasic);
Polymod.addDefaultImport(flixel.tweens.FlxEase);
Polymod.addDefaultImport(flixel.tweens.FlxTween);
Polymod.addDefaultImport(flixel.system.FlxAssets);
Polymod.addDefaultImport(flixel.math.FlxMath);
Polymod.addDefaultImport(flixel.group.FlxGroup);
Polymod.addDefaultImport(flixel.group.FlxGroup.FlxTypedGroup);
Polymod.addDefaultImport(flixel.group.FlxSpriteGroup);
Polymod.addDefaultImport(flixel.text.FlxText);
Polymod.addDefaultImport(flixel.util.FlxTimer);
// Polymod.addDefaultImport(hxvlc.flixel.FlxVideo);
// Polymod.addDefaultImport(hxvlc.flixel.FlxVideoSprite);
// Polymod.addDefaultImport(hxvlc.openfl.Video);
Polymod.addDefaultImport(flixel.FlxBasic);

// Add import aliases for certain classes.
// NOTE: Scripted classes are automatically aliased to their parent class.
Polymod.addImportAlias('flixel.math.FlxPoint', flixel.math.FlxPoint.FlxBasePoint);

// Polymod.addDefaultImport(flixel.util.FlxColor); FUCK
Polymod.addDefaultImport(Type.resolveClass('flixel.util.FlxColor_HSC'), "flixel.util.FlxColor");
Polymod.addDefaultImport(Type.resolveClass('flixel.util.FlxColor_HSC'), "FlxColor");

// Add blacklisting for prohibited classes and packages.

// `Sys`
// Sys.command() can run malicious processes
Polymod.blacklistImport('Sys');
// Polymod.blacklistImport('Sys');
Polymod.addDefaultImport(Sys);

// `Reflect`
// Reflect.callMethod() can access blacklisted packages
Polymod.blacklistImport('Reflect');
// Polymod.blacklistImport('Reflect');
Polymod.addDefaultImport(Reflect);

// `Type`
// Type.createInstance(Type.resolveClass()) can access blacklisted packages
Polymod.blacklistImport('Type');
// Polymod.blacklistImport('Type');
Polymod.addDefaultImport(Type);

// `cpp.Lib`
// Lib.load() can load malicious DLLs
Polymod.blacklistImport('cpp.Lib');
// Polymod.blacklistImport('cpp.Lib');
Polymod.addDefaultImport(cpp.Lib);

// `polymod.*`
// You can probably unblacklist a module
for (cls in ClassMacro.listClassesInPackage('polymod'))
{
if (cls == null) continue;
var className:String = Type.getClassName(cls);
Polymod.blacklistImport(className);
}
/*for (cls in ClassMacro.listClassesInPackage('polymod'))
{
if (cls == null) continue;
var className:String = Type.getClassName(cls);
Polymod.blacklistImport(className);
}*/

// `sys.*`
for (cls in ClassMacro.listClassesInPackage('sys'))
{
if (cls == null) continue;
var className:String = Type.getClassName(cls);
Polymod.blacklistImport(className);
}
/*for (cls in ClassMacro.listClassesInPackage('sys'))
{
if (cls == null) continue;
var className:String = Type.getClassName(cls);
Polymod.blacklistImport(className);
}*/
}

static function buildParseRules():polymod.format.ParseRules
Expand All @@ -276,6 +315,7 @@ class PolymodHandler
// Ensure script files have merge support.
output.addType('hscript', TextFileFormat.PLAINTEXT);
output.addType('hxs', TextFileFormat.PLAINTEXT);
output.addType('haxe', TextFileFormat.PLAINTEXT);
output.addType('hxc', TextFileFormat.PLAINTEXT);
output.addType('hx', TextFileFormat.PLAINTEXT);

Expand Down
39 changes: 20 additions & 19 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ class PlayState extends MusicBeatSubState
*/
public var cameraBopMultiplier:Float = 1.0;

/**
* Multiplier for how slow should camera zoom back.
* Lerped back to 1.0x every frame.
*/
public var cameraZoomingDecay:Float = 1.0;

/**
* Default camera zoom for the current stage.
* If we aren't in a stage, just use the default zoom (1.05x).
Expand Down Expand Up @@ -691,6 +697,7 @@ class PlayState extends MusicBeatSubState
}

Conductor.instance.mapTimeChanges(currentChart.timeChanges);
Conductor.instance.formatOffset = (Constants.EXT_SOUND == 'mp3') ? Constants.MP3_DELAY_MS : 0.0;
Conductor.instance.update((Conductor.instance.beatLengthMs * -5) + startTimestamp);

// The song is now loaded. We can continue to initialize the play state.
Expand Down Expand Up @@ -942,16 +949,9 @@ class PlayState extends MusicBeatSubState
}
else
{
if (Constants.EXT_SOUND == 'mp3')
{
Conductor.instance.formatOffset = Constants.MP3_DELAY_MS;
}
else
{
Conductor.instance.formatOffset = 0.0;
}

Conductor.instance.update(); // Normal conductor update.
Conductor.instance.update(Conductor.instance.songPosition
- (Conductor.instance.instrumentalOffset + Conductor.instance.formatOffset + Conductor.instance.audioVisualOffset)
+ elapsed * 1000 * playbackRate); // Normal conductor update.
}

var androidPause:Bool = false;
Expand Down Expand Up @@ -1018,11 +1018,11 @@ class PlayState extends MusicBeatSubState
// Apply camera zoom + multipliers.
if (subState == null && cameraZoomRate > 0.0) // && !isInCutscene)
{
cameraBopMultiplier = FlxMath.lerp(1.0, cameraBopMultiplier, 0.95); // Lerp bop multiplier back to 1.0x
cameraBopMultiplier = FlxMath.lerp(1.0, cameraBopMultiplier, Math.exp(-elapsed * 3.125 * cameraZoomingDecay)); // Lerp bop multiplier back to 1.0x
var zoomPlusBop = currentCameraZoom * cameraBopMultiplier; // Apply camera bop multiplier.
FlxG.camera.zoom = zoomPlusBop; // Actually apply the zoom to the camera.

camHUD.zoom = FlxMath.lerp(defaultHUDCameraZoom, camHUD.zoom, 0.95);
camHUD.zoom = FlxMath.lerp(defaultHUDCameraZoom, camHUD.zoom, Math.exp(-elapsed * 3.125 * cameraZoomingDecay));
}

if (currentStage != null && currentStage.getBoyfriend() != null)
Expand Down Expand Up @@ -1444,8 +1444,8 @@ class PlayState extends MusicBeatSubState

if (!startingSong
&& FlxG.sound.music != null
&& (Math.abs(FlxG.sound.music.time - (Conductor.instance.songPosition + Conductor.instance.instrumentalOffset)) > 200
|| Math.abs(vocals.checkSyncError(Conductor.instance.songPosition + Conductor.instance.instrumentalOffset)) > 200))
&& (Math.abs(FlxG.sound.music.time - (Conductor.instance.songPosition + Conductor.instance.instrumentalOffset)) > 100 * playbackRate
|| Math.abs(vocals.checkSyncError(Conductor.instance.songPosition + Conductor.instance.instrumentalOffset)) > 100 * playbackRate))
{
trace("VOCALS NEED RESYNC");
if (vocals != null) trace(vocals.checkSyncError(Conductor.instance.songPosition + Conductor.instance.instrumentalOffset));
Expand Down Expand Up @@ -1481,7 +1481,7 @@ class PlayState extends MusicBeatSubState
&& Conductor.instance.currentBeat % cameraZoomRate == 0)
{
// Set zoom multiplier for camera bop.
cameraBopMultiplier = cameraBopIntensity;
cameraBopMultiplier += (cameraBopIntensity - 1.0);
// HUD camera zoom still uses old system. To change. (+3%)
camHUD.zoom += hudCameraZoomIntensity * defaultHUDCameraZoom;
}
Expand Down Expand Up @@ -2092,10 +2092,11 @@ class PlayState extends MusicBeatSubState

vocals.pause();

FlxG.sound.music.play(FlxG.sound.music.time);
FlxG.sound.music.time = Conductor.instance.songPosition;
FlxG.sound.music.play(false, Conductor.instance.songPosition + Conductor.instance.instrumentalOffset);

vocals.time = FlxG.sound.music.time;
vocals.play(false, FlxG.sound.music.time);
vocals.time = Conductor.instance.songPosition;
vocals.play(false, Conductor.instance.songPosition);
}

/**
Expand Down Expand Up @@ -2224,7 +2225,7 @@ class PlayState extends MusicBeatSubState
// Process hold notes on the opponent's side.
for (holdNote in opponentStrumline.holdNotes.members)
{
if (holdNote == null || !holdNote.alive) continue;
if (holdNote == null || !holdNote.alive || holdNote.noAnimation) continue;

// While the hold note is being hit, and there is length on the hold note...
if (holdNote.hitNote && !holdNote.missedNote && holdNote.sustainLength > 0)
Expand Down
62 changes: 62 additions & 0 deletions source/funkin/play/event/AddCameraZoomEvent.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package funkin.play.event;

import flixel.FlxCamera;
// Data from the chart
import funkin.data.song.SongData;
import funkin.data.song.SongData.SongEventData;
// Data from the event schema
import funkin.play.event.SongEvent;
import funkin.data.event.SongEventSchema;
import funkin.data.event.SongEventSchema.SongEventFieldType;

class AddCameraZoomEvent extends SongEvent
{
public function new()
{
super('AddCameraZoom');
}

public override function getTitle():String
{
return 'Add Zoom to Camera';
}

public override function handleEvent(data:SongEventData):Void
{
if (PlayState.instance == null) return;

var toGame:Null<Float> = data.getFloat('gameZoom');
if (toGame == null) toGame = Constants.DEFAULT_BOP_INTENSITY;

var toHUD:Null<Float> = data.getFloat('hudZoom');
if (toHUD == null) toHUD = PlayState.instance.hudCameraZoomIntensity;

// toGame *= PlayState.instance.cameraBopIntensity; //nah
// toHUD *= PlayState.instance.hudCameraZoomIntensity; //nah

PlayState.instance.cameraBopMultiplier += toGame;
PlayState.instance.camHUD.zoom += toHUD;
}

public override function getEventSchema():SongEventSchema
{
return new SongEventSchema([
{
name: 'gameZoom',
title: 'Add to Game',
defaultValue: 0.015,
step: 0.001,
type: SongEventFieldType.FLOAT,
units: 'zoom'
},
{
name: 'hudZoom',
title: 'Add to HUD',
defaultValue: 0.030,
step: 0.001,
type: SongEventFieldType.FLOAT,
units: 'zoom'
}
]);
}
}
Loading

0 comments on commit 3bcfd49

Please sign in to comment.