﻿using JLGames.RocketDriver.Actions.Graphicsx;
using UnityEngine;

namespace JLGames.RocketDriver.Actions.Extensions
{
    public static class ExtColor
    {
        public static string ToRGBA(this Color c)
        {
            Color32 col = c;
            return $"{col.r:X2}{col.g:X2}{col.b:X2}{col.a:X2}";
        }

        public static string ToHtmlRGBA(this Color c)
        {
            return $"#{c.ToRGBA()}";
        }

        public static Color DarkerBrighter(this Color col, float lightToAdd)
        {
            return new Color(col.r + lightToAdd, col.g + lightToAdd, col.b + lightToAdd, col.a);
        }

        public static Color Alphaed(this Color col, float alpha)
        {
            return new Color(col.r, col.g, col.b, alpha);
        }

        public static Color Step(this Color col, float step)
        {
            return new Color(col.r + step, col.g + step, col.b + step, col.a);
        }

        public static Color Inverted(this Color col, bool invertAlpha = false)
        {
            return new Color(1 - col.r, 1 - col.g, 1 + -col.b, (invertAlpha) ? 1 - col.a : col.a);
        }

        public static Color Offset(this Color col, float offset)
        {
            return new Color(col.r + offset, col.g + offset, col.b + offset, col.a);
        }

        public static Color FromHtml(string id)
        {
            return ColorUtil.FromHtml(id);
        }
    }
}