/// <summary> /// Создает указанный тип команды и устанавливает его активным. /// </summary> /// <typeparam name="T">Тип команды.</typeparam> /// <param name="container">Контейнер зависимостей, в котором должны быть зарегистрированы <see cref="ICommandManager"/>, а также типы для создания команды.</param> /// <param name="peerId">Идентификатор чата, в котором необходимо установить команду.</param> /// <param name="overrides">Параметры для переопределения конструктора.</param> /// <returns></returns> public static T CreateCommandAndSetActive <T>(this IUnityContainer container, long peerId, params ResolverOverride[] overrides) { var commandInstance = container.Resolve <T>(overrides); var commandManager = container.Resolve <ICommandManager>(); var metadata = RunMetadata.CreateWithoutDelegate <T>(); commandManager.SetActiveCommand(peerId, metadata, commandInstance); return(commandInstance); }
/// <summary> /// Связывает указанный узел с метаданными запуска команды. /// </summary> /// <param name="endNode">Узел, на котором команда завершается.</param> /// <param name="metadata"> Метаданные запуска.</param> internal void AddMetadata(CommandTreeNode endNode, RunMetadata metadata) { if (metadata.IsGlobal) { _globalCommands.Add(endNode, metadata); } else { _contextCommands.Add(endNode, metadata); } }
public SpeedrunComSubmitDialog(RunMetadata metadata) { this.metadata = metadata; InitializeComponent(); hasPersonalBestDateTime = SpeedrunCom.FindPersonalBestAttemptDate(metadata.LiveSplitRun).HasValue; if (!hasPersonalBestDateTime) { var dateLabel = new Label(); dateLabel.Text = "Date:"; tableLayoutPanel.Controls.Add(dateLabel, 0, 2); dateLabel.Anchor = AnchorStyles.Left; dateLabel.AutoSize = true; datePicker = new DateTimePicker(); datePicker.Anchor = AnchorStyles.Left | AnchorStyles.Right; tableLayoutPanel.Controls.Add(datePicker, 1, 2); tableLayoutPanel.SetColumnSpan(datePicker, 2); } }
public SpeedrunComSubmitDialog(RunMetadata metadata) { this.metadata = metadata; InitializeComponent(); hasPersonalBestDateTime = SpeedrunCom.FindPersonalBestAttemptDate(metadata.LiveSplitRun).HasValue; var row = 2; if (!hasPersonalBestDateTime) { var dateLabel = new Label(); dateLabel.Text = "Date:"; tableLayoutPanel.Controls.Add(dateLabel, 0, row); dateLabel.Anchor = AnchorStyles.Left; dateLabel.AutoSize = true; datePicker = new DateTimePicker(); datePicker.Anchor = AnchorStyles.Left | AnchorStyles.Right; datePicker.TabIndex = row; tableLayoutPanel.Controls.Add(datePicker, 1, row); tableLayoutPanel.SetColumnSpan(datePicker, 2); MinimumSize = new Size(MinimumSize.Width, MinimumSize.Height + datePicker.Height); Size = new Size(Size.Width, Size.Height + datePicker.Height); row++; } var runTime = metadata.LiveSplitRun.Last().PersonalBestSplitTime; var timingMethods = metadata.Game.Ruleset.TimingMethods; var usesGameTime = timingMethods.Contains(SpeedrunComSharp.TimingMethod.GameTime); var usesWithoutLoads = timingMethods.Contains(SpeedrunComSharp.TimingMethod.RealTimeWithoutLoads); var usesBoth = usesGameTime && usesWithoutLoads; if (!runTime.GameTime.HasValue || usesBoth) { if (usesWithoutLoads) { var label = new Label(); label.Text = "Without Loads:"; tableLayoutPanel.Controls.Add(label, 0, row); label.Anchor = AnchorStyles.Left; label.AutoSize = true; txtWithoutLoads = new TextBox(); txtWithoutLoads.Anchor = AnchorStyles.Left | AnchorStyles.Right; txtWithoutLoads.TabIndex = row; tableLayoutPanel.Controls.Add(txtWithoutLoads, 1, row); tableLayoutPanel.SetColumnSpan(txtWithoutLoads, 2); MinimumSize = new Size(MinimumSize.Width, MinimumSize.Height + txtWithoutLoads.Height); Size = new Size(Size.Width, Size.Height + txtWithoutLoads.Height); row++; } if (usesGameTime) { var label = new Label(); label.Text = "Game Time:"; tableLayoutPanel.Controls.Add(label, 0, row); label.Anchor = AnchorStyles.Left; label.AutoSize = true; txtGameTime = new TextBox(); txtGameTime.Anchor = AnchorStyles.Left | AnchorStyles.Right; txtGameTime.TabIndex = row; tableLayoutPanel.Controls.Add(txtGameTime, 1, row); tableLayoutPanel.SetColumnSpan(txtGameTime, 2); MinimumSize = new Size(MinimumSize.Width, MinimumSize.Height + txtGameTime.Height); Size = new Size(Size.Width, Size.Height + txtGameTime.Height); row++; } } }
/// <summary> /// Получает метаданные запуска по указанному узлу контекстного типа. /// </summary> internal RunMetadata GetContextMetadata(CommandTreeNode endNode, RunMetadata executedCommand) { return(_contextCommands.TryGetActualValue(endNode, executedCommand, out var context) ? context : null); }