diff --git a/source/funkin/graphics/TypedGroup.hx b/source/funkin/graphics/TypedGroup.hx index 219778bf..5b606549 100644 --- a/source/funkin/graphics/TypedGroup.hx +++ b/source/funkin/graphics/TypedGroup.hx @@ -1,37 +1,16 @@ package funkin.graphics; import flixel.FlxBasic; +#if (flixel >= "5.7.0") +import flixel.group.FlxContainer.FlxTypedContainer; +#end // Just flixel groups with unsafe gets for performance typedef Group = TypedGroup; -class TypedGroup extends FlxTypedGroup +class TypedGroup extends #if (flixel >= "5.7.0") FlxTypedContainer #else FlxTypedGroup #end { - @:noCompletion - override function get_camera():FlxCamera @:privateAccess { - if (_cameras != null) if (_cameras.length != 0) return _cameras[0]; - return FlxCamera._defaultCameras[0]; - } - - @:noCompletion - override inline function set_camera(Value:FlxCamera):FlxCamera { - if (_cameras == null) _cameras = [Value]; - else _cameras.unsafeSet(0, Value); - return Value; - } - - @:noCompletion - override inline function get_cameras():Array { - @:privateAccess - return (_cameras == null) ? FlxCamera._defaultCameras : _cameras; - } - - @:noCompletion - override inline function set_cameras(Value:Array):Array { - return _cameras = Value; - } - public inline function setNull(object:T) { var index:Int = members.indexOf(object); if (index != -1) { @@ -60,11 +39,11 @@ class TypedGroup extends FlxTypedGroup var index:Int = 0; final l:Int = members.length; while (index < l) { - index++; if (members[index] == null) { members.unsafeSet(index, object); return; } + index++; } members.unshift(object); @@ -104,247 +83,18 @@ typedef SpriteGroup = TypedSpriteGroup; class TypedSpriteGroup extends FlxTypedSpriteGroup { + #if (flixel < "5.7.0") public function new(x:Float = 0, y:Float = 0, maxSize:Int = 0) { super(x, y, maxSize); group.destroy(); - group = new TypedGroup(maxSize); - #if (flixel < "5.7.0") _sprites = cast group.members; - #end - } -} - -/*class TypedSpriteGroup extends FlxObject { - public var group:TypedGroup; // Group containing everything - override inline function get_camera():FlxCamera return group.camera; - override inline function set_camera(Value:FlxCamera):FlxCamera return group.camera = Value; - override inline function get_cameras():Array return group.cameras; - override inline function set_cameras(Value:Array):Array return group.cameras = Value; - - public var members(get, never):Array; - inline function get_members():Array return group.members; - - inline public function add(basic:T):T return group.add(basic); - inline public function recycle(?basicClass:Class):T return group.recycle(basicClass); - - public var offset(default, null):FlxPoint; - public var origin(default, null):FlxPoint; - var _cos(default, null):Float = 1.0; - var _sin(default, null):Float = 0.0; - - override function set_angle(value:Float):Float { - if (angle != value) { - var rads:Float = value * CoolUtil.TO_RADS; - _cos = CoolUtil.cos(rads); - _sin = CoolUtil.sin(rads); - } - return angle = value; - } - - public var alpha:Float = 1.0; - public var color(default, set):FlxColor = FlxColor.WHITE; - - function set_color(value:FlxColor):FlxColor { - if (value != color) { - for (basic in members) - basic.color = value; - } - return color = value; - } - - override function get_width():Float { - var w:Float = 0.0; - for (member in members) { - if (member == null || !member.alive) continue; - - var value = member.x + member.width; - if (value > w) w = value; - } - return w; } - - override function get_height():Float { - var h:Float = 0.0; - for (member in members) { - if (member == null || !member.alive) continue; - - var value = member.y + member.height; - if (value > h) h = value; - } - return h; - } - - public function new (X:Float = 0, Y:Float = 0, ?maxSize:Int) { - super(); + #else + override function initGroup(maxSize:Int):Void + { + @:bypassAccessor group = new TypedGroup(maxSize); - offset = FlxPoint.get(); - origin = FlxPoint.get(); - } - - override function destroy() { - super.destroy(); - group = FlxDestroyUtil.destroy(group); - offset = FlxDestroyUtil.put(offset); - origin = FlxDestroyUtil.put(origin); - } - - override function update(elapsed:Float) { - group.update(elapsed); - } - - override function draw() { - @:privateAccess { - final oldDefaultCameras = FlxCamera._defaultCameras; - if (group.cameras != null) FlxCamera._defaultCameras = group.cameras; - - var point = CoolUtil.point; - point.set(x, y); - point.subtract(offset.x, offset.y); - - for (basic in members) { - var basicX = basic.x; var basicY = basic.y; var basicAngle = basic.angle; var basicAlpha = basic.alpha; - CoolUtil.positionWithTrig(basic, basic.x - origin.x, basic.y - origin.y, _cos, _sin); - - basic.x += point.x + origin.x; - basic.y += point.y + origin.y; - basic.angle += angle; - basic.alpha *= alpha; - - if (basic != null && basic.exists && basic.visible) { - basic.draw(); - } - - basic.x = basicX; - basic.y = basicY; - basic.angle = basicAngle; - basic.alpha = basicAlpha; - } - - FlxCamera._defaultCameras = oldDefaultCameras; - } - } -}*/ - -/* -class BaseTypedSpriteGroup extends TypedGroup -{ - public var x(default, set):Float = 0.0; - public var y(default, set):Float = 0.0; - public var offset(default, null):FlxPoint; - public var scrollFactor(default, null):FlxPoint; - - public inline function setPosition(X:Float = 0, Y:Float = 0) { - x = X; - y = Y; - } - - public inline function screenCenter(axes:FlxAxes = XY) { - if (axes.x) x = (FlxG.width - width) * .5; - if (axes.y) y = (FlxG.height - height) * .5; - return this; - } - - public var alpha:Float = 1.0; - public var color(default, set):FlxColor = FlxColor.WHITE; - - function set_color(value:FlxColor):FlxColor { - if (value != color) { - for (basic in members) - basic.color = value; - } - return color = value; - } - - public var angle(default, set):Float = 0.0; - public var origin(default, null):FlxPoint; - var _cos(default, null):Float = 1.0; - var _sin(default, null):Float = 0.0; - - function set_angle(value:Float):Float { - if (angle != value) { - var rads:Float = value * CoolUtil.TO_RADS; - _cos = CoolUtil.cos(rads); - _sin = CoolUtil.sin(rads); - } - return angle = value; - } - - public var width(get, set):Float; - public var height(get, set):Float; - - function get_width():Float { - var w:Float = 0.0; - for (member in members) { - if (member == null || !member.alive) continue; - - var value = member.x + member.width; - if (value > w) w = value; - } - return w; - } - - function get_height():Float { - var h:Float = 0.0; - for (member in members) { - if (member == null || !member.alive) continue; - - var value = member.y + member.height; - if (value > h) h = value; - } - return h; - } - - public function new(X:Float = 0.0, Y:Float = 0.0, ?maxSize:Int):Void { - super(maxSize); - setPosition(X, Y); - offset = FlxPoint.get(); - origin = FlxPoint.get(); - scrollFactor = new FlxCallbackPoint(function (point:FlxPoint) { - for (basic in members) { - basic.scrollFactor.set(point.x, point.y); - } - }); - - scrollFactor.set(1, 1); - } - - override function destroy() { - super.destroy(); - offset = FlxDestroyUtil.put(offset); - origin = FlxDestroyUtil.put(origin); - scrollFactor = FlxDestroyUtil.destroy(scrollFactor); - } - - override function draw():Void { - @:privateAccess { - final oldDefaultCameras = FlxCamera._defaultCameras; - if (cameras != null) FlxCamera._defaultCameras = cameras; - - var point = CoolUtil.point; - point.set(x, y); - point.subtract(offset.x, offset.y); - - for (basic in members) { - var basicX = basic.x; var basicY = basic.y; var basicAngle = basic.angle; var basicAlpha = basic.alpha; - CoolUtil.positionWithTrig(basic, basic.x - origin.x, basic.y - origin.y, _cos, _sin); - - basic.x += point.x; - basic.y += point.y; - basic.angle += angle; - basic.alpha *= alpha; - - if (basic != null && basic.exists && basic.visible) { - basic.draw(); - } - - basic.x = basicX; - basic.y = basicY; - basic.angle = basicAngle; - basic.alpha = basicAlpha; - } - - FlxCamera._defaultCameras = oldDefaultCameras; - } } -}*/ \ No newline at end of file + #end +} \ No newline at end of file diff --git a/source/funkin/states/menus/FreeplayState.hx b/source/funkin/states/menus/FreeplayState.hx index 7988558a..85033e5f 100644 --- a/source/funkin/states/menus/FreeplayState.hx +++ b/source/funkin/states/menus/FreeplayState.hx @@ -10,7 +10,8 @@ typedef SongMetaData = { var mod:String; } -class FreeplayState extends MusicBeatState { +class FreeplayState extends MusicBeatState +{ var bg:FunkinSprite; var songs:Array = []; diff --git a/source/funkin/util/Paths.hx b/source/funkin/util/Paths.hx index d5a9f097..a92c9da9 100644 --- a/source/funkin/util/Paths.hx +++ b/source/funkin/util/Paths.hx @@ -244,31 +244,37 @@ class Paths return [dirParts[1], dirParts[dirParts.length-1].split('.')[0]]; } - inline static public function getSparrowAtlas(key:String, ?library:String, ?useTexture:Bool, ?lodLevel:LodLevel):FlxAtlasFrames { + // Gotta do this to make sure FlxAtlasFrames doesnt lose his shit when the graphic is smaller than the data + private static function getFrames(image:LodGraphic, getter:()->FlxAtlasFrames) { + image.setSize(image.lodWidth, image.lodHeight); + var frames = getter(); + image.setSize(image.bitmap.width, image.bitmap.height); + return frames; + } + + inline static public function getSparrowAtlas(key:String, ?library:String, ?useTexture:Bool, ?lodLevel:LodLevel):FlxAtlasFrames + { var image = image(key, library, false, useTexture, lodLevel); var xml = CoolUtil.getFileContent(file('images/$key.xml', library)); - - return __checkLodFrames(FlxAtlasFrames.fromSparrow(image, xml)); + + return __checkLodFrames(getFrames(image, () -> return FlxAtlasFrames.fromSparrow(image, xml))); } - inline static public function getSpriteSheetAtlas(key:String, ?library:String, ?useTexture:Bool, ?lodLevel:LodLevel):FlxAtlasFrames { + inline static public function getSpriteSheetAtlas(key:String, ?library:String, ?useTexture:Bool, ?lodLevel:LodLevel):FlxAtlasFrames + { var image = image(key, library, false, useTexture, lodLevel); var txt = CoolUtil.getFileContent(file('images/$key.txt', library)); - return __checkLodFrames(FlxAtlasFrames.fromSpriteSheetPacker(image, txt)); + return __checkLodFrames(getFrames(image, () -> return FlxAtlasFrames.fromSpriteSheetPacker(image, txt))); } inline static public function getAsepriteAtlas(key:String, ?library:String, ?useTexture:Bool, ?lodLevel:LodLevel):FlxAtlasFrames { var image = image(key, library, false, useTexture, lodLevel); var json = CoolUtil.getFileContent(file('images/$key.json', library)); - return __checkLodFrames(JsonUtil.getAsepritePacker(image, json)); + return __checkLodFrames(getFrames(image, () -> return JsonUtil.getAsepritePacker(image, json))); } - //inline static public function getAnimateAtlas(key:String, ?library:String):FlxAtlasFrames { - // return null; - //} - @:noCompletion inline private static function __checkLodFrames(frames:FlxAtlasFrames):FlxAtlasFrames { var parent:LodGraphic = cast(frames.parent, LodGraphic); diff --git a/source/funkin/util/backend/AssetManager.hx b/source/funkin/util/backend/AssetManager.hx index 718aae3e..8633dd05 100644 --- a/source/funkin/util/backend/AssetManager.hx +++ b/source/funkin/util/backend/AssetManager.hx @@ -144,13 +144,22 @@ class LodGraphic extends FlxGraphic imageFrame.frame.sourceSize *= lodScale; } + public var lodWidth(default, null):Int; + public var lodHeight(default, null):Int; + + public inline function setSize(width:Int, height:Int):Void { + this.width = width; + this.height = height; + } + override function set_bitmap(value:BitmapData):BitmapData { if (value != null) { bitmap = value; - width = bitmap.width << lodLevel; - height = bitmap.height << lodLevel; + setSize(bitmap.width, bitmap.height); + lodWidth = bitmap.width << lodLevel; + lodHeight = bitmap.height << lodLevel; } return value;