diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index b7bb255..75d7689 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -77,21 +77,6 @@ public class Entity : LevelObject && otherEntity._attack_damage == _attack_damage; } - public override void LevelDestroy() - { - - } - - public override void LevelStart() - { - - } - - public override void LevelUpdate() - { - - } - public override Dictionary ToDictionary() { return Extensions.ToDictionary(this); diff --git a/Assets/Scripts/LevelManager/LevelTile.cs b/Assets/Scripts/LevelManager/LevelTile.cs index ff471d1..8d319e5 100644 --- a/Assets/Scripts/LevelManager/LevelTile.cs +++ b/Assets/Scripts/LevelManager/LevelTile.cs @@ -19,10 +19,19 @@ public abstract class LevelTile : TileBase, ILevelObject [LevelSerialize] public string Name => name; - public abstract void LevelStart(); - public abstract void LevelDestroy(); - public abstract void LevelUpdate(); - public abstract bool Equals(ILevelObject other); + public virtual void LevelStart() { } + public virtual void LevelDestroy() { } + public virtual void LevelUpdate() { } + public virtual bool Equals(ILevelObject other) + { + if (!other.GetType().Equals(GetType())) return false; + + var otherTile = other as LevelTile; + + return Name == otherTile.Name + && Position == otherTile.Position + && Tilemap == otherTile.Tilemap; + } public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go) { //only execute if application is in play mode @@ -39,11 +48,8 @@ public abstract class LevelTile : TileBase, ILevelObject instance.Position = position; instance.Tilemap = comp.name; - //lambda expression to be used to check if the tile already exists - bool isSameTile(LevelTile tile) => tile.Equals(instance); - - //if tile is exactly the same as before, don't add. - if (LevelManager.Instance.Has(isSameTile)) + //if tile already exists, dont add to level manager + if (LevelManager.Instance.Has(tile => tile.Equals(instance))) { return base.StartUp(position, tilemap, go); } diff --git a/Assets/Scripts/Tiles/LevelObject.cs b/Assets/Scripts/Tiles/LevelObject.cs index 4b812ca..022b9c1 100644 --- a/Assets/Scripts/Tiles/LevelObject.cs +++ b/Assets/Scripts/Tiles/LevelObject.cs @@ -19,10 +19,23 @@ public abstract class LevelObject : MonoBehaviour, ILevelObject LevelManager.Instance.Add(this); } - public abstract void LevelStart(); - public abstract void LevelDestroy(); - public abstract void LevelUpdate(); + public virtual void LevelStart() + { + } + public virtual void LevelDestroy() + { + } + public virtual void LevelUpdate() + { + } - public abstract bool Equals(ILevelObject other); + public virtual bool Equals(ILevelObject other) + { + if (!other.GetType().Equals(this.GetType())) return false; + + var otherObject = other as LevelObject; + return otherObject.Name == Name + && otherObject.Position == Position; + } public abstract Dictionary ToDictionary(); } \ No newline at end of file