Skip to content

Commit

Permalink
Version 0.3.0
Browse files Browse the repository at this point in the history
0.3.0 updates
  • Loading branch information
eAlasdair authored Jul 24, 2022
2 parents 849aec5 + 417fa6f commit 8fac6b1
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 69 deletions.
39 changes: 27 additions & 12 deletions BaseReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace DVPathTracer
{
public static class BaseReporter
{
public static string fileName = "DVTracedPath.csv";
private const string basePath = "./Mods/DVPathTracer/";
public const string defaultFilename = "DVTracedPath.csv";
public static string fileName = defaultFilename;
private const string basePath = "./Mods/DVPathTracer/sessions/";

public const float seaLevel = 110;

Expand Down Expand Up @@ -60,15 +61,23 @@ public static void Deactivate()
}

/**
* Creates an empty .csv file of the set name, overwriting any existing file
* The file will be .csv regardless of whether or not ".csv" is included in the set name
* Creates an empty .csv file named as the current date & time, unless told to use the default
*/
private static void PrepareFile()
{
fileName = Main.settings.fileName;
if (!fileName.EndsWith(".csv"))
if (!Directory.Exists(basePath))
{
fileName += ".csv";
Directory.CreateDirectory(basePath);
Main.Log($"Session folder created");
}
if (Main.settings.useSystemTime)
{
var currentTime = DateTime.Now;
fileName = $"{currentTime:yyyyMMdd_HHmm}.csv"; // System time to nearest minute
}
else
{
fileName = defaultFilename;
}
File.WriteAllText(basePath + fileName, $"Time,{PlayerReporter.Headings},{StockReporter.Headings},{StockReporter.Headings}\n");
Main.Log($"File {fileName} readied");
Expand All @@ -95,7 +104,9 @@ public static string GetReport(float time)
string report = $"{time},{player.Values},";
List<int> toRemove = new List<int>();

foreach (int index in StockFinder.TrackedStock.Keys)
int index = 0;
int remainingStock = StockFinder.numStock;
while (index < StockFinder.TrackedStock.Keys.Count && remainingStock > 0)
{
if (StockFinder.TrackedStock[index] == null) // No car to report on
{
Expand All @@ -106,15 +117,18 @@ public static string GetReport(float time)
Main.Log($"Removing deleted car {StockFinder.TrackedStock[index].ID}");
report += $"{StockReporter.Headings},";
toRemove.Add(index);
remainingStock--;
}
else
{
report += $"{StockFinder.TrackedStock[index].Values},";
remainingStock--;
}
index++;
}
foreach (int index in toRemove)
foreach (int i in toRemove)
{
StockFinder.Remove(index);
StockFinder.Remove(i);
}
return report;
}
Expand All @@ -135,10 +149,11 @@ public static void TimedReport()
{
report = GetReport(upTime);
}
catch // No Report Available, skip
// Should only ever happen while the game is loading
catch //(Exception e) // No Report Available, skip
// Should only ever happen while the game is loading
{
Main.Log($"No report at {upTime} available");
//Main.Log(e.ToString());
nextReportTime += Main.settings.logRate;
return;
}
Expand Down
16 changes: 16 additions & 0 deletions CCLInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using DVCustomCarLoader;

namespace DVPathTracer
{
// Separate file only used if CCL is installed to avoid System.IO.FileNotFoundException
internal static class CCLInterface
{
/**
* Return the human-friendly name of a CCL car
*/
internal static string CustomCarIndentifier(TrainCarType car)
{
return CarTypeInjector.CustomCarByType(car).identifier;
}
}
}
30 changes: 1 addition & 29 deletions Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,6 @@ public static void Register()
Terminal.Log(BaseReporter.player.Rotation.ToString());
});

Register("whatFile", _ => {
Terminal.Log($"Tracer is set to use file: {Main.settings.fileName}");
});

Register("setFileTo", args => {
if (!BaseReporter.isActive)
{
if (args.Length > 0)
{
string newFile = args[0].String;
if (!newFile.EndsWith(".csv"))
{
newFile += ".csv";
}
Main.settings.fileName = newFile;
Terminal.Log($"Tracer set to use file: {newFile}");
}
else
{
Terminal.Log($"ERROR: Provide a file to use!");
}
}
else
{
Terminal.Log($"ERROR: Cannot change file while the tracer is active!");
}
});

