Example #1
0
        /// <summary>Parse the underlying <c>content.json</c> file and set the <see cref="Content"/> and <see cref="Migrator"/> fields.</summary>
        /// <param name="error">The error indicating why the content could not be reloaded, if applicable.</param>
        public bool TryReloadContent(out string error)
        {
            const string filename = "content.json";

            // load raw file
            ContentConfig content = this.ContentPack.ReadJsonFile <ContentConfig>(filename);

            if (content == null)
            {
                error = $"content pack has no {filename} file";
                return(false);
            }

            // validate base fields
            if (content.Format == null)
            {
                error = $"content pack doesn't specify the required {nameof(ContentConfig.Format)} field.";
                return(false);
            }
            if (!content.Changes.Any() && !content.CustomLocations.Any())
            {
                error = $"content pack must specify the {nameof(ContentConfig.Changes)} or {nameof(ContentConfig.CustomLocations)} fields.";
                return(false);
            }

            // apply migrations
            IMigration migrator = new AggregateMigration(content.Format, this.GetMigrations(content));

            if (!migrator.TryMigrate(content, out error))
            {
                return(false);
            }

            // load content
            this.ContentImpl  = content;
            this.MigratorImpl = migrator;
            return(true);
        }
Example #2
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="contentPack">The managed content pack instance.</param>
 /// <param name="content">The raw content configuration for this content pack.</param>
 /// <param name="migrator">The migrations to apply for the content pack version.</param>
 public RawContentPack(IContentPack contentPack, ContentConfig content, IMigration migrator)
 {
     this.ContentPack = contentPack;
     this.Content     = content;
     this.Migrator    = migrator;
 }
Example #3
0
 /// <summary>Construct an instance.</summary>
 /// <param name="copyFrom">A content pack to clone.</param>
 public RawContentPack(RawContentPack copyFrom)
     : this(copyFrom.ContentPack, copyFrom.Index, copyFrom.GetMigrations)
 {
     this.ContentImpl  = copyFrom.Content;
     this.MigratorImpl = copyFrom.Migrator;
 }