private static bool matches(StageBinaryFile.Entity entity, string selectedValue) { return(entity.name.Equals(selectedValue)); }
public static void Main(string[] args) { var mode = Mode.Unknown; bool showHelp = false; var options = new OptionSet() { { "stb", "convert XML to STB", v => mode = v != null ? Mode.ToStb : mode }, { "xml", "convert STB to XML", v => mode = v != null ? Mode.ToXml : mode }, { "h|help", "show this message and exit", v => showHelp = v != null }, }; List <string> extras; try { extras = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); return; } if (mode == Mode.Unknown && extras.Count >= 1) { var extension = Path.GetExtension(extras[0]); if (extension == ".stb") { mode = Mode.ToXml; } else if (extension == ".xml") { mode = Mode.ToStb; } } if (showHelp == true || mode == Mode.Unknown || extras.Count < 1 || extras.Count > 2) { Console.WriteLine("Usage: {0} [OPTIONS]+ input [output]", GetExecutableName()); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } if (mode == Mode.ToStb) { string inputPath = extras[0]; string outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null) + "_converted.stb"; var culture = CultureInfo.InvariantCulture; var stb = new StageBinaryFile(); using (var input = File.OpenRead(inputPath)) { var doc = new XPathDocument(input); var nav = doc.CreateNavigator(); var root = nav.SelectSingleNode("/stage"); if (root == null) { throw new InvalidOperationException(); } var rawRooms = root.Select("room"); var rooms = new List <StageBinaryFile.Room>(); while (rawRooms.MoveNext() == true) { var rawRoom = rawRooms.Current; var room = new StageBinaryFile.Room(); ParseAttribute(rawRoom, "type", out room.Type, culture); ParseAttribute(rawRoom, "variant", out room.Variant, culture); ParseAttribute(rawRoom, "name", out room.Name); ParseAttribute(rawRoom, "difficulty", out room.Difficulty, culture); ParseAttribute(rawRoom, "weight", out room.Weight, culture); ParseAttribute(rawRoom, "width", out room.Width, culture); ParseAttribute(rawRoom, "height", out room.Height, culture); var rawDoors = rawRoom.Select("door"); var doors = new List <StageBinaryFile.Door>(); while (rawDoors.MoveNext() == true) { var rawDoor = rawDoors.Current; var door = new StageBinaryFile.Door(); ParseAttribute(rawDoor, "x", out door.X, culture); ParseAttribute(rawDoor, "y", out door.Y, culture); ParseAttribute(rawDoor, "exists", out door.Exists); doors.Add(door); } room.Doors = doors.ToArray(); var rawSpawns = rawRoom.Select("spawn"); var spawns = new List <StageBinaryFile.Spawn>(); while (rawSpawns.MoveNext() == true) { var rawSpawn = rawSpawns.Current; var spawn = new StageBinaryFile.Spawn(); ParseAttribute(rawSpawn, "x", out spawn.X, culture); ParseAttribute(rawSpawn, "y", out spawn.Y, culture); var rawEntities = rawSpawn.Select("entity"); var entities = new List <StageBinaryFile.Entity>(); while (rawEntities.MoveNext() == true) { var rawEntity = rawEntities.Current; var entity = new StageBinaryFile.Entity(); ParseAttribute(rawEntity, "type", out entity.Type, culture); ParseAttribute(rawEntity, "variant", out entity.Variant, culture); ParseAttribute(rawEntity, "subtype", out entity.Subtype, culture); ParseAttribute(rawEntity, "weight", out entity.Weight, culture); entities.Add(entity); } spawn.Entities = entities.ToArray(); spawns.Add(spawn); } room.Spawns = spawns.ToArray(); rooms.Add(room); } stb.Rooms.Clear(); stb.Rooms.AddRange(rooms); } using (var output = File.Create(outputPath)) { stb.Serialize(output); output.Flush(); } } else if (mode == Mode.ToXml) { string inputPath = extras[0]; string outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null) + "_converted.xml"; var stb = new StageBinaryFile(); using (var input = File.OpenRead(inputPath)) { stb.Deserialize(input); } var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true, OmitXmlDeclaration = true }; var culture = CultureInfo.InvariantCulture; using (var writer = XmlWriter.Create(outputPath, settings)) { writer.WriteStartDocument(); writer.WriteComment("Converted to ANM2 by Gibbed.Rebirth.ConvertStage"); writer.WriteStartElement("stage"); foreach (var room in stb.Rooms) { writer.WriteStartElement("room"); writer.WriteAttributeString("type", room.Type.ToString(culture)); writer.WriteAttributeString("variant", room.Variant.ToString(culture)); writer.WriteAttributeString("name", room.Name); writer.WriteAttributeString("difficulty", room.Difficulty.ToString(culture)); writer.WriteAttributeString("weight", room.Weight.ToString(culture)); writer.WriteAttributeString("width", room.Width.ToString(culture)); writer.WriteAttributeString("height", room.Height.ToString(culture)); foreach (var door in room.Doors) { writer.WriteStartElement("door"); writer.WriteAttributeString("x", door.X.ToString(culture)); writer.WriteAttributeString("y", door.Y.ToString(culture)); if (door.Exists == true) { writer.WriteAttributeString("exists", door.Exists.ToString(culture)); } writer.WriteEndElement(); } foreach (var spawn in room.Spawns) { writer.WriteStartElement("spawn"); writer.WriteAttributeString("x", spawn.X.ToString(culture)); writer.WriteAttributeString("y", spawn.Y.ToString(culture)); foreach (var entity in spawn.Entities) { writer.WriteStartElement("entity"); writer.WriteAttributeString("type", entity.Type.ToString(culture)); writer.WriteAttributeString("variant", entity.Variant.ToString(culture)); writer.WriteAttributeString("subtype", entity.Subtype.ToString(culture)); writer.WriteAttributeString("weight", entity.Weight.ToString(culture)); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); } } else { throw new InvalidOperationException(); } }
private static bool matches(StageBinaryFile.Entity entity, int type, int variant, int subtype) { return(entity.Type == type && entity.Subtype == subtype && entity.Variant == variant); }
private void InitializeComponent() { this.tabs = new TabControl(); TabPage page = new TabPage("edit rooms"); this.mainPanel = new Panel(); this.LoadButton = new Button(); this.EntityBox = new ComboBox(); this.ControlsPanel = new Panel(); this.WeightButton = new Button(); this.weightTextBox = new TextBox(); this.TextboxType = new TextBox(); this.TextboxVariant = new TextBox(); this.TextboxSubType = new TextBox(); this.RemoveButton = new Button(); this.addButton = new Button(); this.tileEntityListBox = new ListBox(); this.LabelSubtype = new Label(); this.LabelVariant = new Label(); this.LabelType = new Label(); this.roomComboBox = new ComboBox(); this.saveButton = new Button(); this.TilePanel = new Panel(); this.mainPanel.Text = "edit rooms"; this.mainPanel.Controls.Add(this.ControlsPanel); this.mainPanel.Controls.Add(TilePanel); page.Controls.Add(mainPanel); this.tabs.Controls.Add(page); // // button1 // this.LoadButton.Name = "LoadButton"; this.LoadButton.TabIndex = 0; this.LoadButton.Text = "Load File"; this.LoadButton.UseVisualStyleBackColor = true; this.LoadButton.Click += this.LoadFileClick; // // comboBox1 // this.EntityBox.FormattingEnabled = true; this.EntityBox.Name = "EntityBox"; this.EntityBox.TabIndex = 1; this.EntityBox.SelectedIndexChanged += (sender, args) => { StageBinaryFile.Entity temp = EntityStore.findByName( this.EntityBox.SelectedItem as string); TextboxType.Text = "" + temp.Type; TextboxVariant.Text = "" + temp.Variant; TextboxSubType.Text = "" + temp.Subtype; }; // // panel1 // this.ControlsPanel.Controls.Add(this.WeightButton); this.ControlsPanel.Controls.Add(this.weightTextBox); this.ControlsPanel.Controls.Add(this.TextboxType); this.ControlsPanel.Controls.Add(this.TextboxVariant); this.ControlsPanel.Controls.Add(this.TextboxSubType); this.ControlsPanel.Controls.Add(this.RemoveButton); this.ControlsPanel.Controls.Add(this.addButton); this.ControlsPanel.Controls.Add(this.tileEntityListBox); this.ControlsPanel.Controls.Add(this.LabelSubtype); this.ControlsPanel.Controls.Add(this.LabelVariant); this.ControlsPanel.Controls.Add(this.LabelType); this.ControlsPanel.Controls.Add(this.roomComboBox); this.ControlsPanel.Controls.Add(this.EntityBox); this.ControlsPanel.Controls.Add(this.saveButton); this.ControlsPanel.Controls.Add(this.LoadButton); this.ControlsPanel.Name = "ControlsPanel"; this.ControlsPanel.TabIndex = 2; // // Tile panel // this.TilePanel.Name = "TilePanel"; this.TilePanel.AutoScroll = true; // // button4 // this.WeightButton.Name = "WeightButton"; this.WeightButton.TabIndex = 8; this.WeightButton.Text = "set weight"; this.WeightButton.UseVisualStyleBackColor = true; this.WeightButton.Click += this.SetWeight; // // textBox1 // this.weightTextBox.Name = "WeightTextbox"; this.weightTextBox.TabIndex = 7; this.TextboxType.Name = "TextboxType"; this.TextboxType.TabIndex = 7; this.TextboxVariant.Name = "TextboxVariant"; this.TextboxVariant.TabIndex = 7; this.TextboxSubType.Name = "TextboxSubtype"; this.TextboxSubType.TabIndex = 7; // // button3 // this.RemoveButton.Name = "RemoveButton"; this.RemoveButton.TabIndex = 6; this.RemoveButton.Text = "REMOVE"; this.RemoveButton.UseVisualStyleBackColor = true; this.RemoveButton.Click += this.RemoveClick; // // button2 // this.addButton.Name = "addButton"; this.addButton.TabIndex = 5; this.addButton.Text = "ADD"; this.addButton.UseVisualStyleBackColor = true; this.addButton.Click += this.AddClick; // // listBox1 // this.tileEntityListBox.FormattingEnabled = true; this.tileEntityListBox.Name = "TileEntitiesList"; this.tileEntityListBox.TabIndex = 4; this.tileEntityListBox.SelectedIndexChanged += this.SelectedEntityChanged; // // label2 // this.LabelVariant.AutoSize = true; this.LabelVariant.Name = "LabelVariant"; this.LabelVariant.TabIndex = 3; this.LabelVariant.Text = "Variant"; this.LabelSubtype.AutoSize = true; this.LabelSubtype.Name = "LabelSubtype"; this.LabelSubtype.TabIndex = 3; this.LabelSubtype.Text = "SubType"; // // label1 // this.LabelType.AutoSize = true; this.LabelType.Name = "LabelType"; this.LabelType.TabIndex = 2; this.LabelType.Text = "Type"; // // comboBox2 // this.roomComboBox.FormattingEnabled = true; this.roomComboBox.Name = "roomComboBox"; this.roomComboBox.TabIndex = 1; this.roomComboBox.SelectedIndexChanged += this.RoomChanged; // // button5 // this.saveButton.Name = "saveButton"; this.saveButton.TabIndex = 0; this.saveButton.Text = "Save file"; this.saveButton.UseVisualStyleBackColor = true; this.saveButton.Click += this.saveFile; // // Form1 // //this.AutoScaleDimensions = new SizeF(6F, 13F); //this.AutoScaleMode = AutoScaleMode.Font; this.ClientSize = new Size(898, 482); this.Controls.Add(tabs); this.Name = "LevelEditor"; this.Text = "Binding of isaac: Rebirth level editor - no level loaded"; doLayout(this.ClientRectangle); }