public virtual void ToWorkshop(WorkshopBuilder b, ToWorkshopContext context)
        {
            var action = Function as ElementJsonAction;

            if (action != null && (action.Indentation == "outdent" || action.Indentation == "drop"))
            {
                b.Outdent();
            }

            // Add a comment and newline
            if (Comment != null)
            {
                b.AppendLine($"\"{Comment}\"");
            }

            // Add the disabled tag if the element is disabled.
            if (Function is ElementJsonAction && Disabled)
            {
                b.AppendKeyword("disabled").Append(" ");
            }

            // Add the name of the element.
            b.AppendKeyword(Function.Name);

            // Add the parameters.
            AddMissingParameters();
            if (ParameterValues.Length > 0)
            {
                b.Append("(");
                ParametersToWorkshop(b);
                b.Append(")");
            }

            if (action != null)
            {
                b.AppendLine(";");
                if (action.Indentation == "indent" || action.Indentation == "drop")
                {
                    b.Indent();
                }
            }
        }
Esempio n. 2
0
 public void ToWorkshop(WorkshopBuilder b, ToWorkshopContext context)
 {
     if (_keyword)
     {
         b.AppendKeyword(Value);
     }
     else
     {
         b.Append(Value);
     }
 }
Esempio n. 3
0
        public override void ToWorkshop(WorkshopBuilder b, ToWorkshopContext context)
        {
            b.AppendKeyword(Localized ? "String" : "Custom String");
            b.Append("(\"" + (Localized ? b.Kw(Value) : Value) + "\"");

            if (ParameterValues.Length > 0)
            {
                b.Append(", ");
                ParametersToWorkshop(b);
            }

            b.Append(")");
        }
Esempio n. 4
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 = GetAllSettings();

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

            // Get the description and/or mode name
            if (Description != null || ModeName != null)
            {
                builder.AppendKeywordLine("main")
                .AppendLine("{")
                .Indent();
                if (Description != null)
                {
                    builder.AppendKeyword("Description").Append(": \"" + Description + "\"").AppendLine();
                }
                if (ModeName != null)
                {
                    builder.AppendKeyword("Mode Name").Append(": \"" + ModeName + "\"").AppendLine();
                }
                builder.Outdent()
                .AppendLine("}");
            }

            // Get the lobby settings.
            if (Lobby != null)
            {
                builder.AppendKeywordLine("lobby");
                builder.AppendLine("{");
                builder.Indent();
                Lobby.ToWorkshop(builder, allSettings);
                builder.Outdent();
                builder.AppendLine("}");
            }

            // Get the mode settings.
            if (Modes != null)
            {
                Modes.ToWorkshop(builder, allSettings);
            }

            // Get the hero settings.
            if (Heroes != null)
            {
                Heroes.ToWorkshop(builder, allSettings);
            }

            // Get the custom workshop settings.
            if (Workshop != null)
            {
                builder.AppendKeywordLine("workshop");
                builder.AppendLine("{");
                builder.Indent();
                Workshop.ToWorkshopCustom(builder);
                builder.Outdent();
                builder.AppendLine("}");
            }

            // Get extensions.
            if (Extensions != null)
            {
                builder.AppendKeywordLine("extensions");
                builder.AppendLine("{");
                builder.Indent();

                foreach (var ext in Extensions)
                {
                    if ((bool)ext.Value)
                    {
                        builder.AppendKeywordLine(ext.Key);
                    }
                }

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

            builder.Outdent();
            builder.AppendLine("}");
        }
        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}");
                }
            }
        }
 public void ToWorkshop(WorkshopBuilder builder, ToWorkshopContext context) => builder.AppendKeyword(WorkshopName());
Esempio n. 9
0
        public void ToWorkshop(WorkshopBuilder builder)
        {
            if (Disabled)
            {
                builder.AppendKeyword("disabled")
                .Append(" ");
            }
            builder.AppendKeyword("rule")
            .AppendLine("(\"" + Name + "\")")
            .AppendLine("{")
            .AppendLine()
            .Indent()
            .AppendKeywordLine("event")
            .AppendLine("{")
            .Indent();

            ElementRoot.Instance.GetEnumValue("Event", RuleEvent.ToString()).ToWorkshop(builder, ToWorkshopContext.Other);
            builder.Append(";").AppendLine();

            // Add attributes.
            switch (RuleType)
            {
            case RuleType.PlayerBased:
                // Player based attributes
                ElementEnumMember.Team(Team).ToWorkshop(builder, ToWorkshopContext.Other);                                   // Team attribute
                builder.Append(";").AppendLine();
                ElementRoot.Instance.GetEnumValue("Player", Player.ToString()).ToWorkshop(builder, ToWorkshopContext.Other); // Player attribute
                builder.Append(";").AppendLine();
                break;

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

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

                foreach (var condition in Conditions)
                {
                    condition.ToWorkshop(builder);
                }

                builder.Outdent().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)
                {
                    action.ToWorkshop(builder, ToWorkshopContext.Action);
                }

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