Exemple #1
0
        public string ToWorkshop()
        {
            var builder = new TabStringBuilder(true);

            builder.Indent = 0;                                                       //
            builder.AppendLine($"rule(\"{Name}\")");                                  // rule("this is the name of the rule!")
            builder.AppendLine("{");                                                  // {
            builder.AppendLine();                                                     //
                                                                                      //
            builder.Indent = 1;                                                       // (indent)
            builder.AppendLine("event");                                              //     event
            builder.AppendLine("{");                                                  //     {
            builder.Indent = 2;                                                       //     (indent)
            builder.AppendLine(EnumData.GetEnumValue(RuleEvent).ToWorkshop() + ";");  //         Ongoing - Each Player
            if (!IsGlobal)                                                            //       --(only if the event is a player event)
            {                                                                         //       |
                builder.AppendLine(EnumData.GetEnumValue(Team).ToWorkshop() + ";");   //       | Team 1
                builder.AppendLine(EnumData.GetEnumValue(Player).ToWorkshop() + ";"); //       | Bastion
            }                                                                         //
            builder.Indent = 1;                                                       //     (outdent)
            builder.AppendLine("}");                                                  //     }
                                                                                      //
            if (Conditions?.Length > 0)                                               // (only if there are 1 or more conditions)
            {                                                                         // |
                builder.AppendLine();                                                 // |
                builder.AppendLine("conditions");                                     // |   conditions
                builder.AppendLine("{");                                              // |   {
                builder.Indent = 2;                                                   // |   (indent)
                foreach (var condition in Conditions)                                 // |
                {
                    builder.AppendLine(condition.ToWorkshop() + ";");                 // |       Number Of Players >= 3;
                }
                builder.Indent = 1;                                                   // |   (outdent)
                builder.AppendLine("}");                                              // |   }
            }                                                                         //
                                                                                      //
            if (Actions?.Length > 0)                                                  // (only if there are 1 or more actions)
            {                                                                         // |
                builder.AppendLine();                                                 // |
                builder.AppendLine("// Action count: " + Actions.Length);             // |   // Action count: #
                builder.AppendLine("actions");                                        // |   actions
                builder.AppendLine("{");                                              // |   {
                builder.Indent = 2;                                                   // |   (indent)
                foreach (var action in Actions)                                       // |
                {
                    builder.AppendLine(action.ToWorkshop());                          // |       Set Global Variable(A, true);
                }
                builder.Indent = 1;                                                   // |   (outdent)
                builder.AppendLine("}");                                              // |   }
            }                                                                         //
            builder.Indent = 0;                                                       // (outdent)
            builder.AppendLine("}");                                                  // }

            return(builder.ToString());
        }
        // Converts an array of actions to a workshop
        public static string ToWorkshop(Element[] actions)
        {
            var builder = new TabStringBuilder(true);

            builder.AppendLine("actions");
            builder.AppendLine("{");
            builder.Indent = 1;
            foreach (Element action in actions)
            {
                builder.AppendLine(action.ToWorkshop());
            }
            builder.Indent = 0;
            builder.AppendLine("}");

            return(builder.ToString());
        }
        public string ToWorkshop(OutputLanguage language, bool optimize)
        {
            var builder = new TabStringBuilder(true);

            builder.Indent = 0;
            if (Disabled)
            {
                builder.Append(LanguageInfo.Translate(language, "disabled") + " ");
            }
            builder.AppendLine($"{LanguageInfo.Translate(language, "rule")}(\"{Name}\")");
            builder.AppendLine("{");
            builder.AppendLine();

            builder.Indent = 1;
            builder.AppendLine(LanguageInfo.Translate(language, "event"));
            builder.AppendLine("{");
            builder.Indent = 2;
            builder.AppendLine(EnumData.GetEnumValue(RuleEvent)
                               .ToWorkshop(language) + ";");

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

            case RuleType.Subroutine:
                builder.AppendLine(Subroutine.ToWorkshop(language) + ";");     // Attribute name
                break;
            }
            builder.Indent = 1;
            builder.AppendLine("}");

            if (Conditions?.Length > 0)
            {
                builder.AppendLine();
                builder.AppendLine(LanguageInfo.Translate(language, "conditions"));
                builder.AppendLine("{");
                builder.Indent = 2;
                foreach (var condition in Conditions)
                {
                    builder.AppendLine(condition.ToWorkshop(language, optimize) + ";");
                }
                builder.Indent = 1;
                builder.AppendLine("}");
            }

            // Add actions.
            if (Actions?.Length > 0)
            {
                builder.AppendLine();
                builder.AppendLine("// Action count: " + Actions.Length); // Action count comment.
                builder.AppendLine(LanguageInfo.Translate(language, "actions"));
                builder.AppendLine("{");
                builder.Indent = 2;

                foreach (var action in Actions)
                {
                    if (optimize)
                    {
                        builder.AppendLine(action.Optimize().ToWorkshop(language));
                    }
                    else
                    {
                        builder.AppendLine(action.ToWorkshop(language));
                    }
                }

                builder.Indent = 1;
                builder.AppendLine("}");
            }
            builder.Indent = 0;
            builder.AppendLine("}");

            return(builder.ToString());
        }