diff --git a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs --- a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs +++ b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs @@ -96,10 +96,10 @@ var contractCount = contractOrganizations.Count(); OrganizationType organization_type = OrganizationType.Unspecified; + var organization_index = random_generator.Next(0, contractCount); if (contractCount > 0) { - var organization_index = random_generator.Next(0, contractCount); organization_type = GetComponent(contractOrganizations[organization_index]).type; } diff --git a/isometric-park-fna/Logging.cs b/isometric-park-fna/Logging.cs --- a/isometric-park-fna/Logging.cs +++ b/isometric-park-fna/Logging.cs @@ -1,9 +1,13 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Reflection; -// using System.Linq; +using System.Linq; + + +using JM.LinqFaster; /* Tiny log library inspired by Python's logging and Glögi. */ @@ -25,6 +29,8 @@ // private // + + public static List entries = new List(); private static Dictionary mappings = new Dictionary { {LogLevel.Critical, (ConsoleColor.White, ConsoleColor.Red)}, @@ -62,7 +68,26 @@ Console.Out.WriteLine(string.Format(" {0} [{1}:{2}]", message, path, lineNumber)); } - public static void Log(LogLevel level, string message, + private static void Log_(LogLevel level, string message, T data, + int lineNumber, string caller, string path) + where T : ITuple + { + Logging.entries.Add(data); + // var d = data.GetType().GetProperties().ToDictionary(Info => Info.Name, Info => Info.GetValue(data)); + // var data_strings = data.GetType().GetProperties().Select(Info => Info.Name + "=" + Info.GetValue(data).ToString()); + // var data_string = string.Join(", ", data_strings); + // var str = String.Format("{0} {1}", message, data_string); + Logging.Log_(level, message, lineNumber, caller, path); + } + + private static void Log_(LogLevel level, string message, + int lineNumber, string caller, string path, params object[] objects) + { + String.Format(message, objects); + Logging.Log_(level, message, lineNumber, caller, path); + } + + public static void Log(LogLevel level, string message, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null, [CallerFilePath] string path = "") @@ -71,6 +96,48 @@ Logging.Log_(level, message, lineNumber, caller, path); } + /* + public static void Log(LogLevel level, string message, T data, + [CallerLineNumber] int lineNumber = 0, + [CallerMemberName] string caller = null, + [CallerFilePath] string path = "") + //Constrain to Tuples and tuple-likes: + where T : ITuple, IStructuralEquatable, IStructuralComparable + { + Logging.Log_(level, message, data, lineNumber, caller, path); + }*/ + + public static void Log(LogLevel level, string message, T data, + [CallerLineNumber] int lineNumber = 0, + [CallerMemberName] string caller = null, + [CallerFilePath] string path = "") + //Constrain to Tuples and tuple-likes: + where T : class + { + + var properties = new List(); + + foreach (var property in typeof(T).GetProperties()) + { + properties.Add(property.ToString() + "=" + property.GetValue(data)); + } + + var message_data = message + " {" + String.Join(", ", properties) + "}"; + + Logging.Log_(level, message_data, lineNumber, caller, path); + + } + + public static void Log(LogLevel level, string message, + object[] format, + [CallerLineNumber] int lineNumber = 0, + [CallerMemberName] string caller = null, + [CallerFilePath] string path = "") + { + + Logging.Log_(level, message, lineNumber, caller, path, format); + } + public static void Critical(string message, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null, diff --git a/isometric-park-fna/UI/DebugWindow.cs b/isometric-park-fna/UI/DebugWindow.cs --- a/isometric-park-fna/UI/DebugWindow.cs +++ b/isometric-park-fna/UI/DebugWindow.cs @@ -171,6 +171,12 @@ Logging.Debug("Test"); Logging.Trace("Test"); + + // var t = (testa: 1, testb: 2); + //Logging.Log(LogLevel.Critical, "Test", t); + Logging.Log(LogLevel.Critical, "test", new{test=9.0f}); + //Logging.Log(LogLevel.Critical, "{0}", 0, null, "", 9.0f); + Logging.Spy(new {debugInfo.cameraPosition, debugInfo.updateTime, test = 9.0f /2}); } diff --git a/isometric-park-fna/UI/NewsWindow.cs b/isometric-park-fna/UI/NewsWindow.cs --- a/isometric-park-fna/UI/NewsWindow.cs +++ b/isometric-park-fna/UI/NewsWindow.cs @@ -35,7 +35,7 @@ var result = grammar.Flatten(variableString); #if DEBUG - Logging.Debug(variableString); + Logging.Trace(String.Format("{0}: {1}", variableString, result)); #endif return new NewsItem {