|
@@ -1,5 +1,6 @@
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
+using System.Drawing;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using NTERA.Core;
|
|
using NTERA.Core;
|
|
using NTERA.EmuEra.Game.EraEmu.Content;
|
|
using NTERA.EmuEra.Game.EraEmu.Content;
|
|
@@ -94,14 +95,14 @@ namespace NTERA.Engine.Runtime
|
|
else if (index >= function.Parameters.Length && function.Parameters.Last().IsArrayParameter)
|
|
else if (index >= function.Parameters.Length && function.Parameters.Last().IsArrayParameter)
|
|
parameter = function.Parameters.Last();
|
|
parameter = function.Parameters.Last();
|
|
else
|
|
else
|
|
- throw new Exception($"Unable to assign parameter #{index + 1}");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unable to assign parameter #{index + 1}");
|
|
|
|
|
|
if (localVariables.ContainsKey(parameter.Name))
|
|
if (localVariables.ContainsKey(parameter.Name))
|
|
localVariables[parameter.Name] = parameters[index];
|
|
localVariables[parameter.Name] = parameters[index];
|
|
else if (globalVariables.ContainsKey(parameter.Name))
|
|
else if (globalVariables.ContainsKey(parameter.Name))
|
|
globalVariables[parameter.Name] = parameters[index];
|
|
globalVariables[parameter.Name] = parameters[index];
|
|
else
|
|
else
|
|
- throw new Exception($"Unable to assign parameter '{parameter.Name}' to a variable");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unable to assign parameter '{parameter.Name}' to a variable");
|
|
}
|
|
}
|
|
|
|
|
|
var executionContents = ExecutionProvider.GetExecutionNodes(function);
|
|
var executionContents = ExecutionProvider.GetExecutionNodes(function);
|
|
@@ -122,7 +123,7 @@ namespace NTERA.Engine.Runtime
|
|
|
|
|
|
if (node.Type == "result")
|
|
if (node.Type == "result")
|
|
{
|
|
{
|
|
- return new ExecutionResult(ExecutionResultType.FunctionReturn, ComputeExpression(context, node.SubNodes.Single()));
|
|
|
|
|
|
+ return new ExecutionResult(ExecutionResultType.FunctionReturn, ComputeExpression(context, node.Single()));
|
|
}
|
|
}
|
|
|
|
|
|
ExecuteNode(context, node);
|
|
ExecuteNode(context, node);
|
|
@@ -139,24 +140,40 @@ namespace NTERA.Engine.Runtime
|
|
string statement = node.Metadata["name"];
|
|
string statement = node.Metadata["name"];
|
|
|
|
|
|
if (!Base.Keywords.StaticKeywords.TryGetValue(statement, out var keywordAction))
|
|
if (!Base.Keywords.StaticKeywords.TryGetValue(statement, out var keywordAction))
|
|
- throw new Exception($"Unknown statement: '{statement}'");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unknown statement: '{statement}'");
|
|
|
|
|
|
keywordAction(this, context, node);
|
|
keywordAction(this, context, node);
|
|
|
|
|
|
return;
|
|
return;
|
|
|
|
+
|
|
case "assignment":
|
|
case "assignment":
|
|
string variableName = node["variable"].Metadata["name"];
|
|
string variableName = node["variable"].Metadata["name"];
|
|
|
|
|
|
if (context.LocalVariables.ContainsKey(variableName))
|
|
if (context.LocalVariables.ContainsKey(variableName))
|
|
- context.LocalVariables[variableName] = ComputeExpression(context, node["value"].SubNodes.Single());
|
|
|
|
|
|
+ context.LocalVariables[variableName] = ComputeExpression(context, node["value"].Single());
|
|
else if (context.GlobalVariables.ContainsKey(variableName))
|
|
else if (context.GlobalVariables.ContainsKey(variableName))
|
|
- context.GlobalVariables[variableName] = ComputeExpression(context, node["value"].SubNodes.Single());
|
|
|
|
|
|
+ context.GlobalVariables[variableName] = ComputeExpression(context, node["value"].Single());
|
|
else
|
|
else
|
|
- throw new Exception($"Unknown variable: '{variableName}'");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unknown variable: '{variableName}'");
|
|
|
|
|
|
return;
|
|
return;
|
|
|
|
+
|
|
|
|
+ case "call":
|
|
|
|
+ string procedureName = node.Metadata["target"];
|
|
|
|
+ var procedure = TotalProcedureDefinitions.FirstOrDefault(func => !func.IsReturnFunction && func.Name.Equals(procedureName, StringComparison.OrdinalIgnoreCase));
|
|
|
|
+
|
|
|
|
+ if (procedure == null)
|
|
|
|
+ throw new EraRuntimeException($"Unknown procedure: '{procedureName}'");
|
|
|
|
+
|
|
|
|
+ var executionResult = Call(procedure, node["parameters"].Select(x => ComputeExpression(context, x)).ToArray());
|
|
|
|
+
|
|
|
|
+ if (executionResult.Type != ExecutionResultType.None || executionResult.Result.HasValue)
|
|
|
|
+ throw new EraRuntimeException($"Unexpected result from procedure '{procedureName}': {executionResult.Type}");
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+
|
|
default:
|
|
default:
|
|
- throw new Exception($"Unknown node type: '{node.Type}'");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unknown node type: '{node.Type}'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -179,19 +196,19 @@ namespace NTERA.Engine.Runtime
|
|
else if (context.GlobalVariables.ContainsKey(variableName))
|
|
else if (context.GlobalVariables.ContainsKey(variableName))
|
|
return context.GlobalVariables[variableName];
|
|
return context.GlobalVariables[variableName];
|
|
else
|
|
else
|
|
- throw new Exception($"Unable to retrieve variable '{variableName}'");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unable to retrieve variable '{variableName}'");
|
|
|
|
|
|
case "call":
|
|
case "call":
|
|
string functionName = expressionNode.Metadata["target"];
|
|
string functionName = expressionNode.Metadata["target"];
|
|
var function = TotalProcedureDefinitions.FirstOrDefault(func => func.IsReturnFunction && func.Name.Equals(functionName, StringComparison.OrdinalIgnoreCase));
|
|
var function = TotalProcedureDefinitions.FirstOrDefault(func => func.IsReturnFunction && func.Name.Equals(functionName, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (function == null)
|
|
if (function == null)
|
|
- throw new Exception($"Unknown function: '{functionName}'");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unknown function: '{functionName}'");
|
|
|
|
|
|
- var executionResult = Call(function, expressionNode["parameters"].SubNodes.Select(x => ComputeExpression(context, x)).ToArray());
|
|
|
|
|
|
+ var executionResult = Call(function, expressionNode["parameters"].Select(x => ComputeExpression(context, x)).ToArray());
|
|
|
|
|
|
if (executionResult.Type != ExecutionResultType.FunctionReturn || !executionResult.Result.HasValue)
|
|
if (executionResult.Type != ExecutionResultType.FunctionReturn || !executionResult.Result.HasValue)
|
|
- throw new Exception($"Unexpected result from function '{functionName}': {executionResult.Type}");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unexpected result from function '{functionName}': {executionResult.Type}");
|
|
|
|
|
|
return executionResult.Result.Value;
|
|
return executionResult.Result.Value;
|
|
|
|
|
|
@@ -205,28 +222,28 @@ namespace NTERA.Engine.Runtime
|
|
{
|
|
{
|
|
case "add": operatorToken = Token.Plus; break;
|
|
case "add": operatorToken = Token.Plus; break;
|
|
case "subtract": operatorToken = Token.Minus; break;
|
|
case "subtract": operatorToken = Token.Minus; break;
|
|
- default: throw new Exception($"Unknown operation type: '{operationType}'");
|
|
|
|
|
|
+ default: throw new EraRuntimeException($"Unknown operation type: '{operationType}'");
|
|
}
|
|
}
|
|
|
|
|
|
if (isUnary)
|
|
if (isUnary)
|
|
{
|
|
{
|
|
- Value innerValue = ComputeExpression(context, expressionNode.SubNodes.Single());
|
|
|
|
|
|
+ Value innerValue = ComputeExpression(context, expressionNode.Single());
|
|
|
|
|
|
switch (operatorToken)
|
|
switch (operatorToken)
|
|
{
|
|
{
|
|
case Token.Plus: return innerValue;
|
|
case Token.Plus: return innerValue;
|
|
case Token.Minus: return innerValue * -1;
|
|
case Token.Minus: return innerValue * -1;
|
|
- default: throw new Exception($"Unsupported unary operation type: '{operationType}'");
|
|
|
|
|
|
+ default: throw new EraRuntimeException($"Unsupported unary operation type: '{operationType}'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var left = ComputeExpression(context, expressionNode.SubNodes[0]);
|
|
|
|
- var right = ComputeExpression(context, expressionNode.SubNodes[1]);
|
|
|
|
|
|
+ var left = ComputeExpression(context, expressionNode[0]);
|
|
|
|
+ var right = ComputeExpression(context, expressionNode[1]);
|
|
|
|
|
|
return left.Operate(right, operatorToken);
|
|
return left.Operate(right, operatorToken);
|
|
|
|
|
|
default:
|
|
default:
|
|
- throw new Exception($"Unknown expression type: '{expressionNode.Type}'");
|
|
|
|
|
|
+ throw new EraRuntimeException($"Unknown expression type: '{expressionNode.Type}'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -247,7 +264,9 @@ namespace NTERA.Engine.Runtime
|
|
|
|
|
|
public CroppedImage GetImage(string name)
|
|
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);
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|