1
Fork 0
mirror of https://github.com/thegeneralist01/Scene-Manager-DevRepo synced 2026-01-11 15:40:29 +01:00

Big refactor

This commit is contained in:
Rich Dunne 2021-01-10 08:41:41 -07:00
parent b66a97fef8
commit 6e2744a02c

View file

@ -6,36 +6,36 @@ using System.IO;
namespace SceneManager namespace SceneManager
{ {
// The only reason this class should change is to modify any plugin settings
internal static class Settings internal static class Settings
{ {
internal static readonly InitializationFile ini = new InitializationFile("Plugins/SceneManager.ini"); internal static readonly InitializationFile ini = new InitializationFile("Plugins/SceneManager.ini");
// Keybindings // Keybindings
internal static Keys ToggleKey = Keys.T; internal static Keys ToggleKey { get; private set; } = Keys.T;
internal static Keys ModifierKey = Keys.LShiftKey; internal static Keys ModifierKey { get; private set; } = Keys.LShiftKey;
internal static ControllerButtons ToggleButton = ControllerButtons.Y; internal static ControllerButtons ToggleButton { get; private set; } = ControllerButtons.Y;
internal static ControllerButtons ModifierButton = ControllerButtons.A; internal static ControllerButtons ModifierButton { get; private set; } = ControllerButtons.A;
// Plugin Settings // Plugin Settings
internal static bool Enable3DWaypoints = true; internal static bool Enable3DWaypoints { get; private set; } = true;
internal static bool EnableMapBlips = true; internal static bool EnableMapBlips { get; private set; } = true;
internal static bool EnableHints = true; internal static bool EnableHints { get; private set; } = true;
internal static SpeedUnits SpeedUnit = SpeedUnits.MPH; internal static SpeedUnits SpeedUnit { get; private set; } = SpeedUnits.MPH;
internal static float BarrierPlacementDistance = 30f; internal static float BarrierPlacementDistance { get; private set; } = 30f;
internal static bool EnableAdvancedBarricadeOptions = false; internal static bool EnableAdvancedBarricadeOptions { get; private set; } = false;
internal static bool EnableBarrierLightsDefaultOn = false; internal static bool EnableBarrierLightsDefaultOn { get; private set; } = false;
// Default Waypoint Settings // Default Waypoint Settings
internal static int CollectorRadius = 1; internal static int CollectorRadius { get; set; } = 1;
internal static int SpeedZoneRadius = 5; internal static int SpeedZoneRadius { get; set; } = 5;
internal static bool StopWaypoint = false; internal static bool StopWaypoint { get; set; } = false;
internal static bool DirectDrivingBehavior = false; internal static bool DirectDrivingBehavior { get; set; } = false;
internal static int WaypointSpeed = 5; internal static int WaypointSpeed { get; set; } = 5;
// Barriers // Barriers
internal static Dictionary<string, Model> barriers = new Dictionary<string, Model>(); internal static Dictionary<string, Model> Barriers { get; private set; } = new Dictionary<string, Model>();
//internal static List<string> barrierKeys = new List<string>(); internal static List<Objects.Path> ImportedPaths { get; private set; } = new List<Objects.Path>();
//internal static List<Model> barrierValues = new List<Model>();
internal static void LoadSettings() internal static void LoadSettings()
{ {
@ -63,77 +63,47 @@ namespace SceneManager
StopWaypoint = ini.ReadBoolean("Default Waypoint Settings", "StopWaypoint", false); StopWaypoint = ini.ReadBoolean("Default Waypoint Settings", "StopWaypoint", false);
DirectDrivingBehavior = ini.ReadBoolean("Default Waypoint Settings", "DirectDrivingBehavior", false); DirectDrivingBehavior = ini.ReadBoolean("Default Waypoint Settings", "DirectDrivingBehavior", false);
WaypointSpeed = ini.ReadInt32("Default Waypoint Settings", "WaypointSpeed", 5); WaypointSpeed = ini.ReadInt32("Default Waypoint Settings", "WaypointSpeed", 5);
CheckForValidWaypointSettings();
// Barriers SettingsValidator.ValidateWaypointSettings();
foreach(string displayName in ini.GetKeyNames("Barriers")) SettingsValidator.ValidateBarrierSettings(ini);
ImportPaths();
}
// This will need to be moved to a different class
internal static void ImportPaths()
{
ImportedPaths.Clear();
// Check if Saved Paths directory exists
var GAME_DIRECTORY = Directory.GetCurrentDirectory();
var SAVED_PATHS_DIRECTORY = GAME_DIRECTORY + "\\plugins\\SceneManager\\Saved Paths\\";
if (!Directory.Exists(SAVED_PATHS_DIRECTORY))
{ {
var model = new Model(ini.ReadString("Barriers", displayName.Trim())); Game.LogTrivial($"Directory '\\plugins\\SceneManager\\Saved Paths' does not exist. No paths available to import.");
if (model.IsValid) return;
{
barriers.Add(displayName, model);
//barrierKeys.Add(key.Trim());
//barrierValues.Add(model);
}
else
{
Game.LogTrivial($"{model.Name} is not valid.");
}
} }
//ImportPaths(); // Check if any XML files are available to import from Saved Paths
var savedPaths = Directory.GetFiles(SAVED_PATHS_DIRECTORY, "*.xml");
void CheckForValidWaypointSettings() if (savedPaths.Length == 0)
{ {
if(CollectorRadius > 50 || CollectorRadius < 1) Game.LogTrivial($"No saved paths found.");
{ return;
CollectorRadius = 1; }
Game.LogTrivial($"Invalid value for CollectorRadius in user settings, resetting to default."); else
} {
if(SpeedZoneRadius > 200 || SpeedZoneRadius < 5) Game.LogTrivial($"{savedPaths.Length} path(s) available to import.");
{
SpeedZoneRadius = 5;
Game.LogTrivial($"Invalid value for SpeedZoneRadius in user settings, resetting to default.");
}
if (CollectorRadius > SpeedZoneRadius)
{
CollectorRadius = 1;
SpeedZoneRadius = 5;
Game.LogTrivial($"CollectorRadius is greater than SpeedZoneRadius in user settings, resetting to defaults.");
}
if (WaypointSpeed > 100 || WaypointSpeed < 5)
{
WaypointSpeed = 5;
Game.LogTrivial($"Invalid value for WaypointSpeed in user settings, resetting to default.");
}
} }
void ImportPaths() // Import paths
foreach (string file in savedPaths)
{ {
//read each file name in Saved Paths Game.LogTrivial($"File: {Path.GetFileName(file)}");
var GAME_DIRECTORY = Directory.GetCurrentDirectory(); var importedPath = PathXMLManager.LoadItemFromXML<Objects.Path>(SAVED_PATHS_DIRECTORY + Path.GetFileName(file));
var SAVED_PATHS_DIRECTORY = GAME_DIRECTORY + "/plugins/SceneManager/Saved Paths/"; importedPath.Name = Path.GetFileNameWithoutExtension(file);
if (!Directory.Exists(SAVED_PATHS_DIRECTORY)) ImportedPaths.Add(importedPath);
{
Game.LogTrivial($"Directory '/plugins/SceneManager/Saved Paths' does not exist. No paths available to import.");
return;
}
//add file name to PathMainMenu.importedPaths
var paths = Directory.GetFiles(SAVED_PATHS_DIRECTORY);
if (paths.Length == 0)
{
Game.LogTrivial($"No saved paths found.");
return;
}
foreach (string path in paths)
{
Game.LogTrivial($"Path to import: {Path.GetFileName(path)}");
// Check if XML is valid before actually importing
}
} }
Game.LogTrivial($"Successfully imported {ImportedPaths.Count} path(s).");
} }
internal static void UpdateSettings(bool threeDWaypointsEnabled, bool mapBlipsEnabled, bool hintsEnabled, SpeedUnits unit) internal static void UpdateSettings(bool threeDWaypointsEnabled, bool mapBlipsEnabled, bool hintsEnabled, SpeedUnits unit)