Created
April 2, 2022 00:04
-
-
Save IntelOrca/680cbcd9d0df497396a342f155c51691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="C:\Users\Ted\Documents\GitHub\openrct2\distribution\openrct2.d.ts" /> | |
function open() { | |
var width = 300; | |
var height = 200; | |
var w = ui.openWindow({ | |
x: (ui.width - width) / 2, | |
y: (ui.height - height) / 2, | |
width: width, | |
height: height, | |
title: 'Test window', | |
classification: 'test-window', | |
widgets: [ | |
{ | |
'type': 'custom', | |
x: 50, | |
y: 50, | |
width: 300, | |
height: 200, | |
onDraw: function (g) { | |
g.colour = 0x05; | |
g.box(0, 0, 64, 32); | |
g.colour = 0x01; | |
g.box(32, 16, 64, 32); | |
g.colour = 0x01; | |
g.well(0, 70, 100, 50); | |
} | |
} | |
] | |
}); | |
} | |
function rotate(pos, direction) { | |
switch (direction & 3) { | |
default: | |
case 0: return { x: pos.x, y: pos.y, z: pos.z }; | |
case 1: return { x: pos.y, y: -pos.x, z: pos.z }; | |
case 2: return { x: -pos.x, y: -pos.y, z: pos.z }; | |
case 3: return { x: -pos.y, y: pos.x, z: pos.z }; | |
} | |
} | |
function highlightSegmentGround(type, origin) { | |
var coordList = []; | |
var segment = context.getTrackSegment(type); | |
var elements = segment.elements; | |
for (var i = 0; i < elements.length; i++) { | |
var el = elements[i]; | |
var offset = rotate(el, origin.direction); | |
coordList.push({ | |
x: origin.x + offset.x, | |
y: origin.y + offset.y | |
}); | |
} | |
ui.tileSelection.tiles = coordList; | |
} | |
var selectedElements = []; | |
function unselectElements() { | |
for (var i = 0; i < selectedElements.length; i++) { | |
var selEl = selectedElements[i]; | |
var tile = map.getTile(selEl.x, selEl.y); | |
if (tile) { | |
var el = tile.getElement(selEl.index); | |
if (el) { | |
el.isHighlighted = false; | |
} | |
} | |
} | |
selectedElements = []; | |
} | |
function highlightSegment(type, origin) { | |
var segment = context.getTrackSegment(type); | |
var elements = segment.elements; | |
for (var i = 0; i < elements.length; i++) { | |
var el = elements[i]; | |
var offset = rotate(el, origin.direction); | |
var x = origin.x + offset.x; | |
var y = origin.y + offset.y; | |
var z = origin.z + offset.z; | |
// console.log(offset.z + ":" + z + ":" + z / 8); | |
var tile = map.getTile(x / 32, y / 32); | |
if (tile) { | |
var tileElements = tile.elements; | |
for (var j = 0; j < tileElements.length; j++) { | |
var tileElement = tileElements[j]; | |
if (tileElement.type === 'track' && | |
tileElement.baseZ === z && | |
tileElement.trackType === type | |
) { | |
tileElement.isHighlighted = true; | |
selectedElements.push({ | |
x: x / 32, | |
y: y / 32, | |
index: j | |
}); | |
} | |
} | |
} | |
} | |
} | |
function main() { | |
ui.registerMenuItem('Test', function() { | |
ui.activateTool({ | |
id: 'test', | |
cursor: 'cross_hair', | |
filter: [ | |
"ride" | |
], | |
onDown: function(e) { | |
ui.tileSelection.tiles = []; | |
unselectElements(); | |
if (e.mapCoords && typeof e.tileElementIndex === 'number') { | |
var trackIterator = map.getTrackIterator(e.mapCoords, e.tileElementIndex); | |
if (trackIterator && trackIterator.segment) { | |
highlightSegment(trackIterator.segment.type, trackIterator.position); | |
for (var i = 0; i < 600; i++) { | |
if (trackIterator.previous()) { | |
highlightSegment(trackIterator.segment.type, trackIterator.position); | |
} else { | |
ui.tileSelection.tiles = [trackIterator.previousPosition]; | |
console.log(trackIterator.previousPosition.z / 8); | |
break; | |
} | |
} | |
// if (trackIterator.previous() && trackIterator.previous()) { | |
// highlightSegment(trackIterator.segment.type, trackIterator.position); | |
// } | |
} | |
} | |
// var tile = map.getTile(e.mapCoords.x / 32, e.mapCoords.y / 32); | |
// if (tile) { | |
// var el = tile.getElement(e.tileElementIndex); | |
// if (el) { | |
// el.isGhost = true; | |
// } | |
// } | |
// if (e.mapCoords) { | |
// highlightSegmentGround(17, e.mapCoords); | |
// } | |
} | |
}); | |
}); | |
} | |
registerPlugin({ | |
name: 'Test', | |
version: '1.0', | |
authors: ['Ted'], | |
type: 'local', | |
licence: 'MIT', | |
main: main | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment