Beispiel #1
0
        /// <summary>
        /// Create a new instance of the <see cref="GodotFileStream"/> class.
        /// </summary>
        /// <param name="path">The path to the file to open. This accepts Godot-style <code>user://</code> and <code>res://</code> paths.</param>
        /// <param name="flags">File flags.</param>
        /// <param name="compressionMode">If not null, this will enable compression/decompression.</param>
        public GodotFileStream(string path, File.ModeFlags flags, File.CompressionMode?compressionMode = null)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            _file  = new File();
            _flags = flags;
            Error result;

            if (compressionMode.HasValue)
            {
                result = _file.OpenCompressed(path, flags, compressionMode.Value);
            }
            else
            {
                result = _file.Open(path, flags);
            }

            if (result != Error.Ok)
            {
                throw new IOException($"Unable to open \"{path}\": {result}");
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
 private bool _getResFolder(Godot.File file, string path, List <string> paths)
 {
     if (file.FileExists(path))
     {
         file.Open(path, File.ModeFlags.Read);
         var ss = file.GetAsText();
         if (string.IsNullOrEmpty(ss))
         {
             return(false);
         }
         var cfg = Hocon.HoconParser.Parse(ss);
         var res = cfg.GetString("res");
         if (res.valid() && !paths.Contains(res))
         {
             if (paths.Count == 0)
             {
                 paths.Add(res);
             }
             else
             {
                 paths[0] = res;
             }
         }
         foreach (var val in cfg.AsEnumerable())
         {
             if (val.Key != "res" && !paths.Contains(val.Key))
             {
                 paths.Add(val.Value.GetString());
             }
         }
         file.Close();
         return(true);
     }
     return(false);
 }
Beispiel #4
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);
        }
    }
Beispiel #5
0
        public void HandleRequest(Request request, Response response)
        {
            // check if file exist at folder (need to assume a base local root)
            var fullPath = "res://public" + Uri.UnescapeDataString(request.uri.LocalPath);
            // get file extension to add to header
            var fileExt = System.IO.Path.GetExtension(fullPath);
            //Debug.Log($"fullPath:{fullPath} fileExt:{fileExt}");

            var f = new Godot.File();

            // not found
            if (!f.FileExists(fullPath))
            {
                response.statusCode = 404;
                response.message    = "Not Found";
                return;
            }

            // serve the file
            response.statusCode = 200;
            response.message    = "OK";
            response.headers.Add("Content-Type", MimeTypeMap.GetMimeType(fileExt));

            var ret = f.Open(fullPath, Godot.File.ModeFlags.Read);

            // read file and set bytes
            if (ret == Error.Ok)
            {
                var length = (int)f.GetLen();
                // add content length
                response.headers.Add("Content-Length", length.ToString());
                response.SetBytes(f.GetBuffer(length));
            }
            f.Close();
        }
    public override void _Ready()
    {
        label = GetNode <RichTextLabel>("RichTextLabel");

        Godot.File file = new Godot.File();
        file.Open("res://Testing/Testing.cs", File.ModeFlags.Read);
        content = file.GetAsText();
        file.Close();

        label.Text = "Line1";
        label.GetVScroll().Connect("value_changed", this, "ScrollLineLock");
        //this.Connect(nameof(MySignal), this, "ScrollLineLock");

        Font font            = (Font)label.GetFont("normal_font", nameof(RichTextLabel));
        int  line_separation = (int)label.GetConstant("line_separation");

        label.RectSize = new Vector2(label.RectSize.x, (font.GetHeight() + line_separation) * 8);

        GD.Print("ready is called");
        GD.Print((int)1.9);
        GD.Print((int)1.3);

        double char_increase_rate = 6;
        int    threshold          = 5;
        int    char_count         = (int)(char_increase_rate - (((int)char_increase_rate / 5) * (5 - 1)));

        GD.Print("ans: " + char_count);
    }
Beispiel #7
0
    private void RefreshDisplay()
    {
        Godot.File file = new Godot.File();
        file.Open(this.SaveLocation, File.ModeFlags.Read);
        if (file.IsOpen())
        {
            this.HasSaveData = true;
        }
        else
        {
            this.HasSaveData = false;
        }
        file.Close();

        if (this.HasSaveData)
        {
            this._loadButton.Text = String.Format("Save Slot {0} - (data)", this.SlotNumber);
            var modified     = file.GetModifiedTime(this.SaveLocation);
            var modifiedDate = DateTimeOffset.FromUnixTimeSeconds((long)modified).ToLocalTime().ToString("yyyy-MM-dd");
            this._lastPlayedLabel.Text = String.Format("Last Played: {0}", modifiedDate);
            this._clearButton.Disabled = false;
        }
        else
        {
            this._loadButton.Text      = String.Format("Save Slot {0} - (empty)", this.SlotNumber);
            this._lastPlayedLabel.Text = "Last Played: never";
            this._clearButton.Disabled = true;
        }
    }
