Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flag extension #1118

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace TrafficManager.Manager.Impl {
using static TrafficManager.Util.Shortcuts;
using static CSUtil.Commons.TernaryBoolUtil;
using TrafficManager.Util;
using TrafficManager.Util.Extensions;

public class JunctionRestrictionsManager
: AbstractGeometryObservingManager,
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/Manager/Impl/ParkingRestrictionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace TrafficManager.Manager.Impl {
using TrafficManager.State.ConfigData;
using TrafficManager.Util;
using ColossalFramework;
using TrafficManager.Util.Extensions;

public class ParkingRestrictionsManager
: AbstractGeometryObservingManager,
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/Patch/_PathManager/CreatePathPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace TrafficManager.Patch._PathManager {
using TrafficManager.Custom.PathFinding;
using TrafficManager.State.ConfigData;
using TrafficManager.Util;
using TrafficManager.Util.Extensions;

[HarmonyPatch]
[UsedImplicitly]
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/Patch/_RoadBaseAI/UpdateNodePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace TrafficManager.Patch._RoadBaseAI {
using JetBrains.Annotations;
using TrafficManager.Manager.Impl;
using TrafficManager.State;
using TrafficManager.Util.Extensions;

[HarmonyPatch(typeof(RoadBaseAI), "UpdateNode")]
[UsedImplicitly]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace TrafficManager.Patch._VehicleAI._AmbulanceAI {
using TrafficManager.API.Traffic.Enums;
using TrafficManager.Manager.Impl;
using ColossalFramework;
using TrafficManager.Util.Extensions;

[HarmonyPatch]
public class StartPathFindPatch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace TrafficManager.Patch._VehicleAI._FireTruckAI {
using TrafficManager.API.Traffic.Enums;
using TrafficManager.Manager.Impl;
using ColossalFramework;
using TrafficManager.Util.Extensions;

[HarmonyPatch]
public class StartPathFindPatch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace TrafficManager.Patch._VehicleAI._PoliceCarAI {
using TrafficManager.API.Traffic.Enums;
using TrafficManager.Manager.Impl;
using ColossalFramework;
using TrafficManager.Util.Extensions;

[HarmonyPatch]
public class StartPathFindPatch {
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
<Compile Include="UI\TransportDemandViewMode.cs" />
<Compile Include="UI\UITransportDemand.cs" />
<Compile Include="Util\AutoTimedTrafficLights.cs" />
<Compile Include="Util\Extensions\FlagsExtensions.cs" />
<Compile Include="Util\InGameUtil.cs" />
<Compile Include="Util\IntVector2.cs" />
<Compile Include="Util\Spiral.cs" />
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/UI/SubTools/LaneConnectorTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace TrafficManager.UI.SubTools {
using TrafficManager.UI.MainMenu.OSD;
using static TrafficManager.Util.Shortcuts;
using TrafficManager.UI.SubTools.PrioritySigns;
using TrafficManager.Util.Extensions;

public class LaneConnectorTool
: LegacySubTool,
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/UI/SubTools/ParkingRestrictionsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace TrafficManager.UI.SubTools {
using TrafficManager.UI.SubTools.PrioritySigns;
using ColossalFramework.UI;
using TrafficManager.UI.MainMenu.OSD;
using TrafficManager.Util.Extensions;

public class ParkingRestrictionsTool
: LegacySubTool,
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/UI/SubTools/SpeedLimits/SpeedLimitsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace TrafficManager.UI.SubTools.SpeedLimits {
using TrafficManager.Util.Caching;
using UnityEngine;
using static TrafficManager.Util.Shortcuts;
using TrafficManager.Util.Extensions;

public class SpeedLimitsTool : LegacySubTool {
public const int
Expand Down
33 changes: 33 additions & 0 deletions TLM/TLM/Util/Extensions/FlagsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace TrafficManager.Util.Extensions {
internal static class FlagsExtensions {
internal static bool IsFlagSet(this NetInfo.LaneType value, NetInfo.LaneType flag) => (value & flag) != 0;

internal static bool IsFlagSet(this VehicleInfo.VehicleType value, VehicleInfo.VehicleType flag) => (value & flag) != 0;

internal static bool IsFlagSet(this Vehicle.Flags value, Vehicle.Flags flag) => (value & flag) != 0;

internal static bool IsFlagSet(this NetNode.Flags value, NetNode.Flags flag) => (value & flag) != 0;

internal static bool IsFlagSet(this NetSegment.Flags value, NetSegment.Flags flag) => (value & flag) != 0;

internal static bool IsFlagSet(this NetLane.Flags value, NetLane.Flags flag) => (value & flag) != 0;

internal static bool CheckFlags(this NetInfo.LaneType value, NetInfo.LaneType required, NetInfo.LaneType forbidden = 0) =>
(value & (required | forbidden)) == required;

internal static bool CheckFlags(this VehicleInfo.VehicleType value, VehicleInfo.VehicleType required, VehicleInfo.VehicleType forbidden = 0) =>
(value & (required | forbidden)) == required;

internal static bool CheckFlags(this Vehicle.Flags value, Vehicle.Flags required, Vehicle.Flags forbidden = 0) =>
(value & (required | forbidden)) == required;

internal static bool CheckFlags(this NetNode.Flags value, NetNode.Flags required, NetNode.Flags forbidden = 0) =>
(value & (required | forbidden)) == required;

internal static bool CheckFlags(this NetSegment.Flags value, NetSegment.Flags required, NetSegment.Flags forbidden = 0) =>
(value & (required | forbidden)) == required;

internal static bool CheckFlags(this NetLane.Flags value, NetLane.Flags required, NetLane.Flags forbidden = 0) =>
(value & (required | forbidden)) == required;
}
}