diff --git a/buildnumber.txt b/buildnumber.txt index 0fb5907f..61b5691d 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -2190 \ No newline at end of file +2193 \ No newline at end of file diff --git a/source/funkin/system/FunkinRatioScaleMode.hx b/source/funkin/system/FunkinRatioScaleMode.hx new file mode 100644 index 00000000..4d49f802 --- /dev/null +++ b/source/funkin/system/FunkinRatioScaleMode.hx @@ -0,0 +1,63 @@ +package funkin.system; + +import flixel.FlxG; +import flixel.system.scaleModes.RatioScaleMode; + +class FunkinRatioScaleMode extends RatioScaleMode { + @:isVar public var width(get, set):Null = null; + @:isVar public var height(get, set):Null = null; + + public override function updateGameSize(Width:Int, Height:Int):Void + { + var ratio:Float = width / height; + var realRatio:Float = Width / Height; + + var scaleY:Bool = realRatio < ratio; + if (fillScreen) + { + scaleY = !scaleY; + } + + if (scaleY) + { + gameSize.x = Width; + gameSize.y = Math.floor(gameSize.x / ratio); + } + else + { + gameSize.y = Height; + gameSize.x = Math.floor(gameSize.y * ratio); + } + + @:privateAccess { + FlxG.width = width; + FlxG.height = height; + + for(c in FlxG.cameras.list) { + c.width = width; + c.height = height; + } + } + } + + public function resetSize() { + width = null; + height = null; + } + private inline function get_width():Null + return this.width == null ? FlxG.initialWidth : this.width; + private inline function get_height():Null + return this.height == null ? FlxG.initialHeight : this.height; + private inline function set_width(v:Null):Null { + this.width = v; + @:privateAccess + FlxG.game.onResize(null); + return v; + } + private inline function set_height(v:Null):Null { + this.height = v; + @:privateAccess + FlxG.game.onResize(null); + return v; + } +} \ No newline at end of file diff --git a/source/funkin/system/Main.hx b/source/funkin/system/Main.hx index 6ba869fd..8a7d05ab 100644 --- a/source/funkin/system/Main.hx +++ b/source/funkin/system/Main.hx @@ -39,6 +39,8 @@ class Main extends Sprite { public static var instance:Main; + public static var scaleMode:FunkinRatioScaleMode; + var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom). var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom). var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions. @@ -203,6 +205,8 @@ class Main extends Sprite refreshAssets(); + FlxG.scaleMode = scaleMode = new FunkinRatioScaleMode(); + Conductor.init(); AudioSwitchFix.init(); WindowsAPI.setDarkMode(true); @@ -238,6 +242,8 @@ class Main extends Sprite // manual asset clearing since base openfl one doesnt clear lime one // doesnt clear bitmaps since flixel fork does it auto + scaleMode.resetSize(); + var cache = cast(Assets.cache, AssetCache); for (key=>font in cache.font) cache.removeFont(key);