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";
28 static Widget m_DebugLayoutCanvas;
29 static CanvasWidget m_CanvasDebug;
37 if (CastTo(obj, entity))
38 return obj.GetDebugNameNative();
40 return entity.GetDebugName();
43 static void InitCanvas()
45 if (!m_DebugLayoutCanvas)
47 m_DebugLayoutCanvas =
g_Game.GetWorkspace().CreateWidgets(
"gui/layouts/debug/day_z_debugcanvas.layout");
48 m_CanvasDebug = CanvasWidget.Cast( m_DebugLayoutCanvas.FindAnyWidget(
"CanvasWidget" ) );
52 static void ClearCanvas()
55 m_CanvasDebug.Clear();
58 static void CanvasDrawLine(
float x1,
float y1,
float x2,
float y2,
float width,
int color)
61 m_CanvasDebug.DrawLine(x1, y1, x2, y2, width, color);
75 static void CanvasDrawPoint(
float x1,
float y1,
int color)
77 CanvasDrawLine(x1, y1, x1+1, y1, 1, color);
87 static void DestroyAll()
94 static void DestroyAllShapes()
96 foreach (
Shape debugShape : m_DebugShapes)
99 m_DebugShapes.Clear();
102 static void DestroyAllTextSS()
104 m_DebugTextsSS.Clear();
107 static void DestroyAllTextWS()
109 m_DebugTextsWS.Clear();
112 static void RemoveShape(out
Shape shape)
117 int nDebugShapes = m_DebugShapes.Count();
118 for (
int i = 0; i < nDebugShapes; ++i)
120 Shape foundShape = m_DebugShapes.Get(i);
122 if (foundShape && foundShape == shape)
124 foundShape.Destroy();
125 m_DebugShapes.Remove(i);
137 int nDebugTextsSS = m_DebugTextsSS.Count();
138 for (
int i = 0; i < nDebugTextsSS; ++i)
142 if (foundText && foundText == text)
145 m_DebugTextsSS.Remove(i);
157 int nDebugTextsWS = m_DebugTextsWS.Count();
158 for (
int i = 0; i < nDebugTextsWS; ++i)
162 if (foundText && foundText == text)
165 m_DebugTextsWS.Remove(i);
182 static void Log(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
184 LogMessage(LOG_DEBUG, plugin, entity, author, label, message);
187 static void ActionLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
189 LogMessage(LOG_DEBUG_ACTION, plugin, entity, author, label, message);
192 static void SymptomLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
194 LogMessage(LOG_DEBUG_SYMPTOM, plugin, entity, author, label, message);
197 static void InventoryMoveLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
199 LogMessage(LOG_DEBUG_INV_MOVE, plugin, entity, author, label, message);
202 static void InventoryReservationLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
204 LogMessage(LOG_DEBUG_INV_RESERVATION, plugin, entity, author, label, message);
207 static void InventoryHFSMLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
209 LogMessage(LOG_DEBUG_INV_HFSM, plugin, entity, author, label, message);
212 static void QuickbarLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
214 LogMessage(LOG_DEBUG_QUICKBAR, plugin, entity, author, label, message);
217 static void BaseBuildingLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
219 LogMessage(LOG_DEBUG_BASEBUILDING, plugin, entity, author, label, message);
222 static void BleedingChancesLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
224 LogMessage(LOG_DEBUG_BLEEDING_CHANCES, plugin, entity, author, label, message);
227 static void TriggerLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
229 LogMessage(LOG_DEBUG_TRIGGER, plugin, entity, author, label, message);
232 static void ParticleLog(
string message = LOG_DEFAULT,
Managed caller = null,
string function =
"",
Managed entity = null)
237 static void TFLog(
string message = LOG_DEFAULT, TestFramework caller = null,
string function =
"")
239 LogMessage(LOG_DEBUG_TF,
GetDebugName(caller),
"",
"", function, message);
242 static void WeightLog(
string message = LOG_DEFAULT,
Managed caller = null,
string function =
"",
Managed entity = null)
249 static void MeleeLog(
Entity entity,
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT)
251 string logMessage =
string.Format(
"%1: %2", entity.GetSimulationTimeStamp(), message);
252 LogMessage(LOG_DEBUG_MELEE, plugin,
GetDebugName(entity), author, label, logMessage);
255 static void WeatherLog(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
262 LogMessage(LOG_DEBUG_WEATHER, plugin, entity, author, label, message);
275 static void LogInfo(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
277 LogMessage(LOG_INFO, plugin, entity, author, label, message);
290 static void LogWarning(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
292 LogMessage(LOG_WARNING, plugin, entity, author, label, message);
305 static void LogError(
string message = LOG_DEFAULT,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
307 LogMessage(LOG_ERROR, plugin, entity, author, label, message);
310 static void LogArrayInt(
array<int> arr = NULL,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
315 int nArr = arr.Count();
316 for (
int i = 0; i < nArr; ++i)
318 LogMessage(LOG_DEBUG, plugin, entity, author, label, arr.Get(i).ToString());
322 static void LogArrayString(
array<string> arr = NULL,
string plugin = LOG_DEFAULT,
string author = LOG_DEFAULT,
string label = LOG_DEFAULT,
string entity = LOG_DEFAULT)
327 int nArr = arr.Count();
328 for (
int i = 0; i < nArr; ++i)
330 LogMessage(LOG_DEBUG, plugin, entity, author, label, arr.Get(i));
334 static void ReceivedLogMessageFromServer(
string message)
344 static void ClearScriptLogs()
358 m_DebugShapes.Insert(shape);
362 static Shape DrawCube(
vector pos,
float size = 1,
int color = 0x1fff7f7f)
367 float size_h = size * 0.5;
369 min[0] = min[0] - size_h;
370 min[1] = min[1] - size_h;
371 min[2] = min[2] - size_h;
373 max[0] = max[0] + size_h;
374 max[1] = max[1] + size_h;
375 max[2] = max[2] + size_h;
378 m_DebugShapes.Insert(shape);
384 Shape shape =
Shape.CreateSphere(color, flags, pos, size);
386 m_DebugShapes.Insert(shape);
392 Shape shape =
Shape.CreateFrustum(horizontalAngle, verticalAngle, length, color, flags);
394 m_DebugShapes.Insert(shape);
400 Shape shape =
Shape.CreateCylinder(color, flags, pos, radius, height);
402 m_DebugShapes.Insert(shape);
406 static array<Shape> DrawCone(
vector pos,
float lenght,
float halfAngle,
float offsetAngle,
int color = 0xFFFFFFFF,
int flags = 0)
411 Math3D.ConePoints(pos, lenght, halfAngle, offsetAngle, endL, endR);
414 shapes.Insert(
Debug.DrawLine(pos, endL, color, flags) );
416 shapes.Insert(
Debug.DrawLine(pos, endR, color, flags) );
418 shapes.Insert(
Debug.DrawLine(endL, endR, color, flags) );
420 shapes.Insert(
Debug.DrawLine(pos, pos +
Vector(
Math.Cos(offsetAngle), 0,
Math.Sin(offsetAngle)).Normalized() * lenght, color, flags) );
427 foreach (
Shape shape : shapes)
428 Debug.RemoveShape(shape);
436 Debug.RemoveTextSS(text);
444 Debug.RemoveTextWS(text);
461 static Shape DrawLine(
vector from,
vector to,
int color = 0xFFFFFFFF,
int flags = 0)
467 Shape shape =
Shape.CreateLines(color, flags, pts, 2);
469 m_DebugShapes.Insert(shape);
474 static Shape DrawLines(
vector[] positions,
int count,
int color = 0xFFFFFFFF,
int flags = 0)
477 Shape shape =
Shape.CreateLines(color, flags, positions, count);
479 m_DebugShapes.Insert(shape);
483 static Shape DrawArrow(
vector from,
vector to,
float size = 0.5,
int color = 0xFFFFFFFF,
int flags = 0)
485 Shape shape =
Shape.CreateArrow(from, to, size, color, flags);
486 m_DebugShapes.Insert(shape);
496 m_DebugTextsSS.Insert(textSS);
505 m_DebugTextsWS.Insert(textWS);
514 static void GetBaseConfigClasses( out
TStringArray base_classes )
516 base_classes.Clear();
535 static void GetFiltredConfigClasses(
string search_string, out
TStringArray filtered_classes,
bool only_public =
true )
538 GetBaseConfigClasses( searching_in );
540 filtered_classes.Clear();
542 search_string.ToLower();
544 int nSearchingIn = searching_in.Count();
545 for (
int s = 0; s < nSearchingIn; ++s )
547 string config_path = searching_in.Get(s);
549 int objects_count =
g_Game.ConfigGetChildrenCount(config_path);
550 for (
int i = 0; i < objects_count; i++)
553 g_Game.ConfigGetChildName(config_path, i, childName);
557 int scope =
g_Game.ConfigGetInt( config_path +
" " + childName +
" scope" );
564 string nchName = childName;
567 if ( nchName.Contains(search_string) != -1)
569 filtered_classes.Insert(childName);
578 private static bool m_EnabledLogs;
580 private static string LogMessage(
string level,
string plugin,
string entity,
string author,
string label,
string message)
585 bool is_server_log = (
g_Game.IsServer() &&
g_Game.IsMultiplayer() );
590 string date = GetDate();
591 string env =
"Client";
592 string msg =
string.Empty;
599 msg =
string.Format(
"%1 | %2 | %3 | %4 | %5 | %6 | %7", date, env, level, plugin, entity, label, message);
606 Param1<string> msg_p =
new Param1<string>(msg);
618 private static void SaveLog(
string log_message)
620 if (log_message.Length() == 0)
651 Print(
string.Format(
"%1", log_message));
655 static void ClearLogs()
673 private static string GetDate()
685 string date = month.ToStringLen(2) +
"-" + day.ToStringLen(2) +
" " + hour.ToStringLen(2) +
":" + minute.ToStringLen(2) +
":" + second.ToStringLen(2);