Exemplo n.º 1
0
        public static bool SaveTemplateAsset(TemplateAsset templateAsset)
        {
            SingletonMod <Mod> .Logger.Debug($"Start save template asset {templateAsset}");

            try
            {
                var meta = new CustomAssetMetaData()
                {
                    name      = $"{templateAsset.Template.Name}_{Guid.NewGuid().Unique()}",
                    timeStamp = DateTime.Now,
                    type      = CustomAssetMetaData.Type.Unknown,
                    dlcMask   = SteamHelper.DLC_BitMask.None,
                    steamTags = new string[] { "Marking" },
                    guid      = templateAsset.Template.Id.ToString(),
                };

                var package = new Package(templateAsset.IsWorkshop ? templateAsset.WorkshopId.ToString() : meta.name)
                {
                    packageMainAsset = meta.name,
                    packageAuthor    = $"steamid:{TemplateManager.UserId}",
                };

                var gameObject  = new GameObject(typeof(MarkingInfo).Name);
                var markingInfo = gameObject.AddComponent <MarkingInfo>();
                markingInfo.data = GetString(templateAsset.Template.ToXml());
                meta.assetRef    = package.AddAsset($"{meta.name}_Data", markingInfo.gameObject);

                if (templateAsset.Preview is Image image)
                {
                    meta.imageRef = package.AddAsset(templateAsset.MetaPreview, image, false, Image.BufferFileFormat.PNG, false, false);
                }

                if (templateAsset.SeparatePreview && templateAsset.SteamPreview is Image steamImage)
                {
                    meta.steamPreviewRef = package.AddAsset(templateAsset.MetaSteamPreview, steamImage, false, Image.BufferFileFormat.PNG, false, false);
                }
                else
                {
                    meta.steamPreviewRef = meta.imageRef;
                }

                package.AddAsset(meta.name, meta, UserAssetType.CustomAssetMetaData);

                var path = Path.Combine(DataLocation.assetsPath, PathUtils.AddExtension(PathEscaper.Escape(templateAsset.FileName), PackageManager.packageExtension));
                package.Save(path);

                SingletonMod <Mod> .Logger.Debug($"Template asset saved to {path}");

                return(true);
            }
            catch (Exception error)
            {
                SingletonMod <Mod> .Logger.Error($"Could not save template asset", error);

                return(false);
            }
        }
Exemplo n.º 2
0
        private string GetSavePathName(string saveName)
        {
            string path = PathUtils.AddExtension(PathEscaper.Escape(saveName), PackageManager.packageExtension);

            return(Path.Combine(DataLocation.assetsPath, path));
        }