Skip to content

Commit

Permalink
Merge pull request #1118 from CitiesSkylinesMods/IsFlagSet-hmem
Browse files Browse the repository at this point in the history
flag extension
  • Loading branch information
kianzarrin committed Jun 8, 2021
2 parents 705667c + fb43821 commit 1d423ac
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 0 deletions.
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;
}
}

0 comments on commit 1d423ac

Please sign in to comment.