Beispiel #8
0
 public void StoreData(String file, Godot.Collections.Dictionary save)
 {
     Godot.File databaseFile = new Godot.File();
     databaseFile.Open("res://databases/" + file + ".json", Godot.File.ModeFlags.Write);
     databaseFile.StoreString(JSON.Print(save));
     databaseFile.Close();
 }
Beispiel #9
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);
                }
            }
        }
Beispiel #10
0
        public static object Exists(string path, string context)
        {
            var passed  = $"{path} exists";
            var failed  = $"{path} does not exist";
            var success = new Godot.File().FileExists(path);
            var result  = success ? passed : failed;

            return(Result(success, passed, result, context));
        }
Beispiel #11
0
    ////////////

    //LOCAL SAVING/LOADING
    #region LOADSAVE
    public void loadDBParams()
    {
        Godot.File file = new Godot.File();

        file.OpenEncryptedWithPass("user://dbFile.dat", Godot.File.ModeFlags.Read, OS.GetUniqueId());
        connectionString = file.GetAsText();
        file.Close();
        database = new BD(connectionString);
    }
Beispiel #12
0
        public static byte[] LoadData(string path)
        {
            var f = new Godot.File();

            f.Open($"res://public/{path}", Godot.File.ModeFlags.Read);

            var buffer = f.GetBuffer((int)f.GetLen());

            f.Close();
            return(buffer);
        }
Beispiel #13
0
    public Godot.Collections.Dictionary ReadData(String file)
    {
        Godot.File databaseFile = new Godot.File();
        databaseFile.Open("res://databases/" + file + ".json", Godot.File.ModeFlags.Read);
        string jsonAsText = databaseFile.GetAsText();

        databaseFile.Close();
        JSONParseResult jsonParsed = JSON.Parse(jsonAsText);

        return(jsonParsed.Result as Godot.Collections.Dictionary);
    }
Beispiel #14
0
    public void saveMailParams()
    {
        Godot.File file = new Godot.File();
        try{
            file.OpenEncryptedWithPass("user://mailFile.dat", File.ModeFlags.Write, OS.GetUniqueId());
            //file.Open("user://mailFile.dat",File.ModeFlags.Write);

            file.Close();
        }
        catch {}
    }
Beispiel #15
0
    private static string ReadJSONFile(string path)
    {
        using var file = new File();
        file.Open(path, File.ModeFlags.Read);
        var result = file.GetAsText();

        // This might be completely unnecessary
        file.Close();

        return(result);
    }
Beispiel #16
0
 public void saveDBParams()
 {
     Godot.File file = new Godot.File();
     try{
         file.OpenEncryptedWithPass("user://dbFile.dat", File.ModeFlags.Write, OS.GetUniqueId());
         //file.Open("user://dbFile.dat",File.ModeFlags.Write);
         file.StoreString(database.GetConnectionString());
         file.Close();
     }
     catch {}
 }
Beispiel #17
0
    private void Save(Node2D node)
    {
        Godot.File savefile = new Godot.File();
        if (savefile.FileExists(_fileLocation))
        {
            throw new NotImplementedException();
        }

        savefile.Open(_fileLocation, Godot.File.ModeFlags.Write);
        savefile.StoreVar(node, true);
        savefile.Close();
    }
Beispiel #18
0
        public static string ReadFile(string filepath)
        {
            File file = new File();

            if (!file.FileExists(_prefix + _root + filepath))
            {
                throw new FileNotFoundException(_prefix + _root + filepath);
            }

            file.Open(_prefix + _root + filepath, File.ModeFlags.Read);
            return(file.GetAsText());
        }
Beispiel #19
0
    public void save_state_to_file(Godot.File file)
    {
        if (story == null)
        {
            PushNullStoryError();
            return;
        }

        if (file.IsOpen())
        {
            file.StoreString(get_state());
        }
    }
    public void LoadCards(string mapName)
    {
        var cardDataFile = new Godot.File();

        cardDataFile.Open("res://Data/Cards/" + _root.Map.MapDataFileName, File.ModeFlags.Read);

        var content       = Godot.JSON.Parse(cardDataFile.GetAsText());
        var contentResult = (Godot.Collections.Dictionary)content.Result;

        _cards     = (Godot.Collections.Array)contentResult["cards"];
        _graveyard = new Godot.Collections.Array();

        cardDataFile.Close();
    }
