Skip to content

Commit a79dd08

Browse files
committed
feat: added writing to HUD files,
Renamed WriteFile -> WriteCfg
1 parent 1a9f26b commit a79dd08

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

src/HUDEditor/Classes/HUD/HUDCustomizations.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,30 @@ string EvaluateValue(string input)
333333
EvaluateSpecial(special, userSetting, enable, specialParameters);
334334
}
335335

336-
// Create and write to files as instructed in the HUD's schema
337-
if (hudSetting.WriteFile is not null && !string.IsNullOrWhiteSpace(hudSetting.WriteFile.FileName))
336+
// Create and write to files to the HUD's tf/cfg directory
337+
if (hudSetting.WriteCfg is not null && !string.IsNullOrWhiteSpace(hudSetting.WriteCfg.FileName))
338338
{
339339
// Find tf/cfg directory and create the HUD's cfg directory if it doesn't exist
340340
var cfgPath = Path.GetFullPath(App.HudPath.Replace("/custom", "/cfg"));
341341
var hudFolder = Path.Combine(cfgPath, Name);
342342
if (!Directory.Exists(hudFolder)) Directory.CreateDirectory(hudFolder);
343343

344+
// Create the file based on WriteCfg.FilePath and WriteCfg.Contents
345+
var filePath = Path.Combine(hudFolder, hudSetting.WriteCfg.FileName);
346+
Directory.CreateDirectory(Path.GetDirectoryName(filePath)!);
347+
348+
// Write to the file depending on the value of the setting
349+
if (userSetting.Value.ToLowerInvariant() == "true")
350+
File.WriteAllText(filePath, hudSetting.WriteCfg.TrueText ?? string.Empty);
351+
else
352+
File.WriteAllText(filePath, hudSetting.WriteCfg.FalseText ?? string.Empty);
353+
}
354+
355+
// Create and write to files to the HUD's tf/custom directory
356+
if (hudSetting.WriteFile is not null && !string.IsNullOrWhiteSpace(hudSetting.WriteFile.FileName))
357+
{
344358
// Create the file based on WriteFile.FilePath and WriteFile.Contents
345-
var filePath = Path.Combine(hudFolder, hudSetting.WriteFile.FileName);
359+
var filePath = Path.Combine(Name, hudSetting.WriteFile.FileName);
346360
Directory.CreateDirectory(Path.GetDirectoryName(filePath)!);
347361

348362
// Write to the file depending on the value of the setting

src/HUDEditor/JSON/Schema/schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@
179179
}
180180
}
181181
},
182+
"WriteCfg": {
183+
"type": "object",
184+
"properties": {
185+
"FileName": {
186+
"type": "string"
187+
},
188+
"TrueText": {
189+
"type": "string"
190+
},
191+
"FalseText": {
192+
"type": "string"
193+
}
194+
}
195+
},
182196
"ComboDirectories": {
183197
"type": "array",
184198
"items": {

src/HUDEditor/Models/Controls.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ public class Controls
2929
[JsonPropertyName("Value")] public string Value = "0";
3030
[JsonPropertyName("Width")] public int Width;
3131
[JsonPropertyName("WriteFile")] public WriteFile WriteFile;
32+
[JsonPropertyName("WriteCfg")] public WriteCfg WriteCfg;
3233
}

src/HUDEditor/Models/Option.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Option
1010
[JsonPropertyName("Label")] public string Label;
1111
[JsonPropertyName("RenameFile")] public RenameFile RenameFile;
1212
[JsonPropertyName("WriteFile")] public WriteFile WriteFile;
13+
[JsonPropertyName("WriteCfg")] public WriteCfg WriteCfg;
1314
[JsonPropertyName("Special")] public string Special;
1415
[JsonPropertyName("SpecialParameters")] public string[] SpecialParameters;
1516
[JsonPropertyName("Value")] public string Value;

src/HUDEditor/Models/WriteCfg.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace HUDEditor.Models;
4+
5+
public class WriteCfg
6+
{
7+
[JsonPropertyName("FileName")] public string FileName;
8+
[JsonPropertyName("TrueText")] public string TrueText;
9+
[JsonPropertyName("FalseText")] public string FalseText;
10+
}

0 commit comments

Comments
 (0)