コード例 #1
0
        public void put()
        {
            errors.Clear();
            if (CraftManager.main_ui.show_transfer_indicator)
            {
                errors.Add("unable to update, another craft is still uploading");
            }
            if (errors.Count == 0)
            {
                CraftManager.main_ui.close_update_kerbalx_craft_dialog();
                CraftManager.main_ui.show_transfer_indicator = true;
                CraftManager.main_ui.transfer_is_upload      = false;

                WWWForm craft_data = new WWWForm();
                craft_data.AddField("craft_name", craft_name);
                craft_data.AddField("craft_file", System.IO.File.ReadAllText(craft.path));
                craft_data.AddField("part_data", JSONX.toJSON(part_info()));

                KerbalX.api.update_craft(update_to_id, craft_data, (resp, code) => {
                    if (code == 200)
                    {
                        CraftManager.log("craft updated OK");
                        KerbalX.api.fetch_existing_craft((empty_resp, status_code) => {
                            CraftManager.main_ui.close_upload_interface();
                        });
                    }
                    else
                    {
                        CraftManager.log("craft update failed");
                    }
                    CraftManager.main_ui.show_transfer_indicator = false;
                });
            }
        }
コード例 #2
0
        public void post()
        {
            if (is_valid)
            {
                CraftManager.main_ui.show_transfer_indicator = true;
                CraftManager.main_ui.transfer_is_upload      = true;
                WWWForm craft_data = new WWWForm();
                craft_data.AddField("craft_name", craft_name);
                craft_data.AddField("craft_style", craft_type);
                craft_data.AddField("craft_file", System.IO.File.ReadAllText(craft.path));
                craft_data.AddField("part_data", JSONX.toJSON(part_info()));
                craft_data.AddField("action_groups", JSONX.toJSON(action_groups));
                craft_data.AddField("hash_tags", hash_tags);

                int pic_count = 0;
                foreach (Image image in images)
                {
                    craft_data.AddField("images[image_" + pic_count++ + "]", Convert.ToBase64String(image.read_as_jpg()));
//                    craft_data.AddField("image_urls[url_" + pic_count++ + "]", "https://i.imgur.com/nSUkIe0.jpg");
                }

                KerbalX.api.upload_craft(craft_data, (resp, code) => {
                    //                        var resp_data = JSON.Parse(resp);
                    if (code == 200)
                    {
                        CraftManager.log("craft uploaded OK");
                        KerbalX.api.fetch_existing_craft((empty_resp, status_code) => {   //refresh remote craft info
                            craft.matching_remote_ids = null;
                            CraftManager.main_ui.close_upload_interface();
                        });
                    }
                    else
                    {
                        CraftManager.log("craft upload failed");
                    }

                    //return UI to craft list mode and show upload complete dialog.
                    CraftManager.main_ui.show_transfer_indicator = false;
                    //                        CraftManager.main_ui.unlock_ui();
                    CraftManager.main_ui.upload_complete_dialog(code, JSON.Parse(resp));
                });
            }
        }