Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private Completable.Score parseScore(XmlElement element, params object[] parameters)
        {
            Completable.Score score = new Completable.Score();

            string tmpString = "";

            tmpString = element.GetAttribute("type");
            if (!string.IsNullOrEmpty(tmpString))
            {
                score.setType(ParseEnum <Completable.Score.ScoreType>(tmpString));
            }

            tmpString = element.GetAttribute("method");
            if (!string.IsNullOrEmpty(tmpString))
            {
                score.setMethod(ParseEnum <Completable.Score.ScoreMethod>(tmpString));
            }

            if (score.getMethod() == Completable.Score.ScoreMethod.SINGLE)
            {
                tmpString = element.GetAttribute("id");
                if (!string.IsNullOrEmpty(tmpString))
                {
                    score.setId(tmpString);
                }
            }
            else
            {
                XmlNode subscores = element.SelectSingleNode("sub-scores");

                if (subscores != null)
                {
                    foreach (XmlElement subscore in subscores.ChildNodes)
                    {
                        score.addSubScore(parseScore(subscore, parameters));
                    }
                }
            }

            return(score);
        }
Ejemplo n.º 3
0
        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 = AnalyticsExtension.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);
        }
Ejemplo n.º 4
0
 public override bool canAddElement(int type)
 {
     return(score.getMethod() != Completable.Score.ScoreMethod.SINGLE && type == AnalyticsController.SCORE);
 }