Skip to content

Commit

Permalink
Improving code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
den-kozlov committed Dec 26, 2018
1 parent 71ba94c commit 33d97a2
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 127 deletions.
66 changes: 58 additions & 8 deletions Source/DisinfectionStorageMod/DisinfectionConduitDispenser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ public class DisinfectionConduitDispenser : KMonoBehaviour, ISaveLoadable
private static readonly Operational.Flag outputConduitFlag = new Operational.Flag("output_conduit", Operational.Flag.Type.Functional);
private int utilityCell = -1;
[SerializeField]
public ConduitType conduitType;
private ConduitType conduitType;
[SerializeField]
public SimHashes[] elementFilter;
private SimHashes[] elementFilter;
[SerializeField]
public bool invertElementFilter;
private bool invertElementFilter;
[SerializeField]
public bool alwaysDispense;
private bool alwaysDispense;
[MyCmpReq]
private Operational operational;
[MyCmpReq]
public Storage storage;
private Storage storage;
[SerializeField]
public double germsDensityThreshold = 10.0;
private double germsDensityThreshold = 10.0;
private HandleVector<int>.Handle partitionerEntry;
private int elementOutputOffset;

Expand All @@ -32,6 +32,34 @@ public ConduitType TypeOfConduit
{
return this.conduitType;
}
set
{
this.conduitType = value;
}
}

public SimHashes[] ElementFilter
{
get
{
return this.elementFilter;
}
set
{
this.elementFilter = value;
}
}

public bool InvertElementFilter
{
get
{
return this.invertElementFilter;
}
set
{
this.invertElementFilter = value;
}
}

public ConduitFlow.ConduitContents ConduitContents
Expand All @@ -42,6 +70,19 @@ public ConduitFlow.ConduitContents ConduitContents
}
}

public double GermsDensityThreshold
{
get
{
return germsDensityThreshold;
}
set
{
germsDensityThreshold = value;
}
}


