public static void ListWorlds(List <string> worldPaths, List <string> worldNames) { string[] files = Directory.GetFiles(WorldFiles.GetWorldsDirectory()); worldPaths.Clear(); foreach (string path in files) { if (WorldFiles.IsWorldFile(path)) { worldPaths.Add(path); } else if (WorldFiles.IsOldWorldFile(path)) { string newPath = WorldFiles.GetNewWorldPath(Path.GetFileNameWithoutExtension(path)); Debug.Log("Updating " + path + " to " + newPath); File.Move(path, newPath); worldPaths.Add(newPath); } } worldPaths.Sort(); worldNames.Clear(); foreach (string path in worldPaths) { worldNames.Add(Path.GetFileNameWithoutExtension(path)); } }
private void ImportWorld(string name) { if (name.Length == 0) { Destroy(this); return; } string newPath = WorldFiles.GetNewWorldPath(name); if (File.Exists(newPath)) { var dialog = DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists."); dialog.yesButtonHandler = DestroyThis; return; } try { ShareMap.ImportSharedFile(newPath); MenuGUI.OpenWorld(newPath, Scenes.EDITOR); openingWorld = true; Destroy(this); } catch (System.Exception e) { Debug.Log(e); var dialog = DialogGUI.ShowMessageDialog(gameObject, "Error importing world"); dialog.yesButtonHandler = DestroyThis; } }
public static bool ValidateName(string name, out string errorMessage) { errorMessage = null; if (name.Length == 0) { return(false); } if (name.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { errorMessage = "That name contains a special character which is not allowed."; return(false); } if (name.StartsWith(".")) { errorMessage = "Name can't start with a period."; return(false); } string path = WorldFiles.GetNewWorldPath(name); if (File.Exists(path)) { errorMessage = "A world with that name already exists."; return(false); } return(true); // you are valid <3 }
private void CopyWorld(string newName) { if (newName.Length == 0) { return; } string newPath = WorldFiles.GetNewWorldPath(newName); if (File.Exists(newPath)) { DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists."); return; } File.Copy(selectedWorldPath, newPath); UpdateWorldList(); }
public static void OpenDemoWorld(string name, string templateName) { if (EditorFile.instance != null) { EditorFile.instance.Save(); } TextAsset worldAsset = Resources.Load <TextAsset>(templateName); string path = WorldFiles.GetNewWorldPath(name); for (int i = 2; File.Exists(path); i++) // autonumber { path = WorldFiles.GetNewWorldPath(name + " " + i); } SelectedWorld.SelectDemoWorld(worldAsset, path); SceneManager.LoadScene(Scenes.EDITOR); }
private void NewWorld(string name, TextAsset template) { if (name.Length == 0) { return; } string path = WorldFiles.GetNewWorldPath(name); if (File.Exists(path)) { DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists."); return; } using (FileStream fileStream = File.Create(path)) { fileStream.Write(template.bytes, 0, template.bytes.Length); } UpdateWorldList(); OpenWorld(path, Scenes.EDITOR); }