Skip to content
Snippets Groups Projects
Commit 4787a4d5 authored by Marco Zimmer's avatar Marco Zimmer
Browse files

+Documentation +misc

parent 3e34ae10
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@ public static void DestroyAllChildren(this GameObject root)
GameObject.Destroy(root.transform.GetChild(i).gameObject);
}
public static GameObject GetNthChild(this GameObject root, List<int> pos)
public static GameObject GetNthChild(this GameObject root, IEnumerable<int> pos)
{
GameObject ret = root;
foreach (var i in pos)
......
......@@ -185,7 +185,7 @@ public bool set_record(PlayerRecord record)
public void push_record(double seconds_s = -1, bool force_push = false)
{
if(!force_push && StageStatic.devel && creatorMode)
if(!force_push && StageStatic.mode == StageStatic.Mode.Create && creatorMode)
// store solution space
{
SetMode(false);
......
......@@ -12,17 +12,12 @@ void Start()
private void OnDestroy()
{
StageStatic.devel = false;
StageStatic.SetMode(Mode.Play); // no Mode.Create
StageStatic.stage.solution.hardreset();
StageStatic.stage.factState.hardreset();
}
public void SetDevel(bool devel)
{
StageStatic.devel = devel;
gameObject.UpdateTagActive("DevelopingMode", devel);
}
// needed as endpoint for unity buttons
public void SetMode(bool create)
{
SetMode(create ? Mode.Create : Mode.Play);
......
......@@ -4,26 +4,56 @@
using System;
using UnityEngine;
/// <summary>
/// Keeps track of all available and current <see cref="Stage"/>
/// </summary>
public static class StageStatic
{
/// <summary>
/// - <c>Key</c>: stage name
/// - <c>Value</c>: stages created by KWARC
/// </summary>
public static Dictionary<string, Stage> StageOfficial;
/// <summary>
/// - <c>Key</c>: stage name
/// - <c>Value</c>: stages created by local user
/// </summary>
public static Dictionary<string, Stage> StageLocal;
/// <summary>
/// Used to map <see cref="StageOfficial"/> <see cref="Stage.category">categories</see> into a ordered list for the StageMenue.
/// </summary>
public static Dictionary<string, int> Category = new Dictionary<string, int> {
{ "", -1 },
{ "Demo Category", 0 },
};
/// <summary>
/// <see cref="Stage.name"/> of current <see cref="stage"/> or one to be loaded.
/// <seealso cref="LoadInitStage(bool, GameObject)"/>
/// </summary>
public static string current_name;
public static bool local_stage;
public static bool devel = false;
/// <summary>
/// !<see cref="Stage.use_install_folder"/> of current <see cref="stage"/> or one to be loaded.
/// <seealso cref="LoadInitStage(bool, GameObject)"/>
/// </summary>
public static bool local_stage;
/// <summary>
/// Current <see cref="Mode"/>
/// </summary>
public static Mode mode;
public static List<string> Worlds
{
get { return _Worlds ?? GenerateWorldList(); }
}
private static List<string> _Worlds = null;
/// <summary>
/// Loadable world scenes
/// </summary>
public static readonly List<string> Worlds = GenerateWorldList();
/// <summary>
/// Current <see cref="Stage"/>
/// </summary>
public static Stage stage {
get {
return (local_stage ? StageLocal : StageOfficial)[current_name];
......@@ -39,19 +69,25 @@ public static Stage stage {
}
}
// TODO: set when encountering an error
public static StageErrorStruct error {
/// <summary>
/// TODO: set when encountering an error
/// </summary>
public static StageErrorStruct last_error {
get;
private set;
}
// TODO! generate at buildtime
/// <summary>
/// Extracts all loadable scenes for <see cref="Worlds"/>.
/// </summary>
/// <returns><see cref="Worlds"/></returns>
private static List<string> GenerateWorldList()
{
#if UNITY_EDITOR
_Worlds = new List<string>();
List<string> _Worlds = new List<string>();
string world = "World";
string ending = ".unity";
......@@ -69,31 +105,57 @@ private static List<string> GenerateWorldList()
}
}
#else
_Worlds = new List<string> {"TreeWorld", "RiverWorld"};
List<string> _Worlds = new List<string> {"TreeWorld", "RiverWorld"};
Debug.Log("WorldList might be incomplete or incorrect!");
#endif
return _Worlds;
}
/// <summary>
/// Available Modes a <see cref="Stage"/> to be selected and/ or loaded in.
/// </summary>
public enum Mode
{
Play,
Create,
}
/// <summary>
/// Created when an error (may) occures while a <see cref="Stage"/> is being created, because of incompatible variables.
/// </summary>
public struct StageErrorStruct
{
/// <summary> set iff <see cref="Stage.category"/> is incompatible </summary>
public bool category { get { return state[0]; } set { state[0] = value; } }
/// <summary> set iff <see cref="Stage.number"/> is incompatible </summary>
public bool id { get { return state[1]; } set { state[1] = value; } }
/// <summary> set iff <see cref="Stage.name"/> is incompatible </summary>
public bool name { get { return state[2]; } set { state[2] = value; } }
/// <summary> set iff <see cref="Stage.description"/> is incompatible </summary>
public bool description { get { return state[3]; } set { state[3] = value; } }
/// <summary> set iff <see cref="Stage.scene"/> is incompatible </summary>
public bool scene { get { return state[4]; } set { state[4] = value; } }
/// <summary> set iff !<see cref="Stage.use_install_folder"/> is incompatible </summary>
public bool local { get { return state[5]; } set { state[5] = value; } }
/// <summary> set iff <see cref="Stage.path"/> was not found </summary>
public bool load { get { return state[6]; } set { state[6] = value; } }
/// <summary>
/// stores all boolish members, to iterate over
/// </summary>
private bool[] state;
/// <summary>
/// <see langword="true"/> iff no error occures.
/// </summary>
public bool pass
{
get { return state.Aggregate(true, (last, next) => last && !next); }
......@@ -103,6 +165,10 @@ public readonly static StageErrorStruct
InvalidFolder = new StageErrorStruct(false, false, false, false, false, true, false),
NotLoadable = new StageErrorStruct(false, false, false, false, false, false, true);
/// <summary>
/// Initiator <br/>
/// canonical
/// </summary>
public StageErrorStruct(bool category, bool id, bool name, bool description, bool scene, bool local, bool load)
{
state = new bool[7];
......@@ -117,6 +183,11 @@ public StageErrorStruct(bool category, bool id, bool name, bool description, boo
}
}
/// <summary>
/// sets <see cref="mode"/> and en-/ disables children of <paramref name="gameObject"/> with certain Tags, only available in certain <see cref="Mode">Modes</see> (e.g. in Def_Stage)
/// </summary>
/// <param name="mode"><see cref="Mode"/> to set</param>
/// <param name="gameObject"> which children will be checked</param>
public static void SetMode(Mode mode, GameObject gameObject = null)
{
gameObject ??= new GameObject();
......@@ -137,7 +208,8 @@ public static void SetMode(Mode mode, GameObject gameObject = null)
{
case Mode.Play:
case Mode.Create:
stage.SetMode(mode == Mode.Create);
if (ContainsKey(current_name, local_stage))
stage.SetMode(mode == Mode.Create);
break;
}
......@@ -170,15 +242,24 @@ public static StageErrorStruct LoadNewStage(string category, int id, string name
return ret;
}
/// <summary>
/// Load current <see cref="stage"/> in <see cref="Mode.Create"/>
/// </summary>
public static void LoadCreate()
{
devel = true;
SetMode(Mode.Create);
Loader.LoadScene(stage.scene);
}
public static int NextNumber(bool local)
/// <summary>
/// Finds first unused <see cref="Stage.number"/> in a certain <paramref name="category"/>.
/// </summary>
/// <param name="local">which kind of stage we are looking at</param>
/// <param name="category">the category in question</param>
/// <returns>first unused <see cref="Stage.number"/> in a certain <paramref name="category"/></returns>
public static int NextNumber(bool local, string category)
{
var numbers = (local ? StageLocal : StageOfficial).Values.Select(s => s.number).ToList();
var numbers = (local ? StageLocal : StageOfficial).Values.Where(s => s.category == category).Select(s => s.number).ToList();
if (0 == numbers.Count)
return 1;
......@@ -260,11 +341,11 @@ public static bool LoadInitStage(bool restore_session, GameObject gameObject = n
else
{
stage.ResetPlay();
if(devel) // block saving "player" progress
if(mode == Mode.Create) // block saving "player" progress
stage.player_record.seconds = -1;
}
gameObject.UpdateTagActive("DevelopingMode", devel);
gameObject.UpdateTagActive("DevelopingMode", mode == Mode.Create);
SetMode(stage.creatorMode ? Mode.Create : Mode.Play);
return true;
}
......@@ -273,7 +354,7 @@ public static bool ContainsKey(string key)
{
return ContainsKey(key, local_stage);
}
public static bool ContainsKey(string key, bool local = false)
public static bool ContainsKey(string key, bool local)
{
return (local ? StageLocal : StageOfficial).ContainsKey(key);
}
......
......@@ -26,7 +26,7 @@ public void Init()
// set implicit load button (whole header)
header.GetComponent<UnityEngine.UI.Button>().onClick.AddListener(delegate {
StageStatic.devel = false;
StageStatic.SetMode(StageStatic.Mode.Play);
// TODO: handle unable to load
Loader.LoadStage(stage.name, !stage.use_install_folder, true);
});
......@@ -76,7 +76,7 @@ public void DrawChildren()
this.Init();
return;
}
StageStatic.devel = false;
StageStatic.SetMode(StageStatic.Mode.Play);
// TODO: handle unable to load
Loader.LoadStage(stage.name, !stage.use_install_folder, true);
});
......
......@@ -18,7 +18,7 @@ protected string category
set { Category.text = value; }
}
protected int id {
get { return Id.text.Length == 0 ? StageStatic.NextNumber(true) : int.Parse(Id.text); }
get { return Id.text.Length == 0 ? StageStatic.NextNumber(true, category) : int.Parse(Id.text); }
set { Id.text = value.ToString(); }
}
protected new string name {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment