Esempio n. 1
0
    public void initialize(string path)
    {
        KWorld = new GDKnyttWorldImpl();
        if (new Directory().DirExists(path))
        {
            KWorld.setDirectory(path, GDKnyttAssetManager.extractFilename(path));
        }
        else
        {
            var loader = new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile(path));
            KWorld.setBinMode(loader);
            KWorld.setDirectory(path, loader.RootDirectory);
        }
        string ini = GDKnyttAssetManager.loadTextFile(KWorld.getWorldData("World.ini"));

        KWorld.loadWorldConfig(ini);

        Texture info = (KWorld.worldFileExists("Info+.png") ? KWorld.getWorldTexture("Info+.png") :
                        KWorld.worldFileExists("Info.png") ? KWorld.getWorldTexture("Info.png") : null) as Texture;

        if (info != null)
        {
            info.Flags |= (uint)Texture.FlagsEnum.Filter;
            GetNode <TextureRect>("InfoRect").Texture = info;
        }

        GetNode <SlotButton>("InfoRect/Slot1Button").BaseFile = "user://Saves/" + KWorld.WorldDirectoryName;
        GetNode <SlotButton>("InfoRect/Slot2Button").BaseFile = "user://Saves/" + KWorld.WorldDirectoryName;
        GetNode <SlotButton>("InfoRect/Slot3Button").BaseFile = "user://Saves/" + KWorld.WorldDirectoryName;
        GetNode <Button>("InfoRect/RatePanel/VBoxContainer/UninstallButton").Disabled = KWorld.WorldDirectory.StartsWith("res://");
    }
Esempio n. 2
0
    private WorldEntry generateDirectoryWorld(string world_dir)
    {
        KnyttWorldInfo world_info;
        string         cache_dir        = "user://Cache/" + GDKnyttAssetManager.extractFilename(world_dir);
        string         ini_cache_name   = cache_dir + "/World.ini";
        string         played_flag_name = cache_dir + "/LastPlayed.flag";

        if (new File().FileExists(ini_cache_name))
        {
            world_info = getWorldInfo(GDKnyttAssetManager.loadFile(ini_cache_name));
        }
        else
        {
            var ini_bin  = GDKnyttAssetManager.loadFile(world_dir + "/world.ini");
            var ini_data = new IniData();
            world_info = getWorldInfo(ini_bin, merge_to: ini_data["World"]);
            GDKnyttAssetManager.ensureDirExists(cache_dir);
            var f = new File();
            f.Open(ini_cache_name, File.ModeFlags.Write);
            f.StoreString(ini_data.ToString());
            f.Close();
        }

        Texture icon        = GDKnyttAssetManager.loadExternalTexture(world_dir + "/icon.png");
        var     last_played = new File().FileExists(played_flag_name) ? new File().GetModifiedTime(played_flag_name) : 0;

        return(new WorldEntry(icon, world_info, world_dir, last_played));
    }
Esempio n. 3
0
    protected sealed override byte[] getExternalWorldData(string filepath)
    {
        var full_path = this.WorldDirectory + "/" + filepath.ToLower();
        var f         = new File();

        if (!f.FileExists(full_path))
        {
            return(null);
        }
        return(GDKnyttAssetManager.loadFile(full_path));
    }
Esempio n. 4
0
    public void loadTutorial()
    {
        var binloader          = new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile("res://knytt/worlds/Nifflas - Tutorial.knytt.bin"));
        var txt                = GDKnyttAssetManager.loadTextFile(binloader.GetFile("World.ini"));
        GDKnyttWorldImpl world = new GDKnyttWorldImpl();

        world.setDirectory("res://knytt/worlds", binloader.RootDirectory);
        world.loadWorldConfig(txt);
        var save_txt = GDKnyttAssetManager.loadTextFile(binloader.GetFile("DefaultSavegame.ini"));

        world.CurrentSave = new KnyttSave(world, save_txt, 1);
        world.setBinMode(binloader);
        GDKnyttDataStore.KWorld = world;
    }
Esempio n. 5
0
    public void initialize(GDKnyttWorldImpl world)
    {
        this.KWorld = world;
        if (world.BinMode)
        {
            world.setBinMode(new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile(world.WorldDirectory)));
        }
        var info = world.getWorldTexture("Info.png");

        GetNode <TextureRect>("InfoRect").Texture    = (Texture)info;
        GetNode <SlotButton>("Slot1Button").BaseFile = "user://Saves/" + world.WorldDirectoryName;
        GetNode <SlotButton>("Slot2Button").BaseFile = "user://Saves/" + world.WorldDirectoryName;
        GetNode <SlotButton>("Slot3Button").BaseFile = "user://Saves/" + world.WorldDirectoryName;
    }
Esempio n. 6
0
    private WorldEntry generateBinWorld(string world_dir)
    {
        byte[]         icon_bin;
        KnyttWorldInfo world_info;

        string cache_dir        = "user://Cache/" + GDKnyttAssetManager.extractFilename(world_dir);
        string icon_cache_name  = cache_dir + "/Icon.png";
        string ini_cache_name   = cache_dir + "/World.ini";
        string played_flag_name = cache_dir + "/LastPlayed.flag";

        if (new Directory().DirExists(cache_dir))
        {
            icon_bin   = GDKnyttAssetManager.loadFile(icon_cache_name);
            world_info = getWorldInfo(GDKnyttAssetManager.loadFile(ini_cache_name));
        }
        else
        {
            KnyttBinWorldLoader binloader;
            byte[] ini_bin;
            try
            {
                binloader = new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile(world_dir));
            }
            catch (InvalidOperationException)
            {
                return(null);
            }
            icon_bin = binloader.GetFile("Icon.png");
            ini_bin  = binloader.GetFile("World.ini");

            GDKnyttAssetManager.ensureDirExists("user://Cache");
            new Directory().MakeDir(cache_dir);
            var f = new File();
            f.Open(icon_cache_name, File.ModeFlags.Write);
            f.StoreBuffer(icon_bin);
            f.Close();

            var ini_data = new IniData();
            world_info = getWorldInfo(ini_bin, merge_to: ini_data["World"]);
            f.Open(ini_cache_name, File.ModeFlags.Write);
            f.StoreString(ini_data.ToString());
            f.Close();
        }

        Texture icon        = GDKnyttAssetManager.loadTexture(icon_bin);
        var     last_played = new File().FileExists(played_flag_name) ? new File().GetModifiedTime(played_flag_name) : 0;

        return(new WorldEntry(icon, world_info, world_dir, last_played));
    }
Esempio n. 7
0
    private KnyttWorldManager <Texture> .WorldEntry generateBinWorld(string world_dir)
    {
        Texture             icon;
        string              txt;
        KnyttBinWorldLoader binloader;

        lock (file_lock) { binloader = new KnyttBinWorldLoader(GDKnyttAssetManager.loadFile(world_dir)); }
        lock (file_lock) { icon = GDKnyttAssetManager.loadTexture(binloader.GetFile("Icon.png")); }
        lock (file_lock) { txt = GDKnyttAssetManager.loadTextFile(binloader.GetFile("World.ini")); }
        GDKnyttWorldImpl world = new GDKnyttWorldImpl();

        world.setDirectory(world_dir, binloader.RootDirectory);
        world.loadWorldConfig(txt);
        world.setBinMode(null);
        return(new KnyttWorldManager <Texture> .WorldEntry(world, icon));
    }
Esempio n. 8
0
 protected sealed override byte[] getSystemWorldData(string filepath)
 {
     return(GDKnyttAssetManager.loadFile("res://knytt/data/" + filepath));
 }