Skip to content

Commit

Permalink
Merge pull request #48 from tobeyStraitjacket/dev
Browse files Browse the repository at this point in the history
SnapBuilder 1.4.1
  • Loading branch information
toebeann authored May 31, 2021
2 parents 45e032d + e63634c commit 56175db
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 16 deletions.
17 changes: 12 additions & 5 deletions SnapBuilder/ColliderRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ class ColliderRecord
{
private static Type[] ExcludedComponentTypes { get; } = new Type[] {
typeof(CoralBlendWhite), // default mesh is good enough and doesn't work well when upgraded
typeof(BaseCell)
typeof(BaseCell),
typeof(ConstructableBase)
};

private static TechType[] ExcludedTechTypes { get; } = new TechType[]
{
TechType.BaseHatch
};

private static Material material;
Expand Down Expand Up @@ -63,7 +69,7 @@ public bool IsImprovable
return (isImprovable = false).Value;
}
}
public bool IsImproved => Collider switch
public bool IsImproved => IsImprovable && Collider switch
{
MeshCollider meshCollider => meshCollider?.sharedMesh is Mesh mesh && mesh == ImprovedMesh,
_ => false
Expand All @@ -80,9 +86,10 @@ public ColliderRecord(Collider collider)
private bool IsExcluded()
{
Transform root = Utils.GetEntityRoot(Collider.transform.gameObject)?.transform ?? Collider.transform;
return ExcludedComponentTypes
.Select(type => root.GetComponent(type))
.Any(component => component is Component);
return ExcludedTechTypes.Contains(Builder.constructableTechType)
|| ExcludedComponentTypes
.Select(type => root.GetComponent(type))
.Any(component => component is Component);
}

public void Improve()
Expand Down
20 changes: 19 additions & 1 deletion SnapBuilder/ExtensionMethods/UnityEngineExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Straitjacket.Subnautica.Mods.SnapBuilder.ExtensionMethods
{
Expand Down Expand Up @@ -67,7 +68,24 @@ public static void Render(this Collider collider, Material material, float scale
/// <returns></returns>
public static Transform GetOptimalTransform(this RaycastHit hit) => Builder.GetSurfaceType(hit.normal) switch
{
SurfaceType.Ground => hit.transform.parent ?? hit.transform,
SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root
&& root.GetComponent<BaseCell>() is BaseCell => root,
SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root
&& root.GetComponent<Base>() is Base => hit.transform,
SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root
&& new float[] { 1, 0, 1 / Mathf.Sqrt(2) }
.Any(dot => Mathf.Approximately(dot, Mathf.Abs(Vector3.Dot(root.forward, hit.transform.forward))))
=> root,

SurfaceType.Ground when hit.transform.parent is Transform parent
&& parent.GetComponent<BaseCell>() is BaseCell => parent,
SurfaceType.Ground when hit.transform.parent is Transform parent
&& parent.GetComponent<Base>() is Base => hit.transform,
SurfaceType.Ground when hit.transform.parent is Transform parent
&& new float[] { 1, 0, 1 / Mathf.Sqrt(2) }
.Any(dot => Mathf.Approximately(dot, Mathf.Abs(Vector3.Dot(parent.forward, hit.transform.forward))))
=> parent,

_ => hit.transform
};

Expand Down
5 changes: 0 additions & 5 deletions SnapBuilder/Patches/BuilderPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public static void BeginHintsPrefix(out bool __state)
[HarmonyPostfix]
public static void BeginHintsPostfix(bool __state)
{
if (Builder.prefab.GetComponent<ConstructableBase>() is ConstructableBase)
{
return;
}

if (__state && Builder.rotationEnabled)
{
ControlHint.Show(Lang.Hint.ToggleFineRotation, SnapBuilder.Config.FineRotation);
Expand Down
4 changes: 2 additions & 2 deletions SnapBuilder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: NeutralResourcesLanguage("en-GB")]

3 changes: 2 additions & 1 deletion SnapBuilder/SnapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ public static Quaternion CalculateRotation(ref float additiveRotation, RaycastHi
empty.transform.position = hit.point; // Set the parent transform's position to our chosen position

// choose whether we should use the global forward, or the forward of the hitTransform
Vector3 forward = hitTransform.forward.y != 0
Vector3 forward = !Mathf.Approximately(Mathf.Abs(Vector3.Dot(Vector3.up, hitTransform.up)), 1)
&& !Player.main.IsInsideWalkable()
&& hitTransform.GetComponent<BaseCell>() is null
&& hitTransform.GetComponent<Base>() is null
? Vector3.forward
: hitTransform.forward;

Expand Down
2 changes: 1 addition & 1 deletion SnapBuilder/mod_BELOWZERO.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "SnapBuilder",
"DisplayName": "SnapBuilder",
"Author": "Tobey Blaber",
"Version": "1.4",
"Version": "1.4.1",
"AssemblyName": "Straitjacket.Subnautica.Mods.SnapBuilder.dll",
"Enable": true,
"Game": "BelowZero",
Expand Down
2 changes: 1 addition & 1 deletion SnapBuilder/mod_SUBNAUTICA.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "SnapBuilder",
"DisplayName": "SnapBuilder",
"Author": "Tobey Blaber",
"Version": "1.4",
"Version": "1.4.1",
"AssemblyName": "Straitjacket.Subnautica.Mods.SnapBuilder.dll",
"Enable": true,
"Game": "Subnautica",
Expand Down

0 comments on commit 56175db

Please sign in to comment.