Skip to content

Commit

Permalink
ugh
Browse files Browse the repository at this point in the history
  • Loading branch information
PurSnake committed Jul 13, 2024
1 parent 7fa6aaa commit 29112e9
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 204 deletions.
4 changes: 0 additions & 4 deletions source/funkin/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import sys.io.File;
*/
class Paths
{


//БЛЯТЬ, ДОБАВЬ ПРОВЕРКУ НА ОКОНЧАНИЕ ПУТЯ К ФАЙЛУ ЗВУКА .ogg

public static var localTrackedAssets:Array<String> = [];
public static var currentTrackedSounds:Map<String, Sound> = [];

Expand Down
75 changes: 52 additions & 23 deletions source/funkin/graphics/FunkinSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ import openfl.display3D.textures.TextureBase;
import funkin.graphics.framebuffer.FixedBitmapData;
import openfl.display.BitmapData;
import funkin.util.MemoryUtil;
import openfl.geom.Matrix;
import flixel.math.FlxAngle;
import haxe.io.Path;
import openfl.Assets;
import flixel.graphics.frames.FlxFrame;
import flixel.graphics.frames.FlxFrame.FlxFrameAngle;
import flixel.system.FlxAssets.FlxGraphicAsset;
import flixel.util.FlxDestroyUtil;
import flixel.util.FlxSignal;

/**
* An FlxSprite with additional functionality.
* - A more efficient method for creating solid color sprites.
* - TODO: Better cache handling for textures.
*/
class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite
@:access(flxanimate.animate)
class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite // FlxSprite
{

/**
* An internal list of all the textures cached with `cacheTexture`.
* This excludes any temporary textures like those from `FlxText` or `makeSolidColor`.
Expand All @@ -47,34 +56,31 @@ class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite
* Works similar to scrollFactor, but with sprite's camera zoom.
*/
public var zoomFactor:Float = 1;

public var initialZoom:Float = 1;

public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect
{
__doPreZoomScaleProcedure(camera);
//var r = super.getScreenBounds(newRect, camera);
// var r = super.getScreenBounds(newRect, camera);
var r = getScreenBoundsFixed(newRect, camera);
__doPostZoomScaleProcedure();
return r;
}

public function getScreenBoundsFixed(?newRect:FlxRect, ?camera:FlxCamera):FlxRect
{
if (newRect == null)
newRect = FlxRect.get();

if (camera == null)
camera = FlxG.camera;

if (newRect == null) newRect = FlxRect.get();

if (camera == null) camera = FlxG.camera;

newRect.setPosition(x, y);
if (pixelPerfectPosition)
newRect.floor();
if (pixelPerfectPosition) newRect.floor();

_scaledOrigin.set(origin.x * Math.abs(scale.x), origin.y * Math.abs(scale.y));
newRect.x += -Std.int(camera.scroll.x * scrollFactor.x) - (offset.x + frameOffset.x) + origin.x - _scaledOrigin.x;
newRect.y += -Std.int(camera.scroll.y * scrollFactor.y) - (offset.y + frameOffset.y) + origin.y - _scaledOrigin.y;
if (isPixelPerfectRender(camera))
newRect.floor();
if (isPixelPerfectRender(camera)) newRect.floor();
newRect.setSize(frameWidth * Math.abs(scale.x), frameHeight * Math.abs(scale.y));
return newRect.getRotatedBounds(angle, _scaledOrigin, newRect);
}
Expand All @@ -87,8 +93,7 @@ class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite

private function __doPreZoomScaleProcedure(camera:FlxCamera)
{
if (__skipZoomProcedure = !__shouldDoScaleProcedure())
return;
if (__skipZoomProcedure = !__shouldDoScaleProcedure()) return;
__oldScale = FlxPoint.get(scale.x, scale.y);
var requestedZoom = FlxMath.lerp(initialZoom, camera.zoom, zoomFactor);
var diff = requestedZoom * camera.zoom;
Expand All @@ -98,13 +103,17 @@ class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite

private function __doPostZoomScaleProcedure()
{
if (__skipZoomProcedure)
return;
if (__skipZoomProcedure) return;
scale.set(__oldScale.x, __oldScale.y);
__oldScale.put();
__oldScale = null;
}

public override function draw()
{
super.draw();
}

public override function drawComplex(camera:FlxCamera)
{
_frame.prepareMatrix(_matrix, flixel.graphics.frames.FlxFrame.FlxFrameAngle.ANGLE_0, checkFlipX(), checkFlipY());
Expand All @@ -121,11 +130,10 @@ class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite
{
updateTrig();

if (angle != 0)
_matrix.rotateWithTrig(_cosAngle, _sinAngle);
if (angle != 0) _matrix.rotateWithTrig(_cosAngle, _sinAngle);
}

updateSkewMatrix();
updateSkew(_matrix);
_matrix.concat(_skewMatrix);
}

Expand Down Expand Up @@ -175,6 +183,23 @@ class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite
return super.getScreenPosition(point, Camera);
}

function updateSkew(matrix:Matrix):Void
{
final tanX = -skew.x * FlxAngle.TO_RAD, tanY = skew.y * FlxAngle.TO_RAD;

var old = matrix.a + matrix.b * tanX;
matrix.b = matrix.a * tanY + matrix.b;
matrix.a = old;

old = matrix.c + matrix.d * tanX;
matrix.d = matrix.c * tanY + matrix.d;
matrix.c = old;

old = _matrix.tx + _matrix.ty * tanX;
_matrix.ty = _matrix.tx * tanY + _matrix.ty;
_matrix.tx = old;
}

/**
* Create a new FunkinSprite with a static texture.
* @param x The starting X position.
Expand Down Expand Up @@ -287,7 +312,7 @@ class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite

public static function cacheTexture(key:String, ?library:String, ?allowGPU:Bool = true):Void
{
//Paths.image(key);
// Paths.image(key);

// We don't want to cache the same texture twice.
if (currentCachedTextures.exists(key)) return;
Expand Down Expand Up @@ -344,8 +369,7 @@ class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite
FlxG.bitmap.remove(graphic);
openfl.Assets.cache.removeBitmapData(graphicKey);
@:privateAccess
if (graphic.bitmap != null && graphic.bitmap.__texture != null)
graphic.bitmap.__texture.dispose();
if (graphic.bitmap != null && graphic.bitmap.__texture != null) graphic.bitmap.__texture.dispose();

graphic.persist = false;
graphic.destroyOnNoUse = true;
Expand Down Expand Up @@ -404,6 +428,11 @@ class FunkinSprite extends flixel.addons.effects.FlxSkewedSprite //FlxSprite
return result;
}

public function loadAvalaibleAnimsFromXml()
{
funkin.util.Utils.findAndLoadXMLAnims(this);
}

public override function destroy():Void
{
frames = null;
Expand Down
10 changes: 6 additions & 4 deletions source/funkin/play/PauseSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,9 @@ class PauseSubState extends MusicBeatSubState
PlayState.instance.needsReset = true;
if (resetState && !PlayState.instance.isChartingMode)
{
FlxG.sound?.music?.volume = 0;
PlayState.instance?.vocals?.volume = 0;
if (FlxG.sound.music != null) FlxG.sound.music.volume = 0;
if (PlayState.instance.vocals != null) PlayState.instance.vocals.playerVolume = PlayState.instance.vocals.opponentVolume = 0;

FlxTransitionableState.skipNextTransIn = FlxTransitionableState.skipNextTransOut = false;
FlxG.resetState();
} else state.close();
Expand All @@ -663,8 +664,9 @@ class PauseSubState extends MusicBeatSubState
PlayState.instance.needsReset = true;
if (resetState && !PlayState.instance.isChartingMode)
{
FlxG.sound?.music?.volume = 0;
PlayState.instance?.vocals?.volume = 0;
if (FlxG.sound.music != null) FlxG.sound.music.volume = 0;
if (PlayState.instance.vocals != null) PlayState.instance.vocals.playerVolume = PlayState.instance.vocals.opponentVolume = 0;

FlxTransitionableState.skipNextTransIn = FlxTransitionableState.skipNextTransOut = false;
FlxG.resetState();
} else state.close();
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/freeplay/DJBoyfriend.hx
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class DJBoyfriend extends FlxAtlasSprite
applyAnimOffset();
}

function applyAnimOffset()
public function applyAnimOffset()
{
var AnimName = getCurrentAnimation();
var daOffset = animOffsets.get(AnimName);
Expand Down
37 changes: 26 additions & 11 deletions source/funkin/ui/freeplay/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import flixel.tweens.misc.ShakeTween;
import funkin.effects.IntervalShake;
import funkin.ui.freeplay.SongMenuItem.FreeplayRank;

import funkin.data.song.SongData.SongTimeChange;

#if discord_rpc
import funkin.api.discord.Discord.DiscordClient;
#end
Expand Down Expand Up @@ -257,10 +259,10 @@ class FreeplayState extends MusicBeatSubState
if (prepForNewRank == false)
{
FunkinSound.playMusic('freakyMenu',
{
overrideExisting: true,
restartTrack: false
});
{
overrideExisting: true,
restartTrack: false
});
}

// Add a null entry that represents the RANDOM option
Expand Down Expand Up @@ -1257,8 +1259,6 @@ class FreeplayState extends MusicBeatSubState
{
case 3:
txtCompletion.offset.x = 10;
case 2:
txtCompletion.offset.x = 0;
case 1:
txtCompletion.offset.x = -24;
default:
Expand Down Expand Up @@ -1492,10 +1492,10 @@ class FreeplayState extends MusicBeatSubState
if (Type.getClass(_parentState) == MainMenuState)
{
FunkinSound.playMusic('freakyMenu',
{
overrideExisting: true,
restartTrack: false
});
{
overrideExisting: true,
restartTrack: false
});
FlxG.sound.music.fadeIn(4.0, 0.0, 1.0);
close();
}
Expand All @@ -1512,6 +1512,19 @@ class FreeplayState extends MusicBeatSubState
}
}

/*override function beatHit():Bool
{
if (!super.beatHit()) return false;
if (dj != null && dj.visible && dj.currentState == Idle && Conductor.instance.currentBeat > 0)
{
dj.playAnimation("Boyfriend DJ", true, true, false);
dj.applyAnimOffset();
}
return true;
}*/

public override function destroy():Void
{
FlxTransitionableState.skipNextTransIn = false;
Expand Down Expand Up @@ -1857,6 +1870,7 @@ class FreeplayState extends MusicBeatSubState
{
var previewSong:Null<Song> = SongRegistry.instance.fetchEntry(daSongCapsule.songData.songId);
var instSuffix:String = previewSong?.getDifficulty(currentDifficulty, previewSong?.variations ?? Constants.DEFAULT_VARIATION_LIST)?.characters?.instrumental ?? '';
var previewTimeChanges = previewSong?.getDifficulty(currentDifficulty, previewSong?.variations ?? Constants.DEFAULT_VARIATION_LIST)?.timeChanges ?? [new SongTimeChange(0, 100)];
instSuffix = (instSuffix != '') ? '-$instSuffix' : '';

FunkinSound.playMusic(daSongCapsule.songData.songId,
Expand All @@ -1870,10 +1884,11 @@ class FreeplayState extends MusicBeatSubState
{
loadPartial: true,
start: 0.05, //0.05,
end: 0.40 //0.30
end: 0.45 //0.30
},
onLoad: () -> {
FlxG.sound.music.fadeIn(2, 0, volume);
Conductor.instance.mapTimeChanges(previewTimeChanges);
}
});
}
Expand Down
55 changes: 3 additions & 52 deletions source/funkin/ui/mainmenu/MainMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ class MainMenuState extends MusicBeatState

subStateOpened.add(sub -> {
if (Type.getClass(sub) == FreeplayState)
{
new FlxTimer().start(0.5, _ -> {
magenta.visible = false;
});
}
new FlxTimer().start(0.5, _ -> magenta.visible = false);
});

// FlxG.camera.setScrollBounds(bg.x, bg.x + bg.width, bg.y, bg.y + bg.height * 1.2);
Expand Down Expand Up @@ -285,16 +281,7 @@ class MainMenuState extends MusicBeatState
rememberedSelectedIndex = menuItems.selectedIndex;

var duration = 0.4;
menuItems.forEach((item) -> {
if (menuItems.selectedIndex != item.ID)
{
FlxTween.tween(item, {alpha: 0}, duration, {ease: FlxEase.quadOut});
}
else
{
item.visible = false;
}
});
menuItems.forEach((item) -> menuItems.selectedIndex != item.ID ? FlxTween.tween(item, {alpha: 0}, duration, {ease: FlxEase.quadOut}) : item.visible = false);

new FlxTimer().start(duration, (_) -> FlxG.switchState(state));
}
Expand All @@ -306,20 +293,10 @@ class MainMenuState extends MusicBeatState
if (FlxG.onMobile)
{
var touch:FlxTouch = FlxG.touches.getFirst();

if (touch != null)
{
for (item in menuItems)
{
if (touch.overlaps(item))
{
if (menuItems.selectedIndex == item.ID && touch.justPressed)
menuItems.accept();
else
menuItems.selectItem(item.ID);
}
}
}
(menuItems.selectedIndex == item.ID && touch.justPressed) ? menuItems.accept() : menuItems.selectItem(item.ID);
}

// Open the debug menu, defaults to ` / ~
Expand All @@ -334,34 +311,8 @@ class MainMenuState extends MusicBeatState
}
#end

#if (debug || FORCE_DEBUG_VERSION)
if (FlxG.keys.pressed.CONTROL && FlxG.keys.pressed.ALT && FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.W)
{
// Give the user a score of 1 point on Weekend 1 story mode.
// This makes the level count as cleared and displays the songs in Freeplay.
funkin.save.Save.instance.setLevelScore('weekend1', 'easy',
{
score: 1,
tallies:
{
sick: 0,
good: 0,
bad: 0,
shit: 0,
missed: 0,
combo: 0,
maxCombo: 0,
totalNotesHit: 0,
totalNotes: 0,
}
});
}
#end

if (FlxG.sound.music != null && FlxG.sound.music.volume < 0.8)
{
FlxG.sound.music.volume += 0.5 * elapsed;
}

if (_exiting) menuItems.enabled = false;

Expand Down
Loading

0 comments on commit 29112e9

Please sign in to comment.