Add junction support
This commit is contained in:
1 parent
a8686a08c0
commit
d11a3a57b7
7 files changed
+24377
-18678
No files matched your search
@@ -2,7 +2,7 @@
|
||||
"Id":"CommunityMapTool",
|
||||
"DisplayName":"Derail Valley Community Map Tool",
|
||||
"Author":"PyroNicampt",
|
||||
"Version":"1.0.0",
|
||||
"Version":"1.1.0",
|
||||
"ManagerVersion":"0.31.1.0",
|
||||
"EntryMethod":"CommunityMapTool.Main.Load"
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityModManagerNet;
|
||||
using DV.LocoRestoration;
|
||||
using DV;
|
||||
|
||||
namespace CommunityMapTool {
|
||||
[EnableReloading]
|
||||
@@ -26,6 +27,8 @@ namespace CommunityMapTool {
|
||||
}
|
||||
}
|
||||
static void OnGUI(UnityModManager.ModEntry modEntry) {
|
||||
if(PlayerManager.PlayerTransform != null) GUILayout.Label($"Player Position: {PlayerManager.PlayerTransform.AbsolutePosition()}");
|
||||
GUILayout.Label($"WorldMover offset: {WorldMover.currentMove}");
|
||||
if(GUILayout.Button("Dump All Tracks")) DumpAllTracks();
|
||||
if(GUILayout.Button("Dump Demonstrator Spawnpoints")) DemonstratorDump();
|
||||
if(GUILayout.Button("Copy Position To Clipboard")) ClipboardPlayerPosition();
|
||||
@@ -38,7 +41,7 @@ namespace CommunityMapTool {
|
||||
}
|
||||
static void DumpAllTracks() {
|
||||
List<string> records = new List<string>();
|
||||
foreach(RailTrack railTrack in UnityEngine.Object.FindObjectsOfType<RailTrack>()) {
|
||||
foreach(RailTrack railTrack in WorldData.RailTracks) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
string[] baseCurveData = new[] {
|
||||
"type", "bezier",
|
||||
@@ -54,15 +57,39 @@ namespace CommunityMapTool {
|
||||
for(int i = 0; i < railTrack.curve.pointCount; i++) {
|
||||
BezierPoint point = railTrack.curve[i];
|
||||
sb.Append("\n\t\t{");
|
||||
sb.Append($"\"position\":{{\"x\":{point.position.x},\"y\":{point.position.y},\"z\":{point.position.z}}}, ");
|
||||
sb.Append($"\"h1\":{{\"x\":{point.globalHandle1.x},\"y\":{point.globalHandle1.y},\"z\":{point.globalHandle1.z}}}, ");
|
||||
sb.Append($"\"h2\":{{\"x\":{point.globalHandle2.x},\"y\":{point.globalHandle2.y},\"z\":{point.globalHandle2.z}}}, ");
|
||||
sb.Append($"\"position\":{{\"x\":{point.position.x - WorldMover.currentMove.x},\"y\":{point.position.y - WorldMover.currentMove.y},\"z\":{point.position.z - WorldMover.currentMove.z}}}, ");
|
||||
sb.Append($"\"h1\":{{\"x\":{point.globalHandle1.x - WorldMover.currentMove.x},\"y\":{point.globalHandle1.y - WorldMover.currentMove.y},\"z\":{point.globalHandle1.z - WorldMover.currentMove.z}}}, ");
|
||||
sb.Append($"\"h2\":{{\"x\":{point.globalHandle2.x - WorldMover.currentMove.x},\"y\":{point.globalHandle2.y - WorldMover.currentMove.y},\"z\":{point.globalHandle2.z - WorldMover.currentMove.z}}}, ");
|
||||
sb.Append($"\"type\":\"{point.handleStyle}\"");
|
||||
sb.Append(i + 1 < railTrack.curve.pointCount ? "}," : "}");
|
||||
}
|
||||
sb.Append("\n\t]\n}");
|
||||
records.Add(sb.ToString());
|
||||
}
|
||||
foreach(Junction junction in WorldData.Junctions) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
string[] baseJunctionData = new[] {
|
||||
"type", "\"junction\"",
|
||||
"name", $"\"{junction.junctionData.junctionIdLong}\"",
|
||||
"position", $"{{\"x\":{junction.junctionData.position.x},\"y\":{junction.junctionData.position.y},\"z\":{junction.junctionData.position.z}}}",
|
||||
"excludeFromJunctionMap", junction.junctionData.excludeFromJunctionMap ? "true" : "false",
|
||||
"isValid", junction.junctionData.isValid ? "true" : "false",
|
||||
"linkedJunctions", $"[{string.Join(", ", junction.junctionData.linkedJunctions)}]",
|
||||
"index", junction.junctionData.junctionIndex.ToString(),
|
||||
"id", junction.junctionData.junctionId.ToString()
|
||||
};
|
||||
sb.Append("\n{");
|
||||
for(int i = 0; i < baseJunctionData.Length; i++) {
|
||||
if(i % 2 == 0) sb.Append($"\n\t\"{baseJunctionData[i]}\":");
|
||||
else {
|
||||
sb.Append($"{baseJunctionData[i]}");
|
||||
if(i < baseJunctionData.Length - 1) sb.Append(",");
|
||||
}
|
||||
}
|
||||
sb.Append("\n}");
|
||||
records.Add(sb.ToString());
|
||||
}
|
||||
File.WriteAllText(trackOutputPath, "[" + string.Join(",", records.ToArray()) + "\n]");
|
||||
}
|
||||
static void DemonstratorDump() {
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
@@ -173,6 +173,12 @@
|
||||
<use href="#speedSign"></use>
|
||||
<text class="signText" style="transform:translate(-35px, 20px)">12</text>
|
||||
</g>
|
||||
<g id="junctionSign" transform="scale(20)" viewBox="0 0 20 20">
|
||||
<g transform="translate(-10 -10)">
|
||||
<rect ry="1.347" y="0.539" x="5.003" height="18.922" width="9.994" style="stroke:#ebebeb;stroke-width:0.9"></rect>
|
||||
<rect ry="0.989" transform="rotate(22.53)" y="-3.763" x="12.079" height="18.335" width="1.979" style="fill:#ebebeb"></rect>
|
||||
</g>
|
||||
</g>
|
||||
<g id="mrk_office" transform="scale(20)" viewBox="0 0 20 20">
|
||||
<circle r="10"></circle>
|
||||
<path transform="translate(-10 -10)" d="M10 3.8l5.56 6.03h-1.66v5.2h-2.51v-3.93h-2.78v3.93h-2.51v-5.2h-1.66z" fill="#fff"></path>
|
||||
|
||||
@@ -293,14 +293,15 @@ function establishDimensions(){
|
||||
let maxY = -Infinity;
|
||||
let maxAlt = -Infinity;
|
||||
for(const obj of mapData){
|
||||
for(const point of obj.points){
|
||||
minX = Math.min(minX, point.position.x, point.h1.x, point.h2.x);
|
||||
minY = Math.min(minY, point.position.z, point.h1.z, point.h2.z);
|
||||
minAlt = Math.min(minAlt, point.position.y, point.h1.y, point.h2.y);
|
||||
maxX = Math.max(maxX, point.position.x, point.h1.x, point.h2.x);
|
||||
maxY = Math.max(maxY, point.position.z, point.h1.z, point.h2.z);
|
||||
maxAlt = Math.max(maxAlt, point.position.y, point.h1.y, point.h2.y);
|
||||
}
|
||||
if(obj.type == 'bezier')
|
||||
for(const point of obj.points){
|
||||
minX = Math.min(minX, point.position.x, point.h1.x, point.h2.x);
|
||||
minY = Math.min(minY, point.position.z, point.h1.z, point.h2.z);
|
||||
minAlt = Math.min(minAlt, point.position.y, point.h1.y, point.h2.y);
|
||||
maxX = Math.max(maxX, point.position.x, point.h1.x, point.h2.x);
|
||||
maxY = Math.max(maxY, point.position.z, point.h1.z, point.h2.z);
|
||||
maxAlt = Math.max(maxAlt, point.position.y, point.h1.y, point.h2.y);
|
||||
}
|
||||
}
|
||||
let width = maxX-minX;
|
||||
let height = maxY-minY;
|
||||
@@ -331,11 +332,14 @@ function establishDimensions(){
|
||||
|
||||
// Flip the z coordinate so the map doesn't display upside-down
|
||||
for(const obj of mapData){
|
||||
for(const point of obj.points){
|
||||
point.position.z = minY+maxY-point.position.z;
|
||||
point.h1.z = minY+maxY-point.h1.z;
|
||||
point.h2.z = minY+maxY-point.h2.z;
|
||||
}
|
||||
if(obj.points)
|
||||
for(const point of obj.points){
|
||||
point.position.z = minY+maxY-point.position.z;
|
||||
point.h1.z = minY+maxY-point.h1.z;
|
||||
point.h2.z = minY+maxY-point.h2.z;
|
||||
}
|
||||
if(obj.position)
|
||||
obj.position.z = minY+maxY-obj.position.z;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,6 +351,9 @@ function fillSvg(){
|
||||
drawTracks(obj);
|
||||
createTrackSignage(obj);
|
||||
break;
|
||||
case 'junction':
|
||||
addJunction(obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
createYardSignage();
|
||||
@@ -567,6 +574,14 @@ function createYardSignage(){
|
||||
}
|
||||
}
|
||||
|
||||
function addJunction(junctionData){
|
||||
if(junctionData.name.startsWith('S-') || junctionData.excludeFromJunctionMap)
|
||||
junctionData.cullLevel = 4;
|
||||
else if(junctionData.name.startsWith('W-'))
|
||||
junctionData.cullLevel = 1;
|
||||
markers.push(junctionData);
|
||||
}
|
||||
|
||||
/** Sort the tracks and put them into the svg */
|
||||
function sortTracks(){
|
||||
tracks.sort((a,b) => {
|
||||
@@ -660,10 +675,11 @@ export function setTrackColorMode(mode){
|
||||
}
|
||||
if(modeFunction != null){
|
||||
for(let curve of mapData){
|
||||
for(let section of curve.points){
|
||||
if(!section.element) continue;
|
||||
modeFunction(section, curve);
|
||||
}
|
||||
if(curve.type == 'bezier')
|
||||
for(let section of curve.points){
|
||||
if(!section.element) continue;
|
||||
modeFunction(section, curve);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -674,16 +690,21 @@ function drawSignage(){
|
||||
const gradeSigns = document.createElementNS(svgns, 'g');
|
||||
const speedSigns = document.createElementNS(svgns, 'g');
|
||||
const yardSigns = document.createElementNS(svgns, 'g');
|
||||
const junctionSigns = document.createElementNS(svgns, 'g');
|
||||
|
||||
signage_container.setAttribute('id', 'signage_container');
|
||||
gradeSigns.setAttribute('id', 'signage_grade');
|
||||
speedSigns.setAttribute('id', 'signage_speed');
|
||||
yardSigns.setAttribute('id', 'signage_yard');
|
||||
junctionSigns.setAttribute('id', 'signage_junction');
|
||||
|
||||
map_markers.appendChild(signage_container);
|
||||
signage_container.appendChild(gradeSigns);
|
||||
signage_container.appendChild(speedSigns);
|
||||
signage_container.appendChild(yardSigns);
|
||||
signage_container.appendChild(junctionSigns);
|
||||
|
||||
junctionSigns.style.display = 'none';
|
||||
|
||||
for(const markerData of markers){
|
||||
let markerElement = document.createElementNS(svgns, 'g');
|
||||
@@ -773,6 +794,13 @@ function drawSignage(){
|
||||
|
||||
yardSigns.appendChild(markerElement);
|
||||
break;
|
||||
case 'junction':
|
||||
markerImg.setAttribute('href', `#junctionSign`);
|
||||
markerImg.setAttribute('fill', '#de2121');
|
||||
markerTooltip.innerHTML = `"${markerData.name}" - #${markerData.index}\n${markerData.excludeFromJunctionMap ? 'Inv' : 'V'}isible On Map\nLinked Junctions:\n- ${markerData.linkedJunctions.join('\n- ')}`;
|
||||
markerElement.setAttribute('transform', `translate(${markerData.position.x} ${markerData.position.z})`);
|
||||
junctionSigns.appendChild(markerElement);
|
||||
break;
|
||||
default:
|
||||
markerElement.remove();
|
||||
continue;
|
||||
|
||||
@@ -54,6 +54,14 @@ let settingEntries = [
|
||||
func: state =>{
|
||||
document.getElementById('signage_yard').style.display = state ? 'unset' : 'none';
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Junctions',
|
||||
id: 'toggle_junctions',
|
||||
state: false,
|
||||
func: state =>{
|
||||
document.getElementById('signage_junction').style.display = state ? 'unset' : 'none';
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
+24284
-18654
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user