Skip to content

Commit

Permalink
Use arrow functions where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Nov 11, 2023
1 parent 0de0430 commit 0571ac5
Show file tree
Hide file tree
Showing 59 changed files with 205 additions and 617 deletions.
10 changes: 2 additions & 8 deletions Assets/Base/ActivatedSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ public bool EntityMatches(EntityComponent entityComponent)
return false;
}

public override string ToString()
{
return entityType.fullName;
}
public override string ToString() => entityType.fullName;
}

// for maps before version 10
Expand All @@ -130,10 +127,7 @@ public bool EntityMatches(EntityComponent entityComponent)
return entityComponent.entity.tag == tag;
}

public override string ToString()
{
return "With tag " + Entity.TagToString(tag);
}
public override string ToString() => "With tag " + Entity.TagToString(tag);
}

public class MultipleTagFilter : Filter
Expand Down
10 changes: 2 additions & 8 deletions Assets/Base/CustomTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,9 @@ public static CustomTexture FromBaseMaterial(Material baseMat, bool overlay)

public ICollection<Property> DeprecatedProperties() => System.Array.Empty<Property>();

public static bool IsCustomTexture(Material material)
{
return material.name.StartsWith("Custom:");
}
public static bool IsCustomTexture(Material material) => material.name.StartsWith("Custom:");

public static string GetBaseMaterialName(Material material)
{
return material.name.Split(':')[1];
}
public static string GetBaseMaterialName(Material material) => material.name.Split(':')[1];

public static Material Clone(Material material)
{
Expand Down
36 changes: 8 additions & 28 deletions Assets/Base/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ private PropertiesObject DefaultConstructor()
return (PropertiesObject)Activator.CreateInstance(type);
}

public PropertiesObject Create()
{
return constructor();
}
public PropertiesObject Create() => constructor();

// assumes both objects are the same type and have the same order of properties
public static void CopyProperties(PropertiesObject source, PropertiesObject dest,
Expand Down Expand Up @@ -231,10 +228,7 @@ public static string TagToString(byte tag)
return "■▲●★♥♦♠♣".Substring(tag, 1);
}

public override string ToString()
{
return TagToString(tag) + " " + ObjectType.fullName;
}
public override string ToString() => TagToString(tag) + " " + ObjectType.fullName;

public virtual PropertiesObjectType ObjectType => objectType;

Expand Down Expand Up @@ -305,10 +299,8 @@ public static EntityComponent FindEntityComponent(GameObject obj)
return null;
}

public static EntityComponent FindEntityComponent(Component c)
{
return FindEntityComponent(c.gameObject);
}
public static EntityComponent FindEntityComponent(Component c) =>
FindEntityComponent(c.gameObject);

public virtual void Start()
{
Expand Down Expand Up @@ -684,10 +676,7 @@ public virtual void Init(T sensor)
this.sensor = sensor;
}

public bool IsOn()
{
return GetActivators().Count > 0;
}
public bool IsOn() => GetActivators().Count > 0;

