Skip to content

Commit

Permalink
Infrastructure updates
Browse files Browse the repository at this point in the history
Smaller code overhead
Bumped API version
Fixed some linting
  • Loading branch information
fidwell committed Jan 17, 2024
1 parent b7652a0 commit b7a3de9
Show file tree
Hide file tree
Showing 15 changed files with 667 additions and 2,864 deletions.
3 changes: 0 additions & 3 deletions app.js

This file was deleted.

5 changes: 0 additions & 5 deletions nodemon.json

This file was deleted.

3,254 changes: 517 additions & 2,737 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 13 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"name": "cartographer",
"version": "1.4.1",
"description": "",
"main": "app.js",
"version": "2.0.0",
"type": "module",
"scripts": {
"start": "npm run watch",
"watch": "nodemon --watch ./src --ext js,ts",
"build": "npm run lint && rollup --config rollup.config.prod.js",
"build:dev": "rollup --config rollup.config.dev.js",
"start": "nodemon --watch ./src --ext js,ts --exec \"npm run build:dev\"",
"build": "rollup --config rollup.config.js --environment BUILD:production",
"build:dev": "rollup --config rollup.config.js",
"lint": "eslint ./src --ext .js --ext .ts"
},
"repository": {
Expand All @@ -21,18 +19,12 @@
},
"homepage": "https://github.com/fidwell/OpenRct2-Cartographer#readme",
"devDependencies": {
"@rollup/plugin-replace": "^3.1.0",
"@rollup/plugin-typescript": "^8.3.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.26.0",
"nodemon": "^2.0.19",
"rollup": "^2.77.0",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.4.0",
"typescript": "^4.7.4"
},
"dependencies": {}
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"nodemon": "^3.0.2",
"rollup": "^3.15.0",
"tslib": "^2.5.0",
"typescript": ">=4.3.0"
}
}
30 changes: 0 additions & 30 deletions rollup.config.dev.js

This file was deleted.

84 changes: 84 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import resolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import { exec } from "child_process";
import { homedir } from "os";
import { promisify } from "util";

const options =
{
filename: "OpenRct2-Cartographer.js",

/**
* Determines in what build mode the plugin should be build. The default here takes
* from the environment (ex. CLI arguments) with "development" as fallback.
*/
build: process.env.BUILD || "development"
};

/**
* Tip: if you change the path here to your personal user folder,
* you can ignore this change in git with:
* ```
* > git update-index --skip-worktree rollup.config.js
* ```
* To accept changes on this file again, use:
* ```
* > git update-index --no-skip-worktree rollup.config.js
* ```
*/
async function getOutput() {
if (options.build !== "development") {
return `./dist/${options.filename}`;
}

const platform = process.platform;
const pluginPath = `OpenRCT2/plugin/${options.filename}`;

if (platform === "win32") // Windows
{
const { stdout } = await promisify(exec)("powershell -command \"[Environment]::GetFolderPath('MyDocuments')\"");
return `${stdout.trim()}/${pluginPath}`;
}
else if (platform === "darwin") // MacOS
{
return `${homedir()}/Library/Application Support/${pluginPath}`;
}
else // Linux
{
const configFolder = process.env.XDG_CONFIG_HOME || `${homedir()}/.config`;
return `${configFolder}/${pluginPath}`;
}
}


/**
* @type {import("rollup").RollupOptions}
*/
const config = {
input: "./src/plugin.ts",
output: {
file: await getOutput(),
format: "iife",
compact: true
},
treeshake: "smallest",
plugins: [
resolve(),
typescript(),
terser({
compress: {
passes: 5,
toplevel: true,
unsafe: true
},
format: {
comments: false,
quote_style: 1,
wrap_iife: true,
beautify: (options.build === "development"),
}
})
]
};
export default config;
28 changes: 0 additions & 28 deletions rollup.config.prod.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/environment.d.ts

