public static ProtocolStatus SetSession(int session, int element = 0) { currentSession = null; currentSessionElement = null; nextSessionElementIndex = -1; if (loadedProtocol == "") { return(ProtocolStatus.Uninitialized); } if (!protocolDictionary.ContainsKey(currentProtocol.id)) { return(ProtocolStatus.InvalidProtocol); } if (session >= currentProtocol.Count) { return(ProtocolStatus.SessionLimitExceeded); } SessionNumber = session; currentSession = currentProtocol[session]; if (element >= currentSession.Count) { return(ProtocolStatus.SessionElementLimitExceeded); } //The next session element to run will be the current one nextSessionElementIndex = element; return(ProtocolStatus.SessionReady); }
public void Add(SessionElement element) { //It was supremely convenient for constructing tasks to allow for (and block) // null session elements if (element != null) { sessionElements.Add(element); } }
public static void HardClearAll() { loadedProtocol = ""; protocolDictionary.Clear(); sessionDictionary.Clear(); sessionElementDictionary.Clear(); Protocol.HardClear(); Session.HardClear(); SessionElement.HardClear(); }
public static void DeserializeSessionElements(JsonArray elements) { sessionElementDictionary.Clear(); foreach (JsonObject element in elements) { SessionElement parsedElement = parseSessionElement?.Invoke(element); if (parsedElement == null) { Debug.LogError($"Failed to parse SessionElement: {element.ToString()}"); continue; } sessionElementDictionary.Add(parsedElement.id, parsedElement); } }
public static void PrepareProtocol(string protocolName, int protocolID) { currentProtocol = null; currentSession = null; currentSessionElement = null; nextSessionElementIndex = -1; loadedProtocol = ""; LoadProtocolSet(protocolName); if (protocolDictionary.ContainsKey(protocolID)) { currentProtocol = protocolDictionary[protocolID]; } else { Debug.LogError($"Loaded Protocol \"{loadedProtocol}\" does not contain requested protocolID {protocolID}."); return; } }
public static ProtocolStatus ExecuteNextElement(bool resuming = false) { if (nextSessionElementIndex == -1) { return(ProtocolStatus.Uninitialized); } if (nextSessionElementIndex == currentSession.Count) { //In principle, this should only happen if an EndSessionElement was forgotten ElementNumber = 0; SessionInProgress = false; ++SessionNumber; sessionElementOverrun?.Invoke(); PlayerData.Save(); return(ProtocolStatus.SessionFinished); } //This only happens when the last element was running currentSessionElement?.CleanupElement(); currentSessionElement = currentSession[nextSessionElementIndex]; ElementNumber = nextSessionElementIndex; SessionInProgress = true; prepareNextElement?.Invoke(resuming); currentSessionElement.ExecuteElement(resuming); PlayerData.Save(); ++nextSessionElementIndex; return(ProtocolStatus.SessionReady); }