public virtual void LateUpdate()
{
Expand All @@ -697,22 +686,13 @@ public virtual void LateUpdate()
// all current activators
// if the number is greater than zero, the sensor is on
// a null activator is possible - this allows the sensor to be on without having any activators
public ICollection<EntityComponent> GetActivators()
{
return activators;
}
public ICollection<EntityComponent> GetActivators() => activators;

// activators that have been added this frame
public ICollection<EntityComponent> GetNewActivators()
{
return newActivators;
}
public ICollection<EntityComponent> GetNewActivators() => newActivators;

// activators that have been removed this frame
public ICollection<EntityComponent> GetRemovedActivators()
{
return removedActivators;
}
public ICollection<EntityComponent> GetRemovedActivators() => removedActivators;

private void NewFrame()
{
Expand Down
5 changes: 1 addition & 4 deletions Assets/Base/EntityReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ public static void DoneLoadingEntities()
}

// has the map file finished loading? are EntityReferences safe to be read?
public static bool EntitiesLoaded()
{
return entitiesLoaded;
}
public static bool EntitiesLoaded() => entitiesLoaded;

public static void AddExistingEntityId(Entity entity, Guid guid)
{
Expand Down
16 changes: 4 additions & 12 deletions Assets/Base/Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ public abstract class ObjectEntity : DynamicEntity
public Color highlight = Color.clear;
public Material highlightMaterial;

public virtual Vector3 PositionOffset()
{
return Vector3.zero;
}
public virtual Vector3 PositionOffset() => Vector3.zero;

public override void UpdateEntityEditor()
{
if (marker != null)
marker.UpdateMarker();
}

public override Vector3 PositionInEditor()
{
return position + new Vector3(0.5f, 0.5f, 0.5f) + PositionOffset();
}
public override Vector3 PositionInEditor() =>
position + new Vector3(0.5f, 0.5f, 0.5f) + PositionOffset();

public override bool AliveInEditor()
{
return marker != null;
}
public override bool AliveInEditor() => marker != null;

public override void SetHighlight(Color c)
{
Expand Down
6 changes: 2 additions & 4 deletions Assets/Base/ResourcesDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ public enum ColorStyle
}
}

public static Material LoadMaterial(MaterialInfo info)
{
return Resources.Load<Material>("GameAssets/" + info.path);
}
public static Material LoadMaterial(MaterialInfo info) =>
Resources.Load<Material>("GameAssets/" + info.path);

public static Material FindMaterial(string name, bool editor)
{
Expand Down
64 changes: 15 additions & 49 deletions Assets/Base/Voxel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ public struct VoxelFace
public byte orientation;
public bool addSelected, storedSelected;

public bool IsEmpty()
{
return material == null && overlay == null;
}
public bool IsEmpty() => material == null && overlay == null;

public void Clear()
{
Expand All @@ -30,20 +27,11 @@ public VoxelFace PaintOnly()
return paintOnly;
}

public override bool Equals(object obj)
{
return obj is VoxelFace && this == (VoxelFace)obj;
}
public override bool Equals(object obj) => obj is VoxelFace && this == (VoxelFace)obj;

public static bool operator ==(VoxelFace s1, VoxelFace s2)
{
return s1.material == s2.material && s1.overlay == s2.overlay
&& s1.orientation == s2.orientation;
}
public static bool operator !=(VoxelFace s1, VoxelFace s2)
{
return !(s1 == s2);
}
public static bool operator ==(VoxelFace s1, VoxelFace s2) =>
s1.material == s2.material && s1.overlay == s2.overlay && s1.orientation == s2.orientation;
public static bool operator !=(VoxelFace s1, VoxelFace s2) => !(s1 == s2);

public override int GetHashCode()
{
Expand All @@ -53,15 +41,9 @@ public override int GetHashCode()
return result;
}

public static int GetOrientationRotation(byte orientation)
{
return orientation & 3;
}
public static int GetOrientationRotation(byte orientation) => orientation & 3;

public static bool GetOrientationMirror(byte orientation)
{
return (orientation & 4) != 0;
}
public static bool GetOrientationMirror(byte orientation) => (orientation & 4) != 0;

public static byte Orientation(int rotation, bool mirror)
{
Expand Down Expand Up @@ -257,10 +239,8 @@ public static Vector3 DirectionForFaceI(int faceI)
}
}

public static Vector3 OppositeDirectionForFaceI(int faceI)
{
return DirectionForFaceI(OppositeFaceI(faceI));
}
public static Vector3 OppositeDirectionForFaceI(int faceI) =>
DirectionForFaceI(OppositeFaceI(faceI));

public static int FaceIForDirection(Vector3 direction)
{
Expand All @@ -280,10 +260,7 @@ public static int FaceIForDirection(Vector3 direction)
return -1;
}

public static int OppositeFaceI(int faceI)
{
return (faceI / 2) * 2 + (faceI % 2 == 0 ? 1 : 0);
}
public static int OppositeFaceI(int faceI) => (faceI / 2) * 2 + (faceI % 2 == 0 ? 1 : 0);

public static int SideFaceI(int faceI, int sideNum)
{
Expand Down Expand Up @@ -359,15 +336,9 @@ public static IEnumerable<int> UnconnectedEdges(int edgeI)
}
}

public static int FaceIAxis(int faceI)
{
return faceI / 2;
}
public static int FaceIAxis(int faceI) => faceI / 2;

public static int EdgeIAxis(int edgeI)
{
return edgeI / 4;
}
public static int EdgeIAxis(int edgeI) => edgeI / 4;

