Skip to content

Commit

Permalink
TMPE version 1.8.12:
Browse files Browse the repository at this point in the history
- Updated for game version 1.6.2-f1
- Bugfix: After leaving the "Manual traffic lights" mode traffic light simulation is not cleaned up correctly (thanks to @ diezelunderwood for reporting this issue)
- Bugfix: Insufficient access rights to log file causes the mod to crash
  • Loading branch information
VictorPhilipp committed Jan 2, 2017
1 parent 42b9d00 commit 35e1992
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ A work-in-progress modification for **Cities: Skylines** to add additional traff
User manual: http://www.viathinksoft.de/tmpe

# Changelog
1.8.12, 01/02/2017
- Updated for game version 1.6.2-f1
- Bugfix: After leaving the "Manual traffic lights" mode traffic light simulation is not cleaned up correctly (thanks to @ diezelunderwood for reporting this issue)
- Bugfix: Insufficient access rights to log file causes the mod to crash

1.8.11, 01/02/2017
- Bugfix: Speed limits for elevated/underground road segments are sometimes not correctly loaded (thanks to @Pirazel and @[P.A.N] Uf0 for reporting this issue)

Expand Down
32 changes: 30 additions & 2 deletions TLM/TLM/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@ private enum LogLevel {
private static string logFilename = Path.Combine(Application.dataPath, "TMPE.log");
private static Stopwatch sw = Stopwatch.StartNew();
private static bool logToConsole = false;
private static bool logFileAccessible = true;


static Log() {
File.Delete(logFilename);
try {
if (File.Exists(logFilename))
File.Delete(logFilename);
} catch (Exception) {
logFileAccessible = false;
}
}

[Conditional("DEBUG")]
public static void _Debug(string s) {
if (!logFileAccessible) {
return;
}

try {
Monitor.Enter(logLock);
if (logToConsole)
Expand All @@ -43,6 +53,10 @@ public static void _Debug(string s) {
}

public static void Info(string s) {
if (!logFileAccessible) {
return;
}

try {
#if DEBUG
if (logToConsole)
Expand All @@ -58,6 +72,10 @@ public static void Info(string s) {
}

public static void Error(string s) {
if (!logFileAccessible) {
return;
}

try {
#if DEBUG
if (logToConsole)
Expand All @@ -73,6 +91,10 @@ public static void Error(string s) {
}

public static void Warning(string s) {
if (!logFileAccessible) {
return;
}

try {
#if DEBUG
if (logToConsole)
Expand All @@ -88,6 +110,10 @@ public static void Warning(string s) {
}

private static void LogToFile(string log, LogLevel level) {
if (! logFileAccessible) {
return;
}

try {
using (StreamWriter w = File.AppendText(logFilename)) {
w.WriteLine($"[{level.ToString()}] @ {sw.ElapsedTicks} {log}");
Expand All @@ -96,7 +122,9 @@ private static void LogToFile(string log, LogLevel level) {
w.WriteLine();
}
}
} catch (Exception) { }
} catch (Exception) {
logFileAccessible = false;
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions TLM/TLM/TrafficLight/TrafficLightSimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ public void SetupManualTrafficLight() {
manualTrafficLights = true;
}

public void DestroyManualTrafficLight() {
internal void DestroyManualTrafficLight() {
if (IsTimedLight())
return;
if (!IsManualLight())
return;
manualTrafficLights = false;

TrafficPriorityManager.Instance.RemovePrioritySegments(NodeId);
}

public void SetupTimedTrafficLight(List<ushort> nodeGroup) {
Expand All @@ -56,14 +60,18 @@ public void SetupTimedTrafficLight(List<ushort> nodeGroup) {
TimedLight = new TimedTrafficLights(NodeId, nodeGroup);
}

public void DestroyTimedTrafficLight() {
internal void DestroyTimedTrafficLight() {
if (!IsTimedLight())
return;
var timedLight = TimedLight;
TimedLight = null;

if (timedLight != null) {
timedLight.Destroy();
}

TrafficPriorityManager.Instance.RemovePrioritySegments(NodeId);

/*if (!IsManualLight() && timedLight != null)
timedLight.Destroy();*/
}
Expand Down
8 changes: 4 additions & 4 deletions TLM/TLM/TrafficManagerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace TrafficManager {
public class TrafficManagerMod : IUserMod {

public static readonly string Version = "1.8.11";
public static readonly string Version = "1.8.12";

public static readonly uint GameVersion = 159638032u;
public static readonly uint GameVersion = 159768848u;
public static readonly uint GameVersionA = 1u;
public static readonly uint GameVersionB = 6u;
public static readonly uint GameVersionC = 1u;
public static readonly uint GameVersionBuild = 2u;
public static readonly uint GameVersionC = 2u;
public static readonly uint GameVersionBuild = 1u;

public string Name => "Traffic Manager: President Edition";

Expand Down
1 change: 0 additions & 1 deletion TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ public override void Cleanup() {

if (nodeSimulation == null || !nodeSimulation.IsManualLight()) return;

nodeSimulation.DestroyManualTrafficLight();
tlsMan.RemoveNodeFromSimulation(SelectedNodeId, true, false);
}
}
Expand Down
10 changes: 10 additions & 0 deletions TLM/TLM/UI/TrafficManagerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,18 @@ public static void SetToolMode(ToolMode mode) {

bool toolModeChanged = (mode != _toolMode);
var oldToolMode = _toolMode;
var oldSubTool = subTools[(int)oldToolMode];
_toolMode = mode;
activeSubTool = subTools[(int)_toolMode];

if (oldSubTool != null) {
if ((oldToolMode == ToolMode.TimedLightsSelectNode || oldToolMode == ToolMode.TimedLightsShowLights || oldToolMode == ToolMode.TimedLightsAddNode || oldToolMode == ToolMode.TimedLightsRemoveNode)) { // TODO refactor to SubToolMode
if (mode != ToolMode.TimedLightsSelectNode && mode != ToolMode.TimedLightsShowLights && mode != ToolMode.TimedLightsAddNode && mode != ToolMode.TimedLightsRemoveNode)
oldSubTool.Cleanup();
} else
oldSubTool.Cleanup();
}

if (toolModeChanged && activeSubTool != null) {
if ((oldToolMode == ToolMode.TimedLightsSelectNode || oldToolMode == ToolMode.TimedLightsShowLights || oldToolMode == ToolMode.TimedLightsAddNode || oldToolMode == ToolMode.TimedLightsRemoveNode)) { // TODO refactor to SubToolMode
if (mode != ToolMode.TimedLightsSelectNode && mode != ToolMode.TimedLightsShowLights && mode != ToolMode.TimedLightsAddNode && mode != ToolMode.TimedLightsRemoveNode)
Expand Down

0 comments on commit 35e1992

Please sign in to comment.