Ejemplo n.º 1
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);
        }
    }
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
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());
        }
Ejemplo n.º 6
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.º 7
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);
    }
    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.º 9
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();
        }
    }
Ejemplo n.º 10
0
    public override void _Ready()
    {
        Godot.File databaseFile = new Godot.File();

        if (!databaseFile.FileExists("res://databases/System.json"))
        {
            databaseFile.Open("res://databases/System.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary systemList     = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary statsData      = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary weaponTypeData = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary armorTypeData  = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary elementData    = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary slotsData      = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary skillTypeData  = new Godot.Collections.Dictionary();
            statsData.Add("0", "hp");
            statsData.Add("1", "mp");
            statsData.Add("2", "atk");
            statsData.Add("3", "def");
            statsData.Add("4", "int");
            statsData.Add("5", "res");
            statsData.Add("6", "spd");
            statsData.Add("7", "luk");
            weaponTypeData.Add("0", "Sword");
            weaponTypeData.Add("1", "Spear");
            weaponTypeData.Add("2", "Axe");
            weaponTypeData.Add("3", "Staff");
            armorTypeData.Add("0", "Armor");
            armorTypeData.Add("1", "Robe");
            armorTypeData.Add("2", "Shield");
            armorTypeData.Add("3", "Hat");
            armorTypeData.Add("4", "Accessory");
            elementData.Add("0", "Physical");
            elementData.Add("1", "Fire");
            elementData.Add("2", "Ice");
            elementData.Add("3", "Wind");
            slotsData.Add("w0", "Weapon");
            slotsData.Add("a1", "Head");
            slotsData.Add("a2", "Body");
            slotsData.Add("a3", "Accessory");
            skillTypeData.Add("0", "Skills");
            skillTypeData.Add("1", "Magic");
            systemList.Add("stats", statsData);
            systemList.Add("weapons", weaponTypeData);
            systemList.Add("armors", armorTypeData);
            systemList.Add("elements", elementData);
            systemList.Add("slots", slotsData);
            systemList.Add("skills", skillTypeData);
            databaseFile.StoreLine(JSON.Print(systemList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/Character.json"))
        {
            databaseFile.Open("res://databases/Character.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary characterList    = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary characterData    = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary equipTypeData    = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary initialEquipData = new Godot.Collections.Dictionary();
            characterData.Add("faceImage", "");
            characterData.Add("charaImage", "");
            characterData.Add("name", "Kate");
            characterData.Add("class", 0);
            characterData.Add("description", "");
            characterData.Add("initialLevel", 1);
            characterData.Add("maxLevel", 99);
            equipTypeData.Add("w0", 0);
            equipTypeData.Add("w1", 1);
            equipTypeData.Add("a2", 0);
            equipTypeData.Add("a3", 3);
            initialEquipData.Add("0", -1);
            initialEquipData.Add("1", -1);
            initialEquipData.Add("2", -1);
            initialEquipData.Add("3", -1);
            characterData.Add("initial_equip", initialEquipData);
            characterData.Add("equip_types", equipTypeData);
            characterList.Add("chara0", characterData);
            databaseFile.StoreLine(JSON.Print(characterList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/Skill.json"))
        {
            databaseFile.Open("res://databases/Skill.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary skillList = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary skillData = new Godot.Collections.Dictionary();
            skillData.Add("name", "Double Attack");
            skillData.Add("icon", "");
            skillData.Add("description", "Attacks an enemy twice");
            skillData.Add("skill_type", 0);
            skillData.Add("mp_cost", 4);
            skillData.Add("tp_cost", 2);
            skillData.Add("target", 1);
            skillData.Add("usable", 1);
            skillData.Add("success", 95);
            skillData.Add("hit_type", 1);
            skillData.Add("damage_type", 1);
            skillData.Add("element", 0);
            skillData.Add("formula", "atk * 4 - def * 2");
            skillList.Add("skill0", skillData);
            databaseFile.StoreLine(JSON.Print(skillList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/Class.json"))
        {
            databaseFile.Open("res://databases/Class.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary classList  = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary classData  = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary classStats = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary skillList  = new Godot.Collections.Dictionary();
            classData.Add("name", "Warrior");
            classData.Add("icon", "");
            classData.Add("experience", "level * 30");
            classStats.Add("hp", "level * 25 + 10");
            classStats.Add("mp", "level * 15 + 5");
            classStats.Add("atk", "level * 5 + 3");
            classStats.Add("def", "level * 5 + 3");
            classStats.Add("int", "level * 5 + 3");
            classStats.Add("res", "level * 5 + 3");
            classStats.Add("spd", "level * 5 + 3");
            classStats.Add("luk", "level * 5 + 3");
            skillList.Add(0, 5);
            classData.Add("skill_list", skillList);
            classData.Add("stat_list", classStats);
            classList.Add("class0", classData);
            databaseFile.StoreLine(JSON.Print(classList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/Item.json"))
        {
            databaseFile.Open("res://databases/Item.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary itemList = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary itemData = new Godot.Collections.Dictionary();
            itemData.Add("name", "Potion");
            itemData.Add("icon", "");
            itemData.Add("description", "Heals 50HP to one ally");
            itemData.Add("item_type", 0);
            itemData.Add("price", 50);
            itemData.Add("consumable", 0);
            itemData.Add("target", 7);
            itemData.Add("usable", 0);
            itemData.Add("success", 100);
            itemData.Add("hit_type", 0);
            itemData.Add("damage_type", 3);
            itemData.Add("element", 0);
            itemData.Add("formula", "50");
            itemList.Add("item0", itemData);
            databaseFile.StoreLine(JSON.Print(itemList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/Weapon.json"))
        {
            databaseFile.Open("res://databases/Weapon.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary weaponList  = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary weaponData  = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary weaponStats = new Godot.Collections.Dictionary();
            weaponData.Add("name", "Broad Sword");
            weaponData.Add("icon", "");
            weaponData.Add("description", "A light and easy to use sword");
            weaponData.Add("weapon_type", 0);
            weaponData.Add("slot_type", 0);
            weaponData.Add("price", 50);
            weaponData.Add("element", 0);
            weaponStats.Add("hp", "0");
            weaponStats.Add("mp", "0");
            weaponStats.Add("atk", "10");
            weaponStats.Add("def", "2");
            weaponStats.Add("int", "2");
            weaponStats.Add("res", "1");
            weaponStats.Add("spd", "0");
            weaponStats.Add("luk", "0");
            weaponData.Add("stat_list", weaponStats);
            weaponList.Add("weapon0", weaponData);
            databaseFile.StoreLine(JSON.Print(weaponList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/Armor.json"))
        {
            databaseFile.Open("res://databases/Armor.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary armorList  = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary armorData  = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary armorStats = new Godot.Collections.Dictionary();
            armorData.Add("name", "Clothes");
            armorData.Add("icon", "");
            armorData.Add("description", "Light Clothes");
            armorData.Add("armor_type", 0);
            armorData.Add("slot_type", 0);
            armorData.Add("price", 50);
            armorStats.Add("hp", "0");
            armorStats.Add("mp", "0");
            armorStats.Add("atk", "10");
            armorStats.Add("def", "2");
            armorStats.Add("int", "2");
            armorStats.Add("res", "1");
            armorStats.Add("spd", "0");
            armorStats.Add("luk", "0");
            armorData.Add("stat_list", armorStats);
            armorList.Add("armor0", armorData);
            databaseFile.StoreLine(JSON.Print(armorList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/Enemy.json"))
        {
            databaseFile.Open("res://databases/Enemy.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary enemyList = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary enemyData = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary statsData = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary dropData  = new Godot.Collections.Dictionary();
            enemyData.Add("name", "Slime");
            enemyData.Add("graphicImage", "");
            statsData.Add("hp", "150");
            statsData.Add("mp", "50");
            statsData.Add("atk", "18");
            statsData.Add("def", "16");
            statsData.Add("int", "8");
            statsData.Add("res", "4");
            statsData.Add("spd", "12");
            statsData.Add("luk", "10");
            dropData.Add("i0", 80);
            enemyData.Add("experience", 6);
            enemyData.Add("money", 50);
            enemyData.Add("stat_list", statsData);
            enemyData.Add("drop_list", dropData);
            enemyList.Add("enemy0", enemyData);
            databaseFile.StoreLine(JSON.Print(enemyList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/State.json"))
        {
            databaseFile.Open("res://databases/State.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary stateList             = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary stateData             = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary eraseCondition        = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary messages              = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary customEraseConditions = new Godot.Collections.Dictionary();
            stateData.Add("name", "Death");
            stateData.Add("icon", "");
            stateData.Add("restriction", 4);
            stateData.Add("priority", 100);
            eraseCondition.Add("turns_min", 0);
            eraseCondition.Add("turns_max", 0);
            eraseCondition.Add("erase_damage", 0);
            eraseCondition.Add("erase_setps", 0);
            stateData.Add("erase_conditions", eraseCondition);
            messages.Add("0", "Insert a custom message");
            stateData.Add("messages", messages);
            customEraseConditions.Add("0", "Insert a custom formula for erase state");
            stateData.Add("custom_erase_conditions", customEraseConditions);

            stateList.Add("state0", stateData);
            databaseFile.StoreLine(JSON.Print(stateList));
            databaseFile.Close();
        }

        if (!databaseFile.FileExists("res://databases/Effect.json"))
        {
            databaseFile.Open("res://databases/Effect.json", Godot.File.ModeFlags.Write);
            Godot.Collections.Dictionary effectList = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary effectData = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary showList   = new Godot.Collections.Dictionary();
            Godot.Collections.Dictionary value2     = new Godot.Collections.Dictionary();
            effectData.Add("name", "hp_recovery");
            showList.Add("show", false);
            showList.Add("data", "");
            effectData.Add("data_type", showList);
            effectData.Add("value1", 1);
            value2.Add("show", true);
            value2.Add("data", 2);
            effectData.Add("value2", value2);

            effectList.Add("effect0", effectData);
            databaseFile.StoreLine(JSON.Print(effectList));
            databaseFile.Close();
        }

        databaseFile.Close();
        GetNode <Control>("Tabs/Character").Call("Start");
    }