public void SetConduitData(ConduitType type)
{
this.conduitType = type;
Expand Down Expand Up @@ -85,16 +126,21 @@ private void ConduitUpdate(float dt)
{
this.operational.SetFlag(DisinfectionConduitDispenser.outputConduitFlag, this.IsConnected);
if (!this.operational.IsOperational && !this.alwaysDispense)
{
return;
}
PrimaryElement suitableElement = this.FindSuitableElement();
if (!((UnityEngine.Object)suitableElement != (UnityEngine.Object)null))
if ((UnityEngine.Object)suitableElement == (UnityEngine.Object)null)
{
return;
}
suitableElement.KeepZeroMassObject = true;
float num1 = this.GetConduitManager().AddElement(this.utilityCell, suitableElement.ElementID, suitableElement.Mass, suitableElement.Temperature, byte.MaxValue, 0);
if ((double)num1 <= 0.0)
{
return;
}
int num2 = (int)((double)(num1 / suitableElement.Mass) * (double)suitableElement.DiseaseCount);
// suitableElement.ModifyDiseaseCount(-num2, "ConduitDispenser.ConduitUpdate");
suitableElement.Mass -= num1;
this.Trigger(-1697596308, (object)suitableElement.gameObject);
}
Expand Down Expand Up @@ -125,7 +171,9 @@ private bool IsFilteredElement(SimHashes element)
for (int index = 0; index != this.elementFilter.Length; ++index)
{
if (this.elementFilter[index] == element)
{
return true;
}
}
return false;
}
Expand All @@ -136,7 +184,9 @@ public bool IsConnected
{
GameObject gameObject = Grid.Objects[this.utilityCell, this.conduitType != ConduitType.Gas ? 16 : 12];
if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
{
return (UnityEngine.Object)gameObject.GetComponent<BuildingComplete>() != (UnityEngine.Object)null;
}
return false;
}
}
Expand Down
13 changes: 5 additions & 8 deletions Source/DisinfectionStorageMod/DisinfectionStorageMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
namespace DisinfectionStorageMod
{
[HarmonyPatch(typeof(GeneratedBuildings), "LoadGeneratedBuildings")]
internal class DisinfectionStorageMod_GeneratedBuildings_LoadGeneratedBuildings
internal static class DisinfectionStorageMod_GeneratedBuildings_LoadGeneratedBuildings
{
[HarmonyPrefix]
private static void Prefix()
{
Debug.Log("Entry DisinfectionStorageMod_GeneratedBuildings_LoadGeneratedBuildings.Prefix ");
Expand All @@ -21,18 +22,14 @@ private static void Prefix()
Strings.Add("STRINGS.BUILDINGS.PREFABS." + LiquidDisinfectionStorageConfig.ID.ToUpper() + ".DESC", "Reservoirs cannot receive manually delivered resources.");
Strings.Add("STRINGS.BUILDINGS.PREFABS." + LiquidDisinfectionStorageConfig.ID.ToUpper() + ".EFFECT", " Stores any Liquid resources piped into it. Output only liquid free from gems. Intended to be used inside a room filled with " + (string)ELEMENTS.CHLORINEGAS.NAME + ".");
ModUtil.AddBuildingToPlanScreen(new HashedString("Medical"), LiquidDisinfectionStorageConfig.ID);

//Strings.Add("STRINGS.BUILDINGS.PREFABS." + LiquidConduitPressureConfig.ID.ToUpper() + ".NAME", "Liquid Pipe Pressure Sensor");
//Strings.Add("STRINGS.BUILDINGS.PREFABS." + LiquidConduitPressureConfig.ID.ToUpper() + ".DESC", "Liquid Pipe Pressure Sensor can disable buildings when contents reach a certain mass.");
//Strings.Add("STRINGS.BUILDINGS.PREFABS." + LiquidConduitPressureConfig.ID.ToUpper() + ".EFFECT", string.Concat(new string[] { "Becomes ", UI.FormatAsLink("Active", "LOGIC"), " or on ", UI.FormatAsLink("Standby", "LOGIC"), " when the pipe contents mass enters the chosen range." }));
//ModUtil.AddBuildingToPlanScreen(new HashedString("Plumbing"), LiquidConduitPressureConfig.ID);
}
}

[HarmonyPatch(typeof(Db), "Initialize")]
internal class DisinfectionStorageMod_Db_Initialize
internal static class DisinfectionStorageMod_Db_Initialize
{
private static void Prefix(Db __instance)
[HarmonyPrefix]
private static void Prefix()
{
Debug.Log("Entry DisinfectionStorageMod_Db_Initialize.Prefix");
List<string> ls = new List<string>(Database.Techs.TECH_GROUPING["MedicalResearch"]);
Expand Down
18 changes: 12 additions & 6 deletions Source/DisinfectionStorageMod/GasDisinfectionStorageConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ namespace DisinfectionStorageMod
{
class GasDisinfectionStorageConfig : IBuildingConfig
{
public const string ID = "GasDisinfectionReservoir";
public static string ID
{
get
{
return "GasDisinfectionReservoir";
}
}
private const ConduitType CONDUIT_TYPE = ConduitType.Gas;
private const int WIDTH = 5;
private const int HEIGHT = 3;

public override BuildingDef CreateBuildingDef()
{
BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(ID, 5, 3, "gasstorage_kanim", 100, 120f, BUILDINGS.CONSTRUCTION_MASS_KG.TIER4, MATERIALS.ALL_METALS, 800f, BuildLocationRule.OnFloor, BUILDINGS.DECOR.PENALTY.TIER1, NOISE_POLLUTION.NOISY.TIER0, 0.2f);
BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(ID, WIDTH, HEIGHT, "gasstorage_kanim", 100, 120f, BUILDINGS.CONSTRUCTION_MASS_KG.TIER4, MATERIALS.ALL_METALS, 800f, BuildLocationRule.OnFloor, BUILDINGS.DECOR.PENALTY.TIER1, NOISE_POLLUTION.NOISY.TIER0, 0.2f);
buildingDef.InputConduitType = ConduitType.Gas;
buildingDef.OutputConduitType = ConduitType.Gas;
buildingDef.Floodable = false;
Expand All @@ -33,15 +39,15 @@ public override void ConfigureBuildingTemplate(GameObject go, Tag prefab_tag)
defaultStorage.capacityKg = 150f;
defaultStorage.SetDefaultStoredItemModifiers(GasReservoirConfig.ReservoirStoredItemModifiers);
ConduitConsumer conduitConsumer = go.AddOrGet<ConduitConsumer>();
conduitConsumer.conduitType = ConduitType.Gas;
conduitConsumer.conduitType = CONDUIT_TYPE;
conduitConsumer.ignoreMinMassCheck = true;
conduitConsumer.forceAlwaysSatisfied = true;
conduitConsumer.alwaysConsume = true;
conduitConsumer.capacityKG = defaultStorage.capacityKg;
DisinfectionConduitDispenser conduitDispenser = go.AddOrGet<DisinfectionConduitDispenser>();
conduitDispenser.conduitType = ConduitType.Gas;
conduitDispenser.elementFilter = (SimHashes[])null;
conduitDispenser.germsDensityThreshold = 10.0; //germs per kg of gas
conduitDispenser.TypeOfConduit = CONDUIT_TYPE;
conduitDispenser.ElementFilter = (SimHashes[])null;
conduitDispenser.GermsDensityThreshold = 10.0; //germs per kg of gas
}

public override void DoPostConfigureComplete(GameObject go)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LiquidDisinfectionStorageConfig : IBuildingConfig

public override BuildingDef CreateBuildingDef()
{
BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(ID, 2, 3, "liquidreservoir_kanim", 100, 120f, BUILDINGS.CONSTRUCTION_MASS_KG.TIER4, MATERIALS.ALL_METALS, 800f, BuildLocationRule.OnFloor, BUILDINGS.DECOR.PENALTY.TIER1, NOISE_POLLUTION.NOISY.TIER0, 0.2f);
BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(ID, WIDTH, HEIGHT, "liquidreservoir_kanim", 100, 120f, BUILDINGS.CONSTRUCTION_MASS_KG.TIER4, MATERIALS.ALL_METALS, 800f, BuildLocationRule.OnFloor, BUILDINGS.DECOR.PENALTY.TIER1, NOISE_POLLUTION.NOISY.TIER0, 0.2f);
buildingDef.InputConduitType = ConduitType.Liquid;
buildingDef.OutputConduitType = ConduitType.Liquid;
buildingDef.Floodable = false;
Expand All @@ -33,15 +33,15 @@ public override void ConfigureBuildingTemplate(GameObject go, Tag prefab_tag)
defaultStorage.capacityKg = 5000f;
defaultStorage.SetDefaultStoredItemModifiers(GasReservoirConfig.ReservoirStoredItemModifiers);
ConduitConsumer conduitConsumer = go.AddOrGet<ConduitConsumer>();
conduitConsumer.conduitType = ConduitType.Liquid;
conduitConsumer.conduitType = CONDUIT_TYPE;
conduitConsumer.ignoreMinMassCheck = true;
conduitConsumer.forceAlwaysSatisfied = true;
conduitConsumer.alwaysConsume = true;
conduitConsumer.capacityKG = defaultStorage.capacityKg;
DisinfectionConduitDispenser conduitDispenser = go.AddOrGet<DisinfectionConduitDispenser>();
conduitDispenser.conduitType = ConduitType.Liquid;
conduitDispenser.elementFilter = (SimHashes[])null;
conduitDispenser.germsDensityThreshold = 100.0d; // germs per kg of liquid
conduitDispenser.TypeOfConduit = ConduitType.Liquid;
conduitDispenser.ElementFilter = (SimHashes[])null;
conduitDispenser.GermsDensityThreshold = 100.0d; // germs per kg of liquid
}

public override void DoPostConfigureComplete(GameObject go)
Expand Down
10 changes: 7 additions & 3 deletions Source/FluidPressureSensorMod/FluidPressureSensorMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ public static class Logger {

public static void Log(string message)
{
// Logs messages only in debug builds
#if DEBUG
Debug.Log(message);
#endif
}

public static void LogFormat(string template, params object[] args)
{
// Logs messages only in debug builds
#if DEBUG
Debug.LogFormat(template, args);
#endif
Expand All @@ -25,8 +27,9 @@ public static void LogFormat(string template, params object[] args)
}

[HarmonyPatch(typeof(GeneratedBuildings), "LoadGeneratedBuildings")]
internal class AdvFluidDistrMod_GeneratedBuildings_LoadGeneratedBuildings
internal static class AdvFluidDistrMod_GeneratedBuildings_LoadGeneratedBuildings
{
[HarmonyPrefix]
private static void Prefix()
{
Strings.Add("STRINGS.BUILDINGS.CONDUITPRESSURESENSOR.MASS", "Mass");
Expand All @@ -47,9 +50,10 @@ private static void Prefix()
}

[HarmonyPatch(typeof(Db), "Initialize")]
internal class AdvFluidDistrMod_Db_Initialize
internal static class AdvFluidDistrMod_Db_Initialize
{
private static void Prefix(Db __instance)
[HarmonyPrefix]
private static void Prefix()
{
Logger.Log("Entry AdvFluidDistrMod_Db_Initialize.Prefix");
List<string> ls = new List<string>(Database.Techs.TECH_GROUPING["HVAC"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace FluidPressureSensor
{
public class GasConduitPressureConfig : ConduitSensorConfig
{
public static string ID = "GasConduitPressureSensor";
public static readonly string ID = "GasConduitPressureSensor";

protected override ConduitType ConduitType
{
Expand All @@ -21,10 +21,6 @@ static GasConduitPressureConfig()

}

public GasConduitPressureConfig()
{
}

public override BuildingDef CreateBuildingDef()
{
return base.CreateBuildingDef(GasConduitPressureConfig.ID, "gas_germs_sensor_kanim", BUILDINGS.CONSTRUCTION_MASS_KG.TIER0, MATERIALS.REFINED_METALS);
Expand Down
47 changes: 0 additions & 47 deletions Source/FluidPressureSensorMod/GasReservoirSmartConfig.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace FluidPressureSensor
{
public class LiquidConduitPressureConfig : ConduitSensorConfig
{
public static string ID = "LiquidConduitPressureSensor";
public static readonly string ID = "LiquidConduitPressureSensor";

protected override ConduitType ConduitType
{
Expand Down
19 changes: 12 additions & 7 deletions Source/TemperatureFilterMod/GasTemperatureFilterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ namespace TemperatureFilterMod
{
public class GasTemperatureFilterConfig : IBuildingConfig
{
private ConduitPortInfo secondaryPort = new ConduitPortInfo(ConduitType.Gas, new CellOffset(0, 0));
public const string ID = "GasTemperatureFilter";
private readonly ConduitPortInfo secondaryPort = new ConduitPortInfo(ConduitType.Gas, new CellOffset(0, 0));
public static string ID
{
get
{
return "GasTemperatureFilter";
}
}
private const ConduitType CONDUIT_TYPE = ConduitType.Gas;

public override BuildingDef CreateBuildingDef()
{
string id = ID;
int width = 3;
int height = 1;
string anim = "filter_gas_kanim";
Expand All @@ -23,7 +28,7 @@ public override BuildingDef CreateBuildingDef()
float melting_point = 1600f;
BuildLocationRule build_location_rule = BuildLocationRule.Anywhere;
EffectorValues tieR1 = NOISE_POLLUTION.NOISY.TIER1;
BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(id, width, height, anim, hitpoints, construction_time, tieR3, rawMetals, melting_point, build_location_rule, BUILDINGS.DECOR.PENALTY.TIER0, tieR1, 0.2f);
BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(ID, width, height, anim, hitpoints, construction_time, tieR3, rawMetals, melting_point, build_location_rule, BUILDINGS.DECOR.PENALTY.TIER0, tieR1, 0.2f);
buildingDef.RequiresPowerInput = true;
buildingDef.EnergyConsumptionWhenActive = 120f;
buildingDef.SelfHeatKilowattsWhenActive = 0.0f;
Expand Down Expand Up @@ -60,15 +65,15 @@ public override void ConfigureBuildingTemplate(GameObject go, Tag prefab_tag)
{
go.GetComponent<KPrefabID>().AddTag(RoomConstraints.ConstraintTags.IndustrialMachinery);
go.AddOrGet<Structure>();
go.AddOrGet<TemperatureFilter>().portInfo = this.secondaryPort;
go.AddOrGet<TemperatureFilter>().PortInfo = this.secondaryPort;
}

public override void DoPostConfigureComplete(GameObject go)
{
go.AddOrGetDef<PoweredActiveController.Def>().showWorkingStatus = true;
TemperatureFilter filter = go.AddOrGet<TemperatureFilter>();
filter.rangeMin = 0f;
filter.rangeMax = 9999f;
filter.RangeMin = 0f;
filter.RangeMax = 9999f;
}
}
}
Loading

0 comments on commit 33d97a2

Please sign in to comment.