public static IEnumerable<int> FaceSurroundingEdges(int faceNum)
{
Expand Down Expand Up @@ -444,10 +415,7 @@ public Bounds GetEdgeBounds(int edgeI)
return new Bounds(center + position, size);
}

public Bounds GetBounds()
{
return new Bounds(position + new Vector3(0.5f, 0.5f, 0.5f), Vector3.one);
}
public Bounds GetBounds() => new Bounds(position + new Vector3(0.5f, 0.5f, 0.5f), Vector3.one);

public bool EdgeIsEmpty(int edgeI)
{
Expand Down Expand Up @@ -1421,10 +1389,8 @@ private static FaceCornerVertices[] GetFaceVertices(VoxelArray voxelArray, Voxel
}


private static Vector3 Vector3FromArray(float[] vector)
{
return new Vector3(vector[0], vector[1], vector[2]);
}
private static Vector3 Vector3FromArray(float[] vector) =>
new Vector3(vector[0], vector[1], vector[2]);

private static Vector2 CalcUV(Voxel voxel, float[] vertex, Vector3 positiveU_xyz, Vector3 positiveV_xyz)
{
Expand Down
15 changes: 3 additions & 12 deletions Assets/Base/VoxelArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ public bool IsEmpty()
return true;
}

public IEnumerable<Voxel> IterateVoxels()
{
return voxels.Values;
}
public IEnumerable<Voxel> IterateVoxels() => voxels.Values;

public ObjectEntity ObjectAt(Vector3Int pos)
{
Expand Down Expand Up @@ -138,10 +135,7 @@ public bool MoveObject(ObjectEntity obj, Vector3Int newPosition)
return true;
}

public IEnumerable<ObjectEntity> IterateObjects()
{
return objects.Values;
}
public IEnumerable<ObjectEntity> IterateObjects() => objects.Values;

public void DeleteSubstance(Substance substance)
{
Expand Down Expand Up @@ -204,10 +198,7 @@ public void RemoveVoxel(Voxel voxel)
}
}

public IEnumerable<VoxelComponent> IterateComponents()
{
return components.Values;
}
public IEnumerable<VoxelComponent> IterateComponents() => components.Values;

public IEnumerable<Voxel> IterateVoxels()
{
Expand Down
5 changes: 1 addition & 4 deletions Assets/Behaviors/Carryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public override void Start()
base.Start();
}

public bool IsCarried()
{
return joint != null;
}
public bool IsCarried() => joint != null;

public void Carry(EntityComponent player)
{
Expand Down
10 changes: 2 additions & 8 deletions Assets/Behaviors/MotionBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ void FixedUpdate()
}

// player standing on top of object will move this amount
public virtual Vector3 GetTranslateFixed()
{
return Vector3.zero;
}
public virtual Vector3 GetTranslateFixed() => Vector3.zero;

public virtual Quaternion GetRotateFixed()
{
return Quaternion.identity;
}
public virtual Quaternion GetRotateFixed() => Quaternion.identity;
}
5 changes: 1 addition & 4 deletions Assets/Behaviors/Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ public class SoundPlayer : AudioPlayer
{
private GameObject gameObject;

public static AudioPlayer Factory(byte[] data)
{
return new SoundPlayer(data);
}
public static AudioPlayer Factory(byte[] data) => new SoundPlayer(data);

public SoundPlayer(byte[] data)
{
Expand Down
6 changes: 2 additions & 4 deletions Assets/Behaviors/Spin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public class SpinBehavior : GenericEntityBehavior<SpinBehavior, SpinComponent>

public class SpinComponent : MotionComponent<SpinBehavior>
{
public override Quaternion GetRotateFixed()
{
return Quaternion.AngleAxis(behavior.speed * Time.fixedDeltaTime,
public override Quaternion GetRotateFixed() =>
Quaternion.AngleAxis(behavior.speed * Time.fixedDeltaTime,
behavior.axis.DirectionFrom(transform));
}
}
5 changes: 1 addition & 4 deletions Assets/Behaviors/Water.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ public override void Start()
base.Start();
}

public float GetWaterLevel(float x, float z)
{
return waterLevel + transform.position.y;
}
public float GetWaterLevel(float x, float z) => waterLevel + transform.position.y;
}
Loading

0 comments on commit 0571ac5

Please sign in to comment.