Skip to content

Commit

Permalink
Added ability to set planet, moon and belt name format #48
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwin99 committed Aug 27, 2020
1 parent 4e875f1 commit 4779c81
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 7 deletions.
3 changes: 3 additions & 0 deletions SEWorldGenPlugin/GUI/PluginWorldSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ protected override void BuildControls()
PlSettings.GeneratorSettings.PlanetSettings.Moons = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.Moons;
PlSettings.GeneratorSettings.PlanetSettings.MandatoryPlanets = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.MandatoryPlanets;
PlSettings.GeneratorSettings.PlanetSettings.GasGiants = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.GasGiants;
//PlSettings.GeneratorSettings.PlanetSettings.PlanetNameFormat = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.PlanetNameFormat;
//PlSettings.GeneratorSettings.PlanetSettings.MoonNameFormat = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.MoonNameFormat;
//PlSettings.GeneratorSettings.BeltSettings.BeltNameFormat = MySettings.Static.Settings.GeneratorSettings.BeltSettings.BeltNameFormat;
}
else
{
Expand Down
14 changes: 12 additions & 2 deletions SEWorldGenPlugin/Generator/SystemGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ private void GeneratePlanet(int index, long distance, int totalObjects, ref int
var height = MyRandom.Instance.GetRandomFloat((float)Math.PI / 180 * -5, (float)Math.PI / 180 * 5);
Vector3D pos = new Vector3D(distance * Math.Sin(angle), distance * Math.Cos(angle), distance * Math.Sin(height));

planet.DisplayName = "Planet " + (++planetIndex);
string name = SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.PlanetNameFormat
.SetProperty("ObjectNumber", ++planetIndex)
.SetProperty("ObjectNumberGreek", greek_letters[planetIndex])
.SetProperty("ObjectId", def.Id.SubtypeId.String);

planet.DisplayName = name;
planet.Type = SystemObjectType.PLANET;
planet.DefName = def.Id.SubtypeId.String;
planet.Size = size;
Expand Down Expand Up @@ -264,12 +269,17 @@ private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity,

if (dist + distance > m_settings.WorldSize && m_settings.WorldSize > 0) return moons;

string name = SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.PlanetNameFormat
.SetProperty("ObjectNumber", i)
.SetProperty("ObjectNumberGreek", greek_letters[i])
.SetProperty("ObjectId", def.Id.SubtypeId.String);

MyPlanetMoonItem item = new MyPlanetMoonItem();
item.Type = SystemObjectType.MOON;
item.DefName = def.Id.SubtypeName.ToString();
item.Distance = dist;
item.Size = SizeByGravity(def.SurfaceGravity, isGasGiant);
item.DisplayName = planetName + " " + (char)('A' + i);
item.DisplayName = name;

moons[i] = item;
}
Expand Down
97 changes: 93 additions & 4 deletions SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ public class MyObjectBuilder_PluginSettings
public MyObjectBuilder_PluginSettings()
{
Enable = false;
GeneratorSettings = new GeneratorSettings();
if(MySettings.Static != null)
if(MySettings.Static.Settings != null)
{
GeneratorSettings = MySettings.Static.Settings.GeneratorSettings.copy();
}
else
{
GeneratorSettings = new GeneratorSettings();
}
}

[ProtoMember(1)]
Expand All @@ -19,6 +27,14 @@ public MyObjectBuilder_PluginSettings()
[ProtoMember(2)]
public GeneratorSettings GeneratorSettings;

public MyObjectBuilder_PluginSettings copy()
{
MyObjectBuilder_PluginSettings s = new MyObjectBuilder_PluginSettings();
s.Enable = Enable;
s.GeneratorSettings = GeneratorSettings.copy();
return s;
}

public void Verify()
{
GeneratorSettings.Verify();
Expand Down Expand Up @@ -89,6 +105,27 @@ public GeneratorSettings()
[ProtoMember(13)]
public bool MoonsOnlyOnce;

public GeneratorSettings copy()
{
GeneratorSettings g = new GeneratorSettings();
g.MinObjectsInSystem = MinObjectsInSystem;
g.MaxObjectsInSystem = MaxObjectsInSystem;
g.MinOrbitDistance = MinOrbitDistance;
g.MaxOrbitDistance = MaxOrbitDistance;
g.AsteroidGenerator = AsteroidGenerator;
g.AsteroidDensity = AsteroidDensity;
g.PlanetSettings = PlanetSettings.copy();
g.BeltSettings = BeltSettings.copy();
g.SemiRandomizedGeneration = SemiRandomizedGeneration;
g.WorldSize = WorldSize;
g.FirstPlanetCenter = FirstPlanetCenter;
g.UseVanillaPlanets = UseVanillaPlanets;
g.PlanetsOnlyOnce = PlanetsOnlyOnce;
g.MoonsOnlyOnce = MoonsOnlyOnce;

return g;
}

public void Verify()
{
Verifier.VerifyInt(0, MaxObjectsInSystem, 5, "MinObjectsInSystem", ref MinObjectsInSystem);
Expand Down Expand Up @@ -116,6 +153,8 @@ public PlanetSettings()
ShowMoonGPS = false;
BlacklistedPlanets = new HashSet<string>();
BlacklistedPlanets.Add("MoonTutorial");
PlanetNameFormat = "Planet [ObjectNumber]";
MoonNameFormat = "Moon [ObjectNumber]";

MandatoryPlanets = new HashSet<string>();

Expand Down Expand Up @@ -143,17 +182,42 @@ public PlanetSettings()
public bool ShowMoonGPS;

[ProtoMember(7)]
public HashSet<string> BlacklistedPlanets;
public string PlanetNameFormat;

[ProtoMember(8)]
public HashSet<string> MandatoryPlanets;
public string MoonNameFormat;

[ProtoMember(9)]
public HashSet<string> Moons;
public HashSet<string> BlacklistedPlanets;

[ProtoMember(10)]
public HashSet<string> MandatoryPlanets;

[ProtoMember(11)]
public HashSet<string> Moons;

[ProtoMember(12)]
public HashSet<string> GasGiants;

public PlanetSettings copy()
{
PlanetSettings p = new PlanetSettings();
p.SizeMultiplier = SizeMultiplier;
p.PlanetSizeCap = PlanetSizeCap;
p.MoonProbability = MoonProbability;
p.RingSettings = RingSettings.copy();
p.ShowPlanetGPS = ShowPlanetGPS;
p.ShowMoonGPS = ShowMoonGPS;
p.PlanetNameFormat = PlanetNameFormat;
p.MoonNameFormat = MoonNameFormat;
p.BlacklistedPlanets = BlacklistedPlanets;
p.MandatoryPlanets = MandatoryPlanets;
p.Moons = Moons;
p.GasGiants = GasGiants;

return p;
}

public void Verify()
{
Verifier.VerifyFloat(0, float.MaxValue, 2, "PlanetSettings.SizeMultiplier", ref SizeMultiplier);
Expand Down Expand Up @@ -187,6 +251,16 @@ public PlanetRingSettings()
[ProtoMember(4)]
public bool ShowRingGPS;

public PlanetRingSettings copy()
{
PlanetRingSettings r = new PlanetRingSettings();
r.MinPlanetRingWidth = MinPlanetRingWidth;
r.MaxPlanetRingWidth = MaxPlanetRingWidth;
r.PlanetRingProbability = PlanetRingProbability;
r.ShowRingGPS = ShowRingGPS;

return r;
}

public void Verify()
{
Expand All @@ -205,6 +279,7 @@ public BeltSettings()
MaxBeltHeight = 40000;
BeltProbability = 0.2f;
ShowBeltGPS = true;
BeltNameFormat = "Belt [ObjectNumberGreek]";
}

[ProtoMember(1)]
Expand All @@ -219,6 +294,20 @@ public BeltSettings()
[ProtoMember(4)]
public bool ShowBeltGPS;

[ProtoMember(5)]
public string BeltNameFormat;

public BeltSettings copy()
{
BeltSettings b = new BeltSettings();
b.MinBeltHeight = MinBeltHeight;
b.MaxBeltHeight = MaxBeltHeight;
b.BeltProbability = BeltProbability;
b.ShowBeltGPS = ShowBeltGPS;
b.BeltNameFormat = BeltNameFormat;
return b;
}

public void Verify()
{
Verifier.VerifyInt(0, MaxBeltHeight, 4000, "BeltSettings.MinBeltHeight", ref MinBeltHeight);
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.5.0")]
[assembly: AssemblyVersion("1.7.6.0")]
[assembly: AssemblyFileVersion("1.0.0")]
1 change: 1 addition & 0 deletions SEWorldGenPlugin/SEWorldGenPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<Compile Include="Utilities\MyPluginTexts.cs" />
<Compile Include="Utilities\NetUtil.cs" />
<Compile Include="Utilities\PluginLog.cs" />
<Compile Include="Utilities\StringExtension.cs" />
<Compile Include="Utilities\Verifier.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions SEWorldGenPlugin/Utilities/StringExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

namespace SEWorldGenPlugin.Utilities
{
static class StringExtension
{

public static string SetProperty<T>(this string s, string propertyName, T value)
{
return s.Replace("[" + propertyName + "]", value.ToString());
}
}
}

0 comments on commit 4779c81

Please sign in to comment.