Converting LFS Colours

Live for Speed text that includes colours is encoded. This guide will help you to extract the colours from the text.

Imagine you made a call to the User Profile API and wanted to decode the following nickname: "nickname": "^1[TC]\u00bbPete\u00ab",. The UTF-8 encoding is not an issue because the browser decodes that automatically for us but the LFS colour prefixes eg. ^1, will need to be decoded by us before being presented.

Our code examples are available in JavaScript and PHP (change language in the top right).

Reference Implementations

The list of LFS colour codes is as follows:

Colour

Code

Black

^0

Red

^1

Light Green

^2

Yellow

^3

Blue

^4

Purple

^5

Light Blue

^6

White

^7

Dark Green (Default)

^8

Original text colour and codepage

^9

All of the examples in this guide require the following CSS to properly display the colours:

CSS

.lfs_col0 {color : #000000;}
.lfs_col1 {color : #ff0000;}
.lfs_col2 {color : #00ff00;}
.lfs_col3 {color : #ffff00;}
.lfs_col4 {color : #0000ff;}
.lfs_col5 {color : #ff00ff;}
.lfs_col6 {color : #00ffff;}
.lfs_col7 {color : #ffffff;}
.lfs_col8, .lfs_col9 {color : #8a8a8a;}

JavaScript

function LFSColours(str) {
  var parts = str.split(/(\^\d)/g).slice(1);
  var res = "";
  parts.forEach(function(el, i, arr) {
    (i % 2 === 0) ? arr[i] = el.slice(1) : res += '<span class="lfs_col' + arr[i-1] + '">' + el + '</span>';
  });
  return res;
}

Example usage

Try out this example on JS Bin

var str = '^1[TC]\u00bbPete\u00ab';

document.body.innerHTML = LFSColours(str);

Last updated