Skip to content

Commit 7b688d8

Browse files
committed
Merge branch 'rectangular-maps'
2 parents 2fab3e0 + 0cff362 commit 7b688d8

4 files changed

Lines changed: 89 additions & 75 deletions

File tree

rollup.config.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,9 @@ import { promisify } from "util";
88
const options =
99
{
1010
filename: "OpenRct2-Cartographer.js",
11-
12-
/**
13-
* Determines in what build mode the plugin should be build. The default here takes
14-
* from the environment (ex. CLI arguments) with "development" as fallback.
15-
*/
1611
build: process.env.BUILD || "development"
1712
};
1813

19-
/**
20-
* Tip: if you change the path here to your personal user folder,
21-
* you can ignore this change in git with:
22-
* ```
23-
* > git update-index --skip-worktree rollup.config.js
24-
* ```
25-
* To accept changes on this file again, use:
26-
* ```
27-
* > git update-index --no-skip-worktree rollup.config.js
28-
* ```
29-
*/
3014
async function getOutput() {
3115
if (options.build !== "development") {
3216
return `./dist/${options.filename}`;
@@ -35,23 +19,19 @@ async function getOutput() {
3519
const platform = process.platform;
3620
const pluginPath = `OpenRCT2/plugin/${options.filename}`;
3721

38-
if (platform === "win32") // Windows
39-
{
22+
if (platform === "win32") { // Windows
4023
const { stdout } = await promisify(exec)("powershell -command \"[Environment]::GetFolderPath('MyDocuments')\"");
4124
return `${stdout.trim()}/${pluginPath}`;
4225
}
43-
else if (platform === "darwin") // MacOS
44-
{
26+
else if (platform === "darwin") { // MacOS
4527
return `${homedir()}/Library/Application Support/${pluginPath}`;
4628
}
47-
else // Linux
48-
{
29+
else { // Linux
4930
const configFolder = process.env.XDG_CONFIG_HOME || `${homedir()}/.config`;
5031
return `${configFolder}/${pluginPath}`;
5132
}
5233
}
5334

54-
5535
/**
5636
* @type {import("rollup").RollupOptions}
5737
*/

src/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const pluginVersion = "2.0.0";
1+
export const pluginVersion = "3.0.0";
22
export const pluginName = "Cartographer";
33
export const pluginAuthors = ["fidwell"];
44
export const isUiAvailable = (typeof ui !== "undefined");

src/ui/mapWindow.ts

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import ColourDecider from "../utilities/colourdecider";
21
import * as Environment from "../environment";
3-
import Graphics from "./graphics";
4-
import * as Logger from "../utilities/logger";
52
import Options from "../models/options";
3+
import ColourDecider from "../utilities/colourdecider";
4+
import * as Logger from "../utilities/logger";
65
import PeepFinder from "../utilities/peepfinder";
6+
import Graphics from "./graphics";
77

88
export default class MapWindow {
99
onUpdate?: () => void;
@@ -24,7 +24,9 @@ export default class MapWindow {
2424
// Map information
2525
private mapColours: number[][] = [];
2626

27-
private mapSize: number = 0;
27+
private mapWidth: number = 0;
28+
29+
private mapHeight: number = 0;
2830

2931
private peepFinder: PeepFinder = new PeepFinder();
3032

@@ -45,7 +47,9 @@ export default class MapWindow {
4547
};
4648

4749
private createWindow(): Window {
48-
this.mapSize = map.size.x - 2; // Size is stored as 2 bigger than it really is for some reason
50+
// Size is stored as 2 bigger than it really is to have a one-tile margin
51+
this.mapWidth = map.size.x - 2;
52+
this.mapHeight = map.size.y - 2;
4953

5054
const btnScaleDown: ButtonDesc = {
5155
type: "button",
@@ -95,7 +99,7 @@ export default class MapWindow {
9599
image: 5169, // SPR_ROTATE_ARROW
96100
onClick: (): void => {
97101
this.rotation = (this.rotation + 1) % 4;
98-
this.draw();
102+
this.changeSize();
99103
}
100104
};
101105

@@ -251,22 +255,23 @@ export default class MapWindow {
251255
}
252256
};
253257

254-
const mapWidgetSize = this.tileSize * this.mapSize;
258+
const mapWidgetWidth = this.tileSize * this.mapWidth;
259+
const mapWidgetHeight = this.tileSize * this.mapHeight;
255260

256261
const mapWidget: ButtonDesc = {
257262
x: this.margin,
258263
y: btnScaleDown.y + btnScaleDown.height + this.margin,
259264
type: "button",
260-
width: mapWidgetSize,
261-
height: mapWidgetSize,
265+
width: mapWidgetWidth,
266+
height: mapWidgetHeight,
262267
name: "mapWidget",
263268
image: this.mapImageId
264269
};
265270

266271
const window = ui.openWindow({
267272
classification: Environment.namespace,
268273
title: `${Environment.pluginName} (v${Environment.pluginVersion})`,
269-
width: this.margin * 2 + this.tileSize * this.mapSize,
274+
width: this.margin * 2 + mapWidgetWidth,
270275
height: mapWidget.y + mapWidget.height + this.margin,
271276
maxHeight: 10000,
272277
maxWidth: 10000,
@@ -322,16 +327,16 @@ export default class MapWindow {
322327
const start = new Date().getTime();
323328

324329
if (this.options.showPeeps) {
325-
this.peepFinder.loadPeepData(this.mapSize);
330+
this.peepFinder.loadPeepData(this.mapWidth, this.mapHeight);
326331
}
327332

328333
this.mapColours = [];
329-
for (let x = 0; x < this.mapSize; x += 1) {
334+
for (let x = 0; x < this.mapWidth; x += 1) {
330335
this.mapColours[x] = [];
331336
}
332337

333-
for (let x = 0; x < this.mapSize; x += 1) {
334-
for (let y = 0; y < this.mapSize; y += 1) {
338+
for (let x = 0; x < this.mapWidth; x += 1) {
339+
for (let y = 0; y < this.mapHeight; y += 1) {
335340
this.mapColours[x][y] = ColourDecider.getColourAtTile(x, y, this.options, this.peepFinder);
336341
}
337342
}
@@ -347,13 +352,15 @@ export default class MapWindow {
347352
}
348353

349354
const mapWidget = <ButtonWidget> this.window.findWidget("mapWidget");
350-
const mapWidgetSize = this.tileSize * this.mapSize;
351-
mapWidget.width = mapWidgetSize;
352-
mapWidget.height = mapWidgetSize;
355+
const isRotated = this.rotation % 2 !== 0;
356+
const mapWidgetWidth = this.tileSize * (isRotated ? this.mapHeight : this.mapWidth);
357+
const mapWidgetHeight = this.tileSize * (isRotated ? this.mapWidth : this.mapHeight);
358+
mapWidget.width = mapWidgetWidth;
359+
mapWidget.height = mapWidgetHeight;
353360

354361
const btnShowPeeps = (this.window.widgets.filter((w) => w.name === "showPeeps")[0] as ButtonWidget);
355-
this.window.minWidth = Math.max(mapWidget.x + mapWidgetSize + this.margin, btnShowPeeps.x + btnShowPeeps.width + this.margin);
356-
this.window.minHeight = mapWidget.y + mapWidgetSize + this.margin;
362+
this.window.minWidth = Math.max(mapWidget.x + mapWidgetWidth + this.margin, btnShowPeeps.x + btnShowPeeps.width + this.margin);
363+
this.window.minHeight = mapWidget.y + mapWidgetHeight + this.margin;
357364

358365
this.window.width = this.window.minWidth;
359366
this.window.height = this.window.minHeight;
@@ -365,30 +372,31 @@ export default class MapWindow {
365372
initializeImage() {
366373
this.mapImageId = Graphics.allocateImage(<RawPixelData>{
367374
type: "raw",
368-
height: this.mapSize,
369-
width: this.mapSize,
375+
height: this.mapHeight,
376+
width: this.mapWidth,
370377
data: new Uint8Array(0)
371378
}) ?? 0;
372379

373380
if (this.window !== undefined) {
374381
const mapWidget = <ButtonWidget> this.window.findWidget("mapWidget");
375-
mapWidget.width = this.mapSize * this.tileSize;
376-
mapWidget.height = this.mapSize * this.tileSize;
382+
mapWidget.width = this.mapWidth * this.tileSize;
383+
mapWidget.height = this.mapHeight * this.tileSize;
377384
mapWidget.image = this.mapImageId ?? 0;
378385
}
379386
}
380387

381388
draw() {
382-
const scaledMap = MapWindow.scaleMap(this.mapColours, this.tileSize);
383-
const rotatedMap = MapWindow.rotateMap(scaledMap, this.rotation);
389+
const rotatedMap = MapWindow.rotateMap(this.mapColours, this.rotation);
390+
const scaledMap = MapWindow.scaleMap(rotatedMap, this.tileSize);
391+
const finalMap = scaledMap;
384392

385393
const start = new Date().getTime();
386394
Logger.debug("Reducing map...");
387395

388396
const flattenedColours: number[] = [];
389-
for (let i = 0; i < rotatedMap.length; i += 1) {
390-
for (let j = 0; j < rotatedMap[i].length; j += 1) {
391-
flattenedColours.push(rotatedMap[i][j]);
397+
for (let y = 0; y < finalMap[0].length; y += 1) {
398+
for (let x = 0; x < finalMap.length; x += 1) {
399+
flattenedColours.push(finalMap[x][y]);
392400
}
393401
}
394402

@@ -398,31 +406,57 @@ export default class MapWindow {
398406

399407
Graphics.setPixelData(this.mapImageId, <RawPixelData>{
400408
type: "raw",
401-
height: this.mapSize * this.tileSize,
402-
width: this.mapSize * this.tileSize,
409+
height: finalMap[0].length,
410+
width: finalMap.length,
403411
data: new Uint8Array(flattenedColours)
404412
});
405413
}
406414

407415
static rotateMap(input: number[][], rotation: number): number[][] {
408416
const start = new Date().getTime();
409417
Logger.debug("Rotating map...");
410-
const returnValue: number[][] = [];
411-
for (let x = 0; x < input.length; x += 1) {
412-
returnValue[x] = [];
413-
}
414418

415-
for (let x = 0; x < input.length; x += 1) {
416-
for (let y = 0; y < input.length; y += 1) {
417-
let colour: number;
418-
switch (rotation) {
419-
case 1: colour = input[-y + input.length - 1][x]; break;
420-
case 2: colour = input[-x + input.length - 1][-y + input.length - 1]; break;
421-
case 3: colour = input[y][-x + input.length - 1]; break;
422-
default: colour = input[x][y]; break;
419+
var numRows = input.length;
420+
var numCols = input[0].length;
421+
var returnValue: number[][];
422+
423+
switch (rotation) {
424+
case 1:
425+
returnValue = [];
426+
for (var x = 0; x < numCols; x++) {
427+
returnValue[x] = [];
428+
for (var y = 0; y < numRows; y++) {
429+
returnValue[x][y] = input[y][numCols - x - 1];
430+
}
423431
}
424-
returnValue[x][y] = colour;
425-
}
432+
break;
433+
case 2:
434+
returnValue = [];
435+
for (var x = 0; x < numRows; x++) {
436+
returnValue[x] = [];
437+
for (var y = 0; y < numCols; y++) {
438+
returnValue[x][y] = input[numRows - x - 1][numCols - y - 1];
439+
}
440+
}
441+
break;
442+
case 3:
443+
returnValue = [];
444+
for (var x = 0; x < numCols; x++) {
445+
returnValue[x] = [];
446+
for (var y = 0; y < numRows; y++) {
447+
returnValue[x][y] = input[numRows - y - 1][x];
448+
}
449+
}
450+
break;
451+
default:
452+
returnValue = [];
453+
for (var x = 0; x < numRows; x++) {
454+
returnValue[x] = [];
455+
for (var y = 0; y < numCols; y++) {
456+
returnValue[x][y] = input[x][y];
457+
}
458+
}
459+
break;
426460
}
427461

428462
const finish = new Date().getTime();
@@ -443,7 +477,7 @@ export default class MapWindow {
443477
}
444478

445479
for (let x = 0; x < mapData.length; x += 1) {
446-
for (let y = 0; y < mapData.length; y += 1) {
480+
for (let y = 0; y < mapData[0].length; y += 1) {
447481
for (let cx = 0; cx < tileSize; cx += 1) {
448482
for (let cy = 0; cy < tileSize; cy += 1) {
449483
returnValue[x * tileSize + cx][y * tileSize + cy] = mapData[x][y];

src/utilities/peepfinder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ export default class PeepFinder {
33

44
public maxPeeps: number = 0;
55

6-
loadPeepData(mapSize: number): void {
7-
this.initializeArray(mapSize);
6+
loadPeepData(mapWidth: number, mapHeight: number): void {
7+
this.initializeArray(mapWidth, mapHeight);
88

9-
const allPeeps = map.getAllEntities("peep");
9+
const allPeeps = map.getAllEntities("guest");
1010
for (let p = 0; p < allPeeps.length; p += 1) {
1111
const x = Math.floor(allPeeps[p].x / 32) - 1;
1212
const y = Math.floor(allPeeps[p].y / 32) - 1;
@@ -19,10 +19,10 @@ export default class PeepFinder {
1919
}
2020
}
2121

22-
private initializeArray(mapSize: number): void {
23-
for (let x = 0; x < mapSize; x += 1) {
22+
private initializeArray(mapWidth: number, mapHeight: number): void {
23+
for (let x = 0; x < mapWidth; x += 1) {
2424
this.peepCount[x] = [];
25-
for (let y = 0; y < mapSize; y += 1) {
25+
for (let y = 0; y < mapHeight; y += 1) {
2626
this.peepCount[x][y] = 0;
2727
}
2828
}

0 commit comments

Comments
 (0)