-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.cs
791 lines (712 loc) · 32.9 KB
/
Utility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace jsonToLuaParser
{
class Utility
{
public class Example_Info
{
public string example { get; set; }
public string description { get; set; }
}
public class ParamInfo
{
public string Name { get; set; }
public string Description { get; set; }
public string enums { get; set; }
public string Type { get; set; }
}
public class CommandEnum
{
public string enum_number { get; set; }
public string enum_member { get; set; }
}
public enum CommandType
{
Function,
Attribute_RO,
Attribute_WO,
Attribute_RW,
Constant
}
public class CommandInfo
{
public string name { get; set; }
public string webhelpfile { get; set; }
public string signature { get; set; }
public string command_return { get; set; }
public string description { get; set; }
public CommandType command_type { get; set; }
public string[] usage { get; set; }
public string default_value { get; set; }
public string details { get; set; }
public Example_Info[] example_info { get; set; }
public string related_commands { get; set; }
public ParamInfo[] param_info { get; set; }
public string[] overloads { get; set; }
public string supportedModels { get; set; }
public string tsplink_supported { get; set; }
}
public class TriggerEventIdInfo
{
public string event_id { get; set; }
public string event_desc { get; set; }
}
public static JObject ParseJSON(string file)
{
var str = File.ReadAllText(file);
JObject cmds = JObject.Parse(str);
return cmds;
}
public static IList<string> get_return_type_and_default_value(CommandInfo cmd)
{
var lst = new List<string>();
var prm = cmd.param_info.Where(param => param.Name.ToUpper() == cmd.command_return.ToUpper()).ToList();
if (prm.Count > 0)
{
var type = prm[0].Type;
lst.Add(type);
var defaultValue = type.Contains("[]") ? "{}" : type == "table" ? "{}" : type == "string" ? "''" : type == "integer" ? "0" : type == "boolean" ? "true" : "0";
if (prm[0].enums != "")
{
defaultValue = prm[0].enums.Split('|')[0].Split(' ')[0];
}
lst.Add(defaultValue);
}
else
System.Console.WriteLine(cmd.name);
return lst;
}
public static IList<CommandInfo> PopulateCommands(ref JObject obj, string feild)
{
IList<CommandInfo> cmdList = obj[feild].ToArray().Select(p => new CommandInfo
{
name = (string)p["name"],
webhelpfile = (string)p["webhelpfile"],
signature = (string)p["signature"],
tsplink_supported = (string)p["tsp_link"],
description = (string)p["description"],
command_type = ((string)p["type"] == "Function" ? CommandType.Function : ((string)p["type"] == "Attribute (RW)" ? CommandType.Attribute_RW : ((string)p["type"] == "Attribute (R)") ? CommandType.Attribute_RO : ((string)p["type"] == "Attribute (Ro)") ? CommandType.Attribute_RO : (string)p["type"] == "Constant" ? CommandType.Constant : CommandType.Attribute_WO)),
default_value = (string)p["default_value"],
usage = p["usage"].ToObject<string[]>(),
overloads = p["overloads"].ToObject<string[]>(),
details = (string)p["details"],
command_return = (string)p["command_return"],
example_info = p["examples"].ToArray().Select(pi => new Example_Info
{
example = pi["example"].ToString(),
description = pi["description"].ToString(),
}).ToArray(),
param_info = p["param_info"].ToArray().Select(pi => new ParamInfo
{
Name = pi["name"].ToString(),
Description = pi["description"].ToString(),
enums = pi["enum"].ToString(),
Type = pi["type"].ToString(),
}).ToArray(),
related_commands = "TODO",
supportedModels = (string)p["supported_models"]
}).ToList();
return cmdList;
}
public static bool arrayCheck(string[] arr, string str, string type_name, out string table)
{
table = "";
foreach (var item in arr)
{
if (str.Contains(item))
{
table = str.Replace(item, type_name);
return true;
}
else
return false;
}
return false;
}
public static void PrintFields(int depth, string file_name, ref Dictionary<string, Dictionary<string, CommandInfo>>[] instrTable, ref string outStr, ref string tsplinkStr, ref string[] arrList, string item)
{
string table_name = "";
string type_name = "";
for (int i = 0; i < depth; i++)
{
foreach (var keyValuePair in instrTable[i])
{
string class_data = "";
if (item != "null")
{
foreach (var keyvalue in keyValuePair.Value)
{
bool a = keyvalue.Value.supportedModels.Contains(item);
if (a == true && !item.Contains("-L") && (item.Contains("2604B") || item.Contains("2614B") || item.Contains("2634B")))
{
return;
}
continue;
}
}
if (keyValuePair.Key.Contains("localnode.settimme()"))
continue;
//Handling Arrays in commands
if (keyValuePair.Key.Contains("[N]") || keyValuePair.Key.Contains("[Y]") || keyValuePair.Key.Contains("[slot]") || keyValuePair.Key.Contains("[1]") || keyValuePair.Key.Contains("[X]"))
{
if (keyValuePair.Key.Contains("[N]"))
{
table_name = keyValuePair.Key.Replace("[N]", "");
type_name = keyValuePair.Key.Replace("[N]", "|").Split('|')[0].Replace(".", "") + "Arr";
}
else if (keyValuePair.Key.Contains("[Y]"))
{
table_name = keyValuePair.Key.Replace("[Y]", "");
type_name = keyValuePair.Key.Replace("[Y]", "|").Split('|')[0].Replace(".", "") + "Arr";
}
else if (keyValuePair.Key.Contains("[1]"))
{
table_name = keyValuePair.Key.Replace("[1]", "");
type_name = keyValuePair.Key.Replace("[1]", "|").Split('|')[0].Replace(".", "") + "Arr";
}
else if (keyValuePair.Key.Contains("[slot]"))
{
table_name = keyValuePair.Key.Replace("[slot]", "");
type_name = keyValuePair.Key.Replace("[slot]", "|").Split('|')[0].Replace(".", "") + "Arr";
}
else
{
table_name = keyValuePair.Key.Replace("[X]", "");
type_name = keyValuePair.Key.Replace("[X]", "|").Split('|')[0].Replace(".", "") + "Arr";
}
if (!arrList.Contains(type_name))
{
arrList = arrList.Append(type_name).ToArray();
class_data += "---@class " + type_name + "\n";
class_data += "local " + type_name + " = {}\n\n";
class_data += "---@type " + type_name + "[]\n";
class_data += table_name + " = {}\n";
}
else
{
class_data += "---@type " + type_name + "[]\n";
string rem = "";
if (keyValuePair.Key.Contains("[N]"))
rem = keyValuePair.Key.Replace("[N]", "|").Split('|')[1];
else if (keyValuePair.Key.Contains("[Y]"))
rem = keyValuePair.Key.Replace("[Y]", "|").Split('|')[1];
else if (keyValuePair.Key.Contains("[1]"))
rem = keyValuePair.Key.Replace("[1]", "|").Split('|')[1];
else if (keyValuePair.Key.Contains("[X]"))
rem = keyValuePair.Key.Replace("[X]", "|").Split('|')[1];
else
rem = keyValuePair.Key.Replace("[slot]", "|").Split('|')[1];
class_data += type_name + rem + " = {}\n";
}
}
else
{
//table_name = keyValuePair.Key.Replace("[1]",""); //DMM6500 slot[1]
table_name = keyValuePair.Key;
if (!table_name.Contains("bufferVar") && !table_name.Contains("scriptVar") && !table_name.Contains(".setblock()"))
{
class_data += "---@class " + table_name + "\n";
if (i == 0)
class_data += table_name + " = {}\n";
else
class_data += table_name + " = {}\n";
}
}
outStr += class_data;
outStr += "\n\n";
bool class_data_populated = false;
foreach (var keyvalue in keyValuePair.Value)
{
HelpContent(keyvalue.Value, file_name, ref outStr, ref tsplinkStr, class_data, class_data_populated, keyValuePair.Key, keyvalue.Key, false);
class_data_populated = true;
}
}
}
}
public static void HelpContent(CommandInfo cmd, string file_name, ref string outStr, ref string tsplinkStr, string class_data, bool class_data_populated, string table, string attr, bool directCall)
{
string command_help = "";
if (cmd.name.Contains("node[N].execute()"))
System.Console.WriteLine(cmd.name);
string[] example = new string[] { };
string[] enum_class = new string[] { };
#region Enum_Population
foreach (var param in cmd.param_info)
{
if (cmd.usage.Length == 0)
continue;
else if ((cmd.command_type == CommandType.Attribute_RW) && (cmd.usage.Length == 1) && (!cmd.usage[0].Contains(param.Name)))
continue;
else if ((cmd.command_type == CommandType.Attribute_RW) && (cmd.usage.Length > 1) && (!cmd.usage[0].Contains(param.Name) || !cmd.usage[1].Contains(param.Name)))
continue;
else if ((cmd.command_type == CommandType.Attribute_RO) && (!cmd.usage[0].Contains(param.Name)))
continue;
else if ((cmd.command_type == CommandType.Function) && ((!cmd.signature.Contains(param.Name) && !cmd.command_return.Contains(param.Name))) && cmd.name != "eventlog.suppress()")
continue;
else if (param.enums != "")
{
var aliasName = param.Type.Contains('|') ? param.Type.Split('|')[0].Trim() : param.Type;
string[] enum_data = param.enums.Split('|');
command_help += "\n";
foreach (var data in enum_data)
{
command_help += data.Split(' ')[0] + " = " + data.Split(' ')[1] + "\n";
}
command_help += "\n---@alias " + aliasName + "\n";
foreach (var data in enum_data)
{
command_help += "---|`" + data.Split(' ')[0] + "`\n";
}
command_help += "\n";
}
}
//}
command_help += "\n";
#endregion
var helpFilePath = $@"{(file_name.Contains("26") ? "Commands_26XX" : "Commands_" + file_name)}/{cmd.webhelpfile}";
command_help += "\n--- **" + cmd.description + "**\n---\n"
+ "--- *Type:* " + cmd.command_type + "\n---\n"
+ "--- *Details:*<br>\n--- " + cmd.details + "\n---\n"
+ "---[command help](command:kic.viewHelpDocument?[\"" + helpFilePath + "\"])" + "\n---\n"
+ "---<br>*Examples:*<br>\n"
+ "--- ```lua\n";
foreach (var x in cmd.example_info)
{
var exmp = x.example.Split(';');
foreach (var item in exmp)
{
command_help += "--- " + item + "\n";
}
//outStr += "--- " + x.example + "\n"
command_help += "--- --" + x.description;
}
command_help += "--- ```\n";
if (cmd.name.Contains("trigger.BLOCK_"))
{
command_help += "--- Additional paramteres are:\n";
foreach (var param in cmd.param_info)
{
if (param.Name != "blockNumber" && param.Name != cmd.name)
{
command_help += "--- - *" + param.Name + "*: " + param.Description + "<br>\n";
if (param.enums != "")
{
string[] enum_data = param.enums.Split('|');
//command_help += "---\n--- This has a paraamter **" + param.Name + "** , that accepets following enum inputs:\n";
foreach (var data in enum_data)
{
command_help += "--- ```" + data.Split(' ')[0] + "```<br>\n";
}
}
}
}
}
/* if (table.Contains("bufferVar"))
{
if (cmd.signature.Contains("[N]"))
{
outStr += "---@type integer[]\n";
outStr += "bufferVar." + attr + "= {}\n";
}
else
{
if (cmd.command_type == CommandType.Function)
outStr += "function bufferVar." + attr + "end \n";
else
outStr += "bufferVar." + attr + "= 0\n";
}
return;
} */
if (cmd.command_type == CommandType.Function)
{
List<string> command_returns = cmd.command_return.ToUpper().Split(',')
.Select(st => st.Trim())
.ToList();
int start = cmd.signature.IndexOf("(") + 1;
int end = cmd.signature.IndexOf(")", start);
string[] s;
try
{
s = cmd.signature.ToUpper().Substring(start, end - start).Replace(" ", "").Split(',');
}
catch (System.Exception)
{
s = new string[] { };
}
foreach (var param in cmd.param_info)
{
if (s.Contains(param.Name.ToUpper()))
{
string temp = "\"" + param.Name + "\"";
command_help += "---@param " + param.Name;
if (s.Contains(temp))
command_help += " " + param.Type + " ";
//else
command_help += " " + param.Type + " ";
command_help += param.Description + "\n";
}
else if (command_returns.Contains(param.Name.ToUpper()))
{
command_help += "---@return ";
if (param.Name.Contains("fileNumber"))
command_help += "file_object ";
else if (param.Name.Contains("scriptVar"))
command_help += "scriptVar ";
else if (param.Name.Contains("bufferName") || param.Name.Contains("bufferVar"))
command_help += "bufferVar ";
else if (param.Name.Contains("connectionID"))
command_help += "tspnetConnectionID ";
else
command_help += param.Type + " ";
command_help += param.Name + " " + param.Description + "\n";
}
else if (cmd.name == "display.input.option()")
{
command_help += "---@return displayInputOption displayOption";
}
/* else if(cmd.name == "eventlog.suppress()")
{
outStr += "---@param eventType eventlogsuppresseventType\n";
} */
}
cmd.signature = cmd.signature.Replace("\"", "");
}
if (cmd.command_type != CommandType.Function && !cmd.name.Contains("trigger.BLOCK_")) // for attributes
{
//foreach (var parm in cmd.param_info)
//{
// if (parm.enums != "" && !table.Contains("bufferVar"))
// {
// if (cmd.usage[0].Contains(parm.Name))// || cmd.usage[1].Contains(parm.Name))
// command_help += "---@type " + parm.Type + "\n";
// }
//}
var lst = get_return_type_and_default_value(cmd);
if (table.Contains("[N]") || table.Contains("[Y]") || table.Contains("[slot]") || table.Contains("[1]") || table.Contains("[X]"))
{
string[] a = table.Split('[');
string type_name = a[0].Replace(".", "") + "Arr";
if (table.Contains("[N]"))
{
a[1] = a[1].Replace("N]", "");
}
if (table.Contains("[Y]"))
{
a[1] = a[1].Replace("Y]", "");
}
if (table.Contains("[slot]"))
{
a[1] = a[1].Replace("slot]", "");
}
if (table.Contains("[1]"))
{
a[1] = a[1].Replace("1]", "");
}
if (table.Contains("[X]"))
{
a[1] = a[1].Replace("X]", "");
}
if (a[1] != "")
{
if (attr.Contains("stimulus") && !attr.Contains("["))
{
command_help += $"---@type {lst[0]}\n";
command_help += type_name + a[1] + "." + attr + "= trigger.EVENT_NONE\n\n";
}
else
{
command_help += $"---@type {lst[0]}\n";
command_help += type_name + a[1] + "." + attr + "= 0\n\n";
}
}
else
{
if (attr.Contains("stimulus["))
{
command_help += $"---@type {lst[0]}\n";
attr = attr.Remove(attr.Length - 3, 3);
command_help += type_name + a[1] + "." + attr + "= trigger.EVENT_NONE\n\n";
}
else if (attr.Contains("stimulus") && !attr.Contains("["))
{
command_help += $"---@type {lst[0]}\n";
command_help += type_name + a[1] + "." + attr + "= trigger.EVENT_NONE\n\n";
}
else
{
command_help += $"---@type {lst[0]}\n";
command_help += $"{type_name}.{attr} = {lst[1]}\n";
}
}
}
else if (table.Contains("bufferVar") || table.Contains("bufferName"))
{
command_help += $"---@type {lst[0]}\n";
command_help += $"bufferVar.{attr} = {lst[1]}\n";
}
else if (table.Contains("scriptVar"))
{
command_help += $"---@type {lst[0]}\n";
command_help += $"scriptVar.{attr} = {lst[1]}\n";
}
else if (attr.Contains("address[N]"))
{
command_help += "---@type integer[]\n";
attr = attr.Replace("[N]", "");
command_help += table + "." + attr + " = 0\n\n";
}
else if (attr.Contains("stimulus"))
{
command_help += "---@type triggerEvents|0\n";
command_help += table + "." + attr + "= 0\n\n";
}
else if (attr.Contains("[N]"))//TODOD need to check this can be removed
{
attr = attr.Remove(attr.Length - 3, 3);
command_help += $"---@type {lst[0]}\n";
command_help += $"{table}.{attr} = {lst[1]}\n";
}
else if (attr.Contains("EVENT_ID"))
{
command_help += "---@type eventID\n";
command_help += table + "." + attr + "= nil\n";
}
else
{
if (directCall)
{
cmd.name = cmd.name.Replace("*", "star_");
command_help += cmd.name + "= 0\n\n";
}
else
{
command_help += $"---@type {lst[0]}\n";
command_help += $"{table}.{attr} = {lst[1]}\n";
}
}
}
else if (cmd.command_type == CommandType.Function || (cmd.command_type == CommandType.Attribute_WO && cmd.name.Contains(" trigger.BLOCK_")))
{
if (cmd.overloads.Length > 0 && !cmd.name.Contains("trigger.BLOCK_"))
{
// System.Console.WriteLine(cmd.signature);
foreach (var sig in cmd.overloads)
{
System.Console.WriteLine(sig);
int startIndex = sig.IndexOf("(") + 1;
int endIndex = sig.IndexOf(")", startIndex);
var overlad_params = sig.Substring(startIndex, endIndex - startIndex).Split(',').Select(str => str.Trim()).ToList();
IList<string> overload_sig_and_type = new List<string>();
IList<string> overload_return_type = new List<string>();
foreach (var param in cmd.param_info)
{
if (cmd.command_return.Contains(param.Name))
overload_return_type.Add($"{param.Name}:{param.Type}");
if (overlad_params.Contains(param.Name))
{
overload_sig_and_type.Add($"{param.Name}:{param.Type}");
}
}
command_help += getOverloadDoc($"({string.Join(",", overload_sig_and_type)}){(overload_return_type.Count > 0 ? ":" : "")}{string.Join(", ", overload_return_type)}") + "\n";
}
}
else
{
if (cmd.name.Contains("trigger.BLOCK_") && cmd.overloads.Length > 0)
command_help += "--\n--- Overloads are:\n";
foreach (var sig in cmd.overloads)
{
command_help += "--- - " + sig + "\n";
}
}
if (table.Contains("[N]") || table.Contains("[Y]") || table.Contains("[slot]") || table.Contains("[X]"))
{
string[] a = cmd.signature.Split('[');
//string[] a = table.Split('[');
string type_name = a[0].Replace(".", "") + "Arr";
if (table.Contains("[N]"))
{
a[1] = a[1].Replace("N]", "");
}
if (table.Contains("[Y]"))
{
a[1] = a[1].Replace("Y]", "");
}
if (table.Contains("[slot]"))
{
a[1] = a[1].Replace("slot]", "");
}
if (table.Contains("[X]"))
{
a[1] = a[1].Replace("X]", "");
}
command_help += "function " + type_name + a[1] + " end\n\n";
}
else if (cmd.signature.Contains("scriptVar"))
{
string sig = cmd.signature.Replace("scriptVar", "scriptVar");
command_help += "function " + sig + " end\n";
}
else if (cmd.signature.Contains("fileVar"))
{
string sig = cmd.signature.Replace("fileVar", "file_object");
command_help += "function " + sig + " end\n";
}
else if (cmd.signature.Contains(".catalog()"))
{
try
{
if (cmd.signature.Contains("display.loadmenu"))
cmd.signature = cmd.signature.Split(' ')[4];
else
cmd.signature = cmd.signature.Split(' ')[3];
command_help += "function " + cmd.signature + " end\n";
}
catch
{
command_help += "function " + cmd.signature + " end\n";
}
}
else if (cmd.signature.Contains("bufferName."))
{
string sig = cmd.signature.Replace("bufferName.", "bufferVar.");
command_help += "function " + sig + " end\n";
}
else if (cmd.signature.Contains("bufferVar."))
{
string sig = cmd.signature.Replace("bufferVar.", "bufferVar.");
command_help += "function " + sig + " end\n";
}
else
{
if (cmd.command_type == CommandType.Function)
command_help += "function " + cmd.signature + " end\n";
else
command_help += table + "." + attr + " = 0\n\n";
}
}
if (cmd.tsplink_supported.Contains("Yes"))
{
if (class_data_populated == false)
tsplinkStr += class_data;
outStr += command_help;
tsplinkStr += command_help;
}
if (cmd.tsplink_supported.Contains("No"))
{
outStr += command_help;
}
}
public static string getOverloadDoc(string signature)
{
var outPut = $@"---@overload fun{signature}";
return outPut;
}
public static void append_nvbuffer_type(ref string outStr, string subString)
{
int index = outStr.IndexOf(subString);
if (index != -1)
{
string modifiedString = outStr.Insert(index, "\n---@type bufferVar\n");
outStr = modifiedString;
}
}
public static void append_defbuffer1_defbuffer2_defination(ref string outStr)
{
outStr += "\n" + @"---@type bufferVar
defbuffer1 = {}
---@type bufferVar
defbuffer2 = {}";
}
public static void append_setblock_signature(ref string outStr)
{
outStr += "\n" + @"
---This is generic function to define trigger model setblock.<br>
---Signature of this function depends on the BlockType.<br>
---For more details, please look at the manual by viewing hover help of blockType or opening command help
---@param blockNumber number
---@param blockType triggerBlockBranch
function trigger.model.setblock(blockNumber, blockType,...) end";
}
public static string get_command_header(CommandInfo cmd, string file_name)
{
var command_header = "\n---**" + cmd.name + "**\n"
+ "----";
var helpFilePath = $@"{(file_name.Contains("26") ? "Commands_26XX" : "Commands_" + file_name)}/{cmd.webhelpfile}";
command_header += "\n--- **" + cmd.description + "**\n---\n"
+ "--- *Type:* " + cmd.command_type + "\n---\n"
+ "--- *Details:*<br>\n--- " + cmd.details + "\n---\n"
+ "---[command help](command:kic.viewHelpDocument?[\"" + helpFilePath + "\"])" + "\n---\n"
+ "---<br>*Examples:*<br>\n"
+ "--- ```lua\n";
foreach (var x in cmd.example_info)
{
var exmp = x.example.Split(';');
foreach (var item in exmp)
{
command_header += "--- " + item + "\n";
}
//outStr += "--- " + x.example + "\n"
command_header += "--- --" + x.description;
}
command_header += "--- ```";
return command_header;
}
public static void append_buffermath_signature(ref string outStr)
{
outStr +=
@"
---@param readingBuffer bufferVar The name of the reading buffer; the reading buffer selected must be set to the style FULL
---@param unit buffermathunit The units to be applied to the value generated by the expression
---@param mathExpression mathExpression
function buffer.math(readingBuffer, unit, mathExpression, ...) end";
}
public static string create_string_constant_alias_type(string alias_name, IList<string> alias_string_list)
{
var alias_string = $"\n---@alias {alias_name}\n";
foreach (var typ in alias_string_list)
{
alias_string += string.Format("---| `\"{0}\"` \n", typ);
}
return alias_string;
}
public static string create_enum_alias_type(ParamInfo param)
{
var command_help = "";
var aliasName = param.Type.Contains('|') ? param.Type.Split('|')[0].Trim() : param.Type;
string[] enum_data = param.enums.Split('|');
command_help += "\n";
foreach (var data in enum_data)
{
command_help += data.Split(' ')[0] + " = " + data.Split(' ')[1] + "\n";
}
command_help += "\n---@alias " + aliasName + "\n";
foreach (var data in enum_data)
{
command_help += "---|`" + data.Split(' ')[0] + "`\n";
}
command_help += "\n";
return command_help;
}
public static void write_to_file(string file_path, string content)
{
File.WriteAllText(file_path, content);
}
public static void SetFileReadOnly(string file_path)
{
try
{
// Set the file as read-only
File.SetAttributes(file_path, File.GetAttributes(file_path) | FileAttributes.ReadOnly);
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred while setting the file as read-only: {ex.Message}");
}
}
}
}