using System;
using System.Collections.Generic;
using System.Text;
namespace VGSBeta
{
public interface ICode
{
string Name { get; set; }
List<Variable> Variables { get; set; }
Parameters Parameters { get; set; }
/// <summary>
/// Actual code, generated and supplied to a complete method/class/etc.
/// </summary>
/// <returns></returns>
List<string> GenerateCode();
/// <summary>
/// The text displayed in the Event-Style Editors.
/// </summary>
/// <returns></returns>
string EditorText();
}
namespace Codes
{
namespace Common
{
public class VariableOperations : ICode
{
private string name;
private List<Variable> variables;
private Parameters parameters;
private Scope scope;
public VariableOperations()
{
name = "Variable Operations";
scope = Scope.Local;
variables = new List<Variable>();
parameters = new Parameters();
VariableListParameter param1 = new VariableListParameter("VariableChoice", "A List of variables.", Scope.Local);
ListParameter param2 = new ListParameter("Action", "A list of actions.", "Set", "Add", "Sub", "Mod", "Multiply", "Divide");
BasicParameter param3 = new BasicParameter("Value", "The value that the variable will be 'actioned' by.");
parameters.Add(param1);
parameters.Add(param2);
parameters.Add(param3);
}
public Scope Scope
{
get { return scope; }
set
{
VariableListParameter param = (VariableListParameter)parameters["VariableChoice"];
param.Scope = scope = value;
parameters["VaraibleChoice"] = param;
}
}
#region ICode Members
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public List<Variable> Variables
{
get
{
return variables;
}
set
{
variables = value;
}
}
public Parameters Parameters
{
get
{
return parameters;
}
set
{
parameters = value;
}
}
public List<string> GenerateCode()
{
List<string> lines = new List<string>();
VariableListParameter vList = (VariableListParameter)parameters["VariableChoice"];
Variable var = VGSBeta.Variables.GetVariable(vList.Value, vList.Scope);
ListParameter action = (ListParameter)parameters["Action"];
BasicParameter value = (BasicParameter)parameters["Value"];
string actionSymbol = "";
if (action.Value == "Set")
actionSymbol = "=";
else if (action.Value == "Add")
actionSymbol = "+";
else if (action.Value == "Sub")
actionSymbol = "-";
else if (action.Value == "Mod")
actionSymbol = "%";
else if (action.Value == "Multiply")
actionSymbol = "*";
else if (action.Value == "Divide")
actionSymbol = "/";
string result = string.Format("{0} {1} {2}", var.FullName, actionSymbol, value.Value);
lines.Add(result);
return lines;
}
public string EditorText()
{
return string.Format("Variable [{0}] {1} {2}", parameters["VariableChoice"], parameters["Action"], parameters["Value"]);
}
#endregion
}
}
}
}