Variables.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. namespace NTERA.Engine.Runtime.Base
  5. {
  6. public static class Variables
  7. {
  8. public class VariableAttribute : Attribute
  9. {
  10. public string Name { get; }
  11. public ValueType Type { get; }
  12. public VariableAttribute(string name, ValueType type)
  13. {
  14. Name = name;
  15. Type = type;
  16. }
  17. }
  18. public static Dictionary<VariableAttribute, Func<EraRuntime, int[], Value>> StaticVariables { get; } = _getFunctions();
  19. private static Dictionary<VariableAttribute, Func<EraRuntime, int[], Value>> _getFunctions()
  20. {
  21. var output = new Dictionary<VariableAttribute, Func<EraRuntime, int[], Value>>();
  22. foreach (MethodInfo method in typeof(Variables).GetMethods(BindingFlags.Public | BindingFlags.Static))
  23. {
  24. var variable = method.GetCustomAttribute<VariableAttribute>();
  25. if (variable != null)
  26. output[variable] = (Func<EraRuntime, int[], Value>)Delegate.CreateDelegate(typeof(Func<EraRuntime, int[], Value>), method);
  27. }
  28. return output;
  29. }
  30. [Variable("LINECOUNT", ValueType.Real)]
  31. public static Value LineCount(EraRuntime runtime, int[] index)
  32. {
  33. return runtime.Console.LineCount;
  34. }
  35. [Variable("GAMEBASE_AUTHOR", ValueType.String)]
  36. public static Value GameBaseAuthor(EraRuntime runtime, int[] index)
  37. {
  38. return runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["作者"];
  39. }
  40. [Variable("GAMEBASE_INFO", ValueType.String)]
  41. public static Value GameBaseInfo(EraRuntime runtime, int[] index)
  42. {
  43. return runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["追加情報"];
  44. }
  45. [Variable("GAMEBASE_YEAR", ValueType.String)]
  46. public static Value GameBaseYear(EraRuntime runtime, int[] index)
  47. {
  48. return runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["製作年"];
  49. }
  50. [Variable("GAMEBASE_TITLE", ValueType.String)]
  51. public static Value GameBaseTitle(EraRuntime runtime, int[] index)
  52. {
  53. return runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["タイトル"];
  54. }
  55. [Variable("GAMEBASE_GAMECODE", ValueType.Real)]
  56. public static Value GameBaseGameCode(EraRuntime runtime, int[] index)
  57. {
  58. return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["コード"]);
  59. }
  60. [Variable("GAMEBASE_VERSION", ValueType.Real)]
  61. public static Value GameBaseVersion(EraRuntime runtime, int[] index)
  62. {
  63. return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["バージョン"]);
  64. }
  65. [Variable("GAMEBASE_ALLOWVERSION", ValueType.Real)]
  66. public static Value GameBaseAllowVersion(EraRuntime runtime, int[] index)
  67. {
  68. return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["バージョン違い認める"]);
  69. }
  70. [Variable("GAMEBASE_DEFAULTCHARA", ValueType.Real)]
  71. public static Value GameBaseDefaultChara(EraRuntime runtime, int[] index)
  72. {
  73. return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["最初からいるキャラ"]);
  74. }
  75. [Variable("GAMEBASE_NOITEM", ValueType.Real)]
  76. public static Value GameBaseNoItem(EraRuntime runtime, int[] index)
  77. {
  78. return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["アイテムなし"]);
  79. }
  80. }
  81. }