public override void Tick()
        {
            if (cachedColor == Color)
            {
                return;
            }
            cachedColor = Color;

            var newPalette = new MutablePalette(preview);

            newPalette.ApplyRemap(new PlayerColorRemap(RemapIndices, Color, Ramp));
            worldRenderer.ReplacePalette(PaletteName, newPalette);
        }
Example #2
0
        public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color c, bool replaceExisting)
        {
            var pal = new MutablePalette(wr.Palette(info.BasePalette).Palette);

            foreach (var i in info.RemapIndex)
            {
                var bw   = (float)(((pal[i] & 0xff) + ((pal[i] >> 8) & 0xff) + ((pal[i] >> 16) & 0xff)) / 3) / 0xff;
                var dstR = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)c.R / 0xff) : 2 * bw * ((float)c.R / 0xff);
                var dstG = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)c.G / 0xff) : 2 * bw * ((float)c.G / 0xff);
                var dstB = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)c.B / 0xff) : 2 * bw * ((float)c.B / 0xff);
                pal[i] = (pal[i] & 0xff000000) | ((uint)(dstR * 0xff) << 16) | ((uint)(dstG * 0xff) << 8) | (uint)(dstB * 0xff);
            }

            wr.AddPalette(info.BaseName + playerName, new ImmutablePalette(pal), info.AllowModifiers, replaceExisting);
        }
        public override void Tick()
        {
            if (cachedColor == Color)
            {
                return;
            }
            cachedColor = Color;

            var newPalette = new MutablePalette(preview);

            foreach (var i in RemapIndices)
            {
                var bw   = (float)(((preview[i] & 0xff) + ((preview[i] >> 8) & 0xff) + ((preview[i] >> 16) & 0xff)) / 3) / 0xff;
                var dstR = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)Color.RGB.R / 0xff) : 2 * bw * ((float)Color.RGB.R / 0xff);
                var dstG = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)Color.RGB.G / 0xff) : 2 * bw * ((float)Color.RGB.G / 0xff);
                var dstB = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)Color.RGB.B / 0xff) : 2 * bw * ((float)Color.RGB.B / 0xff);
                newPalette[i] = (preview[i] & 0xff000000) | ((uint)(dstR * 0xff) << 16) | ((uint)(dstG * 0xff) << 8) | (uint)(dstB * 0xff);
            }

            worldRenderer.ReplacePalette(PaletteName, newPalette);
        }