Explorar o código

Decouple script engine from the game instance

Bepis %!s(int64=6) %!d(string=hai) anos
pai
achega
27043ce3b0

+ 1 - 4
NTERA/Game/EraEmu/Content/BaseImage.cs

@@ -1,10 +1,7 @@
-using System;
 using System.Drawing;
-using MinorShift._Library;
 
 namespace MinorShift.Emuera.Content
 {
-
 	internal sealed class BaseImage : AContentFile
 	{
 		public BaseImage(string name, string path)
@@ -53,4 +50,4 @@ namespace MinorShift.Emuera.Content
             Dispose();
         }
 	}
-}
+}

+ 1 - 8
NTERA/Game/EraEmu/Display/HTMLManager.cs

@@ -1,12 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Text;
-using System.Text.RegularExpressions;
-using MinorShift.Emuera;
-using MinorShift.Emuera.GameData.Expression;
+using System.Collections.Generic;
 using MinorShift.Emuera.Sub;
-using NTERA.Interop;
 
 namespace NTERA.Game.Display
 {

+ 38 - 0
NTERA/Game/EraEmu/EmuEraGameInstance.cs

@@ -0,0 +1,38 @@
+using MinorShift.Emuera;
+using MinorShift.Emuera.GameProc;
+using NTERA.Interop;
+
+namespace NTERA.Game.EraEmu
+{
+	public class EmuEraGameInstance : IScriptEngine
+	{
+		private Process emuera;
+
+		public bool Initialize(IConsole console)
+		{
+			emuera = new Process(console);
+			GlobalStatic.Process = emuera;
+			return emuera.Initialize();
+		}
+
+		public void Start()
+		{
+			emuera.DoScript();
+		}
+
+		public void InputString(string input)
+		{
+			emuera.InputString(input);
+		}
+
+		public void InputInteger(long input)
+		{
+			emuera.InputInteger(input);
+		}
+
+		public void InputSystemInteger(long input)
+		{
+			emuera.InputSystemInteger(input);
+		}
+	}
+}

+ 0 - 1
NTERA/Game/EraEmu/GameData/Function/Creator.Method.cs

@@ -10,7 +10,6 @@ using MinorShift.Emuera.GameData.Expression;
 using MinorShift.Emuera.GameData.Variable;
 using MinorShift.Emuera.Sub;
 using MinorShift._Library;
-using NTERA.Game.Display;
 using NTERA.Interop;
 
 namespace MinorShift.Emuera.GameData.Function

+ 0 - 1
NTERA/Game/EraEmu/GameProc/HeaderFileLoader.cs

@@ -1,5 +1,4 @@
 using System.Collections.Generic;
-using System.Windows.Forms;
 using MinorShift.Emuera.GameData;
 using MinorShift.Emuera.GameData.Variable;
 using MinorShift.Emuera.Sub;

+ 0 - 1
NTERA/Game/EraEmu/GameProc/Process.cs

@@ -9,7 +9,6 @@ using MinorShift.Emuera.GameData.Function;
 using MinorShift.Emuera.GameData.Variable;
 using MinorShift.Emuera.GameProc.Function;
 using MinorShift.Emuera.Sub;
-using MinorShift._Library;
 using NTERA.Interop;
 
 namespace MinorShift.Emuera.GameProc

+ 15 - 41
NTERA/Interop/GameInstance.cs

@@ -5,30 +5,25 @@ namespace NTERA.Interop
 {
 	public class GameInstance
 	{
-		private Process emuera;
+		public IConsole Console { get; protected set; }
+		public IScriptEngine ScriptEngine { get; set; }
 
-		public void Initialize(IConsole console)
+		public void Run(IConsole console, IScriptEngine scriptEngine)
 		{
+			Console = console;
 			GlobalStatic.Console = console;
-			//GlobalStatic.MainWindow = _window;
-			emuera = new Process(console);
-			GlobalStatic.Process = emuera;
-			//ClearDisplay();
-			if (!emuera.Initialize())
-			{
-				//state = ConsoleState.Error;
-				//OutputLog(null);
-				//PrintFlush(false);
-				//RefreshStrings(true);
+
+			ScriptEngine = scriptEngine;
+			
+			if (!ScriptEngine.Initialize(Console))
 				return;
-			}
-			CallEmueraProgram("");
-			//RefreshStrings(true);
+
+			ScriptEngine.Start();
 		}
 
 		public void GiveInput(string input)
 		{
-			InputRequest currentRequest = GlobalStatic.Console.CurrentRequest;
+			InputRequest currentRequest = Console.CurrentRequest;
 
 			if (GlobalStatic.Console.CurrentRequest != null)
 			{
@@ -46,43 +41,22 @@ namespace NTERA.Interop
 						{
 							break;
 						}
+
 						if (currentRequest.IsSystemInput)
-							emuera.InputSystemInteger(inputValue);
+							ScriptEngine.InputSystemInteger(inputValue);
 						else
-							emuera.InputInteger(inputValue);
+							ScriptEngine.InputInteger(inputValue);
 						break;
 					case InputType.StrValue:
 						if (string.IsNullOrEmpty(input) && currentRequest.HasDefValue)// && !IsRunningTimer)
 							input = currentRequest.DefStrValue;
 
-						emuera.InputString(input ?? "");
+						ScriptEngine.InputString(input ?? "");
 						break;
 				}
 			}
 
 			GlobalStatic.Console.GiveInput(input);
 		}
-
-		private void CallEmueraProgram(string str)
-		{
-			//if (!DoInputToEmueraProgram(str))
-			//	return;
-			//if (state == ConsoleState.Error)
-			//	return;
-			//state = ConsoleState.Running;
-			emuera.DoScript();
-//			if (state == ConsoleState.Running)
-//			{
-////RunningならProcessは処理を継続するべき
-//				state = ConsoleState.Error;
-//				PrintError("Emuera error: Unable to determine program status");
-//			}
-			//if (state == ConsoleState.Error && !noOutputLog)
-			//	OutputLog(Program.ExeDir + "emuera.log");
-			//PrintFlush(false);
-			////1819 Refreshは呼び出し側で行う
-			////RefreshStrings(false);
-			//NewGeneration();
-		}
 	}
 }

+ 12 - 0
NTERA/Interop/IScriptEngine.cs

@@ -0,0 +1,12 @@
+namespace NTERA.Interop
+{
+	public interface IScriptEngine
+	{
+		bool Initialize(IConsole console);
+		void Start();
+		
+		void InputString(string input);
+		void InputInteger(long input);
+		void InputSystemInteger(long input);
+	}
+}

+ 2 - 0
NTERA/NTERA.csproj

@@ -80,6 +80,7 @@
     <Compile Include="Game\EraEmu\Content\BaseImage.cs" />
     <Compile Include="Game\EraEmu\Content\CroppedImage.cs" />
     <Compile Include="Game\EraEmu\Display\HTMLManager.cs" />
+    <Compile Include="Game\EraEmu\EmuEraGameInstance.cs" />
     <Compile Include="Game\EraEmu\GameData\ConstantData.cs" />
     <Compile Include="Game\EraEmu\GameData\DefineMacro.cs" />
     <Compile Include="Game\EraEmu\GameData\Expression\CaseExpression.cs" />
@@ -150,6 +151,7 @@
     <Compile Include="Console\HtmlParser.cs" />
     <Compile Include="Interop\IConsole.cs" />
     <Compile Include="Interop\IMainWindow.cs" />
+    <Compile Include="Interop\IScriptEngine.cs" />
     <Compile Include="Interop\ProgramInstance.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

+ 2 - 1
NTERA/formMain.cs

@@ -2,6 +2,7 @@
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using NTERA.Console;
+using NTERA.Game.EraEmu;
 using NTERA.Interop;
 
 namespace NTERA
@@ -17,7 +18,7 @@ namespace NTERA
 			NTERA.Interop.Program.CMain(Directory.GetCurrentDirectory() + "\\");
 
 
-			Task.Factory.StartNew(() => instance.Initialize(new EraConsoleInstance(consoleControl1.Renderer)));
+			Task.Factory.StartNew(() => instance.Run(new EraConsoleInstance(consoleControl1.Renderer), new EmuEraGameInstance()));
 		}
 
 		private void txtInput_KeyUp(object sender, KeyEventArgs e)