Ładowanie mapy z xml'a

This commit is contained in:
Michał Dulski 2019-04-22 16:50:40 +02:00
parent 97cd3630fc
commit 05fc45abda
10 changed files with 176 additions and 54 deletions

View File

@ -25,6 +25,18 @@
/processorParam:TextureFormat=Color
/build:collector.png
#begin glass.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:glass.png
#begin grass.png
/importer:TextureImporter
/processor:TextureProcessor
@ -49,6 +61,42 @@
/processorParam:TextureFormat=Color
/build:house.png
#begin organic.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:organic.png
#begin paper.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:paper.png
#begin plasticmetal.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:plasticmetal.png
#begin road1.png
/importer:TextureImporter
/processor:TextureProcessor

View File

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

View File

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 100 KiB

View File

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -4,8 +4,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using CzokoŚmieciarka.MonoGameView.DataModels.Enums;
using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models;
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans;
using CzokoŚmieciarka.MonoGameView.DataModels.Models;
using MonoGameView.DataModels.Models;
@ -46,9 +48,65 @@ namespace MonoGameView.DataModels
positionNode = objectNode.SelectSingleNode("Position");
x = Convert.ToInt32(positionNode.SelectSingleNode("X").InnerText);
y = Convert.ToInt32(positionNode.SelectSingleNode("Y").InnerText);
House house = new House(new Coords(x,y));
List<ATrashCan> trashCans = new List<ATrashCan>();
foreach (XmlNode trashCanNode in objectNode.SelectSingleNode("TrashCans"))
{
GarbageType type;
switch (trashCanNode.SelectSingleNode("GarbageType").InnerText)
{
case "Glass":
type = GarbageType.Glass;
break;
case "Organic":
type = GarbageType.Organic;
break;
case "Paper":
type = GarbageType.Paper;
break;
default:
type = GarbageType.PlasticMetal;
break;
}
int canDensity = Convert.ToInt32(trashCanNode.SelectSingleNode("Density").InnerText);
int canProcessingTimePerUnit = Convert.ToInt32(trashCanNode.SelectSingleNode("ProcessingTimePerUnit").InnerText);
int volume = Convert.ToInt32(trashCanNode.SelectSingleNode("Volume").InnerText);
TypeOfGarbage canTypeOfGarbage = new TypeOfGarbage(type, canDensity,canProcessingTimePerUnit);
TrashCan trashCan = new TrashCan(canTypeOfGarbage, volume);
trashCans.Add(trashCan);
}
House house = new House(new Coords(x,y), trashCans);
grid[x, y] = house;
break;
case "Dump":
positionNode = objectNode.SelectSingleNode("Position");
x = Convert.ToInt32(positionNode.SelectSingleNode("X").InnerText);
y = Convert.ToInt32(positionNode.SelectSingleNode("Y").InnerText);
XmlNode garbageNode = objectNode.SelectSingleNode("Garbage");
TypeOfGarbage typeOfGarbage;
GarbageType garbageType;
switch (garbageNode.SelectSingleNode("GarbageType").InnerText)
{
case "Glass":
garbageType = GarbageType.Glass;
break;
case "Organic":
garbageType = GarbageType.Organic;
break;
case "Paper":
garbageType = GarbageType.Paper;
break;
default:
garbageType = GarbageType.PlasticMetal;
break;
}
int density = Convert.ToInt32(garbageNode.SelectSingleNode("Density").InnerText);
int processingTimePerUnit = Convert.ToInt32(garbageNode.SelectSingleNode("ProcessingTimePerUnit").InnerText);
int maxVolume = Convert.ToInt32(objectNode.SelectSingleNode("Volume").InnerText);
typeOfGarbage = new TypeOfGarbage(garbageType, density, processingTimePerUnit);
Dump dump = new Dump(typeOfGarbage, maxVolume, new Coords(x, y));
grid[x, y] = dump;
break;
}
}
}

View File

@ -1,13 +1,21 @@
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans;
using CzokoŚmieciarka.MonoGameView.DataModels.Models;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGameView.DataModels.Models;
namespace CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models
{
public class Dump : ADump
public class Dump : ADump, IDrawables
{
public Dump(ITypeOfGarbage typeOfGarbage, int maxVolume, Coords localization) : base(typeOfGarbage, maxVolume, localization)
{
}
public void Draw(SpriteBatch batch, int size)
{
batch.Draw(ImageContainer.GetImage(TypeOfGarbage.GarbageType.ToString()), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
}
}
}

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
@ -11,11 +12,11 @@ using MonoGameView.DataModels.Models;
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
{
public class House : IDrawables
public class House : IDrawables, IGarbageLocalization
{
private Coords Coords;
public Coords Coords { get; }
public House(Coords coords)
public House(Coords coords, IEnumerable<ATrashCan> trashCans)
{
Coords = coords;
}
@ -23,5 +24,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
{
batch.Draw(ImageContainer.GetImage("house"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
}
public IEnumerable<ATrashCan> TrashCans { get; set; }
}
}

View File

@ -21,6 +21,11 @@ namespace MonoGameView.DataModels.Models
_container.Images.Add("road2", content.Load<Texture2D>("road2"));
_container.Images.Add("grass", content.Load<Texture2D>("grass"));
_container.Images.Add("collector", content.Load<Texture2D>("collector"));
_container.Images.Add("Glass", content.Load<Texture2D>("glass"));
_container.Images.Add("Paper", content.Load<Texture2D>("paper"));
_container.Images.Add("PlasticMetal", content.Load<Texture2D>("plasticmetal"));
_container.Images.Add("Organic", content.Load<Texture2D>("organic"));
}
public static Texture2D GetImage(string s)