Skip to content

Commit

Permalink
ran codebase format
Browse files Browse the repository at this point in the history
  • Loading branch information
B3none committed Jan 26, 2024
1 parent 35f04a1 commit 44d27f7
Show file tree
Hide file tree
Showing 16 changed files with 438 additions and 384 deletions.
2 changes: 1 addition & 1 deletion Modules/Configs/JsonConverters/QAngleJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public override void Write(Utf8JsonWriter writer, QAngle value, JsonSerializerOp
var qAngleString = value.ToString();
writer.WriteStringValue(qAngleString);
}
}
}
2 changes: 1 addition & 1 deletion Modules/Configs/JsonConverters/VectorJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public override void Write(Utf8JsonWriter writer, Vector value, JsonSerializerOp
var vectorString = value.ToString();
writer.WriteStringValue(vectorString);
}
}
}
35 changes: 18 additions & 17 deletions Modules/Configs/MapConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MapConfig
private readonly string _mapConfigDirectory;
private readonly string _mapConfigPath;
private MapConfigData? _mapConfigData;

public MapConfig(string moduleDirectory, string mapName)
{
_mapName = mapName;
Expand All @@ -20,7 +20,7 @@ public MapConfig(string moduleDirectory, string mapName)
public void Load()
{
Helpers.WriteLine($"{RetakesPlugin.LogPrefix}Attempting to load map data from {_mapConfigPath}");

try
{
if (!File.Exists(_mapConfigPath))
Expand All @@ -36,7 +36,7 @@ public void Load()
// {
// throw new Exception("No spawns found in config");
// }

Helpers.WriteLine($"{RetakesPlugin.LogPrefix}Data loaded from {_mapConfigPath}");
}
catch (FileNotFoundException)
Expand All @@ -60,23 +60,23 @@ public List<Spawn> GetSpawnsClone()
{
throw new Exception("Map config data is null");
}

return _mapConfigData.Spawns.ToList();
}

public bool AddSpawn(Spawn spawn)
{
_mapConfigData ??= new MapConfigData();

// Check if the spawn already exists based on vector and bombsite
if (_mapConfigData.Spawns.Any(existingSpawn =>
existingSpawn.Vector == spawn.Vector && existingSpawn.Bombsite == spawn.Bombsite))
{
return false; // Spawn already exists, avoid duplication
}

_mapConfigData.Spawns.Add(spawn);

Save();
Load();

Expand All @@ -86,30 +86,31 @@ public bool AddSpawn(Spawn spawn)
public bool RemoveSpawn(Spawn spawn)
{
_mapConfigData ??= new MapConfigData();

if (!_mapConfigData.Spawns.Any(existingSpawn => existingSpawn.Vector == spawn.Vector && existingSpawn.Bombsite == spawn.Bombsite))

if (!_mapConfigData.Spawns.Any(existingSpawn =>
existingSpawn.Vector == spawn.Vector && existingSpawn.Bombsite == spawn.Bombsite))
{
return false; // Spawn doesn't exist, avoid removing
}

_mapConfigData.Spawns.Remove(spawn);

Save();
Load();

return true;
}

private MapConfigData GetSanitisedMapConfigData()
{
if (_mapConfigData == null)
{
throw new Exception("Map config data is null");
}

// Remove any duplicate spawns in the list
_mapConfigData.Spawns = _mapConfigData.Spawns
.GroupBy(spawn => new {spawn.Vector, spawn.Bombsite})
.GroupBy(spawn => new { spawn.Vector, spawn.Bombsite })
.Select(group => group.First())
.ToList();

Expand All @@ -129,7 +130,7 @@ private void Save()
{
Directory.CreateDirectory(_mapConfigDirectory);
}

File.WriteAllText(_mapConfigPath, jsonString);

Helpers.WriteLine($"{RetakesPlugin.LogPrefix}Data has been written to {_mapConfigPath}");
Expand All @@ -149,4 +150,4 @@ public static bool IsLoaded(MapConfig? mapConfig, string currentMap)

return true;
}
}
}
2 changes: 1 addition & 1 deletion Modules/Configs/MapConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
public class MapConfigData
{
public List<Spawn> Spawns { get; set; } = new();
}
}
20 changes: 10 additions & 10 deletions Modules/Configs/RetakesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class RetakesConfig
{
private readonly string _retakesConfigPath;
public RetakesConfigData? RetakesConfigData;

public RetakesConfig(string moduleDirectory)
{
_retakesConfigPath = Path.Combine(moduleDirectory, "retakes_config.json");
Expand All @@ -16,7 +16,7 @@ public RetakesConfig(string moduleDirectory)
public void Load()
{
Helpers.WriteLine($"{RetakesPlugin.LogPrefix}Attempting to load data from {_retakesConfigPath}");

try
{
if (!File.Exists(_retakesConfigPath))
Expand All @@ -31,13 +31,13 @@ public void Load()
{
throw new Exception("Retakes config is null after deserialization");
}

if (RetakesConfigData.Version != RetakesConfigData.CurrentVersion)
{
UpdateVersion();
throw new Exception("Config is outdated");
}

Helpers.WriteLine($"{RetakesPlugin.LogPrefix}Data loaded from {_retakesConfigPath}");
}
catch (FileNotFoundException)
Expand Down Expand Up @@ -78,31 +78,31 @@ public static bool IsLoaded(RetakesConfig? retakesConfig)
Helpers.WriteLine($"{RetakesPlugin.LogPrefix}Retakes config is null");
return false;
}

if (retakesConfig.RetakesConfigData == null)
{
Helpers.WriteLine($"{RetakesPlugin.LogPrefix}Retakes config data is null");
return false;
}

return true;
}

private bool UpdateVersion()
{
if (RetakesConfigData == null)
{
return false;
}

if (RetakesConfigData.Version == RetakesConfigData.CurrentVersion)
{
return true;
}

RetakesConfigData.Version = RetakesConfigData.CurrentVersion;
Save();

return true;
}
}
}
2 changes: 1 addition & 1 deletion Modules/Configs/RetakesConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public class RetakesConfigData
public bool IsAutoPlantEnabled { get; set; } = true;
public string QueuePriorityFlag { get; set; } = "@css/vip";
public bool IsDebugMode { get; set; } = false;
}
}
5 changes: 3 additions & 2 deletions Modules/Configs/Spawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public Spawn(Vector vector, QAngle qAngle)

[JsonConverter(typeof(VectorJsonConverter))]
public Vector Vector { get; }

[JsonConverter(typeof(QAngleJsonConverter))]
public QAngle QAngle { get; }

public CsTeam Team { get; set; }
public Bombsite Bombsite { get; set; }
public bool CanBePlanter { get; set; }
}
}
2 changes: 1 addition & 1 deletion Modules/Enums/Bombsite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public enum Bombsite
{
A = 0,
B = 1
}
}
Loading

0 comments on commit 44d27f7

Please sign in to comment.