Exemple #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://");
    }
Exemple #2
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;
    }
Exemple #3
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));
    }
Exemple #4
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));
    }
Exemple #5
0
        static void Main(string[] args)
        {
            using System.IO.StreamWriter csvfile = new System.IO.StreamWriter("../worlds.csv");
            foreach (var fname in Directory.GetFiles("../worlds/"))
            {
                Console.WriteLine($"Processing {fname}");

                using var f = File.Open(fname, FileMode.Open);
                var world      = new KnyttBinWorldLoader(f);
                var icon       = world.GetFile("Icon.png");
                var buffer     = world.GetFile("World.ini");
                var content    = new ASCIIEncoding().GetString(buffer, 0, buffer.Length);
                var ini_parser = new IniDataParser();
                ini_parser.Configuration.AllowDuplicateKeys     = true;
                ini_parser.Configuration.AllowDuplicateSections = true;
                ini_parser.Configuration.SkipInvalidLines       = true;
                ini_parser.Configuration.CaseInsensitive        = true;
                var ini = ini_parser.Parse(content);

                var filename    = Path.GetFileName(fname);
                var name        = ini["World"]["Name"];
                var author      = ini["World"]["Author"];
                var size        = ini["World"]["Size"];
                var description = ini["World"]["Description"];
                var format      = ini["World"]["Format"];

                var difficulties = new HashSet <String>();
                var categories   = new HashSet <String>();
                foreach (var key in ini["World"])
                {
                    if (key.KeyName.ToLower().StartsWith("difficulty") && key.Value.Length > 0)
                    {
                        difficulties.Add(key.Value);
                    }
                    if (key.KeyName.ToLower().StartsWith("category") && key.Value.Length > 0)
                    {
                        categories.Add(key.Value);
                    }
                }

                HashSet <string> endings   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                HashSet <string> cutscenes = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                foreach (var section in ini.Sections)
                {
                    if (!section.SectionName.ToLower().StartsWith('x'))
                    {
                        continue;
                    }

                    if (section.Keys.ContainsKey("Ending"))
                    {
                        var ending = section.Keys["Ending"];
                        if (world.GetFile($"{ending}/scene1.png") != null)
                        {
                            endings.Add(section.Keys["Ending"]);
                        }
                    }

                    foreach (var key in section.Keys)
                    {
                        if (key.KeyName.ToLower().StartsWith("shiftcutscene") &&
                            key.Value.ToLower() != "ending" &&
                            world.GetFile($"{key.Value}/scene1.png") != null)
                        {
                            cutscenes.Add(key.Value);
                        }
                    }
                }
                if (world.GetFile("ending/scene1.png") != null &&
                    !(world.GetFileSize("ending/scene1.png") == 3655 && world.GetFile("ending/scene2.png") == null))
                {
                    endings.Add("Ending");
                }

                using MemoryStream ms = new MemoryStream();
                if (icon != null)
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.UseShellExecute        = false;
                    startInfo.RedirectStandardInput  = true;
                    startInfo.RedirectStandardOutput = true;
                    startInfo.FileName  = "/usr/bin/pngquant";
                    startInfo.Arguments = "--quality 40-80 -";

                    Process process = new Process();
                    process.StartInfo = startInfo;
                    process.Start();

                    process.StandardInput.BaseStream.Write(icon);
                    process.StandardOutput.BaseStream.CopyTo(ms);
                }

                string[] cells = { "http://knyttlevels.com/levels/" + Uri.EscapeUriString(filename), name,                                  author,
                                   size,                                                             String.Join(';',                       difficulties),  String.Join(';',categories),
                                   format,                                                           new FileInfo(fname).Length.ToString(), description,
                                   String.Join(';',                                                  endings),                              String.Join(';',cutscenes),
                                   icon != null ? Convert.ToBase64String(compress(ms.ToArray())) : "" };
                csvfile.WriteLine(String.Join(',', cells.Select(cell => StringToCSVCell(cell))));
            }
            Console.WriteLine("Done.");
        }