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

+Documentation +misc

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