Esempio n. 1
0
        public void ToWorkshop(WorkshopBuilder builder, List <LobbySetting> allSettings)
        {
            builder.AppendKeywordLine("heroes");
            builder.AppendLine("{");
            builder.Indent();

            if (General != null)
            {
                builder.AppendKeywordLine("General");
                builder.AppendLine("{");
                builder.Indent();
                General.ToWorkshop(builder, allSettings);
                builder.Unindent();
                builder.AppendLine("}");
            }
            if (Team1 != null)
            {
                builder.AppendKeywordLine("Team 1");
                builder.AppendLine("{");
                builder.Indent();
                Team1.ToWorkshop(builder, allSettings);
                builder.Unindent();
                builder.AppendLine("}");
            }
            if (Team2 != null)
            {
                builder.AppendKeywordLine("Team 2");
                builder.AppendLine("{");
                builder.Indent();
                Team2.ToWorkshop(builder, allSettings);
                builder.Unindent();
                builder.AppendLine("}");
            }

            builder.Unindent();
            builder.AppendLine("}");
        }
        public void ToWorkshop(WorkshopBuilder builder)
        {
            if (Subroutines.Count == 0)
            {
                return;
            }

            builder.AppendKeywordLine("subroutines");
            builder.AppendLine("{");
            builder.Indent();

            foreach (Subroutine routine in Subroutines)
            {
                builder.AppendLine(routine.ID.ToString() + ": " + routine.Name);
            }

            builder.Unindent();
            builder.AppendLine("}");
            builder.AppendLine();
        }
