public static void ToWorkshop(Dictionary <String, object> dict, WorkshopBuilder builder, List <LobbySetting> allSettings) { foreach (var setting in dict) { // Get the related setting. LobbySetting relatedSetting = allSettings.FirstOrDefault(ls => ls.Name == setting.Key); string name = relatedSetting.ResolveName(builder); string value = relatedSetting.GetValue(builder, setting.Value); builder.AppendLine($"{name}: {value}"); } }
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(")"); }
public static void WriteList(WorkshopBuilder builder, string[] maps) { builder.AppendLine("{"); builder.Indent(); foreach (string map in maps) { builder.AppendLine(builder.Translate(map).RemoveStructuralChars()); } builder.Unindent(); builder.AppendLine("}"); }
public void PrintClassIdentifiers(WorkshopBuilder builder) { builder.AppendLine("// Class identifiers:"); foreach (CodeType type in AllTypes) { if (type is ClassType classType && classType.Identifier > 0) { builder.AppendLine("// " + classType.Name + ": " + classType.Identifier); } } builder.AppendLine(); }
public void ToWorkshop(WorkshopBuilder builder) { List <LobbySetting> allSettings = GetAllSettings(); builder.AppendKeywordLine("settings"); builder.AppendLine("{"); builder.Indent(); // Get the description if (Description != null) { builder.AppendKeywordLine("main") .AppendLine("{") .Indent() .AppendKeyword("Description").Append(": \"" + Description + "\"").AppendLine() .Unindent() .AppendLine("}"); } // Get the lobby settings. if (Lobby != null) { builder.AppendKeywordLine("lobby"); builder.AppendLine("{"); builder.Indent(); Lobby.ToWorkshop(builder, allSettings); builder.Unindent(); builder.AppendLine("}"); } // Get the mode settings. if (Modes != null) { Modes.ToWorkshop(builder, allSettings); } // Get the hero settings. if (Heroes != null) { Heroes.ToWorkshop(builder, allSettings); } builder.Unindent(); builder.AppendLine("}"); }
public void ToWorkshop(WorkshopBuilder builder) { string result = string.Empty; // Add a comment and newline if (Comment != null) { builder.AppendLine($"\"{Comment}\"\n"); } Value1.ToWorkshop(builder, ToWorkshopContext.ConditionValue); builder.Append(" "); CompareOperator.ToWorkshop(builder, ToWorkshopContext.Other); builder.Append(" "); Value2.ToWorkshop(builder, ToWorkshopContext.ConditionValue); builder.Append(";"); builder.AppendLine(); }
public override string GetValue(WorkshopBuilder builder, object value) { if (SwitchType == SwitchType.OnOff) { return(builder.Translate((bool)value ? "On" : "Off")); } else if (SwitchType == SwitchType.YesNo) { return(builder.Translate((bool)value ? "Yes" : "No")); } else if (SwitchType == SwitchType.EnabledDisabled) { return(builder.Translate((bool)value ? "Enabled" : "Disabled")); } else { throw new NotImplementedException(); } }
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(); } } }
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(); }
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.Outdent(); builder.AppendLine("}"); } if (Team1 != null) { builder.AppendKeywordLine("Team 1"); builder.AppendLine("{"); builder.Indent(); Team1.ToWorkshop(builder, allSettings); builder.Outdent(); builder.AppendLine("}"); } if (Team2 != null) { builder.AppendKeywordLine("Team 2"); builder.AppendLine("{"); builder.Indent(); Team2.ToWorkshop(builder, allSettings); builder.Outdent(); builder.AppendLine("}"); } builder.Outdent(); builder.AppendLine("}"); }
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); } }
void IWorkshopTree.ToWorkshop(WorkshopBuilder b, ToWorkshopContext context) => throw new System.NotImplementedException();
void ToWorkshop(Func <VarCollection, Rule[]> addRules) { // Set up the variable collection. VarCollection.Setup(); // Set up initial global and player rules. InitialGlobal = new TranslateRule(this, "Initial Global", RuleEvent.OngoingGlobal); InitialPlayer = new TranslateRule(this, "Initial Player", RuleEvent.OngoingPlayer); WorkshopRules = new List <Rule>(); // Assign static variables. foreach (var type in types) { type.WorkshopInit(this); } // Assign variables at the rule-set level. foreach (var variable in rulesetVariables) { // Assign the variable an index. DefaultIndexAssigner.Add(VarCollection, variable, true, null); var assigner = DefaultIndexAssigner[variable] as IndexReference; if (assigner != null && variable.InitialValue != null) { var addToInitialRule = GetInitialRule(variable.VariableType == VariableType.Global); addToInitialRule.ActionSet.AddAction(assigner.SetVariable( (Element)variable.InitialValue.Parse(addToInitialRule.ActionSet) )); } } // Setup single-instance methods. foreach (var method in subroutines) { method.SetupSubroutine(); } // Parse the rules. foreach (var rule in rules) { var translate = new TranslateRule(this, rule); WorkshopRules.Add(translate.GetRule()); } if (InitialPlayer.Actions.Count > 0) { WorkshopRules.Insert(0, InitialPlayer.GetRule()); } if (InitialGlobal.Actions.Count > 0) { WorkshopRules.Insert(0, InitialGlobal.GetRule()); } if (addRules != null) { WorkshopRules.AddRange(addRules.Invoke(VarCollection).Where(rule => rule != null)); } // Order the workshop rules by priority. WorkshopRules = WorkshopRules.OrderBy(wr => wr.Priority).ToList(); // Get the final workshop string. WorkshopBuilder result = new WorkshopBuilder(Language); LanguageInfo.I18nWarningMessage(result, Language); // Get the custom game settings. if (MergedLobbySettings != null) { Ruleset settings = Ruleset.Parse(MergedLobbySettings); settings.ToWorkshop(result); result.AppendLine(); } // Get the variables. VarCollection.ToWorkshop(result); result.AppendLine(); // Get the subroutines. SubroutineCollection.ToWorkshop(result); // Get the rules. foreach (var rule in WorkshopRules) { result.AppendLine(rule.ToWorkshop(Language, OptimizeOutput)); } WorkshopCode = result.ToString(); }
public override string GetValue(WorkshopBuilder builder, object value) => builder.Translate((bool)value ? "On" : "Off");
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 override string GetValue(WorkshopBuilder builder, object value) => builder.Translate(value.ToString());
public void ToWorkshop(WorkshopBuilder builder, ToWorkshopContext context) => builder.AppendKeyword(WorkshopName());
public override string GetValue(WorkshopBuilder builder, object value) => builder.Translate((bool)value ? EnabledKey() : DisabledKey());
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 virtual string ResolveName(WorkshopBuilder builder) => builder.Translate(Title);
void ToWorkshop(Func <VarCollection, Rule[]> addRules) { // Set up the variable collection. VarCollection.Setup(); WorkshopConverter = new ToWorkshop(this); // Set up initial global and player rules. InitialGlobal = new TranslateRule(this, "Initial Global", RuleEvent.OngoingGlobal); InitialPlayer = new TranslateRule(this, "Initial Player", RuleEvent.OngoingPlayer); WorkshopRules = new List <Rule>(); WorkshopConverter.InitStatic(); // Init called types. foreach (var workshopInit in _workshopInit) { workshopInit.WorkshopInit(this); } // Assign variables at the rule-set level. foreach (var variable in rulesetVariables) { var addToInitialRule = GetInitialRule(variable.VariableType == VariableType.Global); // Assign the variable an index. IGettable value = variable .GetDefaultInstance(null) .GetAssigner(new(addToInitialRule.ActionSet)) .GetValue(new GettableAssignerValueInfo(addToInitialRule.ActionSet) { SetInitialValue = SetInitialValue.SetIfExists }); DefaultIndexAssigner.Add(variable, value); if (value is IndexReference indexReference) { DebugVariables.Add(variable, indexReference); } } // Parse the rules. foreach (var rule in rules) { var translate = new TranslateRule(this, rule); Rule newRule = GetRule(translate.GetRule()); WorkshopRules.Add(newRule); rule.ElementCountLens.RuleParsed(newRule); } // Add built-in rules. // Initial player if (InitialPlayer.Actions.Count > 0) { WorkshopRules.Insert(0, GetRule(InitialPlayer.GetRule())); } // Initial global if (InitialGlobal.Actions.Count > 0) { WorkshopRules.Insert(0, GetRule(InitialGlobal.GetRule())); } // Additional if (addRules != null) { WorkshopRules.AddRange(addRules.Invoke(VarCollection).Where(rule => rule != null)); } // Complete portable functions WorkshopConverter.LambdaBuilder.Complete(); // Order the workshop rules by priority. WorkshopRules = WorkshopRules.OrderBy(wr => wr.Priority).ToList(); // Get the final workshop string. WorkshopBuilder result = new WorkshopBuilder(Language); LanguageInfo.I18nWarningMessage(result, Language); // Get the custom game settings. if (Importer.MergedLobbySettings != null) { Ruleset settings = Ruleset.Parse(Importer.MergedLobbySettings); settings.ToWorkshop(result); result.AppendLine(); } // Get the variables. VarCollection.ToWorkshop(result); result.AppendLine(); // Get the subroutines. SubroutineCollection.ToWorkshop(result); // Get the rules. for (int i = 0; i < WorkshopRules.Count; i++) { WorkshopRules[i].ToWorkshop(result); ElementCount += WorkshopRules[i].ElementCount(); if (i != WorkshopRules.Count - 1) { result.AppendLine(); } } WorkshopCode = result.GetResult(); }
public void ToWorkshop(WorkshopBuilder builder, List <LobbySetting> allSettings) { ToWorkshop(this, builder, allSettings); }
public virtual void ToWorkshop(WorkshopBuilder b, ToWorkshopContext context) => b.Append(Name);
/// <summary>Adds the value to the workshop output.</summary> public abstract string GetValue(WorkshopBuilder builder, object value);
void ToWorkshop(Func <VarCollection, Rule[]> addRules) { // Set up the variable collection. VarCollection.Setup(); // Set up initial global and player rules. InitialGlobal = new TranslateRule(this, "Initial Global", RuleEvent.OngoingGlobal); InitialPlayer = new TranslateRule(this, "Initial Player", RuleEvent.OngoingPlayer); WorkshopRules = new List <Rule>(); // Init called types. foreach (var type in Types.CalledTypes.Distinct()) { type.WorkshopInit(this); } // Assign variables at the rule-set level. foreach (var variable in rulesetVariables) { // Assign the variable an index. var assigner = DefaultIndexAssigner.Add(VarCollection, variable, true, null) as IndexReference; // Assigner will be non-null if it is an IndexReference. if (assigner != null) { DebugVariables.Add(variable, assigner); // Initial value. if (variable.InitialValue != null) { var addToInitialRule = GetInitialRule(variable.VariableType == VariableType.Global); addToInitialRule.ActionSet.AddAction(assigner.SetVariable( (Element)variable.InitialValue.Parse(addToInitialRule.ActionSet) )); } } } // Setup single-instance methods. foreach (var method in subroutines) { method.SetupSubroutine(); } // Parse the rules. foreach (var rule in rules) { var translate = new TranslateRule(this, rule); Rule newRule = translate.GetRule(); WorkshopRules.Add(newRule); rule.ElementCountLens.RuleParsed(newRule); } // Add built-in rules. // Initial player if (InitialPlayer.Actions.Count > 0) { WorkshopRules.Insert(0, InitialPlayer.GetRule()); } // Initial global if (InitialGlobal.Actions.Count > 0) { WorkshopRules.Insert(0, InitialGlobal.GetRule()); } // Additional if (addRules != null) { WorkshopRules.AddRange(addRules.Invoke(VarCollection).Where(rule => rule != null)); } // Order the workshop rules by priority. WorkshopRules = WorkshopRules.OrderBy(wr => wr.Priority).ToList(); // Get the final workshop string. WorkshopBuilder result = new WorkshopBuilder(Language); LanguageInfo.I18nWarningMessage(result, Language); // Get the custom game settings. if (Importer.MergedLobbySettings != null) { Ruleset settings = Ruleset.Parse(Importer.MergedLobbySettings); settings.ToWorkshop(result); result.AppendLine(); } // Get the variables. VarCollection.ToWorkshop(result); result.AppendLine(); // Print class identifiers. Types.PrintClassIdentifiers(result); // Get the subroutines. SubroutineCollection.ToWorkshop(result); // Get the rules. for (int i = 0; i < WorkshopRules.Count; i++) { WorkshopRules[i].ToWorkshop(result, OptimizeOutput); ElementCount += WorkshopRules[i].ElementCount(OptimizeOutput); if (i != WorkshopRules.Count - 1) { result.AppendLine(); } } WorkshopCode = result.ToString(); }
public void ToWorkshop(WorkshopBuilder builder, ToWorkshopContext context) => throw new NotImplementedException();
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) { 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("}"); }