XMLData class added. This will manage the saving and loading of all scripted objects during runtime. The saved files will be XML formatted.
Added rScript files to the engine. These have not been implemented and currently don't work with the engine. BaseScript has been modified to support the new XMLData class for saving data.
This commit is contained in:
parent
fc27d9fc22
commit
38bdf75bf1
16 changed files with 1174 additions and 25 deletions
126
MudEngine/WinPC_Engine/Scripting/CSharp.cs
Normal file
126
MudEngine/WinPC_Engine/Scripting/CSharp.cs
Normal file
|
@ -0,0 +1,126 @@
|
|||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if WINDOWS_PC
|
||||
using Microsoft.CSharp;
|
||||
#endif
|
||||
|
||||
namespace MudEngine.Scripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Standard C# source code compiler.
|
||||
/// </summary>
|
||||
internal class CSharp : ICompiler
|
||||
{
|
||||
#if WINDOWS_PC
|
||||
/// <summary>
|
||||
/// The file extension used for the script files.
|
||||
/// </summary>
|
||||
public String ScriptExtension { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Provides a collection of Assemblies that the compiler will add to its reference list.
|
||||
/// </summary>
|
||||
public List<String> AssemblyReferences { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The results of the compilation
|
||||
/// </summary>
|
||||
public CompilerResults Results { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Provides compiling options to various compilers, if they support this feature.
|
||||
/// </summary>
|
||||
public Dictionary<String, String> CompilerOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compiles the source files found within the scriptRepository directory matching the ICompiler.ScriptExtension
|
||||
/// The Compiler defaults to the C# 4.0 compiler if none other is supplied via the ICompiler.CompilerOptions argument.
|
||||
/// </summary>
|
||||
/// <param name="param">Compiler Parameters that can be supplied to customize the compilation of the source.</param>
|
||||
/// <returns>Returns true if the compilation was completed without error.</returns>
|
||||
public Boolean Compile(CompilerParameters param, String scriptRepository)
|
||||
{
|
||||
//Make sure we have a compiler version supplied.
|
||||
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||
CompilerOptions.Add("CompilerVersion", "v4.0");
|
||||
|
||||
//Instance a reference to the C# code provider, this is what will perform the compiling.
|
||||
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
|
||||
//Create an array of script files found within the ScriptRepository matching the ScriptExtension properties.
|
||||
String[] scripts = Directory.GetFiles(scriptRepository, "*" + this.ScriptExtension, SearchOption.AllDirectories);
|
||||
|
||||
//Compile the scripts and provide the Results property with a reference to the compilation results.
|
||||
Results = provider.CompileAssemblyFromFile(param, scripts);
|
||||
|
||||
//if the compiler has errors, return false.
|
||||
if (Results.Errors.HasErrors)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compiles the source files found within the scriptFile argument.
|
||||
/// The Compiler defaults to the C# 4.0 compiler if none other is supplied via the ICompiler.CompilerOptions argument.
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public Boolean Compile(CompilerParameters param, FileInfo scriptFile)
|
||||
{
|
||||
//Make sure we have a compiler version supplied.
|
||||
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||
CompilerOptions.Add("CompilerVersion", "v4.0");
|
||||
|
||||
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
|
||||
|
||||
//Make sure the file exists prior to attempting to compile it.
|
||||
if (scriptFile.Exists)
|
||||
{
|
||||
//Compile the script and provide the Results property with a referece to the compilation results.
|
||||
Results = provider.CompileAssemblyFromFile(param, scriptFile.FullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Results.Errors.Add(new CompilerError(scriptFile.FullName, 0, 0, "rS01", "The supplied filename does not exist."));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Results.Errors.HasErrors)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compiles the source code found within the scriptSourceCode argument
|
||||
/// The Compiler defaults to the C# 4.0 compiler if none other is supplied via the ICompiler.CompilerOptions argument.
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public Boolean Compile(CompilerParameters param, String[] scriptSourceCode)
|
||||
{
|
||||
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||
CompilerOptions.Add("CompilerVersion", "v4.0");
|
||||
|
||||
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
|
||||
|
||||
if (scriptSourceCode.Length == 0)
|
||||
{
|
||||
Results.Errors.Add(new CompilerError("None", 0, 0, "rS02", "No Source provided."));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Results = provider.CompileAssemblyFromSource(param, scriptSourceCode);
|
||||
}
|
||||
|
||||
if (Results.Errors.HasErrors)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue