示例#1
0
        // Called when the node enters the scene tree for the first time.
        public override void _Ready()
        {
            buf = (AudioStreamGeneratorPlayback)GetStreamPlayback();

            //FIXME:  IMPLEMENT DRUMS
            channels[9].Mute = true;

            //Setup the patch bank.
            const string BANKPATH = "res://demo/bank0/";
            const string EXT      = ".gfmp";

            for (int i = 0; i < patchBank.Length; i++)
            {
                patchBank[i] = new Patch(MixRate);
                var inst = (GeneralMidiInstrument)i;
                var path = BANKPATH + inst.ToString() + EXT;
                var dir  = new Godot.Directory();

                //Search for a bank to overload the initial one!!
                if (Godot.ResourceLoader.Exists(path) || dir.FileExists(path))
                {
                    var f = new Godot.File();
                    f.Open(path, File.ModeFlags.Read);
                    patchBank[i].FromString(f.GetAsText());
                    f.Close();
                    GD.Print("Program ", i, " (", inst, ") loaded.");
                }
                else
                {
                    //Init patch.
                    patchBank[i].FromString(glue.INIT_PATCH, true);
                }
            }
        }
示例#2
0
 /// <summary>
 ///   Returns true if file exists
 /// </summary>
 /// <param name="path">Path to check</param>
 /// <returns>True if exists, false otherwise</returns>
 public static bool Exists(string path)
 {
     using (var directory = new Directory())
     {
         return(directory.FileExists(path));
     }
 }
    private void _HelperGetScripts(String path, List <string> unprocessed_dirs)
    {
        Godot.Directory dir = new Godot.Directory();
        dir.Open(path);
        dir.ListDirBegin();
        String filename = dir.GetNext();

        while (filename.Length != 0)
        {
            if (dir.CurrentIsDir())
            {
                if (filename[0] != '.')
                {
                    unprocessed_dirs.Add(path + "/" + filename);
                }
            }
            else
            {
                if (filename.Substring(filename.Length - 3).Equals(".cs"))
                {
                    paths_to_scripts.Add(path + "/" + filename);
                }
            }
            filename = dir.GetNext();
        }
    }
示例#4
0
        // get the folder refer to resource
        // first : res/
        // then: res.txt
        // then : res/res.txt
        private List <string> getResFolder()
        {
            List <string> paths = new List <string>();
            var           dir   = new Godot.Directory();

            if (dir.DirExists("res://res/"))
            {
                paths.Add(GameManager.Instance.PrjPath + "res");
            }
            dir.Dispose();

            using (var file = new Godot.File()) {
                if (!_getResFolder(file, "res://res.txt", paths))
                {
                    if (!_getResFolder(file, "res://res/res.txt", paths))
                    {
                        if (paths.Count == 0)
                        {
                            Debug.LogError("no res folder found!");
                        }
                    }
                }
            }
            return(paths);
        }
示例#5
0
    private void _on_FileDialog_dir_selected(String _dir)
    {
        //if directory is selected, update storage path.
        storagePath           = _dir;
        dataPathLineEdit.Text = _dir;

        //update ingredient and volume path
        IngredientPath = $"{storagePath}/{ingredientFile}";
        VolumePath     = $"{storagePath}/{volumeFile}";
        ReceiptPath    = $"{storagePath}/{receiptFile}";

        //update configuration
        updateConfiguration();

        //check if any ingredient, volume and receipt list file exist and copy them over to the new location
        var _file      = new Godot.File();
        var _directory = new Godot.Directory();

        if (_file.FileExists($"data/{volumeFile}"))
        {
            _directory.Copy($"data/{volumeFile}", VolumePath);
        }
        if (_file.FileExists($"data/{ingredientFile}"))
        {
            _directory.Copy($"data/{ingredientFile}", IngredientPath);
        }
        if (_file.FileExists($"data/{receiptFile}"))
        {
            _directory.Copy($"data/{receiptFile}", ReceiptPath);
        }
    }
示例#6
0
    /// <summary>
    ///   Attempts to delete a file
    /// </summary>
    /// <param name="path">Path to the file</param>
    /// <returns>True on success</returns>
    public static bool DeleteFile(string path)
    {
        using var directory = new Directory();
        var result = directory.Remove(path);

        return(result == Error.Ok);
    }
