Update CommunityMapLocation
- Fetch trains whose locomotives are turned in addition to what the player may be standing on. - Add reporting of derailed state and speed.
This commit is contained in:
1 parent
7ebf2556ba
commit
2f27c35f57
5 files changed
+55
-9
No files matched your search
@@ -11,6 +11,7 @@ namespace CommunityMapLocation.Api.Location
|
|||||||
Name = trainCar.name;
|
Name = trainCar.name;
|
||||||
Id = trainCar.ID;
|
Id = trainCar.ID;
|
||||||
CarGuid = trainCar.CarGUID;
|
CarGuid = trainCar.CarGUID;
|
||||||
|
Derailed = trainCar.derailed;
|
||||||
|
|
||||||
// Probable not needed. Commented to remove additional dll dependency
|
// Probable not needed. Commented to remove additional dll dependency
|
||||||
//HandbrakePosition = trainCar.brakeSystem.handbrakePosition;
|
//HandbrakePosition = trainCar.brakeSystem.handbrakePosition;
|
||||||
@@ -25,6 +26,11 @@ namespace CommunityMapLocation.Api.Location
|
|||||||
Z = transform.z;
|
Z = transform.z;
|
||||||
|
|
||||||
Rotation = trainCar.transform.rotation.eulerAngles.y * (Mathf.PI / 180);
|
Rotation = trainCar.transform.rotation.eulerAngles.y * (Mathf.PI / 180);
|
||||||
|
|
||||||
|
Speed = trainCar.rb.velocity.magnitude;
|
||||||
|
|
||||||
|
IsActive = false;
|
||||||
|
IsPlayer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Id { get; }
|
public string Id { get; }
|
||||||
@@ -38,5 +44,9 @@ namespace CommunityMapLocation.Api.Location
|
|||||||
public float Z { get; }
|
public float Z { get; }
|
||||||
public float Length { get; }
|
public float Length { get; }
|
||||||
public float Rotation { get; }
|
public float Rotation { get; }
|
||||||
|
public float Speed { get; }
|
||||||
|
public bool Derailed { get; }
|
||||||
|
public bool IsActive { get; set; }
|
||||||
|
public bool IsPlayer { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
using DV.HUD;
|
using DV.Customization;
|
||||||
|
using DV.HUD;
|
||||||
|
using DV.Simulation.Cars;
|
||||||
|
using DV.Utils;
|
||||||
|
using LocoSim.Implementations;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -20,7 +25,7 @@ namespace CommunityMapLocation.Api.Location
|
|||||||
var reverse = false;
|
var reverse = false;
|
||||||
|
|
||||||
// If the player is in a loco, we want to get the heading of the loco instead of the play
|
// If the player is in a loco, we want to get the heading of the loco instead of the play
|
||||||
if (PlayerManager.Car?.IsLoco == true)
|
if (PlayerManager.Car != null && PlayerManager.Car.IsLoco)
|
||||||
{
|
{
|
||||||
rotationTransform = PlayerManager.Car.transform;
|
rotationTransform = PlayerManager.Car.transform;
|
||||||
|
|
||||||
@@ -36,16 +41,37 @@ namespace CommunityMapLocation.Api.Location
|
|||||||
rotationTransform = PlayerManager.PlayerCamera.transform;
|
rotationTransform = PlayerManager.PlayerCamera.transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cars = Array.Empty<CarLocationResponse>();
|
var relevantCars = new Dictionary<TrainCar, CarLocationResponse>();
|
||||||
if (PlayerManager.Car != null)
|
foreach(var carEntry in TrainCarRegistry.Instance.logicCarToTrainCar) {
|
||||||
{
|
if(IsLocoActive(carEntry.Value)) {
|
||||||
cars = PlayerManager.Car.trainset.cars.Select(c => new CarLocationResponse(c)).ToArray();
|
foreach(var trainsetCar in carEntry.Value.trainset.cars) {
|
||||||
|
if(!relevantCars.ContainsKey(trainsetCar))
|
||||||
|
relevantCars.Add(trainsetCar, new CarLocationResponse(trainsetCar));
|
||||||
|
relevantCars[trainsetCar].IsActive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(PlayerManager.Car != null) {
|
||||||
|
foreach(var car in PlayerManager.Car.trainset.cars) {
|
||||||
|
if(!relevantCars.ContainsKey(car))
|
||||||
|
relevantCars.Add(car, new CarLocationResponse(car));
|
||||||
|
relevantCars[car].IsPlayer = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LocationResponse(PlayerManager.PlayerTransform, reverse)
|
return new LocationResponse(PlayerManager.PlayerTransform, reverse)
|
||||||
{
|
{
|
||||||
Cars = cars
|
Cars = relevantCars.Values.ToArray() ?? Array.Empty<CarLocationResponse>()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsLocoActive(TrainCar loco) {
|
||||||
|
if(!loco.IsLoco) return false;
|
||||||
|
if(string.IsNullOrWhiteSpace(loco.Customization?.electronicsFuseID)) return false;
|
||||||
|
if(loco.SimController == null || loco.SimController.simFlow == null | loco.Customization == null) return false;
|
||||||
|
if(loco.SimController.simFlow.TryGetFuse(loco.Customization.electronicsFuseID, out Fuse fuse) == true)
|
||||||
|
return fuse.State;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -54,6 +54,10 @@
|
|||||||
<HintPath>lib\DV.RailTrack.dll</HintPath>
|
<HintPath>lib\DV.RailTrack.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="DV.Simulation">
|
||||||
|
<HintPath>lib\DV.Simulation.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="DV.UserManagement">
|
<Reference Include="DV.UserManagement">
|
||||||
<HintPath>lib\DV.UserManagement.dll</HintPath>
|
<HintPath>lib\DV.UserManagement.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
@@ -86,6 +90,10 @@
|
|||||||
<HintPath>lib\UnityEngine.InputLegacyModule.dll</HintPath>
|
<HintPath>lib\UnityEngine.InputLegacyModule.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.PhysicsModule">
|
||||||
|
<HintPath>lib\UnityEngine.PhysicsModule.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="UnityEngine.UI">
|
<Reference Include="UnityEngine.UI">
|
||||||
<HintPath>lib\UnityEngine.UI.dll</HintPath>
|
<HintPath>lib\UnityEngine.UI.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"Id":"CommunityMapLocation",
|
"Id":"CommunityMapLocation",
|
||||||
"DisplayName":"Derail Valley Community Map Location",
|
"DisplayName":"Derail Valley Community Map Location",
|
||||||
"Author":"BenjaminGreene",
|
"Author":"BenjaminGreene",
|
||||||
"Version":"0.0.1",
|
"Version":"0.0.2",
|
||||||
"ManagerVersion":"0.31.1.0",
|
"ManagerVersion":"0.31.1.0",
|
||||||
"EntryMethod":"CommunityMapLocation.Main.Load"
|
"EntryMethod":"CommunityMapLocation.Main.Load"
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,11 @@ Assuming Visual Studio Community:
|
|||||||
|
|
||||||
1. Add the following to the `lib` folder from `[steam common dir]/Derail Valley/DerailValley_Data/Managed`:
|
1. Add the following to the `lib` folder from `[steam common dir]/Derail Valley/DerailValley_Data/Managed`:
|
||||||
- `Assembly-CSharp.dll`
|
- `Assembly-CSharp.dll`
|
||||||
|
- `DV.Utils.dll`
|
||||||
- `DV.OriginShiftInfo.dll`
|
- `DV.OriginShiftInfo.dll`
|
||||||
- `UnityEngine.dll`
|
- `UnityEngine.dll`
|
||||||
- `UnityEngine.IMGUIModule.dll`
|
- `UnityEngine.IMGUIModule.dll`
|
||||||
|
- `UnityEngine.PhysicsModule.dll`
|
||||||
- `UnityEngine.CoreModule.dll`
|
- `UnityEngine.CoreModule.dll`
|
||||||
- `/UnityModManager/0Harmony.dll`
|
- `/UnityModManager/0Harmony.dll`
|
||||||
- `/UnityModManager/UnityModManager.dll`
|
- `/UnityModManager/UnityModManager.dll`
|
||||||
|
|||||||
Reference in new issue
Block a user