diff --git a/Assets/.gitignore b/Assets/.gitignore index 97e480b..fe707a1 100644 --- a/Assets/.gitignore +++ b/Assets/.gitignore @@ -1,6 +1,10 @@ # Created by https://www.toptal.com/developers/gitignore/api/unity,rider # Edit at https://www.toptal.com/developers/gitignore?templates=unity,rider + +# Custom +*.meta + ### Rider ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 @@ -154,4 +158,4 @@ sysinfo.txt # End of https://www.toptal.com/developers/gitignore/api/unity,rider -/ProjectSettings/RiderScriptEditorPersistedState.asset \ No newline at end of file +/ProjectSettings/RiderScriptEditorPersistedState.asset diff --git a/Assets/Scripts/Items/TerraformingTools/GrassTool.cs b/Assets/Scripts/Items/TerraformingTools/GrassTool.cs new file mode 100644 index 0000000..1ede3c8 --- /dev/null +++ b/Assets/Scripts/Items/TerraformingTools/GrassTool.cs @@ -0,0 +1,10 @@ +using Tiles; + +namespace Items.TerraformingTools +{ + public class GrassTool : TerraformingTool + { + public GrassTool(int id) : + base(typeof(GrassTile), "Grass Tool", "Sets clicked Tile to Grass", id) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Items/TerraformingTools/TerraformingTool.cs b/Assets/Scripts/Items/TerraformingTools/TerraformingTool.cs new file mode 100644 index 0000000..e60aa2e --- /dev/null +++ b/Assets/Scripts/Items/TerraformingTools/TerraformingTool.cs @@ -0,0 +1,17 @@ +using System; + +namespace Items.TerraformingTools +{ + public abstract class TerraformingTool : UsableItem + { + public readonly Type TileType; + + protected TerraformingTool(Type tileType, string displayName, string description, int id) : + base(displayName, description, id) + { + this.TileType = tileType; + } + + + } +} \ No newline at end of file diff --git a/Assets/Scripts/Items/TerraformingTools/WaterTool.cs b/Assets/Scripts/Items/TerraformingTools/WaterTool.cs new file mode 100644 index 0000000..333d693 --- /dev/null +++ b/Assets/Scripts/Items/TerraformingTools/WaterTool.cs @@ -0,0 +1,10 @@ +using Tiles; + +namespace Items.TerraformingTools +{ + public class WaterTool : TerraformingTool + { + public WaterTool(int id) : + base(typeof(WaterTile), "Water Tool", "Sets clicked Tile to water", id) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index eef9edf..5935a16 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -42,5 +42,4 @@ public class PlayerController : MonoBehaviour { } } - -} +} \ No newline at end of file diff --git a/Assets/Scripts/TileBehaviour.cs b/Assets/Scripts/TileBehaviour.cs index e4992c0..616fd0d 100644 --- a/Assets/Scripts/TileBehaviour.cs +++ b/Assets/Scripts/TileBehaviour.cs @@ -1,13 +1,14 @@ using System; using System.Collections; using System.Collections.Generic; +using Items.TerraformingTools; using Tiles; using UnityEngine; public class TileBehaviour : MonoBehaviour { private BaseTile tile; - + // Start is called before the first frame update void Start() { @@ -18,24 +19,33 @@ public class TileBehaviour : MonoBehaviour // Update is called once per frame void Update() { - } - + void OnMouseDown() { Debug.Log("Clicked"); - - // SelectedItem always null for now - BaseTile temp = tile.Clicked(PlayerController.getInstance().SelectedItem); - if (temp != null) + UsableItem usable = PlayerController.getInstance().SelectedItem; + BaseTile tileToSetTo = null; + if (usable.GetType() == typeof(TerraformingTool)) { - SetTile(temp); + TerraformingTool terraformingTool = (TerraformingTool) usable; + Type tileTypeToSetTo = terraformingTool.TileType; + tileToSetTo = (BaseTile) Activator.CreateInstance(tileTypeToSetTo); + } + else + { + tile.Clicked(usable); + } + if (tileToSetTo != null) + { + SetTile(tileToSetTo); } } void SetTile(BaseTile tileToSet) { + Debug.Log("Set tile to " + tileToSet.ToString()); tile = tileToSet; GetComponent().color = tile.getColor; // TODO: Change to Sprite } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Tiles/BaseTile.cs b/Assets/Scripts/Tiles/BaseTile.cs index 1816d03..949019b 100644 --- a/Assets/Scripts/Tiles/BaseTile.cs +++ b/Assets/Scripts/Tiles/BaseTile.cs @@ -1,5 +1,5 @@ -using System.Collections; -using System.Collections.Generic; +using System; +using Items.TerraformingTools; using UnityEngine; diff --git a/Assets/Scripts/Tiles/GrassTile.cs b/Assets/Scripts/Tiles/GrassTile.cs index 4923c07..cd8f0ce 100644 --- a/Assets/Scripts/Tiles/GrassTile.cs +++ b/Assets/Scripts/Tiles/GrassTile.cs @@ -14,7 +14,7 @@ namespace Tiles /// /// the UsableItem that the Tile was clicked on with /// a subclass of BaseTile if the Tile has to change, null if it stays the same type - new public BaseTile Clicked(UsableItem usable) { + public new BaseTile Clicked(UsableItem usable) { base.Clicked(usable); BaseTile rv = null; if (usable.GetType() == typeof(Items.Hoe))