Пример #1
0
        public CompilerResults Compile(CompileOptions compileOptions)
        {
            CompilerResults result = new CompilerResults();
            GameLoader      loader = new GameLoader();

            UpdateStatus(string.Format("Compiling {0} to {1}", compileOptions.Filename, compileOptions.OutputFolder));
            if (!loader.Load(compileOptions.Filename))
            {
                result.Errors = loader.Errors;
            }
            else
            {
                UpdateStatus("Loaded successfully");
                result.Warnings = loader.Warnings;
                result.Success  = true;
                var substitutionText = GetSubstitutionText(loader, compileOptions.Profile);
                UpdateStatus("Copying dependencies");
                result.IndexHtml = CopyDependenciesToOutputFolder(compileOptions.OutputFolder, substitutionText, compileOptions.DebugMode, compileOptions.Profile, compileOptions.Minify, loader, compileOptions);

                string saveData = string.Empty;

                UpdateStatus("Saving");
                GameSaver saver = new GameSaver(loader.Elements);
                saver.Progress += saver_Progress;
                saveData        = saver.Save();

                UpdateStatus("Copying resources");
                CopyResourcesToOutputFolder(loader.ResourcesFolder, compileOptions.OutputFolder);

                saveData += GetEmbeddedHtmlFileData(loader.ResourcesFolder);
                string saveJs = System.IO.Path.Combine(compileOptions.OutputFolder, "game.js");

                saveData = System.IO.File.ReadAllText(saveJs) + saveData;

                if (compileOptions.Minify)
                {
                    var minifier = new Microsoft.Ajax.Utilities.Minifier();
                    saveData = minifier.MinifyJavaScript(saveData, new Microsoft.Ajax.Utilities.CodeSettings
                    {
                        MacSafariQuirks    = true,
                        RemoveUnneededCode = true,
                        LocalRenaming      = Microsoft.Ajax.Utilities.LocalRenaming.CrunchAll
                    });

                    var encoding = (Encoding)Encoding.ASCII.Clone();
                    encoding.EncoderFallback = new Microsoft.Ajax.Utilities.JSEncoderFallback();
                    using (var writer = new System.IO.StreamWriter(saveJs, false, encoding))
                    {
                        writer.Write(saveData);
                    }
                }
                else
                {
                    System.IO.File.WriteAllText(saveJs, saveData);
                }

                UpdateStatus("Finished");
            }
            return(result);
        }
Пример #2
0
        private bool InitialiseInternal(GameLoader loader)
        {
            if (m_state != GameState.NotStarted)
            {
                throw new Exception("Game already initialised");
            }
            loader.FilenameUpdated += loader_FilenameUpdated;
            loader.LoadStatus += loader_LoadStatus;
            m_state = GameState.Loading;

            bool success;
            if (m_data != null)
            {
                success = loader.Load(data: m_data);
            }
            else
            {
                success = m_filename == null || loader.Load(m_filename);
            }

            DebugEnabled = !loader.IsCompiledFile;
            m_state = success ? GameState.Running : GameState.Finished;
            m_errors = loader.Errors;
            m_saver = new GameSaver(this);
            if (Version <= WorldModelVersion.v530)
            {
                m_legacyOutputLogger = new LegacyOutputLogger(this);
                m_outputLogger = m_legacyOutputLogger;
            }
            else
            {
                m_outputLogger = new OutputLogger(this);
            }
            return success;
        }
Пример #3
0
        public CompilerResults Compile(CompileOptions compileOptions)
        {
            CompilerResults result = new CompilerResults();
            GameLoader loader = new GameLoader();
            UpdateStatus(string.Format("Compiling {0} to {1}", compileOptions.Filename, compileOptions.OutputFolder));
            if (!loader.Load(compileOptions.Filename))
            {
                result.Errors = loader.Errors;
            }
            else
            {
                UpdateStatus("Loaded successfully");
                result.Warnings = loader.Warnings;
                result.Success = true;
                var substitutionText = GetSubstitutionText(loader, compileOptions.Profile);
                UpdateStatus("Copying dependencies");
                result.IndexHtml = CopyDependenciesToOutputFolder(compileOptions.OutputFolder, substitutionText, compileOptions.DebugMode, compileOptions.Profile, compileOptions.Minify, loader, compileOptions);

                string saveData = string.Empty;

                UpdateStatus("Saving");
                GameSaver saver = new GameSaver(loader.Elements);
                saver.Progress += saver_Progress;
                saveData = saver.Save();

                UpdateStatus("Copying resources");
                CopyResourcesToOutputFolder(loader.ResourcesFolder, compileOptions.OutputFolder);

                saveData += GetEmbeddedHtmlFileData(loader.ResourcesFolder);
                string saveJs = System.IO.Path.Combine(compileOptions.OutputFolder, "game.js");

                saveData = System.IO.File.ReadAllText(saveJs) + saveData;

                if (compileOptions.Minify)
                {
                    var minifier = new Microsoft.Ajax.Utilities.Minifier();
                    saveData = minifier.MinifyJavaScript(saveData, new Microsoft.Ajax.Utilities.CodeSettings
                    {
                        MacSafariQuirks = true,
                        RemoveUnneededCode = true,
                        LocalRenaming = Microsoft.Ajax.Utilities.LocalRenaming.CrunchAll
                    });

                    var encoding = (Encoding)Encoding.ASCII.Clone();
                    encoding.EncoderFallback = new Microsoft.Ajax.Utilities.JSEncoderFallback();
                    using (var writer = new System.IO.StreamWriter(saveJs, false, encoding))
                    {
                        writer.Write(saveData);
                    }
                }
                else
                {
                    System.IO.File.WriteAllText(saveJs, saveData);
                }

                UpdateStatus("Finished");
            }
            return result;
        }