Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
s-khechnev committed Apr 13, 2023
1 parent a6ed49e commit 6e7275a
Show file tree
Hide file tree
Showing 38 changed files with 249 additions and 36 deletions.
16 changes: 16 additions & 0 deletions Assets/Scripts/Attackers/Attacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ public abstract class Attacker : MonoBehaviour
private IAttackerFactory _attackerFactory;

public int Health { get; private set; }

/// <summary>
/// Data of attacker
/// </summary>
public AttackerData AttackerData => _attackerData;

/// <summary>
/// Remaining distance to the castle
/// </summary>
public float DistanceToCastle => _mover.DistanceToCastle;

[Inject]
Expand All @@ -40,12 +48,20 @@ private void OnTriggerEnter(Collider other)
}
}

/// <summary>
/// Attack the castle
/// </summary>
/// <param name="castle">castle to attack</param>
protected virtual void Attack(Castle castle)
{
castle.TakeDamage(AttackerData.Damage);
_attackerFactory.Destroy(this);
}

/// <summary>
/// Take the damage
/// </summary>
/// <param name="damage">damage to take</param>
public void TakeDamage(int damage)
{
Health -= damage;
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Attackers/AttackerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class AttackerFactory : IAttackerFactory
{
public event Action<Attacker> AttackerDied;

/// <summary>
/// Count of attackers on scene at the moment
/// </summary>
public int CountAttackers { get; private set; }

private const string AttackerLayerName = "Attacker";
Expand Down
4 changes: 4 additions & 0 deletions Assets/Scripts/Attackers/IAttackerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace Attackers
public interface IAttackerFactory : IFactory<Attacker>
{
public event Action<Attacker> AttackerDied;

/// <summary>
/// Count of attackers on scene at the moment
/// </summary>
public int CountAttackers { get; }
}
}
6 changes: 6 additions & 0 deletions Assets/Scripts/Attackers/Movement/AttackerMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Attackers.Movement
{
/// <summary>
/// The component responsible for the movement of the attacker
/// </summary>
[RequireComponent(typeof(Attacker))]
public class AttackerMovement : MonoBehaviour
{
Expand All @@ -11,6 +14,9 @@ public class AttackerMovement : MonoBehaviour
private Transform _currentPoint;
private Route _route;

/// <summary>
/// Remaining distance to the castle
/// </summary>
public float DistanceToCastle { get; private set; }

[Inject]
Expand Down
12 changes: 12 additions & 0 deletions Assets/Scripts/Attackers/Movement/Route.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ namespace Attackers.Movement
{
public class Route : MonoBehaviour
{
/// <summary>
/// Distance of route to castle
/// </summary>
public float DistanceToCastle { get; private set; }

private void Awake()
{
DistanceToCastle = GetDistanceToCastle();
}

/// <summary>
/// Get the next route point
/// </summary>
/// <param name="currentPoint">current point</param>
/// <returns>Next point relative to the current one</returns>
public Transform GetNextPoint(Transform currentPoint)
{
if (currentPoint == null)
Expand All @@ -21,6 +29,10 @@ public Transform GetNextPoint(Transform currentPoint)
: null;
}

/// <summary>
/// Get the distance of route to castle
/// </summary>
/// <returns>Distance of route to castle</returns>
private float GetDistanceToCastle()
{
var distanceToCastle = 0f;
Expand Down
11 changes: 11 additions & 0 deletions Assets/Scripts/Attackers/Waves/Spawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public enum WaveState
Pause
}

/// <summary>
/// The component responsible for spawn of the attacker
/// </summary>
public class Spawner : MonoBehaviour
{
public event Action WaveEnded;
Expand All @@ -38,6 +41,9 @@ private void Awake()
_currentWaveIndex = -1;
}

/// <summary>
/// Start the next wave
/// </summary>
public void StartNextWave()
{
WaveState = WaveState.InProgress;
Expand All @@ -46,6 +52,11 @@ public void StartNextWave()
StartCoroutine(SpawnCoroutine(_waves[_currentWaveIndex]));
}

/// <summary>
/// Coroutine to spawn attackers
/// </summary>
/// <param name="wave">wave to spawn</param>
/// <returns></returns>
private IEnumerator SpawnCoroutine(Wave wave)
{
foreach (var attackerPrefab in wave.Attackers.Keys)
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/Attackers/Waves/Wave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@ namespace Attackers.Waves
[Serializable]
public class Wave
{
/// <summary>
/// The dictionary in which the key is prefab of attacker, value is count of this attacker
/// </summary>
[SerializeField] private SerializableDictionary<Attacker, int> _attackers;

/// <summary>
/// Delay between spawn of attackers
/// </summary>
[SerializeField, Range(0.01f, 5f)] private float _delayBetweenSpawn;

/// <summary>
/// Returns dictionary in which the key is prefab of attacker, value is count of this attacker
/// </summary>
public IDictionary<Attacker, int> Attackers => _attackers;

/// <summary>
/// Returns delay between spawn of attackers
/// </summary>
public float DelayBetweenSpawn => _delayBetweenSpawn;
}
}
7 changes: 7 additions & 0 deletions Assets/Scripts/Defender/HUD/Bars/AttributeBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ namespace Defender.HUD.Bars
{
public class AttributeBar : Bar
{
/// <summary>
/// The attribute that is currently displayed
/// </summary>
private ILevelChanger _attribute;

/// <summary>
/// Initialize the bar
/// </summary>
/// <param name="attribute">attribute to display</param>
public void Init(ILevelChanger attribute)
{
if (_attribute != null)
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Defender/HUD/Bars/Bar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ private void Awake()
_slider = GetComponent<Slider>();
}

/// <summary>
/// Change the filling of the bar
/// </summary>
/// <param name="value">current value</param>
/// <param name="maxValue">max value</param>
protected void ChangeValue(int value, int maxValue)
{
_slider.value = (float)value / maxValue;
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Defender/HUD/Bars/CastleHealthBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Defender.HUD.Bars
{
public class CastleHealthBar : Bar
{
/// <summary>
/// The castle that is currently displayed
/// </summary>
private Castle _castle;

[Inject]
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/Defender/HUD/BuildTowerButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ namespace Defender.HUD
public class BuildTowerButton : Button
{
[SerializeField] private BaseTower _tower;


/// <summary>
/// Tower to build
/// </summary>
public BaseTower Tower => _tower;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public ChangeTargetSelectorCommand(GUIMenuBase panel, TMP_Text selectorDescripti
_selectorDescription = selectorDescription;
}

/// <summary>
/// Set the TargetFinder to display
/// </summary>
/// <param name="targetFinder">target finder to display</param>
public void SetTargetFinder(TargetFinder targetFinder)
{
_targetFinder = targetFinder;
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Defender/HUD/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Defender.HUD.Commands
{
public abstract class CommandBase : ICommand
{
/// <summary>
/// The menu which contains button which associate with that command
/// </summary>
protected readonly GUIMenuBase Panel;

protected CommandBase(GUIMenuBase panel)
Expand Down
10 changes: 10 additions & 0 deletions Assets/Scripts/Defender/HUD/Commands/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ namespace Defender.HUD.Commands
{
public interface ICommand
{
/// <summary>
/// Execute the command
/// </summary>
/// <param name="context">context of execution</param>
void Execute(Button context);

/// <summary>
/// Get the possibility of executing
/// </summary>
/// <param name="context">context of execution</param>
/// <returns>The possibility of executing</returns>
bool CanExecute(Button context);
}
}
4 changes: 4 additions & 0 deletions Assets/Scripts/Defender/HUD/Commands/RelocateTowerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public RelocateTowerCommand(GUIMenuBase panel, TowerBuilder towerBuilder, Wallet
_wallet = wallet;
}

/// <summary>
/// Set the tower which need relocate
/// </summary>
/// <param name="tower">tower to relocate</param>
public void SetTower(BaseTower tower)
{
_towerToRelocate = tower;
Expand Down
4 changes: 4 additions & 0 deletions Assets/Scripts/Defender/HUD/DefenderGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public static void SetState(DefenderGameState newState)
GameState = newState;
}

/// <summary>
/// Initialize the UI camera
/// </summary>
/// <param name="uiCamera">UI camera</param>
public void InitCamera(Camera uiCamera)
{
_canvas.renderMode = RenderMode.ScreenSpaceCamera;
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/Defender/HUD/Menus/AttributeUpgradeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public class AttributeUpgradeView : MonoBehaviour
[SerializeField] private Button _attributeUpgradeButton;
[SerializeField] private TMP_Text _attributeText;

/// <summary>
/// The attribute that is currently displayed
/// </summary>
private Attribute _attribute;

private Wallet _wallet;

[Inject]
Expand All @@ -23,6 +27,10 @@ private void Construct(Wallet wallet)
_wallet = wallet;
}

/// <summary>
/// Initialize the attribute view
/// </summary>
/// <param name="attribute">attribute to display</param>
public void Init(Attribute attribute)
{
_attribute = attribute;
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/Defender/HUD/Menus/GUIMenuBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace Defender.HUD.Menus
{
public abstract class GUIMenuBase : MonoBehaviour, IGUIMenu
{
/// <summary>
/// The instance of menu
/// </summary>
protected GameObject Instance;
protected Dictionary<Button, ICommand> Associations = new();

Expand Down Expand Up @@ -58,6 +61,11 @@ public virtual void OnSourceChanged()
}
}

/// <summary>
/// Associate the button with command
/// </summary>
/// <param name="button"></param>
/// <param name="command"></param>
protected virtual void AssociateButton(Button button, ICommand command)
{
AddAssociation(button, command);
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Defender/HUD/Menus/MoneyMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class MoneyMenu : GUIMenuBase
{
[SerializeField] private TMP_Text _moneyText;

/// <summary>
/// The wallet which balance that is currently displayed
/// </summary>
private Wallet _wallet;

[Inject]
Expand Down
9 changes: 6 additions & 3 deletions Assets/Scripts/Defender/HUD/Menus/TowerInfoMenu.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using Defender.HUD.Commands;
using Defender.Towers;
using Defender.Towers.Attacking;
Expand Down Expand Up @@ -54,7 +53,7 @@ private void Start()
{
Hide();
}

private void InitButtons()
{
_relocateTowerCommand = new RelocateTowerCommand(this, _towerBuilder, _wallet);
Expand All @@ -66,6 +65,10 @@ private void InitButtons()
AssociateButton(_closeMenuButton, new CloseTowerInfoCommand(this));
}

/// <summary>
/// Handler for the TowerTapped event
/// </summary>
/// <param name="tower">tapped tower</param>
private void OnTowerTapped(BaseTower tower)
{
if (_currentTower == tower)
Expand Down
11 changes: 11 additions & 0 deletions Assets/Scripts/Defender/Towers/Attacking/AttackingTower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ namespace Defender.Towers.Attacking
public class AttackingTower : BaseTower
{
[SerializeField] private AttackingTowerData _towerData;

/// <summary>
/// The position of the point from which the shot will be fired
/// </summary>
[SerializeField] protected Transform _launchPoint;

/// <summary>
/// Time elapsed since the previous shoot
/// </summary>
private float _elapsedTimeFromShoot;

private IWarFactory _warFactory;

private AttackingTowerView _towerView;

/// <summary>
/// Component that give the target
/// </summary>
public TargetFinder TargetFinder { get; private set; }

public override BaseTowerData BaseTowerData => _towerData;
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Defender/Towers/Base/Attribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Defender.Towers.Base
{
/// <summary>
/// Attribute of the tower
/// </summary>
[Serializable]
public class Attribute : ILevelChanger
{
Expand Down
Loading

0 comments on commit 6e7275a

Please sign in to comment.