Added textures to maps

This commit is contained in:
2015-05-09 18:06:30 +03:00
parent 7d5f24c998
commit 11ca59d8bb
43 changed files with 633 additions and 58 deletions

View File

@ -4,13 +4,16 @@ using System.Linq;
using System.Text;
using UnityEngine;
namespace GraphingCalculator
namespace TransportGame.Utils
{
public class Expression
{
#region Types
public enum TokenType
/// <summary>
/// Token types
/// </summary>
protected enum TokenType
{
None, Literal, Identifier, Operator, ArgSeparator,
LParanthesis, RParanthesis, Function
@ -21,9 +24,21 @@ namespace GraphingCalculator
/// </summary>
protected class Token
{
/// <summary>
/// Token type
/// </summary>
public TokenType Type { get; set; }
/// <summary>
/// Token text
/// </summary>
public string Text { get; set; }
/// <summary>
/// Initializes a token
/// </summary>
/// <param name="type">Token type</param>
/// <param name="text">Token text</param>
public Token(TokenType type, string text)
{
Type = type;
@ -33,15 +48,25 @@ namespace GraphingCalculator
#endregion
#region Variables, properties
private string expressionString;
private bool parsed = false;
#region Public properties
/// <summary>
/// Gets the tokens in order
/// </summary>
protected List<Token> Tokens { get; private set; }
/// <summary>
/// Gets the postfix expression
/// </summary>
protected List<Token> Postfix { get; private set; }
/// <summary>
/// Gets the list of variables
/// </summary>
public Dictionary<string, float> Variables { get; private set; }
/// <summary>
/// Gets or sets the expression string
/// </summary>
public string ExpressionString
{
get { return expressionString; }
@ -51,18 +76,21 @@ namespace GraphingCalculator
parsed = false;
}
}
#endregion
#region Other stuff
#region Private fields
public void AddVariable(string name, float value)
{
Variables.Add(name, value);
}
private string expressionString;
private bool parsed = false;
#endregion
#region Constructor
/// <summary>
/// Initializes this instance of expression
/// </summary>
public Expression()
{
Tokens = new List<Token>();
@ -72,13 +100,33 @@ namespace GraphingCalculator
Variables.Add("pi", Mathf.PI);
}
/// <summary>
/// Initializes this instance of expression
/// </summary>
/// <param name="expr">Expression text</param>
public Expression(string expr)
: this()
{
expressionString = expr;
}
#endregion
#region Other stuff
/// <summary>
/// Adds a variable
/// </summary>
/// <param name="name">Variable name</param>
/// <param name="value">Variable value</param>
public void AddVariable(string name, float value)
{
Variables.Add(name, value);
}
#endregion
#region Parser
private void AnalyzeLex()
@ -205,6 +253,9 @@ namespace GraphingCalculator
}
}
/// <summary>
/// Parses the expression
/// </summary>
public void ParseExpression()
{
if (!parsed)
@ -217,6 +268,10 @@ namespace GraphingCalculator
}
}
/// <summary>
/// Evaluates the expression, and parses it if not parsed yet.
/// </summary>
/// <returns>Result of evaluation</returns>
public float Evaluate()
{
// Parse expression first
@ -303,6 +358,7 @@ namespace GraphingCalculator
return stack.Pop();
}
#endregion
#region Helper routines

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9376fb88fdf55af4db8c52c23079dad3
timeCreated: 1431078213
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: