mwg API
    Preparing search index...

    Function recolorTexture

    • Recolours a texture by palette remap: draws it to a canvas, runs remapPixels over the raw pixel data, and returns a new Texture wrapping the result. The source texture is never mutated, so the same base art recolours per team without extra copies kept around by the caller. Needs a real 2D canvas context (unlike remapPixels itself), so pass probe in a test or host integration with no DOM; omitting it uses document.createElement('canvas').

      mode defaults to 'exact', correct for a discrete swap (~RC/~PAL's short, specific from list); a paletteRangeMapping gradient, meant to cover the whole reference palette a team's art is drawn against, wants 'nearest' instead - see PaletteRemapMode's own doc for why the wrong choice silently recolours far more of the image than intended.

      Parameters

      Returns Texture

      import { paletteRangeMapping, recolorTexture } from '@datamoc/mw_games/two-d/render';
      import type { Texture2D } from '@datamoc/mw_games/two-d/render';

      declare const texture: Texture2D;
      const mapping = paletteRangeMapping([0xffffff, 0x808080, 0x000000], { min: 0xffe0e0, mid: 0xc00000, max: 0x400000 });
      const redTeam = recolorTexture(texture, mapping, {}, 'nearest');