Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Ink / InkLibs / InkCompiler / ParsedHierarchy / Number.cs
  1. namespace Ink.Parsed
  2. {
  3. public class Number : Parsed.Expression
  4. {
  5. public object value;
  6. public Number(object value)
  7. {
  8. if (value is int || value is float || value is bool) {
  9. this.value = value;
  10. } else {
  11. throw new System.Exception ("Unexpected object type in Number");
  12. }
  13. }
  14. public override void GenerateIntoContainer (Runtime.Container container)
  15. {
  16. if (value is int) {
  17. container.AddContent (new Runtime.IntValue ((int)value));
  18. } else if (value is float) {
  19. container.AddContent (new Runtime.FloatValue ((float)value));
  20. } else if(value is bool) {
  21. container.AddContent (new Runtime.BoolValue ((bool)value));
  22. }
  23. }
  24. public override string ToString ()
  25. {
  26. if (value is float) {
  27. return ((float)value).ToString(System.Globalization.CultureInfo.InvariantCulture);
  28. } else {
  29. return value.ToString();
  30. }
  31. }
  32. // Equals override necessary in order to check for CONST multiple definition equality
  33. public override bool Equals (object obj)
  34. {
  35. var otherNum = obj as Number;
  36. if (otherNum == null) return false;
  37. return this.value.Equals (otherNum.value);
  38. }
  39. public override int GetHashCode ()
  40. {
  41. return this.value.GetHashCode ();
  42. }
  43. }
  44. }