3 private static const string LOG_DEBUG =
"Debug";
4 private static const string LOG_DEBUG_ACTION =
"Action";
5 private static const string LOG_DEBUG_SYMPTOM =
"Symptom";
6 private static const string LOG_DEBUG_INV_MOVE =
"Inv Move";
7 private static const string LOG_DEBUG_INV_RESERVATION =
"Inv Rrsv";
8 private static const string LOG_DEBUG_INV_HFSM =
"HFSM";
9 private static const string LOG_DEBUG_QUICKBAR =
"Quickbar";
10 private static const string LOG_DEBUG_BASEBUILDING =
"Base Building";
11 private static const string LOG_DEBUG_BLEEDING_CHANCES =
"Bleeding";
12 private static const string LOG_DEBUG_TRIGGER =
"Trigger";
13 private static const string LOG_DEBUG_PARTICLE =
"Particle";
14 private static const string LOG_DEBUG_TF =
"TestFramework";
15 private static const string LOG_DEBUG_WEIGHT =
"Weight";
16 private static const string LOG_DEBUG_MELEE =
"Melee";
17 private static const string LOG_DEBUG_WEATHER =
"Weather";
19 private static const string LOG_INFO =
"Info";
20 private static const string LOG_WARNING =
"Warning";
21 private static const string LOG_ERROR =
"Error";
22 private static const string LOG_DEFAULT =
"n/a";
26 static Widget m_DebugLayoutCanvas;
27 static CanvasWidget m_CanvasDebug;
35 if (CastTo(obj, entity))
36 return obj.GetDebugNameNative();
38 return entity.GetDebugName();
41 static void InitCanvas()
43 if (!m_DebugLayoutCanvas)
45 m_DebugLayoutCanvas =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/debug/day_z_debugcanvas.layout");
46 m_CanvasDebug = CanvasWidget.Cast( m_DebugLayoutCanvas.FindAnyWidget(
"CanvasWidget" ) );
50 static void ClearCanvas()
53 m_CanvasDebug.Clear();
56 static void CanvasDrawLine(
float x1,
float y1,
float x2,
float y2,
float width,
int color)
59 m_CanvasDebug.DrawLine(x1, y1, x2, y2, width, color);
73 static void CanvasDrawPoint(
float x1,
float y1,
int color)
75 CanvasDrawLine(x1, y1, x1+1, y1, 1, color);
83 static void DestroyAllShapes()
85 for (
int i = 0; i < m_DebugShapes.Count(); ++i )
87 if ( m_DebugShapes.Get(i) )
89 m_DebugShapes.Get(i).Destroy();
93 m_DebugShapes.Clear();
96 static void RemoveShape(out
Shape shape)
99 for (
int i = 0; i < m_DebugShapes.Count(); i++ )
101 Shape found_shape = m_DebugShapes.Get(i);
103 if ( found_shape && found_shape == shape )
105 found_shape.Destroy();
106 m_DebugShapes.Remove(i);
122 static void Log(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
124 LogMessage(LOG_DEBUG, plugin, entity, author, label, message);
127 static void ActionLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
129 LogMessage(LOG_DEBUG_ACTION, plugin, entity, author, label, message);
132 static void SymptomLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
134 LogMessage(LOG_DEBUG_SYMPTOM, plugin, entity, author, label, message);
137 static void InventoryMoveLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
139 LogMessage(LOG_DEBUG_INV_MOVE, plugin, entity, author, label, message);
142 static void InventoryReservationLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
144 LogMessage(LOG_DEBUG_INV_RESERVATION, plugin, entity, author, label, message);
147 static void InventoryHFSMLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
149 LogMessage(LOG_DEBUG_INV_HFSM, plugin, entity, author, label, message);
152 static void QuickbarLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
154 LogMessage(LOG_DEBUG_QUICKBAR, plugin, entity, author, label, message);
157 static void BaseBuildingLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
159 LogMessage(LOG_DEBUG_BASEBUILDING, plugin, entity, author, label, message);
162 static void BleedingChancesLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
164 LogMessage(LOG_DEBUG_BLEEDING_CHANCES, plugin, entity, author, label, message);
167 static void TriggerLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
169 LogMessage(LOG_DEBUG_TRIGGER, plugin, entity, author, label, message);
172 static void ParticleLog(
string message = LOG_DEFAULT,
Managed caller = null,
string function =
"",
Managed entity = null)
177 static void TFLog(
string message = LOG_DEFAULT, TestFramework caller = null,
string function =
"")
179 LogMessage(LOG_DEBUG_TF,
GetDebugName(caller),
"",
"", function, message);
182 static void WeightLog(
string message = LOG_DEFAULT,
Managed caller = null,
string function =
"",
Managed entity = null)
189 static void MeleeLog(
Entity entity,
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT)
191 string logMessage =
string.Format(
"%1: %2", entity.GetSimulationTimeStamp(), message);
192 LogMessage(LOG_DEBUG_MELEE, plugin,
GetDebugName(entity), author, label, logMessage);
195 static void WeatherLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
202 LogMessage(LOG_DEBUG_WEATHER, plugin, entity, author, label, message);
215 static void LogInfo(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
217 LogMessage(LOG_INFO, plugin, entity, author, label, message);
230 static void LogWarning(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
232 LogMessage(LOG_WARNING, plugin, entity, author, label, message);
245 static void LogError(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
247 LogMessage(LOG_ERROR, plugin, entity, author, label, message);
250 static void LogArrayInt(
array<int> arr = NULL,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
254 for (
int i = 0; i < arr.Count(); i++)
256 LogMessage(LOG_DEBUG, plugin, entity, author, label, arr.Get(i).ToString());
260 static void LogArrayString(
array<string> arr = NULL,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
265 for (
int i = 0; i < arr.Count(); i++)
267 LogMessage(LOG_DEBUG, plugin, entity, author, label, arr.Get(i));
271 static void ReceivedLogMessageFromServer(
string message)
281 static void ClearScriptLogs()
295 m_DebugShapes.Insert(shape);
299 static Shape DrawCube(
vector pos,
float size = 1,
int color = 0x1fff7f7f)
304 float size_h = size * 0.5;
306 min[0] = min[0] - size_h;
307 min[1] = min[1] - size_h;
308 min[2] = min[2] - size_h;
310 max[0] = max[0] + size_h;
311 max[1] = max[1] + size_h;
312 max[2] = max[2] + size_h;
315 m_DebugShapes.Insert(shape);
321 Shape shape =
Shape.CreateSphere(color, flags, pos, size);
323 m_DebugShapes.Insert(shape);
329 Shape shape =
Shape.CreateFrustum(horizontalAngle, verticalAngle, length, color, flags);
331 m_DebugShapes.Insert(shape);
337 Shape shape =
Shape.CreateCylinder(color, flags, pos, radius, height);
339 m_DebugShapes.Insert(shape);
343 static array<Shape> DrawCone(
vector pos,
float lenght,
float halfAngle,
float offsetAngle,
int color = 0xFFFFFFFF,
int flags = 0)
348 Math3D.ConePoints(pos, lenght, halfAngle, offsetAngle, endL, endR);
351 shapes.Insert(
Debug.DrawLine(pos, endL, color, flags) );
353 shapes.Insert(
Debug.DrawLine(pos, endR, color, flags) );
355 shapes.Insert(
Debug.DrawLine(endL, endR, color, flags) );
357 shapes.Insert(
Debug.DrawLine(pos, pos +
Vector(
Math.Cos(offsetAngle), 0,
Math.Sin(offsetAngle)).Normalized() * lenght, color, flags) );
364 foreach (
Shape shape : shapes)
365 Debug.RemoveShape(shape);
382 static Shape DrawLine(
vector from,
vector to,
int color = 0xFFFFFFFF,
int flags = 0)
388 Shape shape =
Shape.CreateLines(color, flags, pts, 2);
390 m_DebugShapes.Insert(shape);
395 static Shape DrawLines(
vector[] positions,
int count,
int color = 0xFFFFFFFF,
int flags = 0)
398 Shape shape =
Shape.CreateLines(color, flags, positions, count);
400 m_DebugShapes.Insert(shape);
404 static Shape DrawArrow(
vector from,
vector to,
float size = 0.5,
int color = 0xFFFFFFFF,
int flags = 0)
406 Shape shape =
Shape.CreateArrow(from, to, size, color, flags);
407 m_DebugShapes.Insert(shape);
417 static void GetBaseConfigClasses( out
TStringArray base_classes )
419 base_classes.Clear();
438 static void GetFiltredConfigClasses(
string search_string, out
TStringArray filtered_classes,
bool only_public =
true )
441 GetBaseConfigClasses( searching_in );
443 filtered_classes.Clear();
445 search_string.ToLower();
447 for (
int s = 0; s < searching_in.Count(); ++s )
449 string config_path = searching_in.Get(s);
451 int objects_count =
GetGame().ConfigGetChildrenCount(config_path);
452 for (
int i = 0; i < objects_count; i++)
455 GetGame().ConfigGetChildName(config_path, i, childName);
459 int scope =
GetGame().ConfigGetInt( config_path +
" " + childName +
" scope" );
466 string nchName = childName;
469 if ( nchName.Contains(search_string) != -1)
471 filtered_classes.Insert(childName);
480 private static bool m_EnabledLogs;
482 private static string LogMessage(
string level,
string plugin,
string entity,
string author,
string label,
string message)
492 string date = GetDate();
493 string env =
"Client";
494 string msg =
string.Empty;
501 msg =
string.Format(
"%1 | %2 | %3 | %4 | %5 | %6 | %7", date, env, level, plugin, entity, label, message);
508 Param1<string> msg_p =
new Param1<string>(msg);
520 private static void SaveLog(
string log_message)
522 if (log_message.Length() == 0)
553 Print(
string.Format(
"%1", log_message));
557 static void ClearLogs()
570 static string GetFileName()
575 private static string GetDate()
587 string date = month.ToStringLen(2) +
"-" + day.ToStringLen(2) +
" " + hour.ToStringLen(2) +
":" + minute.ToStringLen(2) +
":" + second.ToStringLen(2);