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
58 changes: 55 additions & 3 deletions NC Reactor Planner/Fuel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace NC_Reactor_Planner
{
public class Fuel
{
public class Fuel : IComparable<Fuel>
{
public string Name { get ; private set; }
public double BaseHeat { get => Configuration.Fuels[Name].BaseHeat; }
public double FuelTime { get => Configuration.Fuels[Name].FuelTime; }
Expand All @@ -26,5 +27,56 @@ public override string ToString()
{
return string.Format("{0}{1}{2}{3}", (Name + (SelfPriming ? "*" : "")).PadRight(14), BaseEfficiency.ToString().PadRight(6), BaseHeat.ToString().PadRight(5), CriticalityFactor.ToString().PadRight(4));
}
}

private string getModifier()
{
Match match = Regex.Match(Name, @"\[([a-zA-Z]+)\]");
if (match.Success)
return match.Groups[0].Value;
else
return "";
}

private int getIsotope()
{
Match match = Regex.Match(Name, @"-([0-9]+)");
if (match.Success)
return Int32.Parse(match.Groups[0].Value);
else
return -1;
}

private string getElement()
{
Match match = Regex.Match(Name, @"([a-zA-Z]+)(?!\])\b");
if (match.Success)
return match.Groups[0].Value;
else
return "";
}

public int CompareTo(Fuel right)
{
if (right == null)
return 1;

int leftIsotope = getIsotope();
int rightIsotope = right.getIsotope();
int compareIsotope = leftIsotope.CompareTo(rightIsotope);
if (compareIsotope != 0)
return compareIsotope;

string leftElement = getElement();
string rightElement = right.getElement();
int compareElement = leftElement.CompareTo(rightElement);
if (compareIsotope != 0)
return compareIsotope;

string leftModifier = getModifier();
string rightModifier = right.getModifier();
int compareModifier = leftModifier.CompareTo(rightModifier);

return compareModifier;
}
}
}
6 changes: 5 additions & 1 deletion NC Reactor Planner/PlannerUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ private void Form1_Load(object sender, EventArgs e)
#if !DEBUG
SetUpdateAvailableTextAsync();
#endif
fuelSelector.Items.AddRange(Palette.FuelPalette.Values.ToArray());
fuelSelector.Sorted = false;
List<Fuel> fuels = new List<Fuel>();
fuels.AddRange(Palette.FuelPalette.Values.ToArray());
fuels.Sort();
fuelSelector.Items.AddRange(fuels.ToArray());
coolantRecipeSelector.Items.AddRange(Configuration.CoolantRecipes.Keys.ToArray());
UpdateStatsUIPosition();

Expand Down