예제 #1
0
        public bool GenerateBgmProperty(List <MusicModBgmEntry> bgmEntries)
        {
            var bgmPropertyExecPath = _resourceService.GetBgmPropertyExe();

            if (!File.Exists(bgmPropertyExecPath))
            {
                _logger.LogError("Executable {BgmPropertyExe} could not be found.", bgmPropertyExecPath);
                return(false);
            }

            var tempBgmPropertyYml     = _workspace.GetWorkspaceOutputForBgmPropertyTempFile();
            var templateBgmPropertyYml = _resourceService.GetBgmPropertyYmlResource();

            //Pick either bgm_property.yml or bgm_property.bin if yml doesn't exist
            if (File.Exists(templateBgmPropertyYml))
            {
                File.Copy(templateBgmPropertyYml, tempBgmPropertyYml);
            }
            else
            {
                if (!ExtractBgmPropertyYml(bgmPropertyExecPath, tempBgmPropertyYml))
                {
                    return(false);
                }
            }

            //Deserialize
            var yamlStr     = File.ReadAllText(tempBgmPropertyYml);
            var yamlEntries = _yamlDeserializer.Deserialize <List <BgmPropertyModel> >(yamlStr);

            foreach (var bgmEntry in bgmEntries)
            {
                yamlEntries.Add(new BgmPropertyModel()
                {
                    NameId          = bgmEntry.InternalToneName,
                    TotalSamples    = bgmEntry.CuePoints.TotalSample,
                    TotalTimeMs     = bgmEntry.CuePoints.TotalTimeMs,
                    LoopStartMs     = bgmEntry.CuePoints.LoopStartMs,
                    LoopStartSample = bgmEntry.CuePoints.LoopStartSample,
                    LoopEndMs       = bgmEntry.CuePoints.LoopEndMs,
                    LoopEndSample   = bgmEntry.CuePoints.LoopEndSample,
                });
            }

            //Serialize
            yamlStr = _yamlSerializer.Serialize(yamlEntries);
            File.WriteAllText(tempBgmPropertyYml, yamlStr);

            //Generate Bgm Property Bin output
            var bgmPropertyBin = _workspace.GetWorkspaceOutputForBgmPropertyFile();

            GenerateBgmProperty(bgmPropertyExecPath, tempBgmPropertyYml, bgmPropertyBin);

            return(true);
        }