Esempio n. 1
0
        /// <summary>
        /// Exports a BriefingRoom mission to a DCS .miz file.
        /// </summary>
        /// <param name="mission">The mission to export</param>
        /// <returns>A MizFile if everything went well, null if an error happened.</returns>
        public MizFile ExportToMizFile(DCSMission mission)
        {
            string resourceOggString;

            if (mission == null)
            {
                return(null);
            }

            DebugLog.Instance.Clear();
            DebugLog.Instance.WriteLine($"Started MIZ file export...");

            DateTime exportStartTime = DateTime.Now;
            MizFile  miz             = new MizFile();

            miz.AddEntry("Credits.txt", $"Generated with BriefingRoom for DCS World ({BriefingRoom.WEBSITE_URL})");

            DebugLog.Instance.WriteLine(" Adding \"briefing.html\" entry...", 1);
            miz.AddEntry("briefing.html", mission.BriefingHTML);

            DebugLog.Instance.WriteLine(" Adding \"mission\" entry...", 1);
            using (MizMakerLuaMission luaMission = new MizMakerLuaMission())
                miz.AddEntry("mission", luaMission.MakeLua(mission));

            DebugLog.Instance.WriteLine(" Adding \"options\" entry...", 1);
            miz.AddEntry("options", LuaTools.ReadIncludeLuaFile("Options.lua"));

            DebugLog.Instance.WriteLine(" Adding \"theater\" entry...", 1);
            miz.AddEntry("theatre", mission.Theater);

            DebugLog.Instance.WriteLine(" Adding \"warehouses\" entry...", 1);
            using (MizMakerLuaWarehouse luaWarehouses = new MizMakerLuaWarehouse())
                miz.AddEntry("warehouses", luaWarehouses.MakeLua(mission));

            DebugLog.Instance.WriteLine(" Adding \"l10n/DEFAULT/dictionary\" entry...", 1);
            miz.AddEntry("l10n/DEFAULT/dictionary", LuaTools.ReadIncludeLuaFile("Dictionary.lua"));

            DebugLog.Instance.WriteLine(" Adding \"l10n/DEFAULT/script.lua\" entry...", 1);
            using (MizMakerLuaScript luaScript = new MizMakerLuaScript())
                miz.AddEntry("l10n/DEFAULT/script.lua", luaScript.MakeLua(mission), false);

            DebugLog.Instance.WriteLine(" Adding .ogg audio media files...", 1);
            using (MizMakerMediaAudio oggMedia = new MizMakerMediaAudio())
                oggMedia.AddMediaFiles(miz, mission, out resourceOggString);

            DebugLog.Instance.WriteLine(" Adding \"l10n/DEFAULT/mapResource\" entry...", 1);
            using (MizMakerLuaMapResource luaMapResource = new MizMakerLuaMapResource())
                miz.AddEntry("l10n/DEFAULT/mapResource", luaMapResource.MakeLua(mission, resourceOggString));

            DebugLog.Instance.WriteLine(" Adding .jpg image media files...", 1);
            using (MizMakerMediaImages jpgMedia = new MizMakerMediaImages())
                jpgMedia.AddMediaFiles(miz, mission);

            DebugLog.Instance.WriteLine($"Export to .miz file completed in {(DateTime.Now - exportStartTime).TotalSeconds.ToString("F3", NumberFormatInfo.InvariantInfo)} second(s).");

            return(miz);
        }
        public void AddMediaFiles(MizFile miz, DCSMission mission, out string resourceOggString)
        {
            resourceOggString = "";

            foreach (string ogg in mission.OggFiles)
            {
                AddOggFile(miz, ogg, ref resourceOggString);
            }
        }
        /// <summary>
        /// Adds an .ogg file (read from the Include\Ogg\ directory) to the .miz file.
        /// </summary>
        /// <param name="miz">The .miz file</param>
        /// <param name="file">Name of the ogg file, without .ogg extension.</param>
        /// <param name="resourceOggString"></param>
        private void AddOggFile(MizFile miz, string file, ref string resourceOggString)
        {
            string oggFilePath = $"{BRPaths.INCLUDE_OGG}{file}.ogg";

            if (!File.Exists(oggFilePath))
            {
                DebugLog.Instance.WriteLine($"  WARNING: Failed to load .ogg file Include\\Ogg\\{file}.ogg");
                return; // File doesn't exist
            }

            DebugLog.Instance.WriteLine($"  Added file Include\\Ogg\\{file}.ogg");
            miz.AddEntry($"l10n/DEFAULT/{file}.ogg", File.ReadAllBytes(oggFilePath));

            resourceOggString += $" [\"ResKey_Snd_{Path.GetFileNameWithoutExtension(file)}\"] = \"{file}.ogg\",\r\n";
        }
 public void AddMediaFiles(MizFile miz, DCSMission mission)
 {
     miz.AddEntry($"l10n/DEFAULT/title_{mission.UniqueID}.jpg", GetTitleImage(mission));
 }