Explorar o código

More refactoring

Bepis %!s(int64=6) %!d(string=hai) anos
pai
achega
355ec1a530

+ 3 - 1
NTERA.Interpreter/Engine.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Drawing;
 using System.IO;
 using NTERA.Core;
 using NTERA.EmuEra.Game.EraEmu.Content;
@@ -45,7 +46,8 @@ namespace NTERA.Interpreter
 
 		public CroppedImage GetImage(string name)
 		{
-			throw new NotImplementedException();
+		    var bitmap = new Bitmap(@"M:\era\eraSemifullTest\resources\bbb.png");
+            return new CroppedImage(name, bitmap, new Rectangle(Point.Empty, bitmap.Size), false);
 		}
 	}
 }

+ 17 - 3
NTERA.Interpreter/Interpreter.cs

@@ -263,16 +263,30 @@ namespace NTERA.Interpreter
             console.PrintSingleLine(Expr().ToString());
         }
 
-        private static Regex formRegex = new Regex("{(.*?)}");
+
+        [TargetKeyword(Token.PrintImg)]
+        void PrintImg()
+        {
+            console.PrintImg(Expr().ToString().Trim().Trim('"'));
+        }
+
+
+        [TargetKeyword(Token.PrintButton)]
+        void PrintButton()
+        {
+            console.PrintButton(Expr().ToString(), 0);
+        }
+
+        private static readonly Regex FormRegex = new Regex("{(.*?)}");
 
         [TargetKeyword(Token.PrintFormL)]
         void PrintFormL()
         {
             string rawString = Expr().ToString();
 
-            var evaluator = new MatchEvaluator((match) => { return vars[match.Groups[1].Value].ToString(); });
+            var evaluator = new MatchEvaluator(match => vars[match.Groups[1].Value].ToString());
 
-            console.PrintSingleLine(formRegex.Replace(rawString, evaluator));
+            console.PrintSingleLine(FormRegex.Replace(rawString, evaluator));
         }
 
         [TargetKeyword(Token.DrawLine)]

+ 20 - 18
NTERA.Interpreter/Lexer.cs

@@ -68,6 +68,16 @@ namespace NTERA.Interpreter
             ["TIMES"] = Token.Times,
         };
 
+        private readonly Dictionary<string, Token> TokenLineDictionary = new Dictionary<string, Token>(StringComparer.InvariantCultureIgnoreCase)
+        {
+            ["PRINT"] = Token.Print,
+            ["PRINTL"] = Token.PrintL,
+            ["DRAWLINEFORM"] = Token.DrawLineForm,
+            ["PRINTFORML"] = Token.PrintFormL,
+            ["PRINT_IMG"] = Token.PrintImg,
+            ["PRINTBUTTON"] = Token.PrintButton,
+        };
+
         public IEnumerable<Token> GetTokens()
         {
             while (true)
@@ -85,29 +95,21 @@ namespace NTERA.Interpreter
                     while (char.IsLetterOrDigit(GetChar()) || lastChar == '_')
                         Identifer += lastChar;
 
-                    if (TokenDictionary.ContainsKey(Identifer))
+                    if (TokenDictionary.TryGetValue(Identifer, out Token token))
                     {
-                        yield return TokenDictionary[Identifer];
+                        yield return token;
                         continue;
                     }
 
-                    switch (Identifer.ToUpper())
+                    if (TokenLineDictionary.TryGetValue(Identifer, out token))
                     {
-                        case "DRAWLINEFORM":
-                            foreach (Token t in ReturnAsLine(Token.DrawLineForm))
-                                yield return t;
-                            continue;
-
-                        case "PRINTFORML":
-                            foreach (Token t in ReturnAsLine(Token.PrintFormL))
-                                yield return t;
-                            continue;
-
-                        case "PRINT":
-                            foreach (Token t in ReturnAsLine(Token.Print))
-                                yield return t;
-                            continue;
+                        foreach (Token t in ReturnAsLine(token))
+                            yield return t;
+                        continue;
+                    }
 
+                    switch (Identifer.ToUpper())
+                    {
                         case "REM":
                             while (lastChar != '\n')
                                 GetChar();
@@ -224,7 +226,7 @@ namespace NTERA.Interpreter
 
             yield return token;
 
-            Value = new Value(bodyBuilder.ToString());
+            Value = new Value(bodyBuilder.ToString().TrimEnd());
             yield return Token.Value;
 
             yield return Token.NewLine;

+ 1 - 3
NTERA.Interpreter/NTERA.Interpreter.csproj

@@ -32,11 +32,9 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Drawing" />
     <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Net.Http" />
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>

+ 2 - 0
NTERA.Interpreter/Token.cs

@@ -20,6 +20,8 @@ namespace NTERA.Interpreter
         PrintL,
         PrintForm,
         PrintFormL,
+        PrintImg,
+        PrintButton,
 
         //Keywords
         If,