public void Generate(CampaignTemplate campaignTemplate, string campaignFilePath) { string campaignName = Path.GetFileNameWithoutExtension(campaignFilePath); string campaignDirectory = Path.GetDirectoryName(campaignFilePath); DCSMissionDateTime date = GenerateCampaignDate(campaignTemplate); using (MissionGenerator generator = new MissionGenerator()) { for (int i = 0; i < campaignTemplate.MissionsCount; i++) { // Increment the date by a few days for each mission after the first if (i > 0) { IncrementDate(ref date); } MissionTemplate template = CreateMissionTemplate(campaignTemplate, i); DCSMission mission = generator.Generate(template); mission.MissionName = $"{campaignName}, phase {i + 1}"; mission.DateTime.Day = date.Day; mission.DateTime.Month = date.Month; mission.DateTime.Year = date.Year; MizFile miz = mission.ExportToMiz(); miz.SaveToFile(Path.Combine(campaignDirectory, $"{campaignName}{i + 1:00}.miz")); } } CreateImageFiles(campaignTemplate, campaignFilePath); CreateCMPFile(campaignTemplate, campaignFilePath); }
/// <summary> /// Generates mission(s) from command line arguments. /// </summary> /// <param name="args">Command line arguments</param> /// <returns>True if everything when wrong, false otherwise</returns> public bool DoCommandLine(params string[] args) { ParseCommandLineArguments(args, out string[] templateFiles, out int missionCount); if (templateFiles.Length == 0) { DebugLog.Instance.WriteLine("No mission template files provided", DebugLogMessageErrorLevel.Error); return(false); } using (MissionGenerator generator = new MissionGenerator()) { foreach (string t in templateFiles) { using (MissionTemplate template = new MissionTemplate(t)) { for (int i = 0; i < missionCount; i++) { DCSMission mission = generator.Generate(template); if (mission == null) { DebugLog.Instance.WriteLine($"Failed to generate a mission from template {Path.GetFileName(t)}", DebugLogMessageErrorLevel.Warning); continue; } string mizFileName = Path.Combine(Application.StartupPath, Path.GetFileNameWithoutExtension(t) + ".miz"); mizFileName = GetUnusedFileName(mizFileName); MizFile miz = mission.ExportToMiz(); if ((miz == null) || !miz.SaveToFile(mizFileName)) { DebugLog.Instance.WriteLine($"Failed to export .miz file from template {Path.GetFileName(t)}", DebugLogMessageErrorLevel.Warning); continue; } else { DebugLog.Instance.WriteLine($"Mission {Path.GetFileName(mizFileName)} exported to .miz file from template {Path.GetFileName(t)}"); } } } } } return(true); }
public void Generate(CampaignTemplate campaignTemplate, string campaignFilePath) { string campaignName = Path.GetFileNameWithoutExtension(campaignFilePath); string campaignDirectory = Path.GetDirectoryName(campaignFilePath); DCSMissionDateTime date = GenerateCampaignDate(campaignTemplate); using (MissionGenerator generator = new MissionGenerator()) { for (int i = 0; i < campaignTemplate.MissionsCount; i++) { MissionTemplate template = CreateMissionTemplate(campaignTemplate, i, campaignName, ref date); DCSMission mission = generator.Generate(template); MizFile miz = mission.ExportToMiz(); miz.SaveToFile(Path.Combine(campaignDirectory, $"{campaignName}{i + 1:00}.miz")); } } CreateImageFiles(campaignTemplate, campaignFilePath); CreateCMPFile(campaignTemplate, campaignFilePath); }
private void MenuClick(object sender, EventArgs e) { string senderName = ((ToolStripItem)sender).Name; switch (senderName) { case "M_About": case "T_About": using (AboutForm form = new AboutForm()) form.ShowDialog(); return; case "M_File_New": case "T_File_New": Template.Clear(); TemplatePropertyGrid.Refresh(); GenerateMission(); return; case "M_File_Open": case "T_File_Open": using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "BriefingRoom templates (*.brt)|*.brt"; ofd.RestoreDirectory = true; if ((ofd.ShowDialog() == DialogResult.OK) && File.Exists(ofd.FileName)) { Template.LoadFromFile(ofd.FileName); TemplatePropertyGrid.Refresh(); GenerateMission(); } } return; case "M_File_SaveAs": case "T_File_SaveAs": using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "BriefingRoom templates (*.brt)|*.brt"; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { Template.SaveToFile(sfd.FileName); } } return; case "M_File_Exit": Close(); return; case "M_Mission_Export": case "T_Mission_Export": if (Mission == null) { return; } using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "DCS World missions (*.miz)|*.miz"; sfd.FileName = Mission.MissionName + ".miz"; sfd.RestoreDirectory = true; sfd.InitialDirectory = Toolbox.GetDCSMissionPath(); if (sfd.ShowDialog() == DialogResult.OK) { ExportToMiz(sfd.FileName); } } return; case "M_Mission_ExportBriefingHTML": case "T_Mission_ExportBriefingHTML": if (Mission == null) { return; } using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "HTML pages (*.html)|*.html"; sfd.FileName = Mission.MissionName + ".html"; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { File.WriteAllText(sfd.FileName, Mission.BriefingHTML); } } return; case "M_Mission_Generate": case "T_Mission_Generate": GenerateMission(); return; #if DEBUG case "M_Mission_DebugExport": if (Mission == null) { return; // No mission to export } Toolbox.CreateDirectoryIfMissing(BRPaths.DEBUGOUTPUT); using (MizFile miz = Mission.ExportToMiz()) miz.SaveToDirectory(BRPaths.DEBUGOUTPUT); return; #endif case "M_Tools_CampaignCreator": using (CampaignCreatorForm campaignForm = new CampaignCreatorForm()) campaignForm.ShowDialog(); return; } }