Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
    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);
    }
Ejemplo n.º 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;
        }
    }
Ejemplo n.º 8
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);
    }
Ejemplo n.º 9
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);
    }
Ejemplo n.º 10
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);
    }
Ejemplo n.º 11
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 {}
 }
Ejemplo n.º 12
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 {}
    }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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();
    }
Ejemplo n.º 15
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();
    }
Ejemplo n.º 16
0
    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();
    }
Ejemplo n.º 17
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);
    }
Ejemplo n.º 18
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);
    }
Ejemplo n.º 19
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();
    }
Ejemplo n.º 20
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();
    }
Ejemplo n.º 21
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();
    }
Ejemplo n.º 22
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");
            }
        }
    }
Ejemplo n.º 23
0
    protected UMAReciepe loadEditorReciepeByPath(string filePath)
    {
        if (String.IsNullOrEmpty(filePath))
        {
            return(null);
        }

        var file = new Godot.File();

        if (file.FileExists(filePath))
        {
            file.Open(filePath, Godot.File.ModeFlags.Read);
            var converted = JsonConvert.DeserializeObject <UMAReciepe>(file.GetAsText());
            file.Close();

            return(converted);
        }
        return(null);
    }
Ejemplo n.º 24
0
        public void loadEntities()
        {
            Godot.File entityFile = new Godot.File();
            entityFile.Open("res://data/directive/gameworldentities.json", 1);
            string entityText = entityFile.GetAsText();

            entityFile.Close();
            Godot.JSONParseResult  entityData     = JSON.Parse(entityText);
            GContainers.Dictionary entityDataDict = (GContainers.Dictionary)entityData.Result;
            GContainers.Array      gEntities      = (GContainers.Array)entityDataDict["entities"];

            GContainers.Array gArgs = (GContainers.Array)entityDataDict["args"];

            var         entityList    = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == "Zona.ECSEntity").ToList();
            List <Type> loadedClasses = new List <Type>();

            foreach (object entity in gEntities)
            {
                string e = Convert.ToString(entity);
                foreach (Type classType in entityList)
                {
                    if (classType.Name == e)
                    {
                        loadedClasses.Add(classType);
                        break;
                    }
                }
            }

            for (int i = 0; i < gArgs.Count; i++)
            {
                GContainers.Array gargs = (GContainers.Array)gArgs[i];
                var      c    = gargs.Count;
                object[] args = new object[c];
                for (int j = 0; j < c; j++)
                {
                    args[j] = (object)gargs[j];
                }
                var entityInstance = (Entity)Activator.CreateInstance(loadedClasses[i], args);
                this.entities.Add(entityInstance);
                this.AddChild(entityInstance);
            }
        }
Ejemplo n.º 25
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();
    }
Ejemplo n.º 26
0
    private void OnPressed_about()
    {
        var popup = GetNode <PopupPanel>("about_popup");

        popup.PopupExclusive = true;
        popup.PopupCenteredRatio(0.85f);

        ThemeDefaultHolder(popup.GetNode <VBoxContainer>("about_holder"));
        popup.GetNode <VBoxContainer>("about_holder").GetNode <Label>("title").AddFontOverride("font", new DynamicFont()
        {
            FontData = GD.Load <DynamicFontData>("res://assets/default/Tuffy_Bold.ttf"), Size = 40
        });
        var logo = popup.GetNode <VBoxContainer>("about_holder").GetNode <TextureRect>("logo");

        logo.Expand      = true;
        logo.RectMinSize = logo.Texture.GetSize() * 0.7f;

        ThemeButtons(popup.GetNode <VBoxContainer>("about_holder"));

        var c_label = popup.GetNode <VBoxContainer>("about_holder").GetNode <RichTextLabel>("c_label");

        c_label.BbcodeEnabled = true;
        c_label.RectMinSize   = new Vector2(c_label.RectMinSize.x, 150);
        c_label.BbcodeText    = "[center]Copyright (c) 2017 Leacme\n([color=#996600][url=http://leac.me]http://leac.me[/url][/color])\n\n[/center]";

        c_label.BbcodeText += "[center][u]USAGE\n[/u][/center]";
        using (var instrFil = new Godot.File()) {
            instrFil.Open("res://README.md", File.ModeFlags.Read);
            c_label.BbcodeText += "This application features the ability to " + instrFil.GetAsText().Split(new string[] { "This application features the ability to" }, StringSplitOptions.None)[1].Split("![][image_screenshot]")[0].Trim() + "\n\n";
            c_label.BbcodeText += instrFil.GetAsText().Split(new string[] { "## Application Usage" }, StringSplitOptions.None)[1].Split("## Copyright")[0].Trim() + "\n\n";
            instrFil.Close();
        }

        c_label.BbcodeText += "[center][u]LICENSES\n[/u][/center]";
        c_label.BbcodeText += ProjectSettings.GetSetting("application/config/name").ToString() + ":\n";
        using (var leacLic = new Godot.File()) {
            leacLic.Open("res://LICENSE.md", File.ModeFlags.Read);
            c_label.BbcodeText += leacLic.GetAsText();
            leacLic.Close();
        }
    }
    public void _on_Save_pressed()
    {
        var playerName = GetNode <TextEdit>("TextEdit").Text;
        var saveGame   = new Godot.File();

        if (saveGame.FileExists(SCORE_FILE_PATH))
        {
            saveGame.Open("user://score.save", Godot.File.ModeFlags.ReadWrite);
            string[] content = saveGame.GetAsText().Split("\n");

            //sprawdza czy gracz już istnieje na liście
            //jeśli znajdzie gracza i nowy wynik jest lepszy to go nadpisuje
            for (int i = 0; i < content.Length; i++)
            {
                string[] separated = content[i].Split(':');
                if (separated[0] == playerName)
                {
                    found = true;
                    if (uint.Parse(separated[1]) < uint.Parse(score))
                    {
                        content[i] = $"{playerName}:{score}";
                        saveGame.StoreString($"{string.Join("\n", content)}");
                        break;
                    }
                }
            }
            if (!found)
            {
                saveGame.StoreString($"{string.Join("\n", content)}\n{playerName}:{(score != "" ? score : "0")}");
            }
        }
        else
        {
            saveGame.Open("user://score.save", Godot.File.ModeFlags.Write);
            saveGame.StoreString($"{playerName}:{(score != "" ? score : "0")}");
        }
        saveGame.Close();

        GetTree().ChangeScene("res://scene/TitleScreen.tscn");
    }
