示例#1
0
        protected override void Initialize(ContentCompiler compiler)
        {
            worldObjectWriter = compiler.GetTypeWriter(typeof(WorldObject))
                                as WorldObjectWriter;

            base.Initialize(compiler);
        }
        protected override void Initialize(ContentCompiler compiler)
        {
            fightingCharacterWriter = compiler.GetTypeWriter(typeof(FightingCharacter))
                                      as FightingCharacterWriter;

            base.Initialize(compiler);
        }
示例#3
0
        private static void DeserializeCompileAndLoad <T>(string file, Action <T> doAsserts)
        {
            var result = Deserialize(file, doAsserts);

            var xnbStream = new MemoryStream();

#if XNA
            // In MS XNA the ContentCompiler is completely internal, so we need
            // to use just a little reflection to get access to what we need.
            const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
            var ctor          = typeof(ContentCompiler).GetConstructors(flags)[0];
            var compiler      = (ContentCompiler)ctor.Invoke(null);
            var compileMethod = typeof(ContentCompiler).GetMethod("Compile", flags);
            compileMethod.Invoke(compiler, new object[] { xnbStream, result, TargetPlatform.Windows, GraphicsProfile.Reach,
                                                          false, Directory.GetCurrentDirectory(), "referenceRelocationPath" });
#else
            var compiler = new ContentCompiler();
            compiler.Compile(xnbStream, result, TargetPlatform.Windows, GraphicsProfile.Reach,
                             false, "rootDirectory", "referenceRelocationPath");
#endif

            var content = new TestContentManager(xnbStream);
            var loaded  = content.Load <T>("Whatever");

            doAsserts(loaded);
        }
        protected override void Initialize(ContentCompiler compiler)
        {
            mapEntryWriter = compiler.GetTypeWriter(typeof(MapEntry <T>))
                             as MapEntryWriter <T>;

            base.Initialize(compiler);
        }
示例#5
0
        protected override void Initialize(ContentCompiler compiler)
        {
            equipmentWriter = compiler.GetTypeWriter(typeof(Equipment))
                              as EquipmentWriter;

            base.Initialize(compiler);
        }
        private void WriteXnb(object content, PipelineBuildEvent pipelineEvent)
        {
            // Make sure the output directory exists.
            var outputFileDir = Path.GetDirectoryName(pipelineEvent.DestFile);

            Directory.CreateDirectory(outputFileDir);

            if (_compiler == null)
            {
                _compiler = new ContentCompiler();
            }

            var  type     = content.GetType();
            var  attrib   = type.GetCustomAttribute <CompressedContentAttribute>(true);
            bool compress = attrib == null && CompressContent;

            // Write the XNB.
            using (var fs = new FileStream(
                       pipelineEvent.DestFile, FileMode.Create, FileAccess.Write, FileShare.None))
                _compiler.Compile(fs, content, Platform, Profile, compress, OutputDirectory, outputFileDir);

            // Store the last write time of the output XNB here
            // so we can verify it hasn't been tampered with.
            pipelineEvent.DestTime = File.GetLastWriteTime(pipelineEvent.DestFile);
        }
示例#7
0
        /// <summary>
        /// <para>
        /// Enable SassAndCoffee support in the application.
        /// </para>
        /// <para>
        /// SassAndCoffee supports on the fly compilation and caching of CoffeeScript and Sass,
        /// along with concatenation and minification.
        /// </para>
        /// </summary>
        /// <param name="pipelines">Application pipelines to hook into</param>
        /// <param name="cache">Cache provider to use</param>
        /// <param name="rootPathProvider">Root path provider</param>
        public static void Enable(IPipelines pipelines, ICompiledCache cache, IRootPathProvider rootPathProvider)
        {
            var host = new NancyCompilerHost(rootPathProvider);

            var compiler = new ContentCompiler(host, cache);

            pipelines.BeforeRequest.AddItemToStartOfPipeline(GetPipelineHook(compiler));
        }
示例#8
0
        /// <summary>
        /// <para>
        /// Enable SassAndCoffee support in the application.
        /// </para>
        /// <para>
        /// SassAndCoffee supports on the fly compilation and caching of CoffeeScript and Sass,
        /// along with concatenation and minification.
        /// </para>
        /// </summary>
        /// <param name="pipelines">Application pipelines to hook into</param>
        /// <param name="cache">Cache provider to use</param>
        /// <param name="rootPathProvider">Root path provider</param>
        public static void Enable(IApplicationPipelines pipelines, ICompiledCache cache, IRootPathProvider rootPathProvider)
        {
            var host = new NancyCompilerHost(rootPathProvider);

            var compiler = new ContentCompiler(host, cache);

            pipelines.BeforeRequest.AddItemToStartOfPipeline(GetPipelineHook(compiler));
        }
