Skip to content

Commit

Permalink
Better colour deciders for surface and footpath
Browse files Browse the repository at this point in the history
  • Loading branch information
fidwell committed Jan 18, 2024
1 parent b7a3de9 commit 2fab3e0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 55 deletions.
16 changes: 0 additions & 16 deletions src/enums/terrain.ts

This file was deleted.

24 changes: 1 addition & 23 deletions src/utilities/colourdecider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ export default class ColourDecider {
}

static getColourFromFootpath(element: FootpathElement): number {
if (element.surfaceObject !== null) {
return this.getColourFromFootpathType(element.surfaceObject);
}

return 0;
return ColourUtilities.footpathToPalette(element.surfaceObject ?? element.object ?? 0);
}

static getColourFromSurface(element: SurfaceElement, options: Options): number {
Expand All @@ -98,22 +94,4 @@ export default class ColourDecider {

return options.showSurface ? ColourUtilities.surfaceToPalette(element.surfaceStyle) : ColourUtilities.colourToPalette(Colour.Black);
}

private static getColourFromFootpathType(object: number): number {
// We can't actually know what kind of footpath it is just
// based on the object number, since that number will
// change based on what objects are selected in the map.

// However we should at least differentiate somehow, so
// let's pick some colors at random...
const colours: number[] = [
ColourUtilities.colourToPalette(Colour.Grey),
ColourUtilities.colourToPalette(Colour.LightBrown),
ColourUtilities.colourToPalette(Colour.DarkBrown),
ColourUtilities.colourToPalette(Colour.SaturatedBrown),
ColourUtilities.colourToPalette(Colour.DarkOliveGreen)
];

return colours[(object ?? 0) % colours.length];
}
}
71 changes: 55 additions & 16 deletions src/utilities/colourutilities.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
import { Colour } from "../enums/colour";
import { Terrain } from "../enums/terrain";

// See ImageImporter.h for colour indexes

export default class ColourUtilities {
static surfaceToPalette(surface: number): number {
switch (surface) {
case Terrain.Grass: return 72;
case Terrain.Sand: return 42;
case Terrain.Dirt: return 218;
case Terrain.Rock: return 13;
case Terrain.Martian: return 109;
case Terrain.Checkerboard: return 20;
case Terrain.GrassClumps: return 23;
case Terrain.Ice: return 139;
case Terrain.GridRed: return 173;
case Terrain.GridYellow: return 54;
case Terrain.GridBlue: return 157; // It's really purple
case Terrain.GridGreen: return 101;
case Terrain.SandDark: return 109;
case Terrain.SandLight: return 220;
const surfaceObject = objectManager.getObject("terrain_surface", surface);
switch (surfaceObject.identifier.split(".")[2]) {
case "grass": return 72;
case "grass_clumps": return 23;
case "dirt": return 218;
case "ice": return 139;
case "rock": return 13;
case "sand": return 44;
case "martian": return 109;
case "sand_brown": return 221;
case "sand_red": return 111;

// rct1
case "rust": return 220;
case "wood": return 47;
case "roof_grey": return 17;
case "roof_red": return 176;

case "chequerboard": return 16;
case "grid_green": return 101;
case "grid_purple": return 157;
case "grid_red": return 173;
case "grid_yellow": return 54;
case "void": return 4;
default: return 209; // undefined -> pink
}
}

static footpathToPalette(footpath: number): number {
const pathType = objectManager.getObject("footpath_surface", footpath);
switch (pathType.identifier.split(".")[2]) {
case "dirt":
return 216;
case "crazy_paving":
return 223;
case "ash":
return 10;
case "tarmac_red":
return 62;
case "tarmac_green":
return 75;
case "tarmac_brown":
return 34;
case "tarmac":
case "road":
return 15;
case "queue_yellow":
return 54;
case "queue_red":
return 173;
case "queue_green":
return 100;
case "queue_blue":
return 137;
default:
return 209; // undefined -> pink
}
}

static water(): number {
return 237;
}
Expand Down

0 comments on commit 2fab3e0

Please sign in to comment.