示例#7
0
文件: Save.cs 项目: patana93/Thrive
    private static (SaveInformation info, Save save, Image screenshot) LoadFromFile(string file, bool info,
                                                                                    bool save, bool screenshot, Action readFinished)
    {
        using (var directory = new Directory())
        {
            if (!directory.FileExists(file))
            {
                throw new ArgumentException("save with the given name doesn't exist");
            }
        }

        var(infoStr, saveStr, screenshotData) = LoadDataFromFile(file, info, save, screenshot);

        readFinished?.Invoke();

        SaveInformation infoResult  = null;
        Save            saveResult  = null;
        Image           imageResult = null;

        if (info)
        {
            if (string.IsNullOrEmpty(infoStr))
            {
                throw new IOException("couldn't find info content in save");
            }

            infoResult = ThriveJsonConverter.Instance.DeserializeObject <SaveInformation>(infoStr);
        }

        if (save)
        {
            if (string.IsNullOrEmpty(saveStr))
            {
                throw new IOException("couldn't find save content in save file");
            }

            // This deserializes a huge tree of objects
            saveResult = ThriveJsonConverter.Instance.DeserializeObject <Save>(saveStr);
        }

        if (screenshot)
        {
            imageResult = new Image();

            if (screenshotData != null && screenshotData.Length > 0)
            {
                imageResult.LoadPngFromBuffer(screenshotData);
            }
            else
            {
                // Not a critical error
            }
        }

        return(infoResult, saveResult, imageResult);
    }
示例#8
0
    /// <summary>
    ///   Makes sure the save directory exists
    /// </summary>
    public static void MakeSureDirectoryExists(string path)
    {
        using var directory = new Directory();
        var result = directory.MakeDirRecursive(path);

        if (result != Error.AlreadyExists && result != Error.Ok)
        {
            throw new IOException($"can't create folder: {path}");
        }
    }
示例#9
0
    public static void TakeScreenshot(Node ctx)
    {
        var image = ctx.GetViewport().GetTexture().GetData();

        image.FlipY();
        var dir = new Godot.Directory();

        dir.Open("user://");
        dir.MakeDir("screenshots");

        image.SavePng($"user://screenshots/{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}.png");
    }
示例#10
0
 public void Create(bool recursive = true)
 {
     using (var directory = new Directory())
     {
         if (recursive)
         {
             directory.MakeDir(Path).ThrowOnError();
         }
         else
         {
             directory.MakeDirRecursive(Path).ThrowOnError();
         }
     }
 }
示例#11
0
        /// <summary>
        /// Enumerate through all objects in a directory.
        /// </summary>
        public static IEnumerable <string> EnumerateDirectory(string rootpath)
        {
            List <string> ret = new List <string>();
            var           dir = new Godot.Directory();

            dir.Open(rootpath);
            dir.ListDirBegin();
            for (string path = dir.GetNext(); !string.IsNullOrEmpty(path); path = dir.GetNext())
            {
                if (path[0] != '.')
                {
                    ret.Add(dir.GetCurrentDir() + "/" + path);
                }
            }
            dir.ListDirEnd();
            return(ret);
        }
示例#12
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        _items = new Godot.Collections.Array <ItemResource>();
        Godot.Directory directory = new Godot.Directory();
        directory.Open("res://items");
        directory.ListDirBegin();

        String fileName = directory.GetNext();

        while (fileName != null && fileName.Length != 0)
        {
            if (!directory.CurrentIsDir() && fileName.Contains(".tres") && !fileName.Contains("ItemResource.tres") && !fileName.Contains("Pickup"))
            {
                ItemResource itemResource = ((ItemResource)GD.Load("res://items/" + fileName));

                _items.Add(itemResource);
            }
            fileName = directory.GetNext();
        }
        directory.ListDirEnd();
    }
        public static void scanDir <T>(string path, string filter, ref Godot.Collections.Dictionary <string, T> dic, object defaultObject)
        {
            if (defaultObject == null)
            {
                defaultObject = (bool)false;
            }

            List <string> names = new List <string>();

            if (!String.IsNullOrEmpty(path))
            {
                var dir = new Godot.Directory();
                dir.Open(path);
                dir.ListDirBegin();
                while (true)
                {
                    var file = dir.GetNext();

                    if (String.IsNullOrEmpty(file))
                    {
                        break;
                    }

                    else if (!file.BeginsWith(".") && file.Contains("." + filter))
                    {
                        var fileName = file.Replace("." + filter, "");
                        if (!names.Contains(fileName))
                        {
                            names.Add(fileName);
                        }
                    }
                }

                foreach (var x in names)
                {
                    if (!dic.ContainsKey(x))
                    {
                        if (defaultObject is Resource)
                        {
                            var df = (defaultObject as Resource);
                            df.ResourceLocalToScene = true;
                            var dup = (object)(df.Duplicate());
                            dic.Add(x, (T)dup);
                        }
                        else
                        {
                            dic.Add(x, (T)defaultObject);
                        }
                    }
                }

                foreach (var t in dic)
                {
                    if (!names.Contains(t.Key))
                    {
                        dic.Remove(t.Key);
                    }
                    else
                    {
                        if (t.Value is Resource)
                        {
                            (t.Value as Resource).ResourceLocalToScene = true;
                        }
                    }
                }
            }
            else
            {
                dic.Clear();
            }
        }