示例#9
0
        private static Func <NancyContext, Response> GetPipelineHook(ContentCompiler compiler)
        {
            return(ctx =>
            {
                if (ctx.Request == null)
                {
                    return null;
                }

                if (!compiler.CanCompile(ctx.Request.Url.Path))
                {
                    return null;
                }

                var content = compiler.GetCompiledContent(ctx.Request.Url.Path);

                return content.Compiled ? GetResponse(content) : null;
            });
        }
示例#10
0
        public override bool Execute()
        {
            Log.LogMessage("Building content:");

            XBuildLogger    logger   = new XBuildLogger(this.Log);
            ContentCompiler compiler = new ContentCompiler(PipelineAssemblies);

            foreach (ITaskItem sourceItem in SourceAssets)
            {
                //foreach (string name in sourceItem.MetadataNames)
                //	Log.LogMessage(name + " : " + sourceItem.GetMetadata(name));
                string assetName = sourceItem.GetMetadata("Name");

                Log.LogMessage("Building " + assetName);

                Stream        outputStream  = new FileStream(OutputDirectory + assetName + ".xnb", FileMode.OpenOrCreate);
                ContentWriter contentWriter = new ContentWriter(outputStream, getTargetPlatform(), CompressContent);

                string importerName  = sourceItem.GetMetadata("Importer");
                string processorName = sourceItem.GetMetadata("Processor");

                IContentImporter importer = getImporterInstance(importerName);
                if (importer == null)
                {
                    Log.LogError("Could not find the importer (" + importerName + ")");
                }

                IContentProcessor processor = getProcessorInstance(processorName);
                if (importer == null)
                {
                    Log.LogError("Could not find the processor (" + processorName + ")");
                }

                Log.LogMessage("Using " + importerName + " and " + processorName);

                ContentImporterContext  importerContext  = new ContentImporterContext(this, IntermediateDirectory, OutputDirectory, logger);
                ContentProcessorContext processorContext = new ContentProcessorContext();

                processor.Process(importer.Import(sourceItem.GetMetadata("Include"), importerContext), processorContext);
            }

            return(true);
        }
示例#11
0
        private static Func<NancyContext, Response> GetPipelineHook(ContentCompiler compiler)
        {
            return ctx =>
                {
                    if (ctx.Request == null)
                    {
                        return null;
                    }

                    if (!compiler.CanCompile(ctx.Request.Url.Path))
                    {
                        return null;
                    }

                    var content = compiler.GetCompiledContent(ctx.Request.Url.Path);

                    return content.Compiled ? GetResponse(content) : null;
                };
        }
示例#12
0
        private void WriteXnb(object content, PipelineBuildEvent pipelineEvent)
        {
            // Make sure the output directory exists.
            var outputFileDir = Path.GetDirectoryName(pipelineEvent.DestFile);

            Directory.CreateDirectory(outputFileDir);

            if (_compiler == null)
            {
                _compiler = new ContentCompiler();
            }

            // Write the XNB.
            using (var stream = new FileStream(pipelineEvent.DestFile, FileMode.Create, FileAccess.Write, FileShare.None))
                _compiler.Compile(stream, content, Platform, Profile, false, OutputDirectory, outputFileDir);

            // Store the last write time of the output XNB here
            // so we can verify it hasn't been tampered with.
            pipelineEvent.DestTime = File.GetLastWriteTime(pipelineEvent.DestFile);
        }
        public Generator()
        {
            _graphics     = new GraphicsDeviceManager(this);
            _englishChars = new List <char>
            {
                '©'
            };
            for (var c = '!'; c < '~'; c++)
            {
                _englishChars.Add(c);
            }
            _characters = File.ReadAllText("chars.txt")
                          .Except(_englishChars)
                          .ToArray();
            _compiler  = new ContentCompiler();
            _processor = new DynamicFontDescriptionProcessor();
            _context   = new DfgContext(this);

            Content.RootDirectory = "Content";
        }