Esempio n. 3
0
        public void ToWorkshop(WorkshopBuilder builder, List <LobbySetting> allSettings, string modeName)
        {
            bool enabled = Settings == null || !Settings.TryGetValue("Enabled", out object value) || (value is bool b && b);

            Settings?.Remove("Enabled");

            if (!enabled)
            {
                builder.AppendKeyword("disabled").Append(" ");
            }
            builder.AppendKeywordLine(modeName);

            if (EnabledMaps != null || DisabledMaps != null || (Settings != null && Settings.Count > 0))
            {
                builder.AppendLine("{");
                builder.Indent();

                if (Settings != null)
                {
                    WorkshopValuePair.ToWorkshop(Settings, builder, allSettings);
                }

                if (EnabledMaps != null)
                {
                    builder.AppendKeywordLine("enabled maps");
                    Ruleset.WriteList(builder, EnabledMaps);
                }
                if (DisabledMaps != null)
                {
                    builder.AppendKeywordLine("disabled maps");
                    Ruleset.WriteList(builder, DisabledMaps);
                }

                builder.Unindent();
                builder.AppendLine("}");
            }
        }
 public void ToWorkshop(WorkshopBuilder builder, List <LobbySetting> allSettings)
 {
     foreach (var hero in Settings)
     {
         builder.AppendLine($"{hero.Key}");
         builder.AppendLine("{");
         builder.Indent();
         WorkshopValuePair.ToWorkshop(((JObject)hero.Value).ToObject <Dictionary <string, object> >(), builder, allSettings);
         builder.Unindent();
         builder.AppendLine("}");
     }
     if (EnabledHeroes != null)
     {
         builder.AppendLine();
         builder.AppendKeywordLine("enabled heroes");
         Ruleset.WriteList(builder, EnabledHeroes);
     }
     if (DisabledHeroes != null)
     {
         builder.AppendLine();
         builder.AppendKeywordLine("disabled heroes");
         Ruleset.WriteList(builder, DisabledHeroes);
     }
 }
        public void ToWorkshop(WorkshopBuilder builder, bool optimize)
        {
            if (Disabled)
            {
                builder.AppendKeyword("disabled")
                .Append(" ");
            }
            builder.AppendKeyword("rule")
            .AppendLine("(\"" + Name + "\")")
            .AppendLine("{")
            .AppendLine()
            .Indent()
            .AppendKeywordLine("event")
            .AppendLine("{")
            .Indent()
            .AppendLine(EnumData.GetEnumValue(RuleEvent).ToWorkshop(builder.OutputLanguage, ToWorkshopContext.Other) + ";");

            // Add attributes.
            switch (RuleType)
            {
            case RuleType.PlayerBased:
                // Player based attributes
                builder.AppendLine(EnumData.GetEnumValue(Team).ToWorkshop(builder.OutputLanguage, ToWorkshopContext.Other) + ";");     // Team attribute
                builder.AppendLine(EnumData.GetEnumValue(Player).ToWorkshop(builder.OutputLanguage, ToWorkshopContext.Other) + ";");   // Player attribute
                break;

            case RuleType.Subroutine:
                builder.AppendLine(Subroutine.ToWorkshop(builder.OutputLanguage, ToWorkshopContext.Other) + ";");     // Attribute name
                break;
            }
            builder.Unindent()
            .AppendLine("}");

            if (Conditions?.Length > 0)
            {
                builder.AppendLine()
                .AppendKeywordLine("conditions")
                .AppendLine("{")
                .Indent();

                foreach (var condition in Conditions)
                {
                    builder.AppendLine(condition.ToWorkshop(builder.OutputLanguage, optimize) + ";");
                }

                builder.Unindent()
                .AppendLine("}");
            }

            // Add actions.
            if (Actions?.Length > 0)
            {
                builder.AppendLine()
                .AppendLine("// Action count: " + Actions.Length)     // Action count comment.
                .AppendKeywordLine("actions")
                .AppendLine("{")
                .Indent();

                foreach (var action in Actions)
                {
                    if (optimize)
                    {
                        builder.AppendLine(action.Optimize().ToWorkshop(builder.OutputLanguage, ToWorkshopContext.Action));
                    }
                    else
                    {
                        builder.AppendLine(action.ToWorkshop(builder.OutputLanguage, ToWorkshopContext.Action));
                    }
                }

                builder.Unindent()
                .AppendLine("}");
            }
            builder.Unindent()
            .AppendLine("}");
        }
        public void ToWorkshop(WorkshopBuilder builder)
        {
            if (globalLimitReached || playerLimitReached || extGlobalLimitReached || extPlayerLimitReached)
            {
                List <string> collectionLimitsReached = new List <string>();

                // Add names of the collections that exceed their variable limit.
                if (globalLimitReached)
                {
                    collectionLimitsReached.Add("global");
                }
                if (playerLimitReached)
                {
                    collectionLimitsReached.Add("player");
                }
                if (extGlobalLimitReached)
                {
                    collectionLimitsReached.Add("ext. global");
                }
                if (extPlayerLimitReached)
                {
                    collectionLimitsReached.Add("ext. player");
                }

                builder.AppendLine(string.Format(
                                       "// The {0} reached the variable limit. Only a maximum of 128 variables and 1000 extended variables can be assigned.",
                                       Extras.ListJoin("variable collection", collectionLimitsReached.ToArray())
                                       ));
                builder.AppendLine();
            }

            builder.AppendKeywordLine("variables");
            builder.AppendLine("{");
            builder.Indent();
            builder.AppendKeyword("global"); builder.Append(":"); builder.AppendLine();
            builder.Indent();
            WriteCollection(builder, variableList(true));
            builder.Unindent();

            builder.AppendKeyword("player"); builder.Append(":"); builder.AppendLine();
            builder.Indent();
            WriteCollection(builder, variableList(false));
            builder.Unindent();
            builder.Unindent();
            builder.AppendLine("}");

            bool anyExtendedGlobal = ExtendedVariableList(true).Any(v => v != null);
            bool anyExtendedPlayer = ExtendedVariableList(false).Any(v => v != null);

            if (anyExtendedGlobal || anyExtendedPlayer)
            {
                builder.AppendLine();
                builder.AppendLine($"// Extended collection variables:");

                foreach (var ex in ExtendedVariableList(true))
                {
                    builder.AppendLine($"// global [{ex.Index}]: {ex.DebugName}");
                }
                foreach (var ex in ExtendedVariableList(false))
                {
                    builder.AppendLine($"// player [{ex.Index}]: {ex.DebugName}");
                }
            }
        }