Пример #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://");
    }
Пример #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));
    }
Пример #3
0
    // Call this if you don't want a level placed in RAM
    public void unpackWorld()
    {
        string dir = $"user://Worlds/{BinLoader.RootDirectory}";

        GDKnyttAssetManager.ensureDirExists(dir);

        string marker_name = $"{dir}/_do_not_load_";
        File   marker      = new File();

        marker.Open(marker_name, File.ModeFlags.Write);
        marker.Close();

        foreach (string filename in BinLoader.GetFileNames())
        {
            string fullname = $"{dir}/{filename}";
            GDKnyttAssetManager.ensureDirExists(fullname.Substring(0, fullname.LastIndexOf('/')));

            File f = new File();
            f.Open(fullname, File.ModeFlags.Write);
            f.StoreBuffer(BinLoader.GetFile(filename));
            f.Close();
        }

        new Directory().Remove(marker_name);
        new Directory().Remove(WorldDirectory);
        removeDirectory("user://Cache/" + GDKnyttAssetManager.extractFilename(WorldDirectory));

        purgeBinFile();
        setDirectory(dir, WorldDirectoryName);
        BinMode = false;
    }
Пример #4
0
    public void enableAttachment(string attachment)
    {
        var torch_sprite = GetNode <Sprite>("AttachmentSprite");

        switch (attachment?.ToLower())
        {
        case "true":
        case "":
            torch_sprite.Texture = GDKnyttAssetManager.loadInternalTexture("res://knytt/juni/Attach.png");
            torch_sprite.Visible = true;
            Powers.Attachment    = "true";
            break;

        case "false":
        case null:
            torch_sprite.Visible = false;
            Powers.Attachment    = "false";
            break;

        default:
            torch_sprite.Texture = Game.GDWorld.KWorld.getWorldTexture($"Custom Objects/{attachment}") as Texture;
            torch_sprite.Visible = torch_sprite.Texture != null;
            Powers.Attachment    = attachment;
            break;
        }
    }
Пример #5
0
    private void setupWorld()
    {
        GDKnyttWorldImpl world;

        if (GDKnyttDataStore.KWorld != null)
        {
            world = GDKnyttDataStore.KWorld;
        }
        else
        {
            world = new GDKnyttWorldImpl();
            world.setDirectory(this.demoWorld, "");
            var save_data = GDKnyttAssetManager.loadTextFile(this.demoWorld + "/DefaultSavegame.ini");
            world.CurrentSave = new KnyttSave(world, save_data, 1);
        }

        GDWorld.setWorld(this, world);
        createJuni();
        GDWorld.loadWorld();

        this.changeArea(GDWorld.KWorld.CurrentSave.getArea(), true);
        Juni.moveToPosition(CurrentArea, GDWorld.KWorld.CurrentSave.getAreaPosition());

        UI.initialize(this);
        UI.updatePowers();
    }
Пример #6
0
 public override void _Ready()
 {
     this.Stream = GDKnyttAssetManager.loadRaw(rawPath, sampleRate);
     if (this.Autoplay)
     {
         this.Play();
     }
 }
Пример #7
0
 private void _on_OptimizeButton_pressed()
 {
     // TODO: waiting animation
     if (KWorld.BinMode)
     {
         KWorld.unpackWorld();
     }
     GDKnyttAssetManager.compileInternalTileset(KWorld, recompile: true); // To fix errors if chromakey and alpha channel used together
 }
Пример #8
0
    public void saveGame(KnyttSave save)
    {
        GDKnyttAssetManager.ensureDirExists("user://Saves");
        var f = new File();

        f.Open($"user://Saves/{save.SaveFileName}", File.ModeFlags.Write);
        f.StoreString(save.ToString());
        f.Close();
    }
Пример #9
0
    protected override object getExternalTexture(string filepath)
    {
        var full_path = this.WorldDirectory + "/" + filepath.ToLower();
        var f         = new File();

        if (!f.FileExists(full_path))
        {
            return(null);
        }
        return(GDKnyttAssetManager.loadExternalTexture(full_path));
    }
Пример #10
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));
    }
Пример #11
0
    private KnyttWorldInfo getWorldInfo(byte[] ini_bin, KeyDataCollection merge_to = null)
    {
        string           ini   = GDKnyttAssetManager.loadTextFile(ini_bin);
        GDKnyttWorldImpl world = new GDKnyttWorldImpl();

        world.loadWorldConfig(ini);
        if (merge_to != null)
        {
            merge_to.Merge(world.INIData["World"]);
        }
        return(world.Info);
    }