示例#14
0
    public static void BuildGame(params string[] args)
    {
        BuildTarget[] targets = args.Skip(1).Select(x => (BuildTarget)Enum.Parse(typeof(BuildTarget), x)).ToArray();
        ContentCompiler.CompileAll();

        string   buildDir         = args[0];
        DateTime lastMinorRelease = new DateTime(2021, 7, 8);

        string patch = (DateTime.Now - lastMinorRelease).Days.ToString();
        string build = (DateTime.Now.Second + DateTime.Now.Minute * 60 + DateTime.Now.Hour * 3600).ToString();

        PlayerSettings.bundleVersion = $"0.2.{patch}.{build}";

        if (Directory.Exists(buildDir))
        {
            Directory.Delete(buildDir, true);
        }

        Directory.CreateDirectory(buildDir);

        foreach (var target in targets)
        {
            string dir = Path.Combine(buildDir, target.ToString());
            Directory.CreateDirectory(dir);

            BuildPlayerOptions options = new BuildPlayerOptions()
            {
                targetGroup      = BuildTargetGroup.Standalone,
                target           = target,
                scenes           = buildScenes,
                options          = BuildOptions.None,
                locationPathName = Path.Combine(dir, $"{buildPrefix}-{buildSuffixes[target]}{buildExtensions[target]}")
            };

            BuildPipeline.BuildPlayer(options);
            File.WriteAllText(Path.Combine(dir, "version.txt"), PlayerSettings.bundleVersion);
            File.WriteAllText(Path.Combine(dir, "channel.txt"), buildChannels[target]);
        }
    }
        public static void CompileAndLoadAssets <T>(T data, Action <T> validation)
        {
            ContentCompiler compiler = new ContentCompiler();

            foreach (var platform in Platforms)
            {
                foreach (var gfxProfile in GraphicsProfiles)
                {
                    foreach (var compress in CompressContents)
                    {
                        using (var xnbStream = new MemoryStream())
                        {
                            compiler.Compile(xnbStream, data, platform, gfxProfile, compress, "", "");
                            using (var content = new TestContentManager(xnbStream))
                            {
                                var result = content.Load <T>("foo");
                                validation(result);
                            }
                        }
                    }
                }
            }
        }
示例#16
0
        /// <summary>
        /// Compile the specified input object and return the XNB file as a byte array.
        /// </summary>
        /// <param name="content">
        /// The content to compile.
        /// </param>
        /// <returns>
        /// The compiled XNB file as a byte array.
        /// </returns>
        protected byte[] CompileAndGetBytes(object content)
        {
            var temp     = Path.GetTempFileName();
            var compiler = new ContentCompiler();

            try
            {
                using (var stream = new FileStream(temp, FileMode.Open, FileAccess.Write))
                {
                    compiler.Compile(
                        stream,
                        content,
                        MonoGamePlatform.Windows,
                        GraphicsProfile.Reach,
                        false,
                        Environment.CurrentDirectory,
                        Environment.CurrentDirectory);
                }

                byte[] result;
                using (var stream = new FileStream(temp, FileMode.Open, FileAccess.Read))
                {
                    stream.Position = 0;
                    using (var reader = new BinaryReader(stream))
                    {
                        result = reader.ReadBytes((int)stream.Length);
                    }
                }

                File.Delete(temp);
                return(result);
            }
            finally
            {
                File.Delete(temp);
            }
        }
        protected override void Initialize(ContentCompiler compiler)
        {
            gearWriter = compiler.GetTypeWriter(typeof(Gear)) as GearWriter;

            base.Initialize(compiler);
        }
示例#18
0
 protected override void Initialize(ContentCompiler compiler)
 {
     base.Initialize(compiler);
 }
 /// <inheritdoc/>
 protected override void Initialize(ContentCompiler compiler)
 {
     base.Initialize(compiler);
     _targetWriter = compiler.GetTypeWriter(typeof(T));
 }
示例#20
0
        protected override void Initialize(ContentCompiler compiler)
        {
            playerWriter = compiler.GetTypeWriter(typeof(Player)) as PlayerContentWriter;

            base.Initialize(compiler);
        }
示例#21
0
            protected override void Initialize(ContentCompiler compiler)
            {
                gameobjectWriter = compiler.GetTypeWriter(typeof(GameplayObject)) as GameplayObjectWriter;

                base.Initialize(compiler);
            }