Ejemplo n.º 28
0
        private void loadProcessors()
        {
            Godot.File file = new Godot.File();
            file.Open("res://data/directive/gameworldprocessors.json", 1);
            string text = file.GetAsText();

            file.Close();
            var data = JSON.Parse(text);

            GContainers.Dictionary dataDict = data.Result as GContainers.Dictionary;

            GContainers.Array processors = (GContainers.Array)dataDict["processors"];
            GContainers.Array priorities = (GContainers.Array)dataDict["priorities"];

            var           processorList      = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == "Zona.ECSProcessor").ToList();
            List <string> processorClassList = new List <string>();

            foreach (Type type in processorList)
            {
                if (type.Namespace == "Zona.ECSProcessor")
                {
                    processorClassList.Add(type.Name);
                }
            }

            for (int i = 0; i < processors.Count; i++)
            {
                string pname = (string)processors[i];
                if (processorClassList.Contains(pname))
                {
                    string  className        = "Zona.ECSProcessor." + pname;
                    var     proccessInstance = Activator.CreateInstance(Assembly.GetExecutingAssembly().GetName().Name, className);
                    dynamic process          = proccessInstance.Unwrap();
                    this.AddChild(process);
                    dynamic priority = priorities[i];
                    this.addProcessor(priority, process);
                }
            }
        }
Ejemplo n.º 29
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        _mainText = GetNode <Label>("Container/MainText");
        _reject   = GetNode <Button>("Container/ButtonContainer/NoButton");
        _accept   = GetNode <Button>("Container/ButtonContainer/YesButton");
        _continue = GetNode <Button>("Container/ButtonContainer/ContinueButton");

        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;

        file.Close();
        var prompts = _data["prompts"] as Godot.Collections.Dictionary;

        _mainText.Text = (string)prompts["mainText"];
        _reject.Text   = (string)prompts["reject"];
        _accept.Text   = (string)prompts["accept"];


        var singleton = GetNode <Singleton>("/root/Singleton");

        Connect("MutateControls", singleton, "ScrambleControls");
        singleton.SpeedrunActive = false;

        var evolutions = _data["evolutions"] as Godot.Collections.Array;

        if (singleton.PlayerEvolution < evolutions.Count)
        {
            _nextEvolution = evolutions[singleton.PlayerEvolution] as Godot.Collections.Dictionary;
            var mutateProbability = (float)_nextEvolution["mutateProbability"] * 100;
            _accept.Text = _accept.Text + $" ({mutateProbability}%)";
        }
        else
        {
            _accept.Disabled = true;
        }
    }
Ejemplo n.º 30
0
    private void OnLoadButtonPressed()
    {
        if (this.HasSaveData == false)
        {
            // Initialize new EncounterState, EncounterScene
            var scene    = _encounterPrefab.Instance() as EncounterScene;
            var newState = EncounterState.Create(this.SaveLocation);
            newState.SetStateForNewGame();
            scene.SetEncounterState(newState);

            // Save to slot
            newState.WriteToFile();

            var sceneManager = (SceneManager)GetNode("/root/SceneManager");
            sceneManager.ShowEncounterScene(scene);
        }
        else
        {
            var scene = _encounterPrefab.Instance() as EncounterScene;

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            Godot.File file = new Godot.File();
            file.Open(this.SaveLocation, File.ModeFlags.Read);
            var saveData = file.GetAsText();
            saveData = StringCompression.DecompressString(saveData);
            file.Close();

            var oldState = EncounterState.FromSaveData(saveData);
            stopwatch.Stop();
            GD.Print("SaveSlotScene load completed, elapsed ms: ", stopwatch.ElapsedMilliseconds);
            scene.SetEncounterState(oldState);

            var sceneManager = (SceneManager)GetNode("/root/SceneManager");
            sceneManager.ShowEncounterScene(scene);
        }
    }