Exemplo n.º 1
0
        private bool SaveJson()
        {
            string json = "";

            if (tbFilename.Text == "")
            {
                MessageBox.Show("All fileds have to be comleted");
                return(false);
            }
            switch (tcMain.SelectedTab.Text)
            {
            case "Item":
                if (item_name.Text == "" || item_icon.Text == "")
                {
                    MessageBox.Show("All fileds have to be comleted");
                    return(false);
                }
                Item item = new Item
                {
                    type     = "item",
                    name     = item_name.Text,
                    id       = (int)item_id.Value,
                    texture  = new Texture(item_icon.Text, (int)item_index.Value),
                    maxStack = (int)item_stack.Value
                };
                json = item.ToJson();
                break;

            case "Block":
                if (block_name.Text == "" || block_texture.Text == "")
                {
                    MessageBox.Show("All fileds have to be comleted");
                    return(false);
                }
                Block block = new Block
                {
                    type                = "block",
                    name                = block_name.Text,
                    id                  = (int)block_id.Value,
                    texture             = new Texture(block_texture.Text, (int)block_index.Value),
                    material            = (int)block_material.Value,
                    opaque              = block_opaque.Text == "true",
                    renderType          = (int)block_render.Value,
                    destroyTime         = block_destroy.Value,
                    explosionResistance = block_explosion.Value
                };
                json = block.ToJson();
                break;

            case "Food":
                if (food_name.Text == "" || food_icon.Text == "")
                {
                    MessageBox.Show("All fileds have to be comleted");
                    return(false);
                }
                Food food = new Food
                {
                    type     = "food",
                    name     = food_name.Text,
                    id       = (int)food_id.Value,
                    texture  = new Texture(food_icon.Text, (int)food_index.Value),
                    maxStack = (int)food_stack.Value,
                    restore  = (int)food_restore.Value
                };
                json = food.ToJson();
                break;

            case "Armor":
                if (armor_name.Text == "" || armor_icon.Text == "" || armor_texture.Text == "")
                {
                    MessageBox.Show("All fileds have to be comleted");
                    return(false);
                }
                Armor armor = new Armor
                {
                    type         = "armor",
                    name         = armor_name.Text,
                    id           = (int)armor_id.Value,
                    texture      = new Texture(armor_icon.Text, (int)armor_index.Value),
                    armorType    = armor_type.Text,
                    reduceDamage = (int)armor_reduce.Value,
                    maxDamage    = (int)armor_max.Value,
                    armorTexture = armor_texture.Text
                };
                json = armor.ToJson();
                break;

            case "Throwable":
                if (throwable_name.Text == "" || throwable_icon.Text == "")
                {
                    MessageBox.Show("All fileds have to be comleted");
                    return(false);
                }
                Throwable throwable = new Throwable
                {
                    type     = "throwable",
                    name     = throwable_name.Text,
                    id       = (int)throwable_id.Value,
                    texture  = new Texture(throwable_icon.Text, (int)throwable_index.Value),
                    maxStack = (int)throwable_stack.Value
                };
                json = throwable.ToJson();
                break;
            }
            name = tbFilename.Text;
            try
            {
                filename = ProgramData.Project.OtherResourcesPath + name + ".json";
                File.WriteAllText(filename, json);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Unable to save item description");
                return(false);
            }
            return(true);
        }