private static File GetHistoryFile() { if (CreateHistoryDirectoryIfNotExists(HISTORY_DIR)) { string FullFilePath = HISTORY_DIR + HISTORY_FILE; File CmdFile = new File(); if (!CmdFile.FileExists(FullFilePath)) { CmdFile.Open(FullFilePath, File.ModeFlags.Write); CmdFile.Close(); } CmdFile.Open(FullFilePath, File.ModeFlags.ReadWrite); return(CmdFile); } MDLog.Error(LOG_CAT, "Failed to create command history directory."); return(null); }
public static void SaveLevel(string filepath, Level level) { JsonObject rootObject = new JsonObject(); JsonArray textureArray = new JsonArray(); JsonArray voxelArray = new JsonArray(); List <(VoxelPos, Voxel)> voxelList = level.GetVoxelList(); List <string> textures = new List <string>(); foreach ((VoxelPos, Voxel)pair in voxelList) { VoxelPos pos = pair.Item1; Voxel voxel = pair.Item2; JsonObject voxelObject = new JsonObject(); JsonObject posObject = new JsonObject(); JsonArray faceArray = new JsonArray(); posObject["x"] = pos.x; posObject["y"] = pos.y; posObject["z"] = pos.z; voxelObject["pos"] = posObject; foreach (string face in new string[] { voxel.frontTexture, voxel.backTexture, voxel.leftTexture, voxel.rightTexture, voxel.topTexture, voxel.bottomTexture }) { if (!textures.Contains(face)) { textures.Add(face); } faceArray.Add(new JsonPrimitive(textures.IndexOf(face))); } voxelObject["faces"] = faceArray; voxelArray.Add(voxelObject); } textures.ForEach((texture) => textureArray.Add(new JsonPrimitive(texture))); rootObject.Add("textures", textureArray); rootObject.Add("voxels", voxelArray); Godot.File file = new Godot.File(); file.Open("user://save.json", Godot.File.ModeFlags.Write); file.StoreString(rootObject.ToString()); file.Close(); }
// Creates our time-stamped log file and opens it for writing private static void InitLogFile(string LogDir) { RandomNumberGenerator rnd = new RandomNumberGenerator(); rnd.Randomize(); FullLogFilePath = $"{LogDir}{DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss")}_{rnd.RandiRange(10000,99999).ToString()}{EXT_LOG}"; if (CreateLogDirectoryIfNotExists(LogDir)) { LogFile = new File(); LogFile.Open(FullLogFilePath, File.ModeFlags.Write); Log(LOG_CAT, MDLogLevel.Info, $"Created log file {FullLogFilePath}"); LogFile.Close(); } else { Console.WriteLine("Failed to create log directory."); } }
// Opens the log file for writing private static void OpenLogFile() { LogFile?.Open(FullLogFilePath, File.ModeFlags.ReadWrite); LogFile?.SeekEnd(); }