Skip to content

Commit

Permalink
added documentation up to farmplotcell.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw1589 committed Mar 28, 2024
1 parent 366d890 commit 0a9a36f
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 13 deletions.
8 changes: 7 additions & 1 deletion Assets/Scripts/Components/AdvancePhaseOnClick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using UnityEngine.UI;

// Original Author: Andy Wang
// Used to make a button advance phase on click
/// <summary>
/// Makes a button advance to the next phase on click.
/// Place on an object with a Button component.
/// </summary>
public class AdvancePhaseOnClick : MonoBehaviour
{
[SerializeField] [Range(1, 3)] int phase; // should be from 1 to 3, but it's zero-indexed
Expand All @@ -18,6 +21,9 @@ void Start() {
}
}

/// <summary>
/// Click handler. Advances phase based on the serialized field "phase."
/// </summary>
public void OnClick() {
switch (GameState.s_Phase) {
case 0:
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Components/AvailableLabourDisplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
using TMPro;
using UnityEngine;

/// <summary>
/// Makes a text label show your available labour points from a serialized format string.
/// Place on an object with a TextMeshPro component.
/// This component is unused.
/// </summary>
public class AvailableLabourDisplayer : MonoBehaviour
{
[SerializeField] string formatString;
Expand Down
8 changes: 7 additions & 1 deletion Assets/Scripts/Components/BuyButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using UnityEngine.UI;

// Original Author: Andy Wang
// Put this component on a button to make it buy something from the market on click
/// <summary>
/// Makes a button buy a product from the market on click. Product name is a serialized field.
/// Place on an object with a Button component.
/// </summary>
public class BuyButton : MonoBehaviour
{
[SerializeField] string productName;
Expand All @@ -19,6 +22,9 @@ void Update() {
_btn.interactable = Market.CanBuyerBuy(GameState.s_Player, productName);
}

/// <summary>
/// Click handler.
/// </summary>
public void OnClick() {
Market.Buy(productName, GameState.s_Player);
// we probably don't need error message handling because the buy button can only be clicked if you can buy it
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/Components/ChildPopulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using UnityEngine;

// Original Author: Andy Wang
// Populate the view children scene with your children
/// <summary>
/// Populates a specified grid/list with prefabs containing information about your children.
/// This is unused and has been superceded by FamilyMemberPopulator.cs
/// </summary>
public class ChildPopulator : MonoBehaviour
{
[SerializeField] GameObject childPrefab;
Expand Down
6 changes: 6 additions & 0 deletions Assets/Scripts/Components/ClosePopUpOnClick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using UnityEngine.UI;

// Original Author: Kevin
/// <summary>
/// On click, close a specified game object. Place on a component with a Button.
/// </summary>
public class ClosePopUpOnClick : MonoBehaviour
{
[SerializeField] private GameObject PopUpWindow;
Expand All @@ -14,6 +17,9 @@ void Start() {
}
}

/// <summary>
/// Set object specified by serialized field to be inactive.
/// </summary>
public void OnClick() {
PopUpWindow.SetActive(false);
}
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Components/CloseYieldTable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Unused.
/// </summary>
public class CloseYieldTable : MonoBehaviour
{
public Image yieldTable;
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Components/DisplayTotalWheat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using TMPro;
using UnityEngine;

/// <summary>
/// Add to an object with a TextMeshPro component to make it display the player's total wheat.
/// </summary>
public class DisplayTotalWheat : MonoBehaviour
{
[SerializeField] string text;
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Components/DisplayWeather.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using UnityEngine;

// author: Jacqueline Zhu
/// <summary>
/// Add to an object with a TextMeshPro component to make it show the weather.
/// </summary>
public class DisplayWeather : MonoBehaviour
{
[SerializeField] string text;
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Components/EnableBasedOnPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using Backend;

// Original Author: Bill Guo
/// <summary>
/// Place this on any object and set its fields to make it be active only during the specified phases.
/// </summary>
public class EnableBasedOnPhase : MonoBehaviour
{
[SerializeField] List<int> phases;
Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/Components/FamilyMemberPopulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using UnityEngine.UI;

// Original Author: Andy Wang
// Populate the adult/child view in household manager
/// <summary>
/// Populate grids with information about your adults and children. Used in the household management scene.
/// </summary>
public class FamilyMemberPopulator : MonoBehaviour
{
[SerializeField] GameObject prefab;
Expand Down
32 changes: 29 additions & 3 deletions Assets/Scripts/Components/FarmManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,35 @@
using Backend;

// Original Author: Andy Wang
// Similar to GameState but specific to the Manage Farm scene, holding some variables used in that scene for convenience
/// <summary>
/// Holds the main gameplay logic during the farm management scene (phases 1, 2, 3).
/// Handles the irrigation button and harvest button logic.
/// </summary>
public class FarmManager : MonoBehaviour
{
/// <summary>
/// The tool currently selected during phase 3.
/// </summary>
public static string SelectedTool { get; set; } = null; // just make this a string for now lol

/// <summary>
/// Selected farm plot cells during phases 1/2.
/// </summary>
public static List<FarmPlotCell> SelectedCells = new List<FarmPlotCell>();

/// <summary>
/// Labour cost of selecting a plot cell to be irrigated.
/// </summary>
public const int IrrigationLabour = 2; // const for labour cost for irrigation in case we want to change later

/// <summary>
/// Labour cost of selecting a plot cell to be harvested.
/// </summary>
public const int HarvestLabour = 1;

/// <summary>
/// How many labour points you currently have in this phase.
/// </summary>
public static int LabourPoints { get; set; } // upon loading the farm management screen, show how many labour points you can spend

void Start()
Expand All @@ -25,7 +44,9 @@ private void OnEnable()
SelectedCells.Clear();
}

// Harvests all currently selected Cells
/// <summary>
/// Harvests all selected farm cells.
/// </summary>
public static void HarvestSelectedCells()
{
int gain = 0;
Expand Down Expand Up @@ -55,7 +76,9 @@ public static void HarvestSelectedCells()
}
}

// Irrigates all currently selected Cells
/// <summary>
/// Harvests all selected farm cells.
/// </summary>
public static void IrrigateSelectedCells()
{
foreach (FarmPlotCell cell in SelectedCells)
Expand All @@ -66,6 +89,9 @@ public static void IrrigateSelectedCells()
GameState.AdvanceToPhaseTwo();
}

/// <summary>
/// Deselect all farm plot cells.
/// </summary>
public static void ClearSelectedCells()
{
SelectedCells.Clear();
Expand Down
21 changes: 17 additions & 4 deletions Assets/Scripts/Components/FarmPlotCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System;

// Original Author: Andy Wang
/// <summary>
/// Represents a tile in the farm management screen that can be pressed on. Represents a single farm plot in your land.
/// </summary>
public class FarmPlotCell : MonoBehaviour
{
[SerializeField] Sprite normalSprite;
Expand All @@ -19,6 +22,9 @@ public class FarmPlotCell : MonoBehaviour
private GameObject _irrigatedOverlay;
private Image _image;

/// <summary>
/// The FarmPlot object that this cell represents.
/// </summary>
public FarmPlot Plot { get; set; }

void Start()
Expand All @@ -40,7 +46,9 @@ void Update()
RefreshStatus();
}

// Refreshes visual state of the farm plot cell
/// <summary>
/// Update the farm cell's sprite based on phase and whether it's selected or not.
/// </summary>
public void RefreshVisuals()
{
if (GameState.s_Phase == 2)
Expand All @@ -67,6 +75,10 @@ public void RefreshVisuals()
}
}

/// <summary>
/// Update visuals based on plot's status, aka seed type, irrigated, fertilizer.
/// Essentially sets a bunch of overlays over the main sprite.
/// </summary>
public void RefreshStatus()
{
_hycImage.SetActive(Plot.SeedType == SeedType.HYC);
Expand All @@ -90,9 +102,10 @@ public void RefreshStatus()
_irrigatedOverlay.SetActive(Plot.Irrigated);
}

// Select or deselect this farm cell on click
// Also handle planting/harvesting/irrigating depending on phase (read FarmManager fields)
// Precondition: if the player has a tool selected, that means they can use it in the first place
/// <summary>
/// In phases 1/2, select this farm cell (if the player has enough labour points to do so).
/// In phase 3, set seed/fertilizer type depending on what tool the player has selected.
/// </summary>
void HandleClick()
{
Household owner = Plot.Owner;
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ It is recommended to edit scripts by clicking on them in the Unity editor, as th
UML diagrams can be viewed in the browser, and edited using Violet UML Editor (https://sourceforge.net/projects/violet/).

## Deployment and Github Workflow
Deployment Usage: navigate to D4/Build and run [Green Revolution.exe](deliverables/D4/Build/Green%20Revolution.exe)
Deployment Usage: navigate to deliverables/D4/Build and run [Green Revolution.exe](deliverables/D4/Build/Green%20Revolution.exe)

Communication is done on our Discord server. We say what we're writing and how we're going to merge it (either directly or through a pull request). We honestly aren't very strict about this - as long as it gets the work done. As a rule of thumb, if we're making a small bug fix, we can just push directly to main. If it's a big change, like writing new classes, we'll create a branch for it, and the writer of it will create a pull request. Team lead reviews it and merges it.

Expand All @@ -111,7 +111,7 @@ And we will ignore the note about four spaces instead of tabs.

As for comments, every class and method should be documented. Classes should have authors, and methods should have comments explaining their parameters and return values. These don't need to be in a specific format, as long as they explain the information.

**Always use `//` for comments**
**Always use `//` for comments**, and use `///` for XML comments. Public variables/methods should be documented with XML comments so they'll appear on our auto-generated documentation. (Bonus points if your IDE automatically creates a template for you when you type `///`.)
## Licenses
"You can upload the code to GitHub or other similar publicly available domains."
Expand Down

0 comments on commit 0a9a36f

Please sign in to comment.