diff --git a/buildnumber.txt b/buildnumber.txt index f9a94625..a3ff295b 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -2265 \ No newline at end of file +2286 \ No newline at end of file diff --git a/source/funkin/menus/credits/CreditsCodename.hx b/source/funkin/menus/credits/CreditsCodename.hx index 5b80d55c..309e9c26 100644 --- a/source/funkin/menus/credits/CreditsCodename.hx +++ b/source/funkin/menus/credits/CreditsCodename.hx @@ -1,5 +1,6 @@ package funkin.menus.credits; +import flixel.util.FlxColor; import funkin.shaders.CustomShader; import flixel.math.FlxMath; import funkin.options.type.TextOption; @@ -13,21 +14,18 @@ import funkin.github.GitHub; import funkin.github.GitHubContributor; import funkin.menus.MainMenuState; +using funkin.utils.BitmapUtil; + class CreditsCodename extends OptionsScreen { public var contributorsSprites:Array = []; public var contributorsAvatars:Array = []; + public var contributorsColors:Array = []; public var avatarLoadListId:Int = 0; public var contributors:Array; - public override function create() { + public var interpColor:FlxInterpolateColor; - var bg:FlxSprite = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuBGBlue')); - bg.scrollFactor.set(); - bg.scale.set(1.15, 1.15); - bg.updateHitbox(); - bg.screenCenter(); - bg.antialiasing = true; - add(bg); + public override function create() { contributors = GitHub.getContributors("YoshiCrafter29", "CodenameEngine", function(e) { trace(e); @@ -48,6 +46,7 @@ class CreditsCodename extends OptionsScreen { super.create(); + interpColor = new FlxInterpolateColor(bg.color); } public override function createAdditional() { @@ -66,7 +65,9 @@ class CreditsCodename extends OptionsScreen { for(k=>c in contributors) { var bytes = GitHub.__requestBytesOnGitHubServers('${c.avatar_url}&size=96'); var bmap = BitmapData.fromBytes(bytes); + var color = bmap.getMostPresentSaturatedColor(); contributorsAvatars.push(FlxG.bitmap.add(bmap, false, 'GITHUB-USER:${c.login}')); + contributorsColors.push(color); if (destroyed) return; } }); @@ -88,9 +89,16 @@ class CreditsCodename extends OptionsScreen { var alpha = options[k]; spr.x = alpha.x - 10; } + + interpColor.fpsLerpTo(contributorsColors[curSelected], 0.0625); + bg.color = interpColor.color; } public override function destroy() { super.destroy(); } + + public override function exit() { + FlxG.switchState(new CreditsMain()); + } } \ No newline at end of file diff --git a/source/funkin/options/Options.hx b/source/funkin/options/Options.hx index e154dd9b..2c52d349 100644 --- a/source/funkin/options/Options.hx +++ b/source/funkin/options/Options.hx @@ -86,7 +86,7 @@ class Options public static function load() { if (__save == null) __save = new FlxSave(); - __save.bind("options"); + __save.bind("options", "CodenameEngine"); for(field in Reflect.fields(__save.data)) { var obj = Reflect.field(__save.data, field); Reflect.setProperty(Options, field, obj); diff --git a/source/funkin/options/OptionsScreen.hx b/source/funkin/options/OptionsScreen.hx index 9aad209d..9a9bc5e9 100644 --- a/source/funkin/options/OptionsScreen.hx +++ b/source/funkin/options/OptionsScreen.hx @@ -19,7 +19,6 @@ class OptionsScreen extends MusicBeatState { public static var instance:OptionsScreen; public static var optionHeight:Float = 120; - // public var bgColor:FlxColor = 0xFFFDE871; public var bg:FlxSprite; public var descDrop:FlxBackdrop; @@ -43,11 +42,12 @@ class OptionsScreen extends MusicBeatState { FlxTransitionableState.skipNextTransIn = true; super.create(); - bg = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuBG')); + bg = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuDesat')); bg.scrollFactor.set(); bg.scale.set(1.15, 1.15); bg.updateHitbox(); bg.screenCenter(); + bg.color = defaultBGColor; bg.antialiasing = true; add(bg); diff --git a/source/funkin/system/Main.hx b/source/funkin/system/Main.hx index e4e3cf54..2f4c9f81 100644 --- a/source/funkin/system/Main.hx +++ b/source/funkin/system/Main.hx @@ -195,7 +195,7 @@ class Main extends Sprite Assets.registerLibrary('default', lib); funkin.options.PlayerSettings.init(); - FlxG.save.bind('Codename-Engine'); + FlxG.save.bind('save', 'CodenameEngine'); Options.load(); Highscore.load(); diff --git a/source/funkin/utils/BitmapUtil.hx b/source/funkin/utils/BitmapUtil.hx new file mode 100644 index 00000000..ce22e81e --- /dev/null +++ b/source/funkin/utils/BitmapUtil.hx @@ -0,0 +1,69 @@ +package funkin.utils; + +import openfl.display.BitmapData; +import flixel.util.FlxColor; + +class BitmapUtil { + /** + * Returns the most present color in a Bitmap. + * @param bmap Bitmap + * @return FlxColor Color that is the most present. + */ + public static function getMostPresentColor(bmap:BitmapData):FlxColor { + // map containing all the colors and the number of times they've been assigned. + var colorMap:Map = []; + var color:FlxColor = 0; + var fixedColor:FlxColor = 0; + + for(y in 0...bmap.height) { + for(x in 0...bmap.width) { + color = bmap.getPixel32(x, y); + fixedColor = 0xFF000000 + (color % 0x1000000); + if (colorMap[fixedColor] == null) + colorMap[fixedColor] = 0; + colorMap[fixedColor] += color.alphaFloat; + } + } + + var mostPresentColor:FlxColor = 0; + var mostPresentColorCount:Float = -1; + for(c=>n in colorMap) { + if (n > mostPresentColorCount) { + mostPresentColorCount = n; + mostPresentColor = c; + } + } + return mostPresentColor; + } + /** + * Returns the most present saturated color in a Bitmap. + * @param bmap Bitmap + * @return FlxColor Color that is the most present. + */ + public static function getMostPresentSaturatedColor(bmap:BitmapData):FlxColor { + // map containing all the colors and the number of times they've been assigned. + var colorMap:Map = []; + var color:FlxColor = 0; + var fixedColor:FlxColor = 0; + + for(y in 0...bmap.height) { + for(x in 0...bmap.width) { + color = bmap.getPixel32(x, y); + fixedColor = 0xFF000000 + (color % 0x1000000); + if (colorMap[fixedColor] == null) + colorMap[fixedColor] = 0; + colorMap[fixedColor] += color.alphaFloat * 0.33 + (0.67 * (color.saturation * (2 * (color.lightness > 0.5 ? 0.5 - (color.lightness) : color.lightness)))); + } + } + + var mostPresentColor:FlxColor = 0; + var mostPresentColorCount:Float = -1; + for(c=>n in colorMap) { + if (n > mostPresentColorCount) { + mostPresentColorCount = n; + mostPresentColor = c; + } + } + return mostPresentColor; + } +} \ No newline at end of file diff --git a/source/funkin/utils/FlxInterpolateColor.hx b/source/funkin/utils/FlxInterpolateColor.hx new file mode 100644 index 00000000..d33f15eb --- /dev/null +++ b/source/funkin/utils/FlxInterpolateColor.hx @@ -0,0 +1,40 @@ +package funkin.utils; + +import flixel.FlxG; +import flixel.util.FlxColor; + +class FlxInterpolateColor { + public var red:Float = 0; + public var green:Float = 0; + public var blue:Float = 0; + public var alpha:Float = 0; + + public var color(get, set):FlxColor; + + private inline function get_color() + return FlxColor.fromRGBFloat(red, green, blue, alpha); + + private inline function set_color(c:FlxColor):FlxColor { + red = c.redFloat; + green = c.greenFloat; + blue = c.blueFloat; + alpha = c.alphaFloat; + return c; + } + + public inline function toString() + return '[FlxInterpolateColor - (R:${red} | G:${green} | B:${blue} | A:${alpha})]'; + public function new(color:FlxColor) { + this.color = color; + } + + public function lerpTo(color:FlxColor, ratio:Float) { + red = (color.redFloat - red) * ratio + red; + green = (color.greenFloat - green) * ratio + green; + blue = (color.blueFloat - blue) * ratio + blue; + alpha = (color.alphaFloat - alpha) * ratio + alpha; + } + + public inline function fpsLerpTo(color:FlxColor, ratio:Float) + lerpTo(color, ratio * 60 * FlxG.elapsed); +} \ No newline at end of file