Ejemplo n.º 1
0
        /// <summary>
        /// Adds a rule to the category. DO NOT ADD CHOICES AFTER THIS.
        /// </summary>
        /// <param name="category">The category to add this rule to.</param>
        /// <param name="rule">The rule to add.</param>
        /// <typeparam name="T">The type of value this rule holds.</typeparam>
        public static void AddToCategory <T>(RuleCategoryDef category, LobbyRule <T> rule)
        {
            rule._ruleDef.globalIndex = RuleCatalog.ruleCount;
            _addRule.Invoke(null, new object[] { rule._ruleDef });

            RuleCatalog.allCategoryDefs.Last()?.children.Remove(rule._ruleDef);
            RuleCatalog.allCategoryDefs.FirstOrDefault(x => x == category)?.children.Add(rule._ruleDef);

            rule._ruleDef.category = category;
            rule._ruleDef.choices.ForEach(x => {
                x.globalIndex = RuleCatalog.choiceCount;
                _ruleChoices.Add(x);
            });

            Array.Resize(ref PreGameRuleVoteController.votesForEachChoice, RuleCatalog.choiceCount);

            UpdateValues += (sender, args) => rule.UpdateValue((RuleBook)sender);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Adds a rule to the category. You cannot add choices to that rule after pushing it.
            /// </summary>
            /// <param name="rule">The rule to add.</param>
            /// <typeparam name="T">The type of value this rule holds.</typeparam>
            /// <returns>'this', for chaining.</returns>
            public LobbyCategory PushRule <T>(LobbyRule <T> rule)
            {
                rule.Pushed = true;

                rule.Def.globalIndex = RuleCatalog.ruleCount;
                typeof(RuleCatalog).GetMethodCached("AddRule"
                                                    , new[] { typeof(RuleDef) })
                .Invoke(null, new object[] { rule.Def });

                RuleCatalog.allCategoryDefs.Last()?.children.Remove(rule.Def);
                RuleCatalog.allCategoryDefs.FirstOrDefault(x => x == Def)?.children.Add(rule.Def);

                rule.Def.category = Def;
                rule.Def.choices.ForEach(x => {
                    x.globalIndex = RuleCatalog.choiceCount;
                    InternalRuleChoices.Add(x);
                });

                Array.Resize(ref PreGameRuleVoteController.votesForEachChoice, RuleCatalog.choiceCount);

                UpdateValues += rule.UpdateValue;
                return(this);
            }
Ejemplo n.º 3
0
 public static void AddToCategory <T>(RuleCategoryDef category, LobbyRule <T> rule)
 {
     new LobbyCategory(category).PushRule(rule);
 }