This file was deleted.

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

export const pluginVersion = "1.4.1";
export const pluginVersion = "2.0.0";
export const pluginName = "Cartographer";
export const pluginAuthors = ["fidwell"];
export const buildConfiguration: BuildConfiguration = __BUILD_CONFIGURATION__;
export const isProduction = (buildConfiguration === "production");
export const isDevelopment = (buildConfiguration === "development");
export const isUiAvailable = (typeof ui !== "undefined");
export const namespace = "cartographer";
16 changes: 8 additions & 8 deletions src/models/options.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export default class Options {
showOpenRides: boolean;
showOpenRides: boolean = false;

showTestingRides: boolean;
showTestingRides: boolean = false;

showClosedRides: boolean;
showClosedRides: boolean = false;

showFootpath: boolean;
showFootpath: boolean = false;

showScenery: boolean;
showScenery: boolean = false;

showWater: boolean;
showWater: boolean = false;

showSurface: boolean;
showSurface: boolean = false;

showPeeps: boolean;
showPeeps: boolean = false;
}
6 changes: 2 additions & 4 deletions src/registerPlugin.ts → src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/// <reference path="../lib/openrct2.d.ts" />

import * as Environment from "./environment";
import main from "./main";
import * as Environment from "./environment";

registerPlugin({
name: Environment.pluginName,
version: Environment.pluginVersion,
authors: Environment.pluginAuthors,
type: "local",
licence: "MIT",
targetApiVersion: 65,
targetApiVersion: 81,
main
});
14 changes: 8 additions & 6 deletions src/ui/mapWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class MapWindow {
// Map information
private mapColours: number[][] = [];

private mapSize: number;
private mapSize: number = 0;

private peepFinder: PeepFinder = new PeepFinder();

Expand Down Expand Up @@ -368,12 +368,14 @@ export default class MapWindow {
height: this.mapSize,
width: this.mapSize,
data: new Uint8Array(0)
});
}) ?? 0;

const mapWidget = <ButtonWidget> this.window.findWidget("mapWidget");
mapWidget.width = this.mapSize * this.tileSize;
mapWidget.height = this.mapSize * this.tileSize;
mapWidget.image = this.mapImageId;
if (this.window !== undefined) {
const mapWidget = <ButtonWidget> this.window.findWidget("mapWidget");
mapWidget.width = this.mapSize * this.tileSize;
mapWidget.height = this.mapSize * this.tileSize;
mapWidget.image = this.mapImageId ?? 0;
}
}

draw() {
Expand Down
8 changes: 6 additions & 2 deletions src/utilities/colourdecider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class ColourDecider {
return ColourUtilities.colourToPalette(Colour.DarkGreen);
}

if (element.colourScheme !== undefined) {
if (element.colourScheme !== undefined && element.colourScheme !== null) {
const scheme = ride.colourSchemes[element.colourScheme];
return ColourUtilities.colourToPalette(scheme ? scheme.main : ColourUtilities.colourToPalette(Colour.White));
}
Expand All @@ -84,7 +84,11 @@ export default class ColourDecider {
}

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

return 0;
}

static getColourFromSurface(element: SurfaceElement, options: Options): number {
Expand Down
6 changes: 1 addition & 5 deletions src/utilities/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as Environment from "../environment";

/**
* The available levels of logging.
*/
Expand All @@ -13,9 +11,7 @@ function print(level: LogLevel, color: number, message: string): void {
}

export function debug(message: string): void {
if (Environment.isDevelopment) {
print("debug", 94, message);
}
print("debug", 94, message);
}

export function warning(message: string): void {
Expand Down
27 changes: 27 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "ES2020",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "out",
"strict": true,
"target": "es5",
"lib": [
"es5"
]
},
"include": [
"./lib/**/*.ts",
"./src/**/*.ts",
],
"noEmit": true
}

0 comments on commit b7a3de9

Please sign in to comment.