示例#1
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            Log.Info("Mud Designer Toolkit Editor starting.");
            Log.Info("Loading script references.");


            //Loop through each reference mentioned in the engines properties and add them.
            //This provides support for 3rd party pre-compiled *mods* scripts
            foreach (var path in from string reference in EngineSettings.Default.ScriptLibrary select Path.Combine(System.Environment.CurrentDirectory, reference))
            {
                CompileEngine.AddAssemblyReference(path);
                Log.Info(string.Format("Adding assembly reference {0}", path));
            }

            //Compile the scripts.
            bool result = CompileEngine.Compile(EngineSettings.Default.ScriptsPath);

            if (!result)
            {
                this.mainTxtServerInfo.Text = CompileEngine.Errors;
            }

            //Add the compiled script assembly to the script factory.
            ScriptFactory.AddAssembly(CompileEngine.CompiledAssembly);

            //Add the third party references.
            foreach (string reference in EngineSettings.Default.ScriptLibrary)
            {
                ScriptFactory.AddAssembly(reference);
            }

            if (File.Exists("MudDesigner.Scripts.dll"))
            {
                string path = Path.Combine(System.Environment.CurrentDirectory, "MudDesigner.Scripts.dll");
                ScriptFactory.AddAssembly(Assembly.LoadFile(path));
            }

            //Get a reference to a scripted instance of IGame.
            var game = (IGame)ScriptFactory.GetScript(EngineSettings.Default.GameScript, null);

            //In the event that the scripted Game class specified as the default is missing,
            //just search the engine for another one.
            if (game == null)
            {
                game = (IGame)ScriptFactory.FindInheritedScript("MudDesigner.Engine.Core.Game", null);

                if (game == null) //still could not find anything
                {
                    MessageBox.Show("Critical error: Could not locate a Game script to use. This can cause instability in the editor.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Log.Error(string.Format("{0}", CompileEngine.Errors));
                    //Logger.WriteLine(CompileEngine.Errors, Logger.Importance.Critical);

                    menuWorld.Enabled = false;
                    menuGame.Enabled  = false;
                    menuSave.Enabled  = false;

                    return;
                }
            }
            IServer server = new Server(4000);

            //Initialize the Game. Null reference to a server is passed because we don't need a server.
            game.Initialize(server);

            //Load the save game file.
            game.RestoreWorld();

            //Store a reference to the current game to the static Editor Type
            Editor.Game = game;

            //Update the GUI
            mainPropertyGame.SelectedObject   = Editor.Game;
            mainPropertyServer.SelectedObject = Editor.Game.Server;
            RefreshUI();
        }