Added TerraformingTools & functionality

This commit is contained in:
j-weissen 2022-05-19 15:00:55 +02:00
parent 4612938b54
commit 1e2ae28c12
8 changed files with 65 additions and 15 deletions

6
Assets/.gitignore vendored
View file

@ -1,6 +1,10 @@
# Created by https://www.toptal.com/developers/gitignore/api/unity,rider # Created by https://www.toptal.com/developers/gitignore/api/unity,rider
# Edit at https://www.toptal.com/developers/gitignore?templates=unity,rider # Edit at https://www.toptal.com/developers/gitignore?templates=unity,rider
# Custom
*.meta
### Rider ### ### Rider ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and 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 # 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 # End of https://www.toptal.com/developers/gitignore/api/unity,rider
/ProjectSettings/RiderScriptEditorPersistedState.asset /ProjectSettings/RiderScriptEditorPersistedState.asset

View file

@ -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) { }
}
}

View file

@ -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;
}
}
}

View file

@ -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) { }
}
}

View file

@ -42,5 +42,4 @@ public class PlayerController : MonoBehaviour {
} }
} }
}
}

View file

@ -1,13 +1,14 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Items.TerraformingTools;
using Tiles; using Tiles;
using UnityEngine; using UnityEngine;
public class TileBehaviour : MonoBehaviour public class TileBehaviour : MonoBehaviour
{ {
private BaseTile tile; private BaseTile tile;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
@ -18,24 +19,33 @@ public class TileBehaviour : MonoBehaviour
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
} }
void OnMouseDown() void OnMouseDown()
{ {
Debug.Log("Clicked"); Debug.Log("Clicked");
UsableItem usable = PlayerController.getInstance().SelectedItem;
// SelectedItem always null for now BaseTile tileToSetTo = null;
BaseTile temp = tile.Clicked(PlayerController.getInstance().SelectedItem); if (usable.GetType() == typeof(TerraformingTool))
if (temp != null)
{ {
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) void SetTile(BaseTile tileToSet)
{ {
Debug.Log("Set tile to " + tileToSet.ToString());
tile = tileToSet; tile = tileToSet;
GetComponent<SpriteRenderer>().color = tile.getColor; // TODO: Change to Sprite GetComponent<SpriteRenderer>().color = tile.getColor; // TODO: Change to Sprite
} }
} }

View file

@ -1,5 +1,5 @@
using System.Collections; using System;
using System.Collections.Generic; using Items.TerraformingTools;
using UnityEngine; using UnityEngine;

View file

@ -14,7 +14,7 @@ namespace Tiles
/// </summary> /// </summary>
/// <param name="usable">the UsableItem that the Tile was clicked on with</param> /// <param name="usable">the UsableItem that the Tile was clicked on with</param>
/// <returns>a subclass of BaseTile if the Tile has to change, null if it stays the same type</returns> /// <returns>a subclass of BaseTile if the Tile has to change, null if it stays the same type</returns>
new public BaseTile Clicked(UsableItem usable) { public new BaseTile Clicked(UsableItem usable) {
base.Clicked(usable); base.Clicked(usable);
BaseTile rv = null; BaseTile rv = null;
if (usable.GetType() == typeof(Items.Hoe)) if (usable.GetType() == typeof(Items.Hoe))