Exemple #1
0
        internal bool Run(ExpressionGroup expressionGroup, out InterpreterScope scope)
        {
            var parseError = expressionGroup.Expressions.OfType <ParseErrorExpression>().FirstOrDefault();

            if (parseError != null)
            {
                Error = parseError;
                scope = null;
                return(false);
            }

            scope         = new InterpreterScope(GetGlobalScope());
            scope.Context = new AchievementScriptContext
            {
                Achievements = _achievements,
                Leaderboards = _leaderboards,
                RichPresence = _richPresence
            };

            if (!Evaluate(expressionGroup.Expressions, scope))
            {
                var error = Error;
                if (error != null)
                {
                    expressionGroup.Errors.Add(error);
                }

                return(false);
            }

            if (!String.IsNullOrEmpty(_richPresence.DisplayString))
            {
                RichPresence     = _richPresence.ToString();
                RichPresenceLine = _richPresence.Line;
            }

            return(true);
        }
Exemple #2
0
        internal bool Run(ExpressionGroupCollection expressionGroups, IScriptInterpreterCallback callback)
        {
            AchievementScriptContext scriptContext = null;
            InterpreterScope         scope         = expressionGroups.Scope;

            if (scope != null)
            {
                scriptContext = scope.GetContext <AchievementScriptContext>();
            }

            if (scriptContext == null)
            {
                scriptContext = new AchievementScriptContext();
                scope         = new InterpreterScope(expressionGroups.Scope ?? GetGlobalScope())
                {
                    Context = scriptContext
                };
            }

            expressionGroups.ResetErrors();

            bool result = true;

            foreach (var expressionGroup in expressionGroups.Groups)
            {
                if (expressionGroup.NeedsEvaluated)
                {
                    if (scriptContext.Achievements == null)
                    {
                        scriptContext.Achievements = new List <Achievement>();
                    }
                    if (scriptContext.Leaderboards == null)
                    {
                        scriptContext.Leaderboards = new List <Leaderboard>();
                    }
                    if (scriptContext.RichPresence == null)
                    {
                        scriptContext.RichPresence = new RichPresenceBuilder();
                    }

                    if (!Evaluate(expressionGroup.Expressions, scope, callback))
                    {
                        var error = Error;
                        if (error != null)
                        {
                            expressionGroups.AddEvaluationError(error);
                        }

                        result = false;
                    }

                    if (scriptContext.Achievements.Count > 0)
                    {
                        expressionGroup.GeneratedAchievements = scriptContext.Achievements;
                        scriptContext.Achievements            = null;
                    }
                    else if (expressionGroup.GeneratedAchievements != null)
                    {
                        expressionGroup.GeneratedAchievements = null;
                    }

                    if (scriptContext.Leaderboards.Count > 0)
                    {
                        expressionGroup.GeneratedLeaderboards = scriptContext.Leaderboards;
                        scriptContext.Leaderboards            = null;
                    }
                    else if (expressionGroup.GeneratedLeaderboards != null)
                    {
                        expressionGroup.GeneratedLeaderboards = null;
                    }

                    if (!scriptContext.RichPresence.IsEmpty)
                    {
                        expressionGroup.GeneratedRichPresence = scriptContext.RichPresence;
                        scriptContext.RichPresence            = null;
                    }

                    expressionGroup.MarkEvaluated();
                }
            }

            if (!ReferenceEquals(scope, expressionGroups.Scope))
            {
                if (scope.FunctionCount > 0 || scope.VariableCount > 0)
                {
                    if (expressionGroups.Scope != null)
                    {
                        expressionGroups.Scope.Merge(scope);
                    }
                    else
                    {
                        expressionGroups.Scope = scope;
                    }
                }
            }

            _achievements.Clear();
            _leaderboards.Clear();
            _richPresence.Clear();

            foreach (var expressionGroup in expressionGroups.Groups)
            {
                if (expressionGroup.GeneratedAchievements != null)
                {
                    _achievements.AddRange(expressionGroup.GeneratedAchievements);
                }

                if (expressionGroup.GeneratedLeaderboards != null)
                {
                    _leaderboards.AddRange(expressionGroup.GeneratedLeaderboards);
                }

                if (expressionGroup.GeneratedRichPresence != null)
                {
                    var error = _richPresence.Merge(expressionGroup.GeneratedRichPresence);
                    if (error != null)
                    {
                        expressionGroups.AddEvaluationError(error);
                        result = false;
                    }
                }
            }

            double minimumVersion = 0.30;

            foreach (var achievement in _achievements)
            {
                var achievementMinimumVersion = AchievementBuilder.GetMinimumVersion(achievement);
                if (achievementMinimumVersion > minimumVersion)
                {
                    minimumVersion = achievementMinimumVersion;
                }
            }

            foreach (var leaderboard in _leaderboards)
            {
                var leaderboardMinimumVersion = AchievementBuilder.GetMinimumVersion(leaderboard);
                if (leaderboardMinimumVersion > minimumVersion)
                {
                    minimumVersion = leaderboardMinimumVersion;
                }
            }

            _richPresence.DisableLookupCollapsing = (minimumVersion < 0.79);
            _richPresence.DisableBuiltInMacros    = (minimumVersion < 0.80);

            if (!String.IsNullOrEmpty(_richPresence.DisplayString))
            {
                RichPresence     = _richPresence.ToString();
                RichPresenceLine = _richPresence.Line;
            }

            if (Error == null)
            {
                Error = expressionGroups.Errors.FirstOrDefault();
            }

            return(result);
        }