Map to Lava-Survival map converter

Map to Lava-Survival map converter

Postby joppiesaus » 25 Jun 2013, 12:49

Hello people!
I made a plugin called Map Converter (Lava)

Update v 1.1:
*Now automatically reloads the converted map.

Code: Select all
using System;
using System.IO;
using MCDzienny;
using System.Windows.Forms;

namespace MCDzienny.Plugins
{
    public class mainClass : Plugin
    {
        versionInfoPlugin info = new versionInfoPlugin("Map Converter (Lava)", "Converts a freebuild map to a lava map", "joppiesaus", "1.1", 1);
        plgnGUI gui = new plgnGUI();

        public override string Description
        {
            get { return info.descr; }
        }

        public override string Author
        {
            get { return info.auth; }
        }

        public override string Name
        {
            get { return info.name; }
        }

        public override System.Windows.Forms.UserControl MainInterface
        {
            get { return gui; }
        }

        public override string Version
        {
            get { return info.ver; }
        }

        public override int VersionNumber
        {
            get { return info.verNumber; }
        }

        public override void Initialize()
        {

        }

        public override void Terminate()
        {

        }
    }

    public class versionInfoPlugin
    {
        public string name { get; set; }
        public string descr { get; set; }
        public string auth { get; set; }
        public string ver { get; set; }
        public int verNumber { get; set; }
        public versionInfoPlugin(string nameOfAssembly, string description, string author, string version, int versionNumber)
        {
            name = nameOfAssembly;
            descr = description;
            auth = author;
            ver = version;
            verNumber = versionNumber;
        }
    }
    public partial class plgnGUI : UserControl
    {
        bool customCode = false;
        string levelName;
        public plgnGUI()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                customCode = true;
                textBoxCustomCode.Enabled = true;
            }
            else
            {
                customCode = false;
                textBoxCustomCode.Enabled = false;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBoxLVL2convert.Text != "" && textBoxStartingBlock.Text != "" && textBox_x.Text != "" && textBox_y.Text != "" && textBox_z.Text != "")
            {
                if (checkMap(textBoxLVL2convert.Text))
                {
                    try
                    {
                        levelName = textBoxLVL2convert.Text;
                        exportMap(levelName);
                        saveToXML();
                        Command.all.Find("setlava").Use(null, "reloadmaps");
                        MessageBox.Show("Map added to the lava maps!", "Map added!");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("=ERROR=" + System.Environment.NewLine + System.Environment.NewLine + ex, "Error");
                    }
                }
                else
                {
                    MessageBox.Show("The map you entered doesn't exist.", "Error");
                }
            }
            else
            {
                MessageBox.Show("Not all fields are filled. All fields except type and author must be filled.", "Error");
            }
        }

        public void saveToXML()
        {
            string path1 = string.Format(@"{0}\lava\maps.txt", Application.StartupPath);
            string path2 = string.Format(@"{0}\temp_maps.txt", Application.StartupPath);
            string indx = "<Maps>";
            string finalXmlCode;
            string XmlCode = "  <Map name=\"" + levelName + "\" phase1=\"0\" phase2=\"0\" author=\"" + textBoxAuthor.Text + "\">" + System.Environment.NewLine
                + "    <Source block=\"" + textBoxStartingBlock.Text + "\" x=\"" + textBox_x.Text + "\" y=\"" + textBox_y.Text + "\" z=\"" + textBox_z.Text + "\" type=\"" + textBoxType.Text + "\" delay=\"0\" />" + System.Environment.NewLine;
            if (customCode)
            {
                finalXmlCode = XmlCode + System.Environment.NewLine + textBoxCustomCode + "  </Map>" + System.Environment.NewLine;
            }
            else
            {
                finalXmlCode = XmlCode + "  </Map>" + System.Environment.NewLine;
            }
            using (StreamReader read = new StreamReader(path1))
            {
                string line;
                using (StreamWriter write = new StreamWriter(path2))
                {
                    while ((line = read.ReadLine()) != null)
                    {
                        if (line == indx)
                        {
                            write.WriteLine("<Maps>");
                            write.Write(finalXmlCode);
                        }
                        else
                        {
                            write.WriteLine(line);
                        }
                    }
                }
            }
            File.Delete(path1);
            File.Move(path2, path1);
        }

        public bool checkMap(string lvl)
        {
            Level level = Level.Find(lvl);
            if (level != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public void exportMap(string lvlName)
        {
            string from = string.Format(@"{0}\levels\{1}.lvl", Application.StartupPath, levelName);
            string to = string.Format(@"{0}\lava\maps\{1}.lvl", Application.StartupPath, levelName);
            File.Copy(from, to, true);
        }
    }
    partial class plgnGUI
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.textBoxLVL2convert = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.textBox_x = new System.Windows.Forms.TextBox();
            this.textBoxStartingBlock = new System.Windows.Forms.TextBox();
            this.textBox_y = new System.Windows.Forms.TextBox();
            this.textBox_z = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.textBoxType = new System.Windows.Forms.TextBox();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.textBoxCustomCode = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.textBoxAuthor = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // textBoxLVL2convert
            //
            this.textBoxLVL2convert.Location = new System.Drawing.Point(96, 3);
            this.textBoxLVL2convert.Name = "textBoxLVL2convert";
            this.textBoxLVL2convert.Size = new System.Drawing.Size(332, 20);
            this.textBoxLVL2convert.TabIndex = 0;
            this.toolTip1.SetToolTip(this.textBoxLVL2convert, "The level to convert to a lava survival level.");
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(3, 6);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(87, 13);
            this.label1.TabIndex = 1;
            this.label1.Text = "Level to convert:";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(3, 28);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(156, 13);
            this.label2.TabIndex = 5;
            this.label2.Text = "Starting block:                        at";
            //
            // textBox_x
            //
            this.textBox_x.Location = new System.Drawing.Point(165, 25);
            this.textBox_x.Name = "textBox_x";
            this.textBox_x.Size = new System.Drawing.Size(43, 20);
            this.textBox_x.TabIndex = 6;
            this.toolTip1.SetToolTip(this.textBox_x, "z");
            //
            // textBoxStartingBlock
            //
            this.textBoxStartingBlock.Location = new System.Drawing.Point(96, 25);
            this.textBoxStartingBlock.Name = "textBoxStartingBlock";
            this.textBoxStartingBlock.Size = new System.Drawing.Size(44, 20);
            this.textBoxStartingBlock.TabIndex = 7;
            this.textBoxStartingBlock.Text = "ahl";
            this.toolTip1.SetToolTip(this.textBoxStartingBlock, "Lava block when the map starts");
            //
            // textBox_y
            //
            this.textBox_y.Location = new System.Drawing.Point(214, 25);
            this.textBox_y.Name = "textBox_y";
            this.textBox_y.Size = new System.Drawing.Size(43, 20);
            this.textBox_y.TabIndex = 8;
            this.toolTip1.SetToolTip(this.textBox_y, "y");
            //
            // textBox_z
            //
            this.textBox_z.Location = new System.Drawing.Point(263, 25);
            this.textBox_z.Name = "textBox_z";
            this.textBox_z.Size = new System.Drawing.Size(43, 20);
            this.textBox_z.TabIndex = 9;
            this.toolTip1.SetToolTip(this.textBox_z, "z");
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(312, 28);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(30, 13);
            this.label3.TabIndex = 10;
            this.label3.Text = "type:";
            //
            // textBoxType
            //
            this.textBoxType.Location = new System.Drawing.Point(342, 25);
            this.textBoxType.Name = "textBoxType";
            this.textBoxType.Size = new System.Drawing.Size(86, 20);
            this.textBoxType.TabIndex = 11;
            this.toolTip1.SetToolTip(this.textBoxType, "Type. You can leave this empty.");
            //
            // toolTip1
            //
            this.toolTip1.AutoPopDelay = 5000;
            this.toolTip1.InitialDelay = 150;
            this.toolTip1.ReshowDelay = 100;
            //
            // checkBox1
            //
            this.checkBox1.AutoSize = true;
            this.checkBox1.Location = new System.Drawing.Point(6, 68);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(88, 17);
            this.checkBox1.TabIndex = 12;
            this.checkBox1.Text = "Custom code";
            this.checkBox1.UseVisualStyleBackColor = true;
            this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
            //
            // textBoxCustomCode
            //
            this.textBoxCustomCode.Enabled = false;
            this.textBoxCustomCode.Location = new System.Drawing.Point(6, 91);
            this.textBoxCustomCode.Multiline = true;
            this.textBoxCustomCode.Name = "textBoxCustomCode";
            this.textBoxCustomCode.Size = new System.Drawing.Size(420, 198);
            this.textBoxCustomCode.TabIndex = 13;
            this.toolTip1.SetToolTip(this.textBoxCustomCode, "Custom XML code for you lava survival map. Use with caution.\r\n");
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(6, 295);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(420, 23);
            this.button1.TabIndex = 14;
            this.button1.Text = "Convert!";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // textBoxAuthor
            //
            this.textBoxAuthor.Location = new System.Drawing.Point(96, 47);
            this.textBoxAuthor.Name = "textBoxAuthor";
            this.textBoxAuthor.Size = new System.Drawing.Size(332, 20);
            this.textBoxAuthor.TabIndex = 15;
            this.toolTip1.SetToolTip(this.textBoxAuthor, "Type. You can leave this empty.");
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(3, 50);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(41, 13);
            this.label4.TabIndex = 16;
            this.label4.Text = "Author:";
            //
            // plgnGUI
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.Controls.Add(this.label4);
            this.Controls.Add(this.textBoxAuthor);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.textBoxCustomCode);
            this.Controls.Add(this.checkBox1);
            this.Controls.Add(this.textBoxType);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.textBox_z);
            this.Controls.Add(this.textBox_y);
            this.Controls.Add(this.textBoxStartingBlock);
            this.Controls.Add(this.textBox_x);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.textBoxLVL2convert);
            this.Name = "plgnGUI";
            this.Size = new System.Drawing.Size(429, 324);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox textBoxLVL2convert;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox_x;
        private System.Windows.Forms.TextBox textBoxStartingBlock;
        private System.Windows.Forms.TextBox textBox_y;
        private System.Windows.Forms.TextBox textBox_z;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox textBoxType;
        private System.Windows.Forms.ToolTip toolTip1;
        private System.Windows.Forms.CheckBox checkBox1;
        private System.Windows.Forms.TextBox textBoxCustomCode;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBoxAuthor;
        private System.Windows.Forms.Label label4;
    }
}


Have fun with it. :D

Knipsel.PNG
The view of the plugin
Knipsel.PNG (8.23 KiB) Viewed 922 times

1.0 version old code:
Spoiler:
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: Map to Lava-Survival map converter

Postby ismellike » 25 Jun 2013, 15:04

Nice! Are you planning on making this for zombies too?
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Map to Lava-Survival map converter

Postby joppiesaus » 25 Jun 2013, 16:04

ismellike wrote:Nice! Are you planning on making this for zombies too?

Yes, I am working on it already.
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!


Return to Plugins

Who is online

Users browsing this forum: No registered users and 1 guest

cron