Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
de61fd3
implement retarders
t0stiman Nov 17, 2024
316d11b
hump yard automatic switches
t0stiman Nov 18, 2024
f88cbc9
[Track tools] add option to disable track previews
t0stiman Nov 18, 2024
f24c67d
Implemented custom switches
t0stiman Nov 19, 2024
597a285
make the visual part of the switch work with switches that have more …
t0stiman Nov 19, 2024
4e6664e
label cars with the comms radio for the hump yard
t0stiman Nov 21, 2024
8193d13
build 99 compatibility
t0stiman Nov 22, 2024
02030d9
update cargo enum #79
t0stiman Nov 22, 2024
2f15398
build 99 part 2
t0stiman Nov 22, 2024
b8cc76a
delete obsolete mapify.unitypackage
t0stiman Nov 22, 2024
9a1773e
rm commented code
t0stiman Nov 23, 2024
7f564ab
Merge branch 'build99' of github.com:t0stiman/dv-mapify into humpyard
t0stiman Nov 30, 2024
72181d2
delete unused dll meta files
t0stiman Dec 1, 2024
e3ae55c
track tools: implement custom switch
t0stiman Dec 2, 2024
4d45a07
add car spawner and deleter components, fix switch stalk position, cr…
t0stiman Dec 5, 2024
b807910
Merge branch 'master' of github.com:Insprill/dv-mapify into humpyard
t0stiman Dec 5, 2024
f390feb
Build 99.2
t0stiman Dec 7, 2024
6bbf574
Merge branch 'build99.2' of github.com:t0stiman/dv-mapify into humpyard
t0stiman Dec 7, 2024
baab152
Implemented custom switches
t0stiman Nov 19, 2024
1d49fd7
ez debug logging
t0stiman Jan 28, 2025
6c2dbc9
make the visual part of the switch work with switches that have more …
t0stiman Nov 19, 2024
4897ada
track tools: implement custom switch
t0stiman Dec 2, 2024
4af26d5
add car spawner and deleter components, fix switch stalk position, cr…
t0stiman Dec 5, 2024
c42e9f9
fix 'has no basetype' errors
t0stiman Dec 29, 2024
b07a654
cleanup
t0stiman Jan 28, 2025
fea81bb
SwitchValidator: avoid a nullreferenceexception
t0stiman Jan 28, 2025
6a3bb2a
less magic numbers
t0stiman Jan 28, 2025
46e0022
additional switch validation
t0stiman Jan 28, 2025
2db5b30
fix custom switch branches not connecting to track
t0stiman Jan 28, 2025
542009c
remove todo
t0stiman Jan 28, 2025
d5054af
Merge branch 'master' of github.com:Insprill/dv-mapify into humpyard
t0stiman Jul 11, 2025
87b55fc
merge pls
t0stiman Jul 11, 2025
a70cb93
logging
t0stiman Jul 11, 2025
848ef99
Merge branch 'master' of github.com:Insprill/dv-mapify into custom_sw…
t0stiman Jul 12, 2025
57e87d5
make it build
t0stiman Jul 12, 2025
8372cad
logging
t0stiman Jul 11, 2025
74f0465
correct stalk position
t0stiman Jul 12, 2025
944c071
working snap on CustomSwitch
t0stiman Jul 13, 2025
6aeb72f
avoid errors on validate / export
t0stiman Jul 13, 2025
9c15272
remove todo
t0stiman Jul 13, 2025
5daca6b
cleanup
t0stiman Jul 13, 2025
b80c1ae
fix switchTrigger position
t0stiman Jul 13, 2025
01903b1
Merge branch 'custom_switches' of github.com:Insprill/dv-mapify into …
t0stiman Jul 13, 2025
09464ad
yes
t0stiman Jul 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions Mapify/CarLabeler/CreateLabel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using CommsRadioAPI;
using DV;
using UnityEngine;