Пример #12
0
    private KnyttWorldManager <Texture> .WorldEntry generateDirectoryWorld(string world_dir, string name)
    {
        Texture icon;
        string  txt;

        lock (file_lock) { icon = GDKnyttAssetManager.loadExternalTexture(world_dir + "/Icon.png"); }
        lock (file_lock) { txt = GDKnyttAssetManager.loadTextFile(world_dir + "/World.ini"); }
        GDKnyttWorldImpl world = new GDKnyttWorldImpl();

        world.setDirectory(world_dir, name);
        world.loadWorldConfig(txt);
        return(new KnyttWorldManager <Texture> .WorldEntry(world, icon));
    }
Пример #13
0
    public override void _Ready()
    {
        if (!streamCache.ContainsKey(rawPath))
        {
            streamCache.Add(rawPath, GDKnyttAssetManager.loadRaw(rawPath, sampleRate));
        }
        this.Stream = streamCache[rawPath];

        if (this.Autoplay)
        {
            this.Play();
        }
    }
Пример #14
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;
    }
Пример #15
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;
    }
Пример #16
0
 public void uninstallWorld()
 {
     if (BinMode)
     {
         new Directory().Remove(WorldDirectory);
         removeDirectory("user://Cache/" + GDKnyttAssetManager.extractFilename(WorldDirectory));
     }
     else
     {
         removeDirectory(WorldDirectory);
     }
     removeDirectory($"user://Cache/{WorldDirectoryName}");
     // TODO: also remove .part files which might left after an unfinished download
 }
Пример #17
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));
    }
Пример #18
0
    public void _on_SlotButton_StartGame(bool new_save, string filename, int slot)
    {
        GetNode <LevelSelection>("../LevelSelection").killConsumers();
        string fname = new_save ? KWorld.WorldDirectory + "/DefaultSavegame.ini" : filename;

        KnyttSave save = new KnyttSave(KWorld,
                                       new_save ? GDKnyttAssetManager.loadTextFile(KWorld.getWorldData("DefaultSavegame.ini")) :
                                       GDKnyttAssetManager.loadTextFile(filename),
                                       slot);

        KWorld.CurrentSave      = save;
        GDKnyttDataStore.KWorld = KWorld;
        GDKnyttDataStore.startGame(new_save);
        this.QueueFree();
    }
Пример #19
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));
    }
Пример #20
0
    public void _on_GamePressed(GameButton button)
    {
        if (button.worldEntry.Path == null)
        {
            var timer = GetNode <Timer>("DownloadMonitor");
            if (!timer.IsStopped())
            {
                return;
            }

            GDKnyttAssetManager.ensureDirExists("user://Worlds");

            string filename = button.worldEntry.Link;
            filename = filename.Substring(filename.LastIndexOf('/') + 1);
            if (filename.IndexOf('?') != -1)
            {
                filename = filename.Substring(0, filename.IndexOf('?'));
            }
            if (!filename.EndsWith(".knytt.bin"))
            {
                filename += ".knytt.bin";
            }
            filename = Uri.UnescapeDataString(filename);
            http_node.DownloadFile = $"user://Worlds/{filename}.part";

            var error = http_node.Request(button.worldEntry.Link);
            if (error != Error.Ok)
            {
                download_button.markFailed(); return;
            }

            timer.Start();

            download_button = button;
            button.setDownloaded(0);
        }
        else
        {
            ClickPlayer.Play();
            var info_screen = info_scene.Instance() as InfoScreen;
            info_screen.initialize(button.worldEntry.Path);
            info_screen.worldEntry = button.worldEntry;
            this.GetParent().AddChild(info_screen);
        }
    }
Пример #21
0
    public void loadWorld()
    {
        // If info is not initialized, load it
        if (KWorld.Info == null)
        {
            var txt = GDKnyttAssetManager.loadTextFile(KWorld.getWorldData("World.ini"));
            KWorld.loadWorldConfig(txt);
        }

        var map_data = KWorld.getWorldData("Map.bin");

        System.IO.MemoryStream map_stream = new System.IO.MemoryStream(map_data);

        this.KWorld.loadWorldMap(map_stream);

        // Enable this if there will be level load screen
        //if (KWorld.BinMode) { KWorld.unpackWorld(); }
        //AssetManager.compileInternalTileset();
    }
