public static void SaveSettings() { using (StreamWriter sw = new StreamWriter(Utility.SETTINGS_FILE)) { string jsonString = JsonConvert.SerializeObject(settings, Formatting.Indented); sw.Write(jsonString); LogManager.AddEntry("Settings saved!"); } }
public static void LoadSettings() { if (SettingsFileExists() && LogiXDirectoryExists()) { LogManager.AddEntry("LogiX Settings found."); LoadSettingsFile(); } else { LogManager.AddEntry("Could not find settings file or LogiX directory.", LogEntryType.WARNING); CreateLogiXDirectory(); CreateDefaultSettingsFile(); LoadSettings(); } }
public static string GetSetting(string key, string def) { try { if (settings.ContainsKey(key)) { return(settings[key]); } return(def); } catch (Exception ex) { LogManager.AddEntry($"Failed to retrieve setting '{key}': {ex.Message}"); return(def); } }
public static bool LoadFile(string filePath) { try { IAssetLoader loader = GetLoaderFromFilePath(filePath); Asset asset = loader.LoadAsset(filePath); asset.Name = Path.GetFileNameWithoutExtension(filePath); LoadedAssets.Add(asset.Name, asset); LogManager.AddEntry($"Successfully loaded asset '{asset.Name}'!", LogEntryType.INFO); return(true); } catch { LogManager.AddEntry($"Failed to load asset '{Path.GetFileNameWithoutExtension(filePath)}'!", LogEntryType.ERROR); return(false); } }
public static bool LoadSettingsFile() { try { LogManager.AddEntry("Loading settings..."); using (StreamReader sr = new StreamReader(Utility.SETTINGS_FILE)) { settings = JsonConvert.DeserializeObject <Dictionary <string, string> >(sr.ReadToEnd()); } // Could load settings successfully. LogManager.AddEntry("Successfully loaded settings!"); return(true); } catch (Exception ex) { // Failed to load settings. LogManager.AddEntry("Failed to load settings!", LogEntryType.ERROR); return(false); } }
public static LogiXProject LoadFromFile(string path) { try { using (StreamReader sr = new StreamReader(path)) { string json = sr.ReadToEnd(); LogiXProject lp = JsonConvert.DeserializeObject <LogiXProject>(json); Tuple <List <DrawableComponent>, List <DrawableWire> > tup = lp.Container.GenerateDrawables(lp.GetAllDescriptions(), Vector2.Zero); lp.Simulation = new Simulator(); lp.Simulation.AllComponents = tup.Item1; lp.Simulation.AllWires = tup.Item2; return(lp); } } catch (Exception ex) { LogManager.AddEntry($"Failed to load project at {path}: {ex.Message}", LogEntryType.ERROR); return(null); } }
public override void Initialize() { // Should initialize some basic settings and stuff // Load settings files etc. // Set window icon and stuff can also be done with this. SettingManager.LoadSettings(); // Apply window size settings to window int windowWidth = int.Parse(SettingManager.GetSetting("window-width", "1440")); int windowHeight = int.Parse(SettingManager.GetSetting("window-height", "768")); Vector2 size = new Vector2(windowWidth, windowHeight); SetWindowSize(size, false); LogManager.AddEntry($"Creating LogiX window with width = {(int)size.X} and height = {(int)size.Y}"); // Create new camera that's focused on (0,0). // This should maybe be done somewhere else. But is good for testing atm. cam = new Camera2D(size / 2f, Vector2.Zero, 0f, 1f); _simulationOn = true; _makingIc = false; }
public static bool CreateDefaultSettingsFile() { try { LogManager.AddEntry("Creating default settings file."); Dictionary <string, string> s = GenerateDefaultSettings(); using (StreamWriter wr = new StreamWriter(Utility.SETTINGS_FILE)) { string jsonString = JsonConvert.SerializeObject(s, Formatting.Indented); wr.Write(jsonString); } // Successfully created default settings file LogManager.AddEntry("Successfully created default settings file."); return(true); } catch (Exception ex) { // Failed to create default settings file. LogManager.AddEntry("Failed to create default settings file.", LogEntryType.ERROR); return(false); } }
public ICCollection GetCollection(string name) { try { foreach (string collection in IncludedCollections) { string fileName = Path.GetFileName(collection); if (fileName == name) { using (StreamReader sr = new StreamReader(collection)) { return(JsonConvert.DeserializeObject <ICCollection>(sr.ReadToEnd())); } } } return(null); } catch (Exception ex) { LogManager.AddEntry($"Failed to load collection '{name}': {ex.Message}"); return(null); } }
public static bool CreateLogiXDirectory() { LogManager.AddEntry("Creating LogiX directory in AppData/Roaming."); Directory.CreateDirectory(Utility.LOGIX_DIR); return(true); }