-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added Roslyn to the project. - Added an example of parsing game logic settings from a .csx file.
- Loading branch information
1 parent
a0b4c4d
commit 2f6360b
Showing
11 changed files
with
339 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Arrowgene.Ddon.GameServer.Scripting | ||
{ | ||
public class DdonLibrary | ||
{ | ||
public DdonLibrary() | ||
{ | ||
} | ||
|
||
public static uint GetValue() | ||
{ | ||
return 1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Arrowgene.Ddon.Server; | ||
using Arrowgene.Ddon.Shared; | ||
using Arrowgene.Ddon.Shared.Model; | ||
using Arrowgene.Logging; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Scripting; | ||
using Microsoft.CodeAnalysis.Scripting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace Arrowgene.Ddon.GameServer.Scripting | ||
{ | ||
public class Globals | ||
{ | ||
public DdonGameServer Server { get; set; } | ||
public GameLogicSetting GameLogicSetting { get; set; } | ||
} | ||
|
||
public class ScriptManager | ||
{ | ||
public string ScriptsRoot { get; private set; } | ||
public string SettingsPath { get; private set; } | ||
|
||
public Script Settings { | ||
get { | ||
return CompiledScripts["Settings"]; | ||
} | ||
set | ||
{ | ||
CompiledScripts["Settings"] = value; | ||
} | ||
} | ||
|
||
private Dictionary<string, Script> CompiledScripts; | ||
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(ScriptManager)); | ||
private Globals Globals { get; } | ||
private DdonGameServer Server { get; } | ||
|
||
public event EventHandler<AssetChangedEventArgs> AssetChanged; | ||
private readonly DirectoryInfo ScriptsDirectory; | ||
private readonly Dictionary<string, FileSystemWatcher> FileSystemWatchers; | ||
|
||
public ScriptManager(DdonGameServer server) | ||
{ | ||
ScriptsRoot = $"{server.AssetRepository.AssetsPath}\\scripts"; | ||
SettingsPath = $"{ScriptsRoot}\\Settings.csx"; | ||
|
||
Server = server; | ||
Globals = new Globals() | ||
{ | ||
Server = server, | ||
GameLogicSetting = server.Setting.GameLogicSetting | ||
}; | ||
|
||
ScriptsDirectory = new DirectoryInfo(ScriptsRoot); | ||
if (!ScriptsDirectory.Exists) | ||
{ | ||
Logger.Error($"Could not compile scripts, unable to locate the path '{ScriptsRoot}'"); | ||
return; | ||
} | ||
|
||
FileSystemWatchers = new Dictionary<string, FileSystemWatcher>(); | ||
|
||
CompiledScripts = new Dictionary<string, Script>(); | ||
|
||
CompileScripts(); | ||
} | ||
|
||
private void CompileScripts() | ||
{ | ||
var options = ScriptOptions.Default | ||
.WithReferences(MetadataReference.CreateFromFile(typeof(DdonGameServer).Assembly.Location)) | ||
.WithReferences(MetadataReference.CreateFromFile(typeof(GameLogicSetting).Assembly.Location)) | ||
.WithReferences(MetadataReference.CreateFromFile(typeof(WalletType).Assembly.Location)) | ||
.WithImports("System", "System.Collections", "System.Collections.Generic", | ||
"Arrowgene", "Arrowgene.Ddon", "Arrowgene.Ddon.Shared", "Arrowgene.Ddon.Shared.Model"); | ||
|
||
// Load The Game Settings | ||
Settings = CSharpScript.Create( | ||
code: File.ReadAllText(SettingsPath), | ||
options: options, | ||
globalsType: typeof(Globals) | ||
); | ||
// Execute the script file to populate the settings | ||
Settings.RunAsync(Globals); | ||
|
||
// TODO: Load other game functionality we want to have scripted. | ||
} | ||
} | ||
} |
Oops, something went wrong.