namespace Mapify.CarLabeler
{
public class CreateLabel: SubState
{
private TrainCar pointedCar;
private RaycastHit[] hits = new RaycastHit[5];

private static bool isSetup;
private static GameObject trainHighlighter;
private static Material selectionMaterial;
private static MeshRenderer trainHighlighterRender;

public CreateLabel(YardDestination aDestination) :
base(aDestination,
$"Point at a car and click to label it.\n" +
$"{aDestination.StationName()}-{aDestination.YardID}-{aDestination.TrackNumber}"
)
{
if(isSetup) return;
DoSetup();
}

private static void DoSetup()
{
var deleter = (CommsRadioCarDeleter)ControllerAPI.GetVanillaMode(VanillaMode.Clear);

if (deleter == null)
{
Mapify.LogError($"{nameof(CreateLabel)}: Could not get deleter");
return;
}

trainHighlighter = deleter.trainHighlighter;
selectionMaterial = deleter.selectionMaterial;
trainHighlighterRender = deleter.trainHighlighterRender;

isSetup = true;
}

public override AStateBehaviour OnAction(CommsRadioUtility utility, InputAction action)
{
switch (action)
{
case InputAction.Activate:
MarkCar(utility);
goto default; //C#, why...
default:
return new CreateLabel(destination);
}
}

private void MarkCar(CommsRadioUtility utility)
{
if (pointedCar == null){
utility.PlaySound(VanillaSoundCommsRadio.Warning);
return;
}

var labelComponent = pointedCar.gameObject.GetComponent<YardDestinationComponent>();
if (labelComponent == null)
{
labelComponent = pointedCar.gameObject.AddComponent<YardDestinationComponent>();
}

labelComponent.Setup(destination);
utility.PlaySound(VanillaSoundCommsRadio.Confirm);
}

public override AStateBehaviour OnUpdate(CommsRadioUtility utility)
{
TrainCar car = null;

// Why does the direction need to be downward? I would expect forward.
if(Physics.RaycastNonAlloc(utility.SignalOrigin.position, -utility.SignalOrigin.up, hits, maxDistance: 100f) > 0)
{
foreach (var hit in hits)
{
if (hit.transform == null) continue;

car = TrainCar.Resolve(hit.transform.root);
if (car == null) continue;

Mapify.LogDebug($"hit car {car.gameObject.name}");
Mapify.LogDebug($"layer: {car.gameObject.layer}");
break;
}
}

PointToCar(car, utility);
return this;
}

private void PointToCar(TrainCar car, CommsRadioUtility utility)
{
if (pointedCar == car) return;

pointedCar = car;
ClearHighlightCar();

if (pointedCar == null) return;

HighlightCar(pointedCar);
utility.PlaySound(VanillaSoundCommsRadio.HoverOver);
}

private static void HighlightCar(TrainCar car)
{
Mapify.LogDebug($"{nameof(HighlightCar)}: {car}");

trainHighlighterRender.material = selectionMaterial;
var transform = trainHighlighter.transform;
var bounds = car.Bounds;
var vector3_1 = bounds.size + CommsRadioCarDeleter.HIGHLIGHT_BOUNDS_EXTENSION;
transform.localScale = vector3_1;
var vector3_2 = car.transform.up * (trainHighlighter.transform.localScale.y / 2f);
var forward = car.transform.forward;
bounds = car.Bounds;
double z = bounds.center.z;
var vector3_3 = forward * (float) z;
trainHighlighter.transform.SetPositionAndRotation(car.transform.position + vector3_2 + vector3_3, car.transform.rotation);
trainHighlighter.SetActive(true);
trainHighlighter.transform.SetParent(car.transform, true);
}

private static void ClearHighlightCar()
{
Mapify.LogDebug($"{nameof(ClearHighlightCar)}");

trainHighlighter.SetActive(false);
trainHighlighter.transform.SetParent(null);
}
}
}
50 changes: 50 additions & 0 deletions Mapify/CarLabeler/SelectStation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using CommsRadioAPI;

namespace Mapify.CarLabeler
{
public class SelectStation: SubState
{
public SelectStation(YardDestination aDestination) :
base(aDestination, $"station:\n{aDestination.StationName()}"
)
{}

public override AStateBehaviour OnAction(CommsRadioUtility utility, InputAction action)
{
switch (action)
{
case InputAction.Activate:
utility.PlaySound(VanillaSoundCommsRadio.Confirm);
return new SelectYard(destination);
case InputAction.Up:
utility.PlaySound(VanillaSoundCommsRadio.Switch);
return NextOrPreviousStation(1);
case InputAction.Down:
utility.PlaySound(VanillaSoundCommsRadio.Switch);
return NextOrPreviousStation(-1);
default:
return new SelectStation(destination);
}
}

private AStateBehaviour NextOrPreviousStation(int stationIndexDelta)
{
var allStations = StationController.allStations;
var stationIndex = 0;

for (int index = 0; index < allStations.Count; index++)
{
if (allStations[index].stationInfo.YardID != destination.StationID) continue;

stationIndex = index;
break;
}

stationIndex = Utils.Misc.BetterModulo(stationIndex + stationIndexDelta, allStations.Count);

destination.StationID = allStations[stationIndex].stationInfo.YardID;

return new SelectStation(destination);
}
}
}
61 changes: 61 additions & 0 deletions Mapify/CarLabeler/SelectTrack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Linq;
using CommsRadioAPI;
using Mapify.Utils;

namespace Mapify.CarLabeler
{
public class SelectTrack: SubState
{
public SelectTrack(YardDestination aDestination) :
base(aDestination, $"track: {aDestination.TrackNumber}"
)
{}

public override AStateBehaviour OnAction(CommsRadioUtility utility, InputAction action)
{
switch (action)
{
case InputAction.Activate:
utility.PlaySound(VanillaSoundCommsRadio.Confirm);
return new CreateLabel(destination);
case InputAction.Up:
utility.PlaySound(VanillaSoundCommsRadio.Switch);
return NextOrPreviousTrack(1);
case InputAction.Down:
utility.PlaySound(VanillaSoundCommsRadio.Switch);
return NextOrPreviousTrack(-1);
default:
return new SelectTrack(destination);
}
}

private AStateBehaviour NextOrPreviousTrack(int trackIndexDelta)
{
//TODO cache this
var yardTracks = RailTrackRegistry.Instance
.GetTrackNumbersOfSubYard(destination.StationID, destination.YardID)
.ToList();

Mapify.LogDebug("yardTracks:");
foreach (var track in yardTracks)
{
Mapify.LogDebug(track);
}

var trackIndex = 0;

for (int index = 0; index < yardTracks.Count; index++)
{
if (yardTracks[index] != destination.TrackNumber) continue;

trackIndex = index;
break;
}

trackIndex = Utils.Misc.BetterModulo(trackIndex + trackIndexDelta, yardTracks.Count);
destination.TrackNumber = yardTracks[trackIndex];

return new SelectTrack(destination);
}
}
}
59 changes: 59 additions & 0 deletions Mapify/CarLabeler/SelectYard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Linq;
using CommsRadioAPI;
using Mapify.Utils;

namespace Mapify.CarLabeler
{
public class SelectYard: SubState
{
public SelectYard(YardDestination aDestination) :
base(aDestination, $"yard: {aDestination.YardID}"
)
{}

public override AStateBehaviour OnAction(CommsRadioUtility utility, InputAction action)
{
switch (action)
{
case InputAction.Activate:
utility.PlaySound(VanillaSoundCommsRadio.Confirm);
return new SelectTrack(destination);
case InputAction.Up:
utility.PlaySound(VanillaSoundCommsRadio.Switch);
return NextOrPreviousYard(1);
case InputAction.Down:
utility.PlaySound(VanillaSoundCommsRadio.Switch);
return NextOrPreviousYard(-1);
default:
return new SelectYard(destination);
}
}

private AStateBehaviour NextOrPreviousYard(int yardIndexDelta)
{
//TODO cache this
var stationYards = RailTrackRegistry.Instance.GetSubYardIDsOfYard(destination.StationID).ToList();

Mapify.LogDebug("stationYards:");
foreach (var yard in stationYards)
{
Mapify.LogDebug(yard);
}

var yardIndex = 0;

for (int index = 0; index < stationYards.Count; index++)
{
if (stationYards[index] != destination.YardID) continue;

yardIndex = index;
break;
}

yardIndex = Utils.Misc.BetterModulo(yardIndex + yardIndexDelta, stationYards.Count);
destination.YardID = stationYards[yardIndex];

return new SelectYard(destination);
}
}
}
32 changes: 32 additions & 0 deletions Mapify/CarLabeler/Start.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using CommsRadioAPI;

namespace Mapify.CarLabeler
{
public class Start: AStateBehaviour
{
public Start() : base(new CommsRadioState(
titleText: SubState.LABELER_TITLE,
contentText: "enable yard car labeler?"
))
{}

public override AStateBehaviour OnAction(CommsRadioUtility utility, InputAction action)
{
switch (action)
{
case InputAction.Activate:
utility.PlaySound(VanillaSoundCommsRadio.ModeEnter);
return new SelectStation(SetupDestination());
default:
return new Start();
}
}

private static YardDestination SetupDestination()
{
var aDestination = Mapify.Settings.lastUsedLabel;
YardDestination.Validate(ref aDestination);
return aDestination;
}
}
}
22 changes: 22 additions & 0 deletions Mapify/CarLabeler/SubState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using CommsRadioAPI;
using DV;

namespace Mapify.CarLabeler
{
public abstract class SubState: AStateBehaviour
{
public const string LABELER_TITLE = "car labeler";

protected YardDestination destination;

protected SubState(YardDestination aDestination, string contentText_) :
base(new CommsRadioState(
titleText: LABELER_TITLE,
buttonBehaviour: ButtonBehaviourType.Override,
contentText: contentText_
))
{
destination = aDestination;
}
}
}
Loading