Skip to content
Open
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
9 changes: 5 additions & 4 deletions BulldozeIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Bulldozer
public class BulldozeIcon
{
// var fileBytes = File.ReadAllBytes("C:\\Users\\matts\\src\\dsp-factory-map\\Bulldozer\\Bulldozer\\bulldozer_gs.png");
private static byte[] pngBytes =
private static readonly byte[] pngBytes =
{
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x06, 0x00,
0x00, 0x00, 0xF4, 0x78, 0xD4, 0xFA, 0x00, 0x00, 0x00, 0x04, 0x73, 0x42, 0x49, 0x54, 0x08, 0x08, 0x08, 0x08, 0x7C, 0x08, 0x64, 0x88, 0x00, 0x00, 0x00, 0x09, 0x70,
Expand Down Expand Up @@ -729,8 +729,10 @@ public class BulldozeIcon

public static Texture2D GetIconTexture(string spriteName)
{
var readTex = new Texture2D(48, 48);
readTex.name = spriteName;
var readTex = new Texture2D(48, 48)
{
name = spriteName
};
var result = readTex.LoadImage(pngBytes, false);
if (result)
{
Expand Down Expand Up @@ -758,7 +760,6 @@ public static Texture2D GetIconTexture(string spriteName)
tex.Apply(true);
return tex;
}

return null;
}
}
Expand Down
26 changes: 11 additions & 15 deletions BulldozerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ private void Update()
}

var platformSystem = GameMain.localPlanet.factory.platformSystem;
if (_reformIndexInfoProvider == null)
{
_reformIndexInfoProvider = new ReformIndexInfoProvider(platformSystem);
}
_reformIndexInfoProvider ??= new ReformIndexInfoProvider(platformSystem);

_reformIndexInfoProvider.DoInitWork(GameMain.localPlanet);

Expand Down Expand Up @@ -157,7 +154,7 @@ private void Decorate()
if (_reformIndexInfoProvider.platformSystem != GameMain.localPlanet?.factory?.platformSystem)
{
_reformIndexInfoProvider.PlanetChanged(GameMain.localPlanet);
}
}
LogAndPopupMessage("not initted");
return;
}
Expand Down Expand Up @@ -272,7 +269,7 @@ private void InvokePavePlanetNoBury()
GameMain.localPlanet.factory.RenderLocalPlanetHeightmap();
}

factory.planet.landPercentDirty = true;
factory.planet.landPercentDirtyFlag = true;

