private static void LoadContents() { foreach (var elements in XmlLoader.GetEmbeddedGameAssets()) { foreach (var elem in elements.XPathSelectElements("//Object")) { XmlContent content; switch ((ContentType)int.Parse(elem.Attribute("type").Value)) { case ContentType.Objects: { content = new ObjectsContent(elem); ObjectsXml.Add(content.Id, (ObjectsContent)content); } break; case ContentType.Items: { content = new ItemsContent(elem); ItemsXml.Add(content.Id, (ItemsContent)content); } break; case ContentType.Tiles: { content = new TilesContent(elem); TilesXml.Add(content.Id, (TilesContent)content); } break; } } } }
public static XElement ToXml(this TilesContent content) => new XElement("Object", new XAttribute("type", (int)ContentType.Tiles), new XAttribute("id", content.Id), new XAttribute("name", content.Name), content.Walkable ? new XElement("Walkable") : null, content.LayerData != null ? new XElement("Layer", new XAttribute("type", (int)content.LayerData.Type), new XAttribute("group", content.LayerData.Group) ) : null, content.TextureData != null ? new XElement("Texture", new XAttribute("x", content.TextureData.X), new XAttribute("y", content.TextureData.Y), new XElement("FileName", content.TextureData.File) ) : null );
private void SaveButton_Click(object sender, EventArgs e) { var type = default(ContentType); if (ObjectsButton.Checked) { type = ContentType.Objects; } if (ItemsButton.Checked) { type = ContentType.Items; } if (TilesButton.Checked) { type = ContentType.Tiles; } var id = (int)ItemId.Value; var name = ItemName.Text; var maptype = default(MapLayer); if (UndergroundButton.Checked) { maptype = MapLayer.UNDERGROUND; } if (GroundButton.Checked) { maptype = MapLayer.GROUND; } if (ObjectButton.Checked) { maptype = MapLayer.OBJECT; } if (SkyButton.Checked) { maptype = MapLayer.SKY; } var layerdata = new LayerData() { Type = maptype, Group = ItemGroup.Text }; var texturedata = new TextureData() { File = (string)ItemFile.SelectedItem, X = (int)ItemX.Value, Y = (int)ItemY.Value, Animated = ItemAnimated.Checked }; var blocked = ItemBlocked.Checked; var walkable = ItemWalkable.Checked; ObjectsContent sampleobject = null; ItemsContent sampleitem = null; TilesContent sampletile = null; foreach (var samples in Manager.XmlObjects.Values.Select(values => values).ToList()) { foreach (var sample in samples) { if (sample.Id == id) { sampleobject = sample; break; } } } foreach (var samples in Manager.XmlItems.Values.Select(values => values).ToList()) { foreach (var sample in samples) { if (sample.Id == id) { sampleitem = sample; break; } } } foreach (var samples in Manager.XmlTiles.Values.Select(values => values).ToList()) { foreach (var sample in samples) { if (sample.Id == id) { sampletile = sample; break; } } } if (sampleobject != null) { MessageBox.Show($"Object '{sampleobject.Name}' has same ID '{sampleobject.Id}', consider to change.", "Error!"); return; } if (sampleitem != null) { MessageBox.Show($"Item '{sampleitem.Name}' has same ID '{sampleitem.Id}', consider to change.", "Error!"); return; } if (sampletile != null) { MessageBox.Show($"Tile '{sampletile.Name}' has same ID '{sampletile.Id}', consider to change.", "Error!"); return; } switch (type) { case ContentType.Objects: Manager.XmlObjects[(string)ItemXml.SelectedItem].Add(new ObjectsContent() { Type = type, Id = id, Name = name, LayerData = layerdata, TextureData = texturedata, Blocked = blocked }); break; case ContentType.Items: Manager.XmlItems[(string)ItemXml.SelectedItem].Add(new ItemsContent() { Type = type, Id = id, Name = name, TextureData = texturedata }); break; case ContentType.Tiles: Manager.XmlTiles[(string)ItemXml.SelectedItem].Add(new TilesContent() { Type = type, Id = id, Name = name, LayerData = layerdata, TextureData = texturedata, Walkable = walkable }); break; } DialogResult = DialogResult.OK; }