Skip to content

Commit d0bedfe

Browse files
committed
Add custom space center
1 parent 654be5c commit d0bedfe

4 files changed

Lines changed: 103 additions & 0 deletions

File tree

BASPModules/BASPModules.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
</ItemGroup>
6565
<ItemGroup>
6666
<Compile Include="AutoDetachModule.cs" />
67+
<Compile Include="BRPack.cs" />
68+
<Compile Include="Patch/SpaceCenterPatcher.cs" />
69+
<Compile Include="Util/BuildingUtil.cs" />
6770
<Compile Include="Properties\AssemblyInfo.cs" />
6871
</ItemGroup>
6972
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

BASPModules/BRPack.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using UnityEngine;
2+
using HarmonyLib;
3+
using static SFS.World.SpaceCenter;
4+
5+
[CreateAssetMenu(fileName = "BRPack", menuName = "BR-Apollo Mod", order = 1)]
6+
public class BRPack : ScriptableObject
7+
{
8+
public static BRPack Main;
9+
public const string ModIdPatching = "brapollo.brioche.github";
10+
public Building vab, launchPad;
11+
12+
public BRPack()
13+
{
14+
Main = this;
15+
}
16+
17+
public void OnEnable()
18+
{
19+
if (Application.isEditor)
20+
{
21+
return;
22+
}
23+
24+
Debug.Log("patch functions BR Apollo!");
25+
Harmony harmony = new Harmony(ModIdPatching);
26+
harmony.PatchAll();
27+
Debug.Log("BR Apollo Ready!");
28+
}
29+
30+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using HarmonyLib;
2+
using SFS.World;
3+
using SFS;
4+
using SFS.WorldBase;
5+
using UnityEngine;
6+
using SFS.Parts.Modules;
7+
8+
[HarmonyPatch(typeof(SpaceCenter), "Start")]
9+
class SpaceCenterPatcher
10+
{
11+
[HarmonyPostfix]
12+
public static void Postfix(SpaceCenter __instance)
13+
{
14+
__instance.vab.building.gameObject.SetActive(false);
15+
__instance.launchPad.building.gameObject.SetActive(false);
16+
17+
18+
SpaceCenterData spaceCenter = Base.planetLoader.spaceCenter;
19+
20+
// VAB building
21+
GameObject vabGameObject = GameObject.Instantiate(BRPack.Main.vab.building.gameObject);
22+
vabGameObject.transform.parent = __instance.transform;
23+
vabGameObject.SetActive(true);
24+
25+
BuildingUtil.AddBuildingToWorld(vabGameObject, spaceCenter.address.GetPlanet(), spaceCenter.LaunchPadLocation.position + new Double2(-750.0, -9.0));
26+
foreach (I_InitializePartModule initialize in vabGameObject.GetComponentsInChildren<I_InitializePartModule>())
27+
{
28+
initialize.Initialize();
29+
}
30+
foreach (BaseMesh mesh in vabGameObject.GetComponentsInChildren<BaseMesh>())
31+
{
32+
mesh.GenerateMesh();
33+
}
34+
35+
WorldLocation vabLocation = vabGameObject.GetComponent<WorldLocation>();
36+
__instance.vab.building.location.position.Value = vabLocation.position.Value + new Double2(80,0);
37+
38+
39+
// Launch pad building
40+
GameObject launchPadGameObject = GameObject.Instantiate(BRPack.Main.launchPad.building.gameObject);
41+
launchPadGameObject.transform.parent = __instance.transform;
42+
launchPadGameObject.SetActive(true);
43+
44+
BuildingUtil.AddBuildingToWorld(launchPadGameObject, spaceCenter.address.GetPlanet(), spaceCenter.LaunchPadLocation.position + new Double2(-130, -10.0));
45+
foreach (I_InitializePartModule initialize in launchPadGameObject.GetComponentsInChildren<I_InitializePartModule>())
46+
{
47+
initialize.Initialize();
48+
}
49+
foreach (BaseMesh mesh in launchPadGameObject.GetComponentsInChildren<BaseMesh>())
50+
{
51+
mesh.GenerateMesh();
52+
}
53+
54+
}
55+
}
56+

BASPModules/Util/BuildingUtil.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using SFS.World;
2+
using SFS.WorldBase;
3+
using UnityEngine;
4+
5+
6+
public class BuildingUtil
7+
{
8+
9+
public static void AddBuildingToWorld(GameObject building, Planet planet, Double2 position)
10+
{
11+
WorldLocation location = building.GetComponent<WorldLocation>();
12+
location.Value = new Location(planet, position, default(Double2));
13+
}
14+
}

0 commit comments

Comments
 (0)