Пример #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);
 }
Пример #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);
                }
            }
        }
Пример #3
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);
    }
Пример #4
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);
    }
Пример #5
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);
    }
Пример #6
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);
    }
Пример #7
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();
        }
    }
Пример #8
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());
        }
Пример #9
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();
    }
Пример #10
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);
    }
Пример #11
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();
    }
Пример #12
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();
    }
Пример #13
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);
        }
Пример #14
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();
    }
Пример #15
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");
            }
        }
    }
Пример #16
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);
    }
Пример #17
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);
            }
        }
Пример #18
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());
        }
    }
Пример #19
0
        private static void loadRegistry()
        {
            File registryFile = new File();

            registryFile.Open("user://mcdata/reports/blocks.json", File.ModeFlags.Read);
            string  content = registryFile.GetAsText();
            JObject o       = JObject.Parse(content);

            foreach (var entry in o)
            {
                string name   = entry.Key.Split(':')[1];
                JArray states = (entry.Value["states"]) as JArray;
                foreach (var state in states)
                {
                    uint id = state["id"].Value <uint>();
                    add(new BlockState(name, id));
                }
            }
            GD.Print($"Loaded {idToState.Count} states");
        }
    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");
    }
Пример #21
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);
                }
            }
        }
Пример #22
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;
        }
    }
Пример #23
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);
        }
    }
Пример #24
0
    public override void _EnterTree()
    {
        if (Settings._loaded)
        {
            GD.PrintErr("Error: Settings is an AutoLoad singleton and it shouldn't be instanced elsewhere.");
            GD.PrintErr("Please delete the instance at: " + GetPath());
        }
        else
        {
            Settings._loaded = true;
        }

        var file = new Godot.File();


        if (file.FileExists(_save_path))
        {
            file.Open(_save_path, File.ModeFlags.Read);
            string     text       = file.GetAsText();
            var        jsonFile   = JSON.Parse(text).Result;
            Dictionary ParsedData = jsonFile as Dictionary;
            file.Close();

            try
            {
                render_distance = (float)ParsedData["render_distance"];
                fog_enabled     = (bool)ParsedData["fog_enabled"];
            }
            catch (Exception ex) {
                GD.PrintErr(ex);
            }
        }
        else
        {
            save_settings();
        }
    }