Skip to content

Commit

Permalink
v 1.1
Browse files Browse the repository at this point in the history
Fixed many eslint warnings
  • Loading branch information
fidwell committed Sep 11, 2021
1 parent c4e6d82 commit 5c446c2
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 120 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"spaced-comment": 0,
"max-len": [
"error",
{ "code": 120 }
{ "code": 150 }
],
"import/extensions": [
"error",
Expand All @@ -40,7 +40,10 @@
"linebreak-style": "off",
"comma-dangle": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": [ "error" ]
"@typescript-eslint/no-shadow": [ "error" ],
"no-param-reassign": "off",
"no-use-before-define": "off",
"import/prefer-default-export": "off"
},
"settings": {
"import/resolver": {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cartographer",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "app.js",
"scripts": {
Expand Down
89 changes: 0 additions & 89 deletions src/enums/palette.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference path="environment.d.ts" />

export const pluginVersion = "1.0";
export const pluginVersion = "1.1";
export const pluginName = "Cartographer";
export const pluginAuthors = ["fidwell"];
export const buildConfiguration: BuildConfiguration = __BUILD_CONFIGURATION__;
Expand Down
4 changes: 4 additions & 0 deletions src/models/options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default class Options {
showRides: boolean;

showFootpath: boolean;

showScenery: boolean;

showWater: boolean;

showSurface: boolean;
}
33 changes: 19 additions & 14 deletions src/ui/mapWindow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ColourDecider from "../utilities/colourdecider"
import ColourDecider from "../utilities/colourdecider";
import * as Environment from "../environment";
import Options from "../models/options";

Expand All @@ -11,16 +11,21 @@ export default class MapWindow {

// Window-building constants
private margin: number = 10;

private toolbarHeight: number = 10;

private buttonSize: number = 26;

// Map information
private mapColours: number[][] = [];

private mapSize: number;

// Display parameters
private rotation: number = 0;

private tileSize: number = 4;

private options: Options = {
showRides: true,
showFootpath: true,
Expand All @@ -46,7 +51,7 @@ export default class MapWindow {
image: 29357 + 9, // SPR_G2_ZOOM_OUT
onClick: (): void => {
if (this.tileSize > 1) {
this.tileSize = this.tileSize / 2;
this.tileSize /= 2;
this.changeSize();
}
}
Expand All @@ -64,7 +69,7 @@ export default class MapWindow {
image: 29357 + 7, // SPR_G2_ZOOM_IN
onClick: (): void => {
if (this.tileSize < 16) {
this.tileSize = this.tileSize * 2;
this.tileSize *= 2;
this.changeSize();
}
}
Expand Down Expand Up @@ -99,7 +104,7 @@ export default class MapWindow {
onClick: (): void => {
this.options.showSurface = !this.options.showSurface;
this.loadData();
(window.widgets.filter(w => w.name == "showSurface")[0] as ButtonWidget).isPressed = this.options.showSurface;
(window.widgets.filter((w) => w.name === "showSurface")[0] as ButtonWidget).isPressed = this.options.showSurface;
}
};

Expand All @@ -117,7 +122,7 @@ export default class MapWindow {
onClick: (): void => {
this.options.showWater = !this.options.showWater;
this.loadData();
(window.widgets.filter(w => w.name == "showWater")[0] as ButtonWidget).isPressed = this.options.showWater;
(window.widgets.filter((w) => w.name === "showWater")[0] as ButtonWidget).isPressed = this.options.showWater;
}
};

Expand All @@ -131,11 +136,11 @@ export default class MapWindow {
border: true,
tooltip: "Toggle scenery visible",
isPressed: this.options.showScenery,
image: 5171, // SPR_SCENERY
image: 5171, // SPR_SCENERY
onClick: (): void => {
this.options.showScenery = !this.options.showScenery;
this.loadData();
(window.widgets.filter(w => w.name == "showScenery")[0] as ButtonWidget).isPressed = this.options.showScenery;
(window.widgets.filter((w) => w.name === "showScenery")[0] as ButtonWidget).isPressed = this.options.showScenery;
}
};

Expand All @@ -153,7 +158,7 @@ export default class MapWindow {
onClick: (): void => {
this.options.showFootpath = !this.options.showFootpath;
this.loadData();
(window.widgets.filter(w => w.name == "showFootpath")[0] as ButtonWidget).isPressed = this.options.showFootpath;
(window.widgets.filter((w) => w.name === "showFootpath")[0] as ButtonWidget).isPressed = this.options.showFootpath;
}
};

Expand All @@ -171,7 +176,7 @@ export default class MapWindow {
onClick: (): void => {
this.options.showRides = !this.options.showRides;
this.loadData();
(window.widgets.filter(w => w.name == "showRides")[0] as ButtonWidget).isPressed = this.options.showRides;
(window.widgets.filter((w) => w.name === "showRides")[0] as ButtonWidget).isPressed = this.options.showRides;
}
};

Expand All @@ -186,8 +191,8 @@ export default class MapWindow {
g.fill = 1; // Yes fill
g.stroke = 0; // No stroke

for (let x = 0; x < this.mapSize; x++) {
for (let y = 0; y < this.mapSize; y++) {
for (let x = 0; x < this.mapSize; x += 1) {
for (let y = 0; y < this.mapSize; y += 1) {
let colour: number;
switch (this.rotation) {
case 1: colour = this.mapColours[-y + this.mapSize - 1][x]; break;
Expand Down Expand Up @@ -255,12 +260,12 @@ export default class MapWindow {

loadData(): void {
this.mapColours = [];
for (let x = 0; x < this.mapSize; x++) {
for (let x = 0; x < this.mapSize; x += 1) {
this.mapColours[x] = [];
}

for (let x = 0; x < this.mapSize; x++) {
for (let y = 0; y < this.mapSize; y++) {
for (let x = 0; x < this.mapSize; x += 1) {
for (let y = 0; y < this.mapSize; y += 1) {
this.mapColours[x][y] = ColourDecider.getColourAtTile(x, y, this.options);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/utilities/colourdecider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export default class ColourDecider {
static getColourAtTile(x: number, y: number, options: Options): number {
const tile = map.getTile(x + 1, y + 1); // Off-by-one index

const validElements = tile.elements.filter(e => this.isValidElement(e, options));
const validElements = tile.elements.filter((e) => this.isValidElement(e, options));

if (validElements.length === 0) {
return ColourUtilities.colourToPalette(Colour.Black);
}

const topElement = validElements.reduce((prev, current) => prev.baseHeight > current.baseHeight ? prev : current);
const topElement = validElements.reduce((prev, current) => (prev.baseHeight > current.baseHeight ? prev : current));

if (!topElement) {
return ColourUtilities.colourToPalette(Colour.Black);
Expand Down Expand Up @@ -42,12 +42,12 @@ export default class ColourDecider {

const tE = e as TrackElement;
const ride = map.getRide(tE.ride);
return ride.type <= 97 && [82, 83, 84, 85, 89].indexOf(ride.type) == -1;
return ride.type <= 97 && [82, 83, 84, 85, 89].indexOf(ride.type) === -1;
}

return (options.showFootpath && e.type === "footpath") ||
(options.showScenery && (e.type === "small_scenery" || e.type === "large_scenery")) ||
e.type === "surface";
return (options.showFootpath && e.type === "footpath")
|| (options.showScenery && (e.type === "small_scenery" || e.type === "large_scenery"))
|| e.type === "surface";
}

static getColourFromTrack(element: TrackElement): number {
Expand Down
5 changes: 2 additions & 3 deletions src/utilities/colourutilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Colour } from "../enums/colour";
import { Palette } from "../enums/palette";
import { Terrain } from "../enums/terrain";

export default class ColourUtilities {
Expand All @@ -19,9 +18,8 @@ export default class ColourUtilities {
case Terrain.GridGreen: return 101;
case Terrain.SandDark: return 109;
case Terrain.SandLight: return 220;
default: return 209; // undefined -> pink
}

return 209; // undefined -> pink
}

static water(): number {
Expand Down Expand Up @@ -63,6 +61,7 @@ export default class ColourUtilities {
case Colour.DarkPink: return 203;
case Colour.BrightPink: return 208;
case Colour.LightPink: return 212;
default: return 9; // undefined -> black
}
}
}

0 comments on commit 5c446c2

Please sign in to comment.