Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DebugLinePlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Debug Line Shortcut", description: "Insert a debug line, as formatted in its options", shortcut: "Ctrl+Shift+D", wbModules: { "ScriptEditor" }, awesomeFontCode: 0xF1CD)]
3class SCR_DebugLinePlugin : WorkbenchPlugin
4{
5 [Attribute(defvalue: "[%1.%2] debug line (%4 L%5)", desc: "Text to be printed in the debug line"
6 + "\n- %1 = class name (as string, hardcoded)"
7 + "\n- %2 = method name (as string, hardcoded)"
8 + "\n- %3 = file name (as preprocess command)"
9 + "\n- %4 = file's full path (as preprocessor command)"
10 + "\n- %5 = debug line number (as preprocessor command)", uiwidget: UIWidgets.EditBoxMultiline, category: "Format")]
11 protected string m_sFormat;
12
13 [Attribute(defvalue: LogLevel.WARNING.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Log level of the debug line",
14 enums: GetLogLevelEnumOptions(),
15 category: "Log Level"
16 )]
17 protected LogLevel m_eLogLevel;
18
19 [Attribute(defvalue: "0", desc: "Make debug line use PrintFormat to output custom variables", category: "Format")]
20 protected bool m_bIncludeParams;
21
22 //------------------------------------------------------------------------------------------------
23 override void Run()
24 {
25 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
26
27 string fileFormat;
28 if (!scriptEditor.GetCurrentFile(fileFormat))
29 {
30 Print("Cannot insert debug line, no file is opened!", LogLevel.WARNING);
31 return;
32 }
33
34 string lineText;
35 scriptEditor.GetLineText(lineText);
36
37 int tabIndex = lineText.LastIndexOf(SCR_StringHelper.TAB);
38 if (lineText.EndsWith("{"))
39 tabIndex++;
40
41 string tabPrefix;
42 for (int i; i <= tabIndex; ++i)
43 {
44 tabPrefix += SCR_StringHelper.TAB;
45 }
46
47 int nextLine = scriptEditor.GetCurrentLine() + 1;
48 string debugLine = tabPrefix + GetDebugLine(scriptEditor);
49 scriptEditor.InsertLine(debugLine, nextLine);
50 }
51
52 //------------------------------------------------------------------------------------------------
56 protected string GetDebugLine(notnull ScriptEditor scriptEditor)
57 {
58 string debugLine = m_sFormat;
59 debugLine.TrimInPlace();
60 if (!debugLine)
61 {
62 if (m_bIncludeParams)
63 return "PrintFormat(\"%1\", this);";
64 else
65 return "Print(\"test\");";
66 }
67
68 string className, methodName;
69
70 if (debugLine.Contains("%1"))
71 {
72 if (!className)
73 SCR_CopyClassAndMethodPlugin.GetCursorClassAndMethodNames(scriptEditor, className, methodName);
74
75 debugLine.Replace("%1", className);
76 }
77
78 if (debugLine.Contains("%2"))
79 {
80 if (!className) // methodName can be empty
81 SCR_CopyClassAndMethodPlugin.GetCursorClassAndMethodNames(scriptEditor, className, methodName);
82
83 debugLine.Replace("%2", methodName);
84 }
85
86 if (debugLine.Contains("%3"))
87 debugLine.Replace("%3", "\" + FilePath.StripPath(__FILE__) + \"");
88
89 if (debugLine.Contains("%4"))
90 debugLine.Replace("%4", "\" + __FILE__ + \"");
91
92 if (debugLine.Contains("%5"))
93 debugLine.Replace("%5", "\" + __LINE__ + \"");
94
95 if (m_bIncludeParams)
96 {
97 debugLine = "PrintFormat(\"" + debugLine + "\", this";
98 if (m_eLogLevel > -1 && m_eLogLevel != int.MAX)
99 debugLine += ", level: LogLevel." + typename.EnumToString(LogLevel, m_eLogLevel);
100 }
101 else
102 {
103 debugLine = "Print(\"" + debugLine + "\"";
104 if (m_eLogLevel > -1 && m_eLogLevel != int.MAX)
105 debugLine += ", LogLevel." + typename.EnumToString(LogLevel, m_eLogLevel);
106 }
107
108 debugLine += ");";
109
110 return debugLine;
111 }
112
113 //------------------------------------------------------------------------------------------------
115 protected static ParamEnumArray GetLogLevelEnumOptions()
116 {
117 typename e = LogLevel;
118 ParamEnumArray result = { new ParamEnum("No LogLevel (temporary Print)", "-1") };
119
120 int val;
121 string firstLetter;
122 string displayName;
123
124 for (int i, count = e.GetVariableCount(); i < count; ++i)
125 {
126 if (e.GetVariableType(i) == int && e.GetVariableValue(null, i, val))
127 {
128 displayName = e.GetVariableName(i);
129 firstLetter = displayName[0];
130 firstLetter.ToUpper(); // not needed as they are all uppercase
131 displayName.ToLower();
132 displayName = firstLetter + displayName.Substring(1, displayName.Length() - 1);
133 result.Insert(new ParamEnum(displayName, val.ToString()));
134 }
135 }
136
137 return result;
138 }
139
140 //------------------------------------------------------------------------------------------------
141 override void Configure()
142 {
143 Workbench.ScriptDialog("Configure the 'Insert Debug Line' plugin", "", this);
144 }
145
146 //------------------------------------------------------------------------------------------------
147 [ButtonAttribute("Close")]
148 protected bool ButtonClose()
149 {
150 return true;
151 }
152}
153#endif // WORKBENCH
void ParamEnum(string key, string value, string desc="")
Definition attributes.c:25
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
string m_sFormat
Definition Attributes.c:870
override void Run()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
override void Configure()
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
@ MAX