예제 #1
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);
    }
예제 #2
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");
        }
    }