Term.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using NTERA.EmuEra.Game.EraEmu.GameData.Variable;
  3. namespace NTERA.EmuEra.Game.EraEmu.GameData.Expression
  4. {
  5. internal sealed class NullTerm : IOperandTerm
  6. {
  7. public NullTerm(Int64 i)
  8. : base(typeof(Int64))
  9. {
  10. }
  11. public NullTerm(string s)
  12. : base(typeof(string))
  13. {
  14. }
  15. }
  16. /// <summary>
  17. /// 項。一単語だけ。
  18. /// </summary>
  19. internal sealed class SingleTerm : IOperandTerm
  20. {
  21. public SingleTerm(bool i)
  22. : base(typeof(Int64))
  23. {
  24. if (i)
  25. iValue = 1;
  26. else
  27. iValue = 0;
  28. }
  29. public SingleTerm(Int64 i)
  30. : base(typeof(Int64))
  31. {
  32. iValue = i;
  33. }
  34. public SingleTerm(string s)
  35. : base(typeof(string))
  36. {
  37. sValue = s;
  38. }
  39. readonly Int64 iValue;
  40. string sValue;
  41. public override long GetIntValue(ExpressionMediator exm)
  42. {
  43. return iValue;
  44. }
  45. public override string GetStrValue(ExpressionMediator exm, bool translate=false)
  46. {
  47. //Modified by Bartoum
  48. //PRINTS go through here.
  49. if (exm != null && exm.Process != null && exm.Process.getCurrentLine != null)
  50. {
  51. string name = exm.Process.getCurrentLine.ToString();
  52. name = Translation.searchParentFile(name);
  53. sValue = Translation.translate(sValue, name, translate);
  54. }
  55. return sValue;
  56. }
  57. public override SingleTerm GetValue(ExpressionMediator exm, bool tryTranslate =false)
  58. {
  59. return this;
  60. }
  61. public string Str
  62. {
  63. get => sValue;
  64. set // JVN: Set method needed to make things work smoother for PARAM stuff
  65. {
  66. sValue = value;
  67. }
  68. }
  69. public Int64 Int => iValue;
  70. public override string ToString()
  71. {
  72. if (GetOperandType() == typeof(Int64))
  73. return iValue.ToString();
  74. if (GetOperandType() == typeof(string))
  75. return sValue;
  76. return base.ToString();
  77. }
  78. public override IOperandTerm Restructure(ExpressionMediator exm, bool tryTranslate=false)
  79. {
  80. return this;
  81. }
  82. }
  83. /// <summary>
  84. /// 項。一単語だけ。
  85. /// </summary>
  86. internal sealed class StrFormTerm : IOperandTerm
  87. {
  88. public StrFormTerm(StrForm sf)
  89. : base(typeof(string))
  90. {
  91. sfValue = sf;
  92. }
  93. readonly StrForm sfValue;
  94. public StrForm StrForm => sfValue;
  95. public override string GetStrValue(ExpressionMediator exm, bool translate=false)
  96. {
  97. // Bartoum: If the current line containts <nonbutton (for HTML) we translate it.
  98. if (exm.Process.getCurrentLine.ToString().Contains("<nonbutton"))
  99. {
  100. translate = true;
  101. }
  102. return sfValue.GetString(exm, translate);
  103. }
  104. public override SingleTerm GetValue(ExpressionMediator exm, bool tryTranslate =false)
  105. {
  106. return new SingleTerm(sfValue.GetString(exm, tryTranslate));
  107. }
  108. public override IOperandTerm Restructure(ExpressionMediator exm, bool tryTranslate=false)
  109. {
  110. sfValue.Restructure(exm);
  111. if(sfValue.IsConst)
  112. return new SingleTerm(sfValue.GetString(exm, tryTranslate));
  113. IOperandTerm term = sfValue.GetIOperandTerm();
  114. if(term != null)
  115. return term;
  116. return this;
  117. }
  118. }
  119. }