Пример #22
0
    public void loadWorld()
    {
        var wd = new Directory();

        wd.Open(KWorld.WorldDirectory);

        // If info is not initialized, load it
        if (KWorld.Info == null)
        {
            var txt = GDKnyttAssetManager.loadTextFile(KWorld.getWorldData("World.ini"));
            KWorld.loadWorldConfig(txt);
        }

        var map_data = KWorld.getWorldData("Map.bin");

        System.IO.MemoryStream map_stream = new System.IO.MemoryStream(map_data);

        this.KWorld.loadWorldMap(map_stream);
    }
Пример #23
0
    public void _on_SlotButton_StartGame(bool new_save, string filename, int slot)
    {
        GetNode <LevelSelection>("../LevelSelection").killConsumers();

        string cache_dir = GDKnyttAssetManager.extractFilename(KWorld.WorldDirectory);

        GDKnyttAssetManager.ensureDirExists($"user://Cache/{cache_dir}");
        var f = new File();

        f.Open($"user://Cache/{cache_dir}/LastPlayed.flag", File.ModeFlags.Write);
        f.Close();

        KnyttSave save = new KnyttSave(KWorld,
                                       new_save ? GDKnyttAssetManager.loadTextFile(KWorld.getWorldData("DefaultSavegame.ini")) :
                                       GDKnyttAssetManager.loadTextFile(filename),
                                       slot);

        KWorld.CurrentSave      = save;
        GDKnyttDataStore.KWorld = KWorld;
        GDKnyttDataStore.startGame(new_save);
        this.QueueFree();
    }
Пример #24
0
    private WorldEntry generateRemoteWorld(Dictionary json_item)
    {
        WorldEntry world_info = new WorldEntry();

        world_info.HasServerInfo = true;
        world_info.Name          = HTTPUtil.jsonValue <string>(json_item, "name");
        world_info.Author        = HTTPUtil.jsonValue <string>(json_item, "author");
        world_info.Description   = HTTPUtil.jsonValue <string>(json_item, "description");
        var base64_icon = HTTPUtil.jsonValue <string>(json_item, "icon");

        world_info.Icon = base64_icon != null && base64_icon.Length > 0 ?
                          GDKnyttAssetManager.loadTexture(decompress(Convert.FromBase64String(base64_icon))) : null;
        world_info.Link      = HTTPUtil.jsonValue <string>(json_item, "link");
        world_info.FileSize  = HTTPUtil.jsonInt(json_item, "file_size");
        world_info.Upvotes   = HTTPUtil.jsonInt(json_item, "upvotes");
        world_info.Downvotes = HTTPUtil.jsonInt(json_item, "downvotes");
        world_info.Downloads = HTTPUtil.jsonInt(json_item, "downloads");
        world_info.Complains = HTTPUtil.jsonInt(json_item, "complains");
        world_info.Verified  = HTTPUtil.jsonBool(json_item, "verified");
        world_info.Approved  = HTTPUtil.jsonBool(json_item, "approved");
        return(world_info);
    }
Пример #25
0
 protected override object bytesToSound(byte[] data, bool loop)
 {
     return(GDKnyttAssetManager.loadOGG(data, loop));
 }
Пример #26
0
 protected override object getSystemTexture(string filepath)
 {
     return(GDKnyttAssetManager.loadInternalTexture("res://knytt/data/" + filepath));
 }
Пример #27
0
 protected sealed override byte[] getSystemWorldData(string filepath)
 {
     return(GDKnyttAssetManager.loadFile("res://knytt/data/" + filepath));
 }
Пример #28
0
 protected override object getSystemTexture(string filepath)
 {
     return((object)GDKnyttAssetManager.loadInternalTileset($"res://knytt/data/Compiled/{filepath}.res") ??
            GDKnyttAssetManager.loadInternalTexture("res://knytt/data/" + filepath));
 }
Пример #29
0
 protected override object getSystemSound(string filepath, bool loop)
 {
     return(GDKnyttAssetManager.loadInternalSound("res://knytt/data/" + filepath, loop));
 }
Пример #30
0
 protected override object bytesToTexture(byte[] data)
 {
     return(GDKnyttAssetManager.loadTexture(data));
 }