Register("whatReportInterval", _ => {
Terminal.Log($"Tracer is set to report every {Main.settings.logRate} seconds");
});
Expand Down Expand Up @@ -138,7 +110,7 @@ public static void Register()

Register("disablePreventActivationOnStartup", _ => {
Main.settings.forceStartInactive = false;
Terminal.Log("Tracer will remember if it was active when you end the game and will, if active on startup, overwrite any existing file.");
Terminal.Log("Tracer will remember whether or not it was active when you ended the game");
});

Register("enablePreventActivationOnStartup", _ => {
Expand Down
8 changes: 7 additions & 1 deletion DVPathTracer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DVPathTracer</RootNamespace>
<AssemblyName>DVPathTracer</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -40,6 +41,9 @@
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>D:\Games\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="DVCustomCarLoader">
<HintPath>..\..\..\CCL\DVCustomCarLoader.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -63,6 +67,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BaseReporter.cs" />
<Compile Include="CCLInterface.cs" />
<Compile Include="PlayerReporter.cs" />
<Compile Include="StockFinder.cs" />
<Compile Include="StockReporter.cs" />
Expand All @@ -74,6 +79,7 @@
<ItemGroup>
<None Include="info.json" />
<None Include="README.md" />
<None Include="repository.json" />
</ItemGroup>
<ItemGroup>
<Folder Include="readmeAssets\" />
Expand Down
24 changes: 20 additions & 4 deletions LICENSE_THIRD_PARTY
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ Licensed under MIT.
==============================================================================

==============================================================================
Plotly.js
noUiSlider
------------------------------------------------------------------------------
https://plotly.com/javascript/
Copyright (c) 2021 Plotly, Inc.
https://refreshless.com/nouislider/
Copyright (c) 2019 Léon Gersen.
Licensed under MIT.
==============================================================================

Expand All @@ -54,5 +54,21 @@ pathAnimator/worldMap.png
------------------------------------------------------------------------------
This is an edited in-game screenshot of the world map.
Copyright (c) Altfuture.
Used in this mod with permission.
Used in DV Path Tracer with permission.
==============================================================================

==============================================================================
Plotly.js
------------------------------------------------------------------------------
https://plotly.com/javascript/
Copyright (c) 2021 Plotly, Inc.
Licensed under MIT.
==============================================================================

==============================================================================
wNumb.js
------------------------------------------------------------------------------
https://refreshless.com/wnumb/
Copyright (c) 2019 Léon Gersen.
Licensed under MIT.
==============================================================================
36 changes: 35 additions & 1 deletion Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class Main
public static bool enabled;
public static Settings settings = new Settings();
public static UnityModManager.ModEntry entry;
internal static bool cclEnabled = false;

/**
* Mod entrypoint
Expand All @@ -16,7 +17,6 @@ public static class Main
public static bool Load(UnityModManager.ModEntry modEntry)
{
entry = modEntry;
Log("Hello World!");

try
{
Expand All @@ -39,6 +39,40 @@ public static bool Load(UnityModManager.ModEntry modEntry)
settings.version = modEntry.Info.Version;
}

try
{
if (UnityModManager.FindMod("Mph").Loaded)
{
modEntry.Logger.Log("MPH mod is active, recording speeds in mph");
settings.mph = true;
}
else if (settings.mph)
{
modEntry.Logger.Log("MPH mod is not active but speeds are still being recorded in mph");
}
}
catch
{
// MPH mod is not installed, UMM reports this itself
if (settings.mph)
{
modEntry.Logger.Log("Speeds are being recorded in mph");
}
}

try
{
if (UnityModManager.FindMod("DVCustomCarLoader").Loaded)
{
modEntry.Logger.Log("CCL mod is active");
cclEnabled = true;
}
}
catch
{
// CCL is not installed
}

var harmony = new Harmony(modEntry.Info.Id);
harmony.PatchAll();

Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Import the file into Google Sheets or equivalent and go ham!

- As of version 0.2.0 the tracer is always active by default.
- This can be changed in the mod settings.
- While active, the tracer will periodically write information to **DVTracedPath.csv** in the folder this mod was installed to.
*(i.e. /Derail Valley/Mods/DVPathTracer/DVTracedPath.csv)*
- If the file exists from a previous time the tracer was active then the file will be overwritten
- While active, the tracer will periodically write information to a csv file in the **sessions** folder of the folder this mod was installed to.
*(i.e. /Derail Valley/Mods/DVPathTracer/sessions/\<date\_time\>.csv)*
- By default a new file is created every session; if this is disabled in the mod settings each new session will overwrite the file **DVTracedPath.csv**.

### Path Animator

Expand All @@ -40,7 +40,7 @@ Import the file into Google Sheets or equivalent and go ham!

The tracer reports to a .csv file with the following information:

### Player information
### Player information:

The first 5 columns indicate information about you, the player:

Expand All @@ -55,15 +55,14 @@ The first 5 columns indicate information about you, the player:
The following columns indicate information about all spawned locomotives and the caboose, in sets of 7:

- `CID` The object's in-game identifier (e.g. **L-001**).
- `CType` The type of rolling stock (e.g. **DE2**).
***Note:** The tracer will report a string of numbers for modded locos.
This will be fixed in a future update.*
- `CType` The type of rolling stock (e.g. **DE2**).
- `CPosX` [m] Current x coordinate (distance from the *West* edge of the map).
- `CPosY` [m] Current height (above sea level).
- `CPosZ` [m] Current z coordinate (distance from the *South* edge of the map).
- `CRotA` [&deg;] Current rotation about the vertical axis, in degrees from North (like a compass).
- `CSpd` [Default: kph] Current reported speed.
- Imperial units can be enabled in the mod settings.
- If the [MPH](https://www.nexusmods.com/derailvalley/mods/401) mod is detected, imperial units will be enabled by default.

Order is preserved to an extent - information about each object will occupy the same column it started in until that object despawns.
After the object despawns, until a new object takes its place, the tracer will fill that space with the column headings listed above.
Expand All @@ -74,6 +73,11 @@ After the object despawns, until a new object takes its place, the tracer will f
- More included analysis tools.
- *Potentially* add tracing of active job cars.

## Contributing

I greatly appreciate enthusiasm for my project and any offers to contribute, however I am hesitant to accept them for a number of reasons.
**If you would like to contribute** please let me know in advance - in either the issue tracker here or the official Altfuture Discord (@Talkingpeanut).

## Many thanks

This mod uses code for registering custom in-game terminal commands (i.e. **Commands.cs**) created by Miles "Zeibach" Spielberg.
Expand Down
4 changes: 3 additions & 1 deletion Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace DVPathTracer
public class Settings : UnityModManager.ModSettings, IDrawable
{
public string version;
public string fileName = "DVTracedPath.csv";

[Draw("Report rate (seconds per report)", Min = 1f)]
public float logRate = 5f;
Expand All @@ -19,6 +18,9 @@ public class Settings : UnityModManager.ModSettings, IDrawable
[Draw("Prevent activation on startup")]
public bool forceStartInactive = false;

[Draw("Save each session to a new file")]
public bool useSystemTime = true;

override public void Save(UnityModManager.ModEntry entry)
{
Save(this, entry);
Expand Down
4 changes: 4 additions & 0 deletions StockFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static Dictionary<int, StockReporter> TrackedStock
}
}

public static int numStock = 0;

/**
* Inserts the given TrainCar into the earliest available space
*/
Expand All @@ -25,6 +27,7 @@ public static void Add(TrainCar car)
i++;
}
trackedStock[i] = new StockReporter(car);
numStock++;
}

/**
Expand Down Expand Up @@ -70,6 +73,7 @@ public static void Remove(TrainCar car)
public static void Remove(int carIndex)
{
trackedStock[carIndex] = null;
numStock--;
}

/**
Expand Down
Loading

0 comments on commit 8fac6b1

Please sign in to comment.