using System; using System.Collections.Generic; using System.Reflection; namespace NTERA.Engine.Runtime.Base { public static class Variables { public class VariableAttribute : Attribute { public string Name { get; } public ValueType Type { get; } public VariableAttribute(string name, ValueType type) { Name = name; Type = type; } } public static Dictionary> StaticVariables { get; } = _getFunctions(); private static Dictionary> _getFunctions() { var output = new Dictionary>(); foreach (MethodInfo method in typeof(Variables).GetMethods(BindingFlags.Public | BindingFlags.Static)) { var variable = method.GetCustomAttribute(); if (variable != null) output[variable] = (Func)Delegate.CreateDelegate(typeof(Func), method); } return output; } [Variable("LINECOUNT", ValueType.Real)] public static Value LineCount(EraRuntime runtime, int[] index) { return runtime.Console.LineCount; } [Variable("GAMEBASE_AUTHOR", ValueType.String)] public static Value GameBaseAuthor(EraRuntime runtime, int[] index) { return runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["作者"]; } [Variable("GAMEBASE_INFO", ValueType.String)] public static Value GameBaseInfo(EraRuntime runtime, int[] index) { return runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["追加情報"]; } [Variable("GAMEBASE_YEAR", ValueType.String)] public static Value GameBaseYear(EraRuntime runtime, int[] index) { return runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["製作年"]; } [Variable("GAMEBASE_TITLE", ValueType.String)] public static Value GameBaseTitle(EraRuntime runtime, int[] index) { return runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["タイトル"]; } [Variable("GAMEBASE_GAMECODE", ValueType.Real)] public static Value GameBaseGameCode(EraRuntime runtime, int[] index) { return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["コード"]); } [Variable("GAMEBASE_VERSION", ValueType.Real)] public static Value GameBaseVersion(EraRuntime runtime, int[] index) { return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["バージョン"]); } [Variable("GAMEBASE_ALLOWVERSION", ValueType.Real)] public static Value GameBaseAllowVersion(EraRuntime runtime, int[] index) { return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["バージョン違い認める"]); } [Variable("GAMEBASE_DEFAULTCHARA", ValueType.Real)] public static Value GameBaseDefaultChara(EraRuntime runtime, int[] index) { return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["最初からいるキャラ"]); } [Variable("GAMEBASE_NOITEM", ValueType.Real)] public static Value GameBaseNoItem(EraRuntime runtime, int[] index) { return double.Parse(runtime.ExecutionProvider.CSVDefinition.GameBaseInfo["アイテムなし"]); } } }