if (!outOfSoilPile || PluginConfig.soilPileConsumption.Value != OperationMode.Honest)
{
Expand Down Expand Up @@ -331,18 +328,15 @@ public static void UIBuildMenu_OnCategoryButtonClick_Postfix(UIBuildMenu __insta

if (uiBuildMenu.currentCategory != 9)
{
if (instance._ui != null)
{
instance._ui.Hide();
}
instance._ui?.Hide();

return;
}

var inittedThisTime = false;
if (instance._ui == null)
{
instance.InitUi(uiBuildMenu);
instance.InitUi();
inittedThisTime = true;
}
else
Expand All @@ -365,21 +359,21 @@ public static void UIBuildMenu_OnCategoryButtonClick_Postfix(UIBuildMenu __insta
instance._ui.Show(inittedThisTime);
}

private void InitUi(UIBuildMenu uiBuildMenu)
private void InitUi()
{
GameObject environmentModificationContainer = GameObject.Find("UI Root/Overlay Canvas/In Game/Function Panel/Build Menu/child-group");
var containerRect = environmentModificationContainer.GetComponent<RectTransform>();
var foundationButton = GameObject.Find("UI Root/Overlay Canvas/In Game/Function Panel/Build Menu/child-group/button-1");
var reformAllButton = GameObject.Find("UI Root/Overlay Canvas/In Game/Function Panel/Build Menu/reform-group/button-reform-all");

_ui = containerRect.gameObject.AddComponent<UIElements>();
UIElements.logger = logger;
if (containerRect == null || foundationButton == null)
{
return;
}

_ui.AddBulldozeComponents(containerRect, uiBuildMenu, foundationButton, reformAllButton, bt =>
_ui.AddBulldozeComponents(containerRect, foundationButton, bt =>
{
StartCoroutine(InvokeAction(1, () =>
{
Expand Down Expand Up @@ -473,7 +467,7 @@ private string ConstructPopupMessage(PlanetData localPlanet)
if (PluginConfig.IsLatConstrained())
{
popupMessage += "\nAdd foundation to locations in Selected Latitudes";
}
}
else if (PluginConfig.guideLinesOnly.Value)
{
popupMessage += "\nAdd foundation needed to paint guidelines";
Expand Down Expand Up @@ -613,7 +607,9 @@ static void EnterGame()

[HarmonyPostfix]
[HarmonyPatch(typeof(GameSave), "LoadCurrentGame")]
#pragma warning disable IDE0060 // Remove unused parameter
static void LoadCurrentGame(bool __result, string saveName)
#pragma warning restore IDE0060 // Remove unused parameter
{
if (instance != null && instance._reformIndexInfoProvider != null)
instance._reformIndexInfoProvider.PlanetChanged(null);
Expand Down
4 changes: 2 additions & 2 deletions CheckboxControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CheckboxControl : MonoBehaviour, IPointerEnterHandler, IPointerExit
{
private GameObject _hoverText;
public string HoverText = "";
public event Action<PointerEventData> onClick;
public event Action<PointerEventData> OnClick;
public Text textObject;

public void Start()
Expand Down Expand Up @@ -50,7 +50,7 @@ public void OnPointerExit(PointerEventData eventData)

public void OnPointerClick(PointerEventData eventData)
{
onClick?.Invoke(eventData);
OnClick?.Invoke(eventData);
}
}
}
13 changes: 6 additions & 7 deletions GridExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public delegate void PostComputeReformAction(SnapArgs snapArgs, Vector3 center,
float lastLat = 0, float lastLon = 0);


public static void IterateReform(BuildTool_Reform reformTool, PostComputeReformAction postComputeFn, int maxExecutionMs, float startLat = -89.9f,
float startLon = -179.9f)
public static void IterateReform(BuildTool_Reform reformTool, PostComputeReformAction postComputeFn, int maxExecutionMs, float startLat = -89.9f)
{
var checkedReformIndices = new HashSet<int>();
var checkedDataPos = new HashSet<int>();
Expand Down Expand Up @@ -69,17 +68,17 @@ public static void IterateReform(BuildTool_Reform reformTool, PostComputeReformA
{
checkedDataPos.Add(reformTool.planet.data.QueryIndex(cursorPoint));
}

var flattenTerrainReform = reformTool.factory.ComputeFlattenTerrainReform(snapArgs.points, center, radius, cursorPointCount);
postComputeFn?.Invoke(snapArgs, center, radius, 10, flattenTerrainReform);
int costSandCount = 0;
int getSandcount = 0;
reformTool.factory.ComputeFlattenTerrainReform(snapArgs.points, center, radius, cursorPointCount, ref costSandCount, ref getSandcount);
postComputeFn?.Invoke(snapArgs, center, radius, 10, costSandCount);

if (stopwatch.ElapsedMilliseconds > maxExecutionMs)
{
LogAndPopupMessage($"cancel after running ${stopwatch.ElapsedMilliseconds} lat={lat} / lon={lon}");
stopwatch.Stop();
// signal that we did not finish this task
if (postComputeFn != null)
postComputeFn(snapArgs, center, radius, 10, 0, true, lat, lon);
postComputeFn?.Invoke(snapArgs, center, radius, 10, 0, true, lat, lon);
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions GuideMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void PaintEquator(PlatformSystem platformSystem)
{
// equator stripe
var coordLineOffset = GetCoordLineOffset(platformSystem.planet);
List<int> indexes = new List<int>();
List<int> indexes = new();
for (var lon = -179.9f; lon < 180; lon += 0.25f)
{
for (var latOffset = -1; latOffset < 1; latOffset++)
Expand Down Expand Up @@ -159,7 +159,7 @@ private static void PaintMeridians(PlatformSystem platformSystem)

var lonOffsetMax = 2;

HashSet<int> actualIndexes = new HashSet<int>();
HashSet<int> actualIndexes = new();
for (var lonOffset = lonOffsetMin; lonOffset < lonOffsetMax; lonOffset++)
{
var lon = coordLineOffset * lonOffset + meridianOffset * 90f;
Expand Down Expand Up @@ -208,13 +208,13 @@ private static void PaintMinorMeridians(PlatformSystem platformSystem)
if (PluginConfig.LatitudeOutOfBounds(lat))
continue;

for (var meridianOffset = -180; meridianOffset < 180; meridianOffset += interval)
for (var meridianOffset = -180; meridianOffset < 180; meridianOffset += Mathf.RoundToInt(interval))
{
var lonOffsetMin = -1;

var lonOffsetMax = 2;

HashSet<int> actualIndexes = new HashSet<int>();
HashSet<int> actualIndexes = new();
for (var lonOffset = lonOffsetMin; lonOffset < lonOffsetMax; lonOffset++)
{
var lon = coordLineOffset * lonOffset + meridianOffset;
Expand Down
14 changes: 7 additions & 7 deletions LatLon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Bulldozer
public float Lat => Precision == 1 ? _lat : _lat / (float) Precision;

public float Long => Precision == 1 ? _lng : _lng / (float) Precision;
public static LatLon Empty => new (-1000, -1000, 1);
public static LatLon Empty => new (-0, 0, 0);

private static readonly Dictionary<int, Dictionary<int, LatLon>> PoolLatToLonToInstance = new();
public readonly int Precision;
Expand Down Expand Up @@ -44,8 +44,8 @@ public static LatLon FromCoords(double lat, double lon, int precisionMultiple =
throw new InvalidDataException("Invalid precision multiple " + precisionMultiple);
}

int newLat = lat < 0 ? Mathf.CeilToInt((float)lat * precisionMultiple) : Mathf.FloorToInt((float)lat * precisionMultiple);
int newLon = lon < 0 ? Mathf.CeilToInt((float)lon * precisionMultiple) : Mathf.FloorToInt((float)lon * precisionMultiple);
int newLat = Mathf.RoundToInt((float)lat * precisionMultiple);
int newLon = Mathf.RoundToInt((float)lon * precisionMultiple);
if (!PoolLatToLonToInstance.TryGetValue(newLat, out var lonLookup))
{
lonLookup = new Dictionary<int, LatLon>();
Expand All @@ -62,12 +62,12 @@ public static LatLon FromCoords(double lat, double lon, int precisionMultiple =

public bool Equals(LatLon other)
{
return _lat == other._lat && _lng == other._lng;
return _lat == other._lat && _lng == other._lng && Precision == other.Precision;
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
if (obj is null)
{
return false;
}
Expand All @@ -90,15 +90,15 @@ public override int GetHashCode()

public bool IsEmpty()
{
return Precision == 0 || _lat == Empty._lat && _lng == Empty._lng;
return Precision == 0;
}

public override string ToString()
{
return $"{Lat},{Long}";
}

public LatLon Offset(int latOffset, int lonOffset)
public LatLon Offset(float latOffset, float lonOffset)
{
return FromCoords(Lat + latOffset, Long + lonOffset, Precision);
}
Expand Down
2 changes: 1 addition & 1 deletion Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void Warn(string message)
logger.LogWarning($"[{DateTime.Now:HH:mm:ss.fff}] {message}");
}

private static Dictionary<string, int> _logCount = new ();
private static readonly Dictionary<string, int> _logCount = new();
public static void LogNTimes(string msg, int maxTimes, params object[] args)
{
if (!_logCount.ContainsKey(msg) || maxTimes < 0)
Expand Down
31 changes: 16 additions & 15 deletions PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using BepInEx.Configuration;
using System;
using System.Collections;
using System.ComponentModel;
using BepInEx.Configuration;
using System.Globalization;

namespace Bulldozer
{
Expand Down Expand Up @@ -52,8 +53,8 @@ public static class PluginConfig
public static ConfigEntry<int> factoryTeardownRunTimePerFrame;
public static ConfigEntry<OperationMode> soilPileConsumption;
public static ConfigEntry<OperationMode> foundationConsumption;
public static ConfigEntry<int> maxLatitude;
public static ConfigEntry<int> minLatitude;
public static ConfigEntry<float> maxLatitude;
public static ConfigEntry<float> minLatitude;

// used to make UI checkbox values persistent
public static ConfigEntry<bool> addGuideLines;
Expand All @@ -64,7 +65,7 @@ public static class PluginConfig
public static ConfigEntry<bool> addGuideLinesMeridian;
public static ConfigEntry<bool> addGuideLinesTropic;
public static ConfigEntry<bool> addGuideLinesPoles;
public static ConfigEntry<int> minorMeridianInterval;
public static ConfigEntry<float> minorMeridianInterval;

public static ConfigEntry<int> guideLinesEquatorColor;
public static ConfigEntry<int> guideLinesTropicColor;
Expand Down Expand Up @@ -94,13 +95,13 @@ public static void InitConfig(ConfigFile configFile)
{
PluginConfigFile = configFile;

minLatitude = configFile.Bind("Control", "Min Latitude", -90,
minLatitude = configFile.Bind("Control", "Min Latitude", -90f,
new ConfigDescription("Minimum latitude to work on. Set equal to Max Latitude to apply to entire planet",
new AcceptableValueRange<int>(-90, 90)));
new AcceptableValueRange<float>(-90f, 90f)));

maxLatitude = configFile.Bind("Control", "Max Latitude", 90,
maxLatitude = configFile.Bind("Control", "Max Latitude", 90f,
new ConfigDescription("Max latitude to work on, set min and max to the same value to apply to entire planet",
new AcceptableValueRange<int>(-90, 90)));
new AcceptableValueRange<float>(-90f, 90f)));
minLatitude.SettingChanged += OnMinLatitudeChange;
maxLatitude.SettingChanged += OnMaxLatitudeChange;

Expand Down Expand Up @@ -141,10 +142,10 @@ public static void InitConfig(ConfigFile configFile)
"Enable/disable of the tropic guidelines individually. No effect if AddGuideLines is disabled");
addGuideLinesPoles = configFile.Bind("Decoration", "AddGuideLinesPoles", false,
"Enable/disable painting polar areas. No effect if AddGuideLines is disabled. Poles are considered first 2 tropics");
minorMeridianInterval = configFile.Bind("Decoration", "MinorMeridianInterval", 0,
minorMeridianInterval = configFile.Bind("Decoration", "MinorMeridianInterval", 0f,
new ConfigDescription(
"Paint meridians starting at 0 and incrementing by this value. E.g., a value of 10 would add a meridian line every 10 degrees 18, 36 total. 0 to disable",
new AcceptableValueRange<int>(0, 89), "meridians"));
new AcceptableValueRange<float>(0f, 120f), "meridians"));

guideLinesEquatorColor = configFile.Bind("CustomColors", "Equator Color", 7,
new ConfigDescription("Index of color in palette to paint equator. Default is green", new AcceptableValueRange<int>(0, 31), "color"));
Expand Down Expand Up @@ -196,17 +197,17 @@ public static void InitConfig(ConfigFile configFile)

private static void OnMaxLatitudeChange(object sender, EventArgs e)
{
if (sender is ConfigEntry<int> entry && minLatitude.Value > entry.Value)
if (sender is ConfigEntry<float> entry && minLatitude.Value > entry.Value)
{
minLatitude.Value = maxLatitude.Value;
}
}

private static void OnMinLatitudeChange(object sender, EventArgs e)
{
if (sender is ConfigEntry<int> entry && maxLatitude.Value < entry.Value)
if (sender is ConfigEntry<float> entry && maxLatitude.Value < entry.Value)
{
maxLatitude.Value = entry.Value;
maxLatitude.Value = minLatitude.Value;
}
}

Expand Down Expand Up @@ -300,7 +301,7 @@ public static string GetLatRangeString()
maxLatDir = "° ";
}

return $"{minlat}{latDir} - {maxlat}{maxLatDir}";
return $"{minlat.ToString("F2", CultureInfo.CurrentCulture)}{latDir} - {maxlat.ToString("F2", CultureInfo.CurrentCulture)}{maxLatDir}";
}
}
}
Loading