Esempio 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);
        }
Esempio n. 2
0
        public override bool addElement(int type, string id)
        {
            var elementAdded = false;

            if (type == AnalyticsController.SCORE)
            {
                var newSubScore = new Completable.Score();
                newSubScore.setMethod(Completable.Score.ScoreMethod.SINGLE);
                string target = null;
                var    vars   = controller.VarFlagSummary.getVars();
                if (vars != null && vars.Length > 0)
                {
                    target = vars[0];
                    newSubScore.setType(Completable.Score.ScoreType.VARIABLE);
                }
                else
                {
                    var completables = controller.IdentifierSummary.getIds <Completable>();
                    if (completables != null && completables.Length > 0)
                    {
                        target = completables[0];
                        newSubScore.setType(Completable.Score.ScoreType.COMPLETABLE);
                    }
                }

                if (!string.IsNullOrEmpty(target))
                {
                    newSubScore.setId(target);
                    score.addSubScore(newSubScore);
                    scoreDataControls.Add(new ScoreDataControl(newSubScore));
                }
            }

            return(elementAdded);
        }
Esempio n. 3
0
        public void Awake()
        {
            instance = this;
            //Create Main game completable
            var trackerConfigs = Game.Instance.GameState.Data.getObjects <TrackerConfig>();

            PrepareTracker(trackerConfigs.Count == 0 ? new TrackerConfig() : trackerConfigs[0]);

            Completable mainGame = new Completable();

            Completable.Milestone gameStart = new Completable.Milestone();
            gameStart.setType(Completable.Milestone.MilestoneType.SCENE);
            gameStart.setId(Game.Instance.GameState.InitialChapterTarget.getId());
            mainGame.setStart(gameStart);
            mainGame.setId(Game.Instance.GameState.Data.getTitle());
            mainGame.setType(Completable.TYPE_GAME);

            Completable.Milestone gameEnd = new Completable.Milestone();
            gameEnd.setType(Completable.Milestone.MilestoneType.ENDING);
            mainGame.setEnd(gameEnd);

            Completable.Progress gameProgress = new Completable.Progress();
            gameProgress.setType(Completable.Progress.ProgressType.SUM);

            Completable.Score mainScore = new Completable.Score();
            mainScore.setMethod(Completable.Score.ScoreMethod.AVERAGE);

            var completables = Game.Instance.GameState.GetObjects <Completable>();

            foreach (Completable part in completables)
            {
                Completable.Milestone tmpMilestone = new Completable.Milestone();
                tmpMilestone.setType(Completable.Milestone.MilestoneType.COMPLETABLE);
                tmpMilestone.setId(part.getId());
                gameProgress.addMilestone(tmpMilestone);

                Completable.Score tmpScore = new Completable.Score();
                tmpScore.setMethod(Completable.Score.ScoreMethod.SINGLE);
                tmpScore.setType(Completable.Score.ScoreType.COMPLETABLE);
                tmpScore.setId(part.getId());
                mainScore.addSubScore(tmpScore);
            }
            mainGame.setProgress(gameProgress);
            mainGame.setScore(mainScore);

            completables.Insert(0, mainGame);

            SetCompletables(completables);

            Game.Instance.GameState.OnConditionChanged += (_, __) => ConditionChanged();
            Game.Instance.OnTargetChanged     += TargetChanged;
            Game.Instance.OnElementInteracted += ElementInteracted;
        }
Esempio n. 4
0
        // #########################################
        // ############### COMPLETABLES ############
        // #########################################



        private void InitCompletables()
        {
            //Create Main game completabl
            Completable mainGame = new Completable();

            Completable.Milestone gameStart = new Completable.Milestone();
            gameStart.setType(Completable.Milestone.MilestoneType.SCENE);
            gameStart.setId(Game.Instance.GameState.InitialChapterTarget.getId());
            mainGame.setStart(gameStart);
            mainGame.setId(Game.Instance.GameState.Data.getTitle());
            mainGame.setType(Completable.TYPE_GAME);

            Completable.Milestone gameEnd = new Completable.Milestone();
            gameEnd.setType(Completable.Milestone.MilestoneType.ENDING);
            mainGame.setEnd(gameEnd);

            Completable.Progress gameProgress = new Completable.Progress();
            gameProgress.setType(Completable.Progress.ProgressType.SUM);

            Completable.Score mainScore = new Completable.Score();
            mainScore.setMethod(Completable.Score.ScoreMethod.AVERAGE);

            completables = new List <Completable>(Game.Instance.GameState.GetObjects <Completable>());

            foreach (Completable part in completables)
            {
                Completable.Milestone tmpMilestone = new Completable.Milestone();
                tmpMilestone.setType(Completable.Milestone.MilestoneType.COMPLETABLE);
                tmpMilestone.setId(part.getId());
                gameProgress.addMilestone(tmpMilestone);

                Completable.Score tmpScore = new Completable.Score();
                tmpScore.setMethod(Completable.Score.ScoreMethod.SINGLE);
                tmpScore.setType(Completable.Score.ScoreType.COMPLETABLE);
                tmpScore.setId(part.getId());
                mainScore.addSubScore(tmpScore);
            }
            mainGame.setProgress(gameProgress);
            mainGame.setScore(mainScore);

            completables.Insert(0, mainGame);

            SetCompletables(completables);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        private void performAddElement(object sender, string id)
        {
            // If some value was typed and the identifier is valid
            if (!controller.isElementIdValid(id))
            {
                id = controller.makeElementValid(id);
            }

            // Add thew new scene
            var newCompletable = new Completable();

            newCompletable.setId(id);
            var score = new Completable.Score();

            score.setMethod(Completable.Score.ScoreMethod.SINGLE);
            score.setType(Completable.Score.ScoreType.VARIABLE);
            newCompletable.setScore(score);
            completables.Add(newCompletable);
            completableDataControls.Add(new CompletableDataControl(newCompletable));
            controller.IdentifierSummary.addId <Completable>(id);
            controller.DataModified();
        }
        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);
        }
Esempio n. 8
0
 public ScoreDataControl(Completable.Score score)
 {
     this.score             = score;
     this.scoreDataControls = score.getSubScores().ConvertAll(s => new ScoreDataControl(s));
 }