Beispiel #1
0
    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));
        }
    }
Beispiel #2
0
    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;
        }
    }
Beispiel #3
0
    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
    }
Beispiel #4
0
    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();
    }
Beispiel #5
0
    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);
    }
Beispiel #6
0
    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);
    }