Beispiel #21
0
    /// <summary>
    /// Display the Credits
    /// </summary>
    private void DisplayCredits()
    {
        Godot.File file = new Godot.File();
        file.Open("res://Credits/credits.txt", Godot.File.ModeFlags.Read);
        string content = file.GetAsText();

        file.Close();
        Label name = new Label();

        name.AddFontOverride("font", dFont);
        name.Text = content;
        name.AddColorOverride("font_color", new Color(0, 0, 0));
        gridContainer.AddChild(name);
    }
Beispiel #22
0
    public void save_settings()
    {
        var file = new Godot.File();

        file.Open(_save_path, File.ModeFlags.Write);
        var data = new Dictionary();

        data["render_distance"] = render_distance;
        data["fog_enabled"]     = fog_enabled;
        String text = JSON.Print(data);

        file.StoreString(text);
        file.Close();
    }
Beispiel #23
0
    private Node2D Load()
    {
        Godot.File savefile = new Godot.File();
        if (!savefile.FileExists(_fileLocation))
        {
            throw new NotImplementedException();
        }

        savefile.Open(_fileLocation, Godot.File.ModeFlags.Read);
        var scene = savefile.GetVar(true);

        savefile.Close();

        return(scene as Node2D);
    }
Beispiel #24
0
    private void LoadMapData()
    {
        var mapDataFile = new Godot.File();

        mapDataFile.Open("res://Data/Maps/" + mapData, File.ModeFlags.Read);

        var content       = Godot.JSON.Parse(mapDataFile.GetAsText());
        var contentResult = (Godot.Collections.Dictionary)content.Result;

        _collisionMaps = (Godot.Collections.Dictionary)contentResult["collisionMaps"];
        _windows       = (Godot.Collections.Dictionary)contentResult["windows"];
        _searchables   = (Godot.Collections.Dictionary)contentResult["searchables"];

        mapDataFile.Close();
    }
Beispiel #25
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        var singleton = GetNode <Singleton>("/root/Singleton");

        singleton.SpeedrunActive = false;

        var file = new Godot.File();

        file.Open("res://global/data.json", Godot.File.ModeFlags.Read);
        _data    = JSON.Parse(file.GetAsText()).Result as Godot.Collections.Dictionary;
        _ending  = _data["ending"] as Godot.Collections.Dictionary;
        _credits = _data["credits"] as Godot.Collections.Dictionary;
        file.Close();

        printEndingAndCredits();
    }
        private void LoadJson()
        {
            var file = new File();

            if (file.Open(_formationDataPath, (int)File.ModeFlags.Read) != Error.Ok)
            {
                file.Close();
                throw new FileLoadException($"There was a problem loading: {_formationDataPath}");
            }

            var data = file.GetAsText();

            file.Close();

            _formationList = JsonConvert.DeserializeObject <List <List <List <int> > > >(data);
        }
Beispiel #27
0
    protected void loadDefaultBones()
    {
        if (!String.IsNullOrEmpty(_defaultPose))
        {
            var file = new Godot.File();
            file.Open(_defaultPose, Godot.File.ModeFlags.Read);
            var content = file.GetAsText();
            file.Close();

            bones = Newtonsoft.Json.JsonConvert.DeserializeObject <List <GodotBindPose> >(content);

            if (bones.Count <= 0)
            {
                GD.PrintErr("No bones found in default pose");
            }
        }
    }
Beispiel #28
0
    public void GetFromJSON(string filename)
    {
        var file = new File();

        file.Open(filename, 1);
        var          text = file.GetAsText();
        List <Story> data = JsonConvert.DeserializeObject <List <Story> >(
            text);
//        replace line below with Godot's own method for getting the JSON text from file
//        System.IO.File.ReadAllText(@"C:\Users\Nathan - User\OneDrive\Godot\Loopy Lips - C#\loopy_lips.json")
        Random rnd = new Random();
        var    i   = rnd.Next(0, data.Count);

        _story  = data[i].story;
        Prompts = data[i].inputs;
        file.Close();
    }
Beispiel #29
0
    public void load_state_from_file(Godot.File file)
    {
        if (story == null)
        {
            PushNullStoryError();
            return;
        }

        if (!file.IsOpen())
        {
            return;
        }

        file.Seek(0);
        if (file.GetLen() > 0)
        {
            story.state.LoadJson(file.GetAsText());
        }
    }
Beispiel #30
0
    public void loadMailParams()
    {
        //Read file with mail info
        Godot.File file = new Godot.File();
        //file.OpenEncryptedWithPass("user://mailFile.dat",Godot.File.ModeFlags.Read,OS.GetUniqueId());

        file.Open("user://mailFile.txt", Godot.File.ModeFlags.Read);
        string serviceUrl, port, email, password;

        serviceUrl = file.GetLine();
        port       = file.GetLine();
        email      = file.GetLine();
        password   = file.GetLine();
        file.Close();

        //Create mail object
        mail = new Mail();
        mail.sendTestMail();
    }