Commander Wars Image Recoloring - Robosturm/Commander_Wars GitHub Wiki

Commander Wars comes with two different ways of applying a color to a sprites. This page describes both ways.

Color applied to a mask

This approach applies a single color to a texture\mask. The resulting color is mask color multiplied with the player color. Where the ARGB Values of each color range between 0.0 and 1.0.

The ARGB Color White (1.0, 1.0, 1.0, 1.0) would result in the player color.

The ARGB Color Black (1.0, 0.0, 0.0, .0) would result in the color black.

Each gray color in between makes the given color darker.

Colors applied via a Colortable to a mask

This approach uses a predefined colortable to recolor the mask. In the first part i'll describe the specifications for the colortable. And in the second part the specification for the mask.

Colortable

The colortable has to have a width 256 pixel and a heigth of 256. The first pixel of the colortable has to be transparent. The next three pixel always represent a new color. So their is a maximum of 85 colors for a colortable. This means the pixels 1, 2, 3 need to be the same colors the pixels 4, 5, 6 have the next same color.

Mask

The engine uses the Red-Color and Green-Color channel to determine with which color it needs to replace the mask color from the colortable. In a normal RGB range from 0 to 255. The Red-Value 0 replaces a mask color with transparent.

The Red Value 2 replaces a mask color with the first color.

The Red Value 5 replaces a mask color with the second color.

etc.

The Blue Color of the mask can have any value you like. However i recommend to have them represent a similar darkness like the resulting ingame image will have. So it's easier to visually see how the mask will look ingame.

Current Color Table usage

Currently the first 6 Colors are used for overworld units and battleanimations (the later may change since battleanmations use more colors) and buildings use the colors 7 to 10. Colortables are either predefined in the colortable folder and mapped via the general/player.js script or are directly generted using the selected color and the general/player.js script.

Automatic Converting of old mask sprites into colortable sprites

Note this may lead to suboptimal results but is an easy way to intially recolor all sprites of a mod. In the game open the console and type in createColorTableSprites("folder", "filter", startpixel, colors) Where

  • folder is the path in which the files lay
  • filter is a default string filter e.g. *+mask.png
  • start pixel is currently 2 for units and 20 for buildings
  • colors is the amount of following colors used for refactoring the image. At the moment 6 for units and 4 for buildings and the next 25 for battleanimations. Note: The command will not create a backup of the files!!!!