public override bool isValid(string currentPath, List <string> incidences) { var valid = score != null; if (!valid) { return(false); } if (score.getMethod() == Completable.Score.ScoreMethod.SINGLE) { valid &= scoreDataControls.Count == 0; if (score.getType() == Completable.Score.ScoreType.COMPLETABLE) { valid &= controller.IdentifierSummary.getIds <Completable>().Contains(score.getId()); } } else { valid &= scoreDataControls.Count > 0; } valid &= scoreDataControls.All(s => s.isValid(currentPath, incidences)); return(valid); }
public static XmlElement buildScoreDOM(Completable.Score score) { XmlElement progressNode = Writer.GetDoc().CreateElement("score"); progressNode.SetAttribute("type", score.getType().ToString()); progressNode.SetAttribute("method", score.getMethod().ToString()); if (score.getMethod() == Completable.Score.ScoreMethod.SINGLE) { progressNode.SetAttribute("id", score.getId()); } else { XmlElement subScores = Writer.GetDoc().CreateElement("sub-scores"); foreach (Completable.Score s in score.getSubScores()) { subScores.AppendChild(CompletableDOMWriter.buildScoreDOM(s)); } progressNode.AppendChild(subScores); } return(progressNode); }
private float CalculateScore(Completable.Score completableScore) { float score = 0; switch (completableScore.getMethod()) { // Base case (calculated based on target) case Completable.Score.ScoreMethod.SINGLE: var targetId = completableScore.getId(); switch (completableScore.getType()) { case Completable.Score.ScoreType.VARIABLE: // In case of variable type, the target id points to a variable var variableValue = Game.Instance.GameState.GetVariable(targetId); score = variableValue; break; case Completable.Score.ScoreType.COMPLETABLE: // In case of completable type, the target id points to a completable var referencedCompletable = CompletablesController.Instance.GetCompletable(targetId); score = referencedCompletable.Score; break; } break; // Recursive cases (calculated based on subscores) case Completable.Score.ScoreMethod.AVERAGE: score = completableScore.getSubScores().Average(s => CalculateScore(s)); break; case Completable.Score.ScoreMethod.SUM: score = completableScore.getSubScores().Sum(s => CalculateScore(s)); break; } return(score); }