示例#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 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();
    }
示例#3
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);
    }
示例#4
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));
    }
示例#5
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;
    }
示例#6
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();
    }
示例#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));
    }
示例#8
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();
    }
示例#9
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);
    }
示例#10
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();
    }
示例#11
0
    private void _on_StatHTTPRequest_request_completed(int result, int response_code, string[] headers, byte[] body)
    {
        if (result == (int)HTTPRequest.Result.Success && response_code == 200)
        {
            ;
        }
        else
        {
            return;
        }
        var response = Encoding.UTF8.GetString(body, 0, body.Length);
        var json     = JSON.Parse(response);

        if (json.Error != Error.Ok)
        {
            return;
        }

        var my_powers    = new HashSet <int>();
        var my_cutscenes = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
        var my_endings   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

        for (int slot = 1; slot <= 3; slot++)
        {
            string savename = $"user://Saves/{KWorld.WorldDirectoryName} {slot}.ini";
            if (new File().FileExists(savename))
            {
                KnyttSave save = new KnyttSave(KWorld, GDKnyttAssetManager.loadTextFile(savename), slot);
                for (int i = 0; i < 13; i++)
                {
                    if (save.getPower(i))
                    {
                        my_powers.Add(i);
                    }
                }
                my_cutscenes.UnionWith(save.Cutscenes);
                my_endings.UnionWith(save.Endings);
            }
        }

        upvotes   = HTTPUtil.jsonInt(json.Result, "upvotes");
        downvotes = HTTPUtil.jsonInt(json.Result, "downvotes");
        complains = HTTPUtil.jsonInt(json.Result, "complains");
        updateRates();

        var stat_panel = GetNode <StatPanel>("InfoRect/StatPanel");

        int[] powers_count = new int[13];
        for (int i = 0; i < 13; i++)
        {
            powers_count[i] = HTTPUtil.jsonInt(json.Result, $"power{i}");
        }

        if (powers_count.Any(c => c > 0))
        {
            stat_panel.addLabel("Powers:");
            for (int i = 0; i < 13; i++)
            {
                if (powers_count[i] > 0)
                {
                    stat_panel.addPower(i, powers_count[i], my_powers.Contains(i));
                }
            }
        }

        List <string> cutscenes       = new List <string>();
        List <int>    cutscenes_count = new List <int>();
        List <string> endings         = new List <string>();
        List <int>    endings_count   = new List <int>();

        var cutscene_infos = HTTPUtil.jsonValue <Godot.Collections.Array>(json.Result, "cutscenes");

        foreach (Dictionary record in cutscene_infos)
        {
            bool is_ending = HTTPUtil.jsonBool(record, "ending");
            (is_ending ? endings : cutscenes).Add(HTTPUtil.jsonValue <string>(record, "name"));
            (is_ending ? endings_count : cutscenes_count).Add(HTTPUtil.jsonInt(record, "counter"));
        }

        if (endings.Count > 0)
        {
            stat_panel.addLabel("Endings:");
            foreach (var p in endings.Zip(endings_count, (a, b) => new { Name = a, Count = b }))
            {
                stat_panel.addEnding(p.Name, p.Count, my_endings.Contains(p.Name));
            }
        }

        if (cutscenes.Count > 0)
        {
            stat_panel.addLabel("Cutscenes:");
            foreach (var p in cutscenes.Zip(cutscenes_count, (a, b) => new { Name = a, Count = b }))
            {
                stat_panel.addCutscene(p.Name, p.Count, my_cutscenes.Contains(p.Name));
            }
        }

        if (!(powers_count.Any(c => c > 0) || endings.Count > 0 || cutscenes.Count > 0))
        {
            stat_panel.addLabel("No achievements found");
        }
    }