Skip to content
Snippets Groups Projects
Commit 1b4333aa authored by dbuderus's avatar dbuderus
Browse files

Added more documentation

parent 29d66405
No related branches found
No related tags found
No related merge requests found
Showing
with 87 additions and 21 deletions
......@@ -3,9 +3,16 @@ using UnityEngine;
namespace Framework.Network
{
/// <summary>
/// Manages all <c>NetworkAdapters</c>
/// </summary>
public class NetworkHandler : MonoBehaviour
{
public static NetworkHandler Instance { get; private set; }
/// <summary>
/// Returns current active Adapter, as long it exists
/// </summary>
public static NetworkAdapter NetworkAdapter { get => Instance.Adapters.Count > 0 ? Instance.Adapters.Peek() : null; }
private Queue<NetworkAdapter> Adapters { get; set; }
......
......@@ -3,6 +3,9 @@ using System.Collections.Generic;
namespace Framework.Network
{
/// <summary>
/// Represents a series of requests to a device
/// </summary>
public class Request : Subject
{
private readonly int Cycle;
......@@ -10,6 +13,9 @@ namespace Framework.Network
private readonly string RequestMessage;
private List<Func<string, string>> Transforms;
/// <summary>
/// The last answer of the device after transformation
/// </summary>
public string Value { get; protected set; }
public Request(string message, int cycle) : base()
......@@ -21,12 +27,20 @@ namespace Framework.Network
Value = "";
}
/// <summary>
/// Needs to be called if the
/// request needs a reset
/// </summary>
public void CleanUp()
{
Counter = Cycle;
Value = "";
}
/// <summary>
/// Interprets the last answer as integer
/// </summary>
/// <returns>last answer as integer</returns>
public int ValueAsInt()
{
try
......@@ -38,14 +52,13 @@ namespace Framework.Network
return 0;
}
/// <summary>
/// Interprets the last answer as integer
/// and then as boolean
/// </summary>
/// <returns>last answer as boolean</returns>
public bool ValueAsBoolean()
{
try
{
return Convert.ToBoolean(Value);
}
catch (Exception) { }
return Convert.ToBoolean(ValueAsInt());
}
......@@ -54,6 +67,10 @@ namespace Framework.Network
Transforms.Add(transform);
}
/// <summary>
/// Requests a new answer from the device and updates value
/// </summary>
/// <param name="adapter">Used <c>NetworkAdapter</c></param>
public async System.Threading.Tasks.Task Update(NetworkAdapter adapter)
{
if (Counter >= Cycle)
......

/// <summary>
/// Standard observer from an observer pattern
/// </summary>
public interface IObserver
{
void ObserverUpdate();
}
\ No newline at end of file

public interface Observer
{
void ObserverUpdate();
}
\ No newline at end of file

using System.Collections.Generic;
/// <summary>
/// Standard subject/observable from an observer pattern
/// </summary>
public abstract class Subject
{
protected List<Observer> Observers;
protected List<IObserver> Observers;
protected Subject()
{
this.Observers = new List<Observer>();
this.Observers = new List<IObserver>();
}
protected void Notify()
{
foreach(Observer observer in Observers)
foreach(IObserver observer in Observers)
{
observer.ObserverUpdate();
}
}
public void RegisterObserver(Observer observer)
public void RegisterObserver(IObserver observer)
{
this.Observers.Add(observer);
}
public void UnregisterObserver(Observer observer)
public void UnregisterObserver(IObserver observer)
{
this.Observers.Remove(observer);
}
......
......@@ -14,7 +14,7 @@ namespace Framework.TaskHandling
/// <summary>
/// Handles the selected <c>FullTask</c>
/// </summary>
public class TaskExecuter : MonoBehaviour, Observer
public class TaskExecuter : MonoBehaviour, IObserver
{
//Diagnostic
public static bool DiagnosticMode = false;
......
namespace Framework.Tasks.Decisions
{
/// <summary>
/// Represents a decision in the maintenance job
/// </summary>
public abstract class Decision : Subject
{
private int decisionValue;
......@@ -17,12 +20,20 @@
Notify();
}
/// <summary>
/// Needs to be called after the result of
/// the decision is no longer needed
/// </summary>
public virtual void CleanUp()
{
DecisionValue = -1;
ClearObservers();
}
/// <summary>
/// Creates the everything needed to
/// determine the decision
/// </summary>
public abstract void CreateDecision();
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
namespace Framework.Tasks.Decisions
{
public class DeviceDecision : Decision, Observer
public class DeviceDecision : Decision, IObserver
{
private Request request;
public Request Request { get => request; set => SetCondtion(value); }
......
......@@ -2,7 +2,7 @@
namespace Framework.Tasks.FinishingConditions
{
public class DeviceCondition : FinishingCondition, Observer
public class DeviceCondition : FinishingCondition, IObserver
{
private Request condtion;
public Request Condtion { get => condtion; set => SetCondtion(value); }
......

namespace Framework.Tasks.FinishingConditions
{
/// <summary>
/// Determines if a <c>WorkingTask</c> is finished
/// </summary>
public abstract class FinishingCondition : Subject
{
private bool fullFilled;
......@@ -16,12 +19,20 @@ namespace Framework.Tasks.FinishingConditions
}
}
/// <summary>
/// Needs to be called after the result of
/// the condition is no longer needed
/// </summary>
public virtual void CleanUp()
{
fullFilled = false;
ClearObservers();
}
/// <summary>
/// Creates the everything needed to
/// determine the condition
/// </summary>
public abstract void CreateCondition();
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ namespace Framework.Tasks.Info
/// <summary>
/// Represents any kind of given information
/// </summary>
public abstract class Information : Observer
public abstract class Information : IObserver
{
/// <summary>
/// Creates the specified information
......
......@@ -6,7 +6,7 @@ namespace Framework.Tasks.Info.InformationParts
/// <summary>
/// Represents image or text information
/// </summary>
public abstract class InformationPart : Observer
public abstract class InformationPart : IObserver
{
protected float y;
protected float x;
......@@ -21,9 +21,19 @@ namespace Framework.Tasks.Info.InformationParts
public float Height { get => height; set => height = value; }
private Request selector;
/// <summary>
/// Represent the request that selects
/// which information should be shown
/// </summary>
public Request Selector { get => selector; set => SetSelector(value); }
public abstract void ObserverUpdate();
/// <summary>
/// Creates the specified information
/// </summary>
/// <returns><c>GameObject</c> which represents the information</returns>
public abstract GameObject GetObject();
/// <summary>
......@@ -54,6 +64,10 @@ namespace Framework.Tasks.Info.InformationParts
this.selector = selector;
}
/// <summary>
/// Returns value of the selector as integer.
/// Returns <c>0</c> if there is no selector
/// </summary>
protected int GetValue()
{
return Selector != null ? Selector.ValueAsInt() : 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment