Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Xml;
- namespace CellChunkGenerator
- {
- public enum WallStyle
- {
- None,
- WestWall,
- WestWallTrans,
- WestWindow,
- WestDoorFrame,
- NorthWall,
- NorthWallTrans,
- NorthWindow,
- NorthDoorFrame,
- NorthWestCorner,
- NorthWestCornerTrans,
- SouthEastCorner,
- }
- public enum RoofStyle
- {
- None,
- WestRoofB,
- WestRoofM,
- WestRoofT,
- }
- public enum TileBlockStyle
- {
- None,
- Solid,
- SolidTransparent,
- }
- public enum Direction
- {
- None,
- N,
- NE,
- E,
- SE,
- S,
- SW,
- W,
- NW,
- }
- public enum StairStyle
- {
- None,
- BottomW,
- MiddleW,
- TopW,
- BottomN,
- MiddleN,
- TopN,
- }
- public enum DoorStyle
- {
- None,
- North,
- West,
- }
- public enum LightPolyStyle
- {
- None,
- WallW,
- WallN,
- }
- public class UIProperties
- {
- [DescriptionAttribute("Light style"),
- CategoryAttribute("Light Settings"),
- DefaultValueAttribute(LightPolyStyle.None)]
- public LightPolyStyle LightPolyStyle { get; set; }
- [DescriptionAttribute("Climb Sheet North"),
- CategoryAttribute("Sheet Settings"),
- DefaultValueAttribute(false)]
- public bool ClimbSheetN { get; set; }
- [DescriptionAttribute("Climb Sheet West"),
- CategoryAttribute("Sheet Settings"),
- DefaultValueAttribute(false)]
- public bool ClimbSheetW { get; set; }
- [DescriptionAttribute("Is tile collidable from the north?"),
- CategoryAttribute("Collision Settings"),
- DefaultValueAttribute(false)]
- public bool CollideNorth { get; set; }
- [DescriptionAttribute("Is tile collidable from the west?"),
- CategoryAttribute("Collision Settings"),
- DefaultValueAttribute(false)]
- public bool CollideWest { get; set; }
- [DescriptionAttribute("Is tile pre-'seen' on the map (aka not starting out black)"),
- CategoryAttribute("Visibility Functions"),
- DefaultValueAttribute(false)]
- public bool PreSeen { get; set; }
- [DescriptionAttribute("Force square tile is on to ambient lighting (useful to get rid of uneven lighting on roofs, for e.g."),
- CategoryAttribute("Lighting Functions"),
- DefaultValueAttribute(false)]
- public bool ForceAmbient { get; set; }
- [DescriptionAttribute("If it is a door what direction is it facing?"),
- CategoryAttribute("Door Functions"),
- DefaultValueAttribute(DoorStyle.None)]
- public DoorStyle Door { get; set; }
- [DescriptionAttribute("If it is a window what direction is it facing?"),
- CategoryAttribute("Window Functions"),
- DefaultValueAttribute(DoorStyle.None)]
- public DoorStyle Window { get; set; }
- [DescriptionAttribute("Smashed Tile Offset (0 == this tile)"),
- CategoryAttribute("Window Functions"),
- DefaultValueAttribute(0)]
- public int SmashedTileOffset { get; set; }
- [DescriptionAttribute("Is window openable?"),
- CategoryAttribute("Window Functions"),
- DefaultValueAttribute(false)]
- public bool WindowLocked { get; set; }
- [DescriptionAttribute("Open Tile Offset (0 == this tile)"),
- CategoryAttribute("Window Functions"),
- DefaultValueAttribute(0)]
- public int OpenTileOffset { get; set; }
- [DescriptionAttribute("If it is a door frame what direction is it facing?"),
- CategoryAttribute("Door Functions"),
- DefaultValueAttribute(DoorStyle.None)]
- public DoorStyle DoorFrame { get; set; }
- [DescriptionAttribute("Is it a water source piped?"),
- CategoryAttribute("Water Functions"),
- DefaultValueAttribute(false)]
- public bool WaterPiped { get; set; }
- [DescriptionAttribute("How many units worth of water is in here? (10 = one bottle)"),
- CategoryAttribute("Water Functions"),
- DefaultValueAttribute(0)]
- public int WaterAmount { get; set; }
- [DescriptionAttribute("How many max units worth of water is in here when filled? (10 = one bottle)"),
- CategoryAttribute("Water Functions"),
- DefaultValueAttribute(0)]
- public int WaterMaxAmount { get; set; }
- [DescriptionAttribute("Can the player / NPCs sleep on the object?"),
- CategoryAttribute("Extra Functions"),
- DefaultValueAttribute(false)]
- public bool IsBed { get; set; }
- [DescriptionAttribute("Hoppable North"),
- CategoryAttribute("Wall Settings"),
- DefaultValueAttribute(false)]
- public bool HoppableN { get; set; }
- [DescriptionAttribute("Hoppable West"),
- CategoryAttribute("Wall Settings"),
- DefaultValueAttribute(false)]
- public bool HoppableW { get; set; }
- [DescriptionAttribute("If it is a wall piece, the type of wall."),
- CategoryAttribute("Wall Settings"),
- DefaultValueAttribute(WallStyle.None)]
- public WallStyle WallStyle { get; set; }
- [DescriptionAttribute("If it is a stair piece, the type of stair."),
- CategoryAttribute("Stair Settings"),
- DefaultValueAttribute(StairStyle.None)]
- public StairStyle StairStyle { get; set; }
- [DescriptionAttribute("If it is a roof piece, the type of roof piece."),
- CategoryAttribute("Roof Settings"),
- DefaultValueAttribute(RoofStyle.None)]
- public RoofStyle RoofStyle { get; set; }
- [DescriptionAttribute("Is there a floor on the tile characters can walk on?"),
- CategoryAttribute("Floor Settings"),
- DefaultValueAttribute(false)]
- public bool IsFloor { get; set; }
- [DescriptionAttribute("Is the tilepiece an indoor tile? (Cuts higher floors if stood on) Only indoor floor tiles need this."),
- CategoryAttribute("Floor Settings"),
- DefaultValueAttribute(true)]
- public bool IsIndoor { get; set; }
- [DescriptionAttribute("Is tile an overlay for a floor piece? (i.e. smooth lit decal)"),
- CategoryAttribute("Floor Settings"),
- DefaultValueAttribute(false)]
- public bool FloorOverlay { get; set; }
- [DescriptionAttribute("If it is an in-tile object, is it collidable / transparent?"),
- CategoryAttribute("Global Settings"),
- DefaultValueAttribute(TileBlockStyle.None)]
- public TileBlockStyle TileBlockStyle { get; set; }
- [DescriptionAttribute("Is tile an overlay for a wall piece? (i.e. smooth lit decal)"),
- CategoryAttribute("Wall Settings"),
- DefaultValueAttribute(false)]
- public bool WallOverlay { get; set; }
- [DescriptionAttribute("Orientation of floor height item shelves (None = no shelves)"),
- CategoryAttribute("Shelf Settings"),
- DefaultValueAttribute(Direction.None)]
- public Direction FloorItemShelf { get; set; }
- [DescriptionAttribute("Orientation of floor height item shelves (None = no shelves)"),
- CategoryAttribute("Shelf Settings"),
- DefaultValueAttribute(Direction.None)]
- public Direction TableItemShelf { get; set; }
- [DescriptionAttribute("Orientation of head height item shelves (None = no shelves)"),
- CategoryAttribute("Shelf Settings"),
- DefaultValueAttribute(Direction.None)]
- public Direction HighItemShelf { get; set; }
- [DescriptionAttribute("Name, if any, of the container the tile can store items in."),
- CategoryAttribute("Object Settings"),
- DefaultValueAttribute("")]
- public String ContainerType { get; set; }
- [DescriptionAttribute("Is it a wheeliebin?"),
- CategoryAttribute("Object Settings"),
- DefaultValueAttribute(false)]
- public bool WheelieBin { get; set; }
- public void FromProperties(Dictionary<string, string> properties)
- {
- if (properties.ContainsKey("WheelieBin"))
- {
- WheelieBin = true;
- }
- if (properties.ContainsKey("collideW"))
- {
- CollideWest = true;
- }
- if (properties.ContainsKey("collideN"))
- {
- CollideNorth = true;
- }
- if (properties.ContainsKey("climbSheetN"))
- {
- ClimbSheetN = true;
- }
- if (properties.ContainsKey("climbSheetW"))
- {
- ClimbSheetW = true;
- }
- if (properties.ContainsKey("HoppableN"))
- {
- HoppableN = true;
- }
- if (properties.ContainsKey("HoppableW"))
- {
- HoppableW = true;
- }
- if (properties.ContainsKey("ForceAmbient"))
- {
- ForceAmbient = true;
- }
- if (properties.ContainsKey("bed"))
- {
- IsBed = true;
- }
- if (properties.ContainsKey("PreSeen"))
- {
- PreSeen = true;
- }
- if (properties.ContainsKey("WindowLocked"))
- {
- WindowLocked = true;
- }
- if (properties.ContainsKey("SmashedTileOffset"))
- {
- SmashedTileOffset = Convert.ToInt32(properties["SmashedTileOffset"]);
- }
- if (properties.ContainsKey("OpenTileOffset"))
- {
- SmashedTileOffset = Convert.ToInt32(properties["OpenTileOffset"]);
- }
- if (properties.ContainsKey("LightPolyStyle"))
- {
- LightPolyStyle = (LightPolyStyle)Enum.Parse(LightPolyStyle.GetType(), properties["LightPolyStyle"]);
- }
- if (properties.ContainsKey("doorN"))
- {
- Door = DoorStyle.North;
- }
- if (properties.ContainsKey("doorW"))
- {
- Door = DoorStyle.West;
- }
- if (properties.ContainsKey("windowN"))
- {
- Window = DoorStyle.North;
- }
- if (properties.ContainsKey("windowW"))
- {
- Window = DoorStyle.West;
- }
- if (properties.ContainsKey("doorFrN"))
- {
- DoorFrame = DoorStyle.North;
- }
- if (properties.ContainsKey("doorFrW"))
- {
- DoorFrame = DoorStyle.West;
- }
- if (properties.ContainsKey("waterAmount"))
- {
- WaterAmount = Convert.ToInt32(properties["waterAmount"]);
- }
- if (properties.ContainsKey("waterMaxAmount"))
- {
- WaterMaxAmount = Convert.ToInt32(properties["waterMaxAmount"]);
- }
- if (properties.ContainsKey("waterPiped"))
- {
- WaterPiped = true;
- }
- if (properties.ContainsKey("WestRoofB"))
- {
- RoofStyle = RoofStyle.WestRoofB;
- }
- else if (properties.ContainsKey("WestRoofM"))
- {
- RoofStyle = RoofStyle.WestRoofM;
- }
- else if (properties.ContainsKey("WestRoofT"))
- {
- RoofStyle = RoofStyle.WestRoofT;
- }
- if (properties.ContainsKey("WallOverlay"))
- {
- WallOverlay = true;
- }
- if (properties.ContainsKey("FloorOverlay"))
- {
- FloorOverlay = true;
- }
- if (properties.ContainsKey("stairsBW"))
- {
- StairStyle = StairStyle.BottomW;
- }
- else if (properties.ContainsKey("stairsMW"))
- {
- StairStyle = StairStyle.MiddleW;
- }
- else if (properties.ContainsKey("stairsTW"))
- {
- StairStyle = StairStyle.TopW;
- }
- else if (properties.ContainsKey("stairsBN"))
- {
- StairStyle = StairStyle.BottomN;
- }
- else if (properties.ContainsKey("stairsMN"))
- {
- StairStyle = StairStyle.MiddleN;
- }
- else if (properties.ContainsKey("stairsTN"))
- {
- StairStyle = StairStyle.TopN;
- }
- IsIndoor = true;
- if (properties.ContainsKey("windowFW"))
- {
- WallStyle = WallStyle.WestWindow;
- properties.Remove("collideW");
- }
- else if (properties.ContainsKey("windowFN"))
- {
- WallStyle = WallStyle.NorthWindow;
- properties.Remove("collideN");
- }
- else if (properties.ContainsKey("collideW") && properties.ContainsKey("cutW") && !properties.ContainsKey("collideN") && !properties.ContainsKey("windowFW"))
- {
- WallStyle = WallStyle.WestWall;
- }
- else if (properties.ContainsKey("collideW") && properties.ContainsKey("cutW") && properties.ContainsKey("collideN"))
- {
- WallStyle = WallStyle.NorthWestCorner;
- }
- else if (properties.ContainsKey("cutN") && properties.ContainsKey("cutW") && !properties.ContainsKey("collideN") && !properties.ContainsKey("collideW"))
- {
- WallStyle = WallStyle.SouthEastCorner;
- }
- else if (properties.ContainsKey("cutN"))
- {
- WallStyle = WallStyle.NorthDoorFrame;
- }
- else if (properties.ContainsKey("cutW"))
- {
- WallStyle = WallStyle.WestDoorFrame;
- }
- if (properties.ContainsKey("WallW"))
- {
- WallStyle = WallStyle.WestWall;
- }
- else if (properties.ContainsKey("WallN"))
- {
- WallStyle = WallStyle.NorthWall;
- }
- else if (properties.ContainsKey("WallNW"))
- {
- WallStyle = WallStyle.NorthWestCorner;
- }
- else if (properties.ContainsKey("WallWTrans"))
- {
- WallStyle = WallStyle.WestWallTrans;
- }
- else if (properties.ContainsKey("WallNTrans"))
- {
- WallStyle = WallStyle.NorthWallTrans;
- }
- else if (properties.ContainsKey("WallNWTrans"))
- {
- WallStyle = WallStyle.NorthWestCornerTrans;
- }
- else if (properties.ContainsKey("WallSE"))
- {
- WallStyle = WallStyle.SouthEastCorner;
- }
- else if (properties.ContainsKey("WindowW"))
- {
- WallStyle = WallStyle.WestWindow;
- }
- else if (properties.ContainsKey("WindowN"))
- {
- WallStyle = WallStyle.NorthWindow;
- }
- else if (properties.ContainsKey("DoorWallW"))
- {
- WallStyle = WallStyle.WestDoorFrame;
- }
- else if (properties.ContainsKey("DoorWallN"))
- {
- WallStyle = WallStyle.NorthDoorFrame;
- }
- if (properties.ContainsKey("solid"))
- {
- TileBlockStyle = TileBlockStyle.Solid;
- }
- if (properties.ContainsKey("solidtrans"))
- {
- TileBlockStyle = TileBlockStyle.SolidTransparent;
- }
- if(properties.ContainsKey("container"))
- {
- ContainerType = properties["container"];
- }
- if (properties.ContainsKey("solidfloor"))
- {
- IsFloor = true;
- }
- properties.Remove("interior");
- if (properties.ContainsKey("exterior"))
- {
- IsIndoor = false;
- }
- if (properties.ContainsKey("floorS") && properties.ContainsKey("floorW"))
- {
- FloorItemShelf = Direction.SW;
- }
- else if (properties.ContainsKey("floorN") && properties.ContainsKey("floorW"))
- {
- FloorItemShelf = Direction.NW;
- }
- else if (properties.ContainsKey("floorS") && properties.ContainsKey("floorE"))
- {
- FloorItemShelf = Direction.SE;
- }
- else if (properties.ContainsKey("floorN") && properties.ContainsKey("floorE"))
- {
- FloorItemShelf = Direction.NE;
- }
- else if (properties.ContainsKey("floorE"))
- {
- FloorItemShelf = Direction.E;
- }
- else if (properties.ContainsKey("floorN"))
- {
- FloorItemShelf = Direction.N;
- }
- else if (properties.ContainsKey("floorS"))
- {
- FloorItemShelf = Direction.S;
- }
- else if (properties.ContainsKey("floorW"))
- {
- FloorItemShelf = Direction.W;
- }
- if (properties.ContainsKey("tableS") && properties.ContainsKey("tableW"))
- {
- HighItemShelf = Direction.SW;
- }
- else if (properties.ContainsKey("tableN") && properties.ContainsKey("tableW"))
- {
- HighItemShelf = Direction.NW;
- }
- else if (properties.ContainsKey("tableS") && properties.ContainsKey("tableE"))
- {
- TableItemShelf = Direction.SE;
- }
- else if (properties.ContainsKey("tableN") && properties.ContainsKey("tableE"))
- {
- TableItemShelf = Direction.NE;
- }
- else if (properties.ContainsKey("tableE"))
- {
- TableItemShelf = Direction.E;
- }
- else if (properties.ContainsKey("tableN"))
- {
- TableItemShelf = Direction.N;
- }
- else if (properties.ContainsKey("tableS"))
- {
- TableItemShelf = Direction.S;
- }
- else if (properties.ContainsKey("tableW"))
- {
- TableItemShelf = Direction.W;
- }
- if (properties.ContainsKey("shelfS") && properties.ContainsKey("shelfW"))
- {
- HighItemShelf = Direction.SW;
- }
- else if (properties.ContainsKey("shelfN") && properties.ContainsKey("shelfW"))
- {
- HighItemShelf = Direction.NW;
- }
- else if (properties.ContainsKey("shelfS") && properties.ContainsKey("shelfE"))
- {
- HighItemShelf = Direction.SE;
- }
- else if (properties.ContainsKey("shelfN") && properties.ContainsKey("shelfE"))
- {
- HighItemShelf = Direction.NE;
- }
- else if (properties.ContainsKey("shelfE"))
- {
- HighItemShelf = Direction.E;
- }
- else if (properties.ContainsKey("shelfN"))
- {
- HighItemShelf = Direction.N;
- }
- else if (properties.ContainsKey("shelfS"))
- {
- HighItemShelf = Direction.S;
- }
- else if (properties.ContainsKey("shelfW"))
- {
- HighItemShelf = Direction.W;
- }
- }
- }
- public class Tile
- {
- public Dictionary<String, String> Properties = new Dictionary<string, string>();
- public UIProperties propertyUI = new UIProperties();
- public void ChangeProperties(string label, object oldValue, object value)
- {
- /*
- if (properties.ContainsKey("WaterAmount"))
- {
- WaterAmount = Convert.ToInt32(properties["WaterAmount"]);
- }
- if (properties.ContainsKey("WaterPiped"))
- {
- WaterPiped = true;
- }
- */
- if (label == "LightPolyStyle")
- {
- Properties.Remove("LightPolyStyle");
- if ((LightPolyStyle)value != LightPolyStyle.None)
- {
- Properties["LightPolyStyle"] = ((LightPolyStyle)value).ToString();
- }
- }
- if (label == "ClimbSheetN")
- {
- Properties.Remove("climbSheetN");
- if ((bool)value == true)
- {
- Properties["climbSheetN"] = "";
- }
- }
- if (label == "ClimbSheetW")
- {
- Properties.Remove("climbSheetW");
- if ((bool)value == true)
- {
- Properties["climbSheetW"] = "";
- }
- }
- if (label == "WheelieBin")
- {
- Properties.Remove("WheelieBin");
- if ((bool)value == true)
- {
- Properties["WheelieBin"] = "";
- }
- }
- if (label == "CollideWest")
- {
- Properties.Remove("collideW");
- if ((bool)value == true)
- {
- Properties["collideW"] = "";
- }
- }
- if (label == "CollideNorth")
- {
- Properties.Remove("collideN");
- if ((bool)value == true)
- {
- Properties["collideN"] = "";
- }
- }
- if (label == "PreSeen")
- {
- Properties.Remove("PreSeen");
- if ((bool)value == true)
- {
- Properties["PreSeen"] = "";
- }
- }
- if (label == "HoppableW")
- {
- Properties.Remove("HoppableW");
- if ((bool)value == true)
- {
- Properties["HoppableW"] = "";
- }
- }
- if (label == "HoppableN")
- {
- Properties.Remove("HoppableN");
- if ((bool)value == true)
- {
- Properties["HoppableN"] = "";
- }
- }
- if (label == "IsBed")
- {
- Properties.Remove("bed");
- if ((bool)value == true)
- {
- Properties["bed"] = "";
- }
- }
- if (label == "ForceAmbient")
- {
- Properties.Remove("ForceAmbient");
- if ((bool)value == true)
- {
- Properties["ForceAmbient"] = "";
- }
- }
- if (label == "WindowLocked")
- {
- Properties.Remove("WindowLocked");
- if ((bool)value == true)
- {
- Properties["WindowLocked"] = "";
- }
- }
- if (label == "SmashedTileOffset")
- {
- Properties["SmashedTileOffset"] = ((int)value).ToString();
- }
- if (label == "OpenTileOffset")
- {
- Properties["OpenTileOffset"] = ((int)value).ToString();
- }
- if (label == "Door")
- {
- Properties.Remove("doorN");
- Properties.Remove("doorW");
- switch ((DoorStyle)value)
- {
- case DoorStyle.North:
- Properties["doorN"] = "";
- break;
- case DoorStyle.West:
- Properties["doorW"] = "";
- break;
- }
- }
- if (label == "Window")
- {
- Properties.Remove("windowN");
- Properties.Remove("windowW");
- switch ((DoorStyle)value)
- {
- case DoorStyle.North:
- Properties["windowN"] = "";
- break;
- case DoorStyle.West:
- Properties["windowW"] = "";
- break;
- }
- }
- if (label == "DoorFrame")
- {
- Properties.Remove("doorFrN");
- Properties.Remove("doorFrW");
- switch ((DoorStyle)value)
- {
- case DoorStyle.North:
- Properties["doorFrN"] = "";
- break;
- case DoorStyle.West:
- Properties["doorFrW"] = "";
- break;
- }
- }
- if (label == "WaterAmount")
- {
- Properties.Remove("waterAmount");
- if ((int)value != 0)
- {
- Properties["waterAmount"] = ((int)value).ToString();
- }
- }
- if (label == "WaterMaxAmount")
- {
- Properties.Remove("waterMaxAmount");
- if ((int)value != 0)
- {
- Properties["waterMaxAmount"] = ((int)value).ToString();
- }
- }
- else if (label == "WaterPiped")
- {
- Properties.Remove("waterPiped");
- if((bool)value == true)
- {
- Properties["waterPiped"] = "";
- }
- }
- if (label == "RoofStyle")
- {
- Properties.Remove("WestRoofB");
- Properties.Remove("WestRoofM");
- Properties.Remove("WestRoofT");
- switch ((RoofStyle)value)
- {
- case RoofStyle.WestRoofB:
- Properties["WestRoofB"] = "";
- break;
- case RoofStyle.WestRoofM:
- Properties["WestRoofM"] = "";
- break;
- case RoofStyle.WestRoofT:
- Properties["WestRoofT"] = "";
- break;
- }
- }
- if (label == "TileBlockStyle")
- {
- Properties.Remove("solid");
- Properties.Remove("solidtrans");
- switch ((TileBlockStyle)value)
- {
- case TileBlockStyle.Solid:
- Properties["solid"] = "";
- break;
- case TileBlockStyle.SolidTransparent:
- Properties["solidtrans"] = "";
- break;
- }
- }
- if (label == "IsIndoor")
- {
- Properties.Remove("interior");
- Properties.Remove("exterior");
- if (((bool)(value)) == false)
- {
- Properties["exterior"] = "";
- }
- }
- if (label == "FloorOverlay")
- {
- Properties.Remove("FloorOverlay");
- if (((bool)(value)) == true)
- {
- Properties["FloorOverlay"] = "";
- }
- }
- if (label == "WallOverlay")
- {
- Properties.Remove("WallOverlay");
- if (((bool)(value)) == true)
- {
- Properties["WallOverlay"] = "";
- }
- }
- if (label == "IsFloor")
- {
- Properties.Remove("solidfloor");
- if(((bool)(value)) == true)
- {
- Properties["solidfloor"] = "";
- }
- }
- else if(label=="WallStyle")
- {
- Properties.Remove("wall");
- Properties.Remove("WallN");
- Properties.Remove("WallW");
- Properties.Remove("WallNTrans");
- Properties.Remove("WallWTrans");
- Properties.Remove("DoorWallN");
- Properties.Remove("DoorWallW");
- Properties.Remove("WallNW");
- Properties.Remove("WallNWTrans");
- Properties.Remove("doorFrW");
- Properties.Remove("doorFrN");
- Properties.Remove("WallSE");
- Properties.Remove("WindowW");
- Properties.Remove("WindowN");
- Properties.Remove("collideW");
- Properties.Remove("collideN");
- Properties.Remove("cutW");
- Properties.Remove("cutN");
- Properties.Remove("transparentW");
- Properties.Remove("transparentN");
- Properties.Remove("windowFW");
- Properties.Remove("windowFN");
- Properties["wall"] = "";
- switch ((WallStyle)value)
- {
- case WallStyle.None:
- Properties.Remove("wall");
- break;
- case WallStyle.NorthWall:
- Properties["WallN"] = "";
- break;
- case WallStyle.WestWall:
- Properties["WallW"] = "";
- break;
- case WallStyle.NorthWallTrans:
- Properties["WallNTrans"] = "";
- break;
- case WallStyle.WestWallTrans:
- Properties["WallWTrans"] = "";
- break;
- case WallStyle.NorthDoorFrame:
- Properties["DoorWallN"] = "";
- break;
- case WallStyle.WestDoorFrame:
- Properties["DoorWallW"] = "";
- break;
- case WallStyle.NorthWestCorner:
- Properties["WallNW"] = "";
- break;
- case WallStyle.NorthWestCornerTrans:
- Properties["WallNWTrans"] = "";
- break;
- case WallStyle.SouthEastCorner:
- Properties["WallSE"] = "";
- break;
- case WallStyle.WestWindow:
- Properties["WindowW"] = "";
- break;
- case WallStyle.NorthWindow:
- Properties["WindowN"] = "";
- break;
- }
- }
- else if (label == "ContainerType")
- {
- Properties.Remove("container");
- if (((string)value).Trim().Length > 0)
- Properties["container"] = ((string)value).Trim();
- }
- else if (label == "StairStyle")
- {
- Properties.Remove("stairsBW");
- Properties.Remove("stairsMW");
- Properties.Remove("stairsTW");
- Properties.Remove("stairsBN");
- Properties.Remove("stairsMN");
- Properties.Remove("stairsTN");
- switch ((StairStyle)value)
- {
- case StairStyle.BottomW:
- Properties["stairsBW"] = "";
- break;
- case StairStyle.MiddleW:
- Properties["stairsMW"] = "";
- break;
- case StairStyle.TopW:
- Properties["stairsTW"] = "";
- break;
- case StairStyle.BottomN:
- Properties["stairsBN"] = "";
- break;
- case StairStyle.MiddleN:
- Properties["stairsMN"] = "";
- break;
- case StairStyle.TopN:
- Properties["stairsTN"] = "";
- break;
- }
- }
- }
- }
- public class Tileset
- {
- public String name;
- public int widthTiles;
- public int heightTiles;
- public List<Tile> Tiles = new List<Tile>();
- public string source;
- public void ChangeProperties(List<int> selectionList, string label, object oldValue, object value)
- {
- int n = 0;
- foreach (var tile in Tiles)
- {
- if(selectionList.Contains(n))
- {
- tile.ChangeProperties(label, oldValue, value);
- }
- n++;
- }
- }
- }
- public class TileSetSystem
- {
- public static TileSetSystem instance = new TileSetSystem();
- //public List<Tileset> Tilesets = new List<Tileset>();
- public Dictionary<String, Tileset> Tilesets = new Dictionary<String, Tileset>();
- public void Add(String filename)
- {
- String ofilename = filename;
- if (filename.Contains("/"))
- {
- filename = filename.Substring(filename.LastIndexOf("/") + 1);
- }
- if (filename.Contains("\\"))
- {
- filename = filename.Substring(filename.LastIndexOf("\\") + 1);
- }
- Tileset set = null;
- if (Tilesets.ContainsKey(filename.Replace(".png", "")))
- set = Tilesets[filename.Replace(".png", "")];
- else
- {
- set = new Tileset();
- set.source = filename;
- if (set.source.Contains("/"))
- {
- set.source = set.source.Substring(set.source.LastIndexOf("/") + 1);
- }
- if (set.source.Contains("\\"))
- {
- set.source = set.source.Substring(set.source.LastIndexOf("\\") + 1);
- }
- set.name = set.source.Replace(".png", "");
- Image bmp = Image.FromFile(ofilename);
- set.widthTiles = bmp.Width / 64;
- set.heightTiles = bmp.Height / 128;
- Tilesets[set.name] = set;
- for (int m = 0; m < set.widthTiles * set.heightTiles; m++)
- {
- Tile t = new Tile();
- set.Tiles.Add(t);
- }
- }
- }
- public void Import(String filename)
- {
- XmlDocument doc = new XmlDocument();
- doc.Load(filename);
- XmlNode n = doc.FirstChild.NextSibling.FirstChild;
- while(n != null)
- {
- if(n.Name == "tileset")
- {
- XmlNode image = n.FirstChild;
- XmlNode tile = n.FirstChild.NextSibling;
- Tileset set = null;
- if (Tilesets.ContainsKey(image.Attributes["source"].Value.Replace(".png", "")))
- set = Tilesets[image.Attributes["source"].Value.Replace(".png", "")];
- else
- {
- set = new Tileset();
- set.source = image.Attributes["source"].Value;
- if (set.source.Contains("/"))
- {
- set.source = set.source.Substring(set.source.LastIndexOf("/") + 1);
- }
- set.name = set.source.Replace(".png", "");
- Image bmp = Image.FromFile(set.source);
- set.widthTiles = bmp.Width/64;
- set.heightTiles = bmp.Height / 128;
- Tilesets[set.name] = set;
- for (int m = 0; m < set.widthTiles * set.heightTiles; m++)
- {
- Tile t = new Tile();
- set.Tiles.Add(t);
- }
- }
- while (tile != null)
- {
- XmlNode properties = tile.FirstChild;
- int id = Convert.ToInt32(tile.Attributes["id"].Value);
- Tile t = set.Tiles[id];
- if (properties != null)
- {
- XmlNode property = properties.FirstChild;
- while (property != null)
- {
- if (property.Attributes["name"].Value == "interior")
- {
- t.Properties["exterior"] = "";
- }
- else
- {
- t.Properties[property.Attributes["name"].Value] = property.Attributes["value"].Value;
- }
- property = property.NextSibling;
- }
- t.propertyUI.FromProperties(t.Properties);
- }
- tile = tile.NextSibling;
- }
- }
- n = n.NextSibling;
- }
- }
- public void SaveString(BinaryWriter binWriter, String str)
- {
- foreach (var c in str)
- {
- binWriter.Write(c);
- }
- binWriter.Write('\n');
- }
- private string ReadString(BinaryReader binReader)
- {
- String str = "";
- char c = ' ';
- while(c!='\n')
- {
- c = binReader.ReadChar();
- if( c!='\n')
- str += c;
- }
- return str;
- }
- public void Save(string fileName)
- {
- ASCIIEncoding utf8 = new ASCIIEncoding();
- using (BinaryWriter binWriter =
- new BinaryWriter(File.Open(fileName, FileMode.Create), utf8))
- {
- binWriter.Write(this.Tilesets.Count);
- foreach (var tileset in Tilesets.Values)
- {
- SaveString(binWriter, tileset.name);
- SaveString(binWriter, tileset.source);
- binWriter.Write(tileset.widthTiles);
- binWriter.Write(tileset.heightTiles);
- binWriter.Write(tileset.Tiles.Count);
- foreach (var tile in tileset.Tiles)
- {
- if (tile.propertyUI.WallStyle != WallStyle.None)
- tile.Properties["wall"] = "";
- binWriter.Write(tile.Properties.Count);
- foreach (var property in tile.Properties)
- {
- SaveString(binWriter,property.Key);
- SaveString(binWriter,property.Value);
- }
- }
- }
- binWriter.Close();
- }
- }
- public void Load(String filename)
- {
- ASCIIEncoding utf8 = new ASCIIEncoding();
- using (BinaryReader binReader =
- new BinaryReader(File.Open(filename, FileMode.Open), utf8))
- {
- filename = filename.Substring(0, filename.LastIndexOf("\\"));
- int c = binReader.ReadInt32();
- for(int n=0;n<c;n++)
- {
- Tileset t = new Tileset();
- t.name = ReadString(binReader);
- t.source = ReadString(binReader);
- t.widthTiles = binReader.ReadInt32();
- t.heightTiles = binReader.ReadInt32();
- Image bmp = Image.FromFile(filename+"\\"+t.source);
- t.widthTiles = bmp.Width / 64;
- t.heightTiles = bmp.Height / 128;
- int c2 = binReader.ReadInt32();
- for(int m=0;m<c2;m++)
- {
- Tile tile = new Tile();
- t.Tiles.Add(tile);
- int np = binReader.ReadInt32();
- for(int q=0;q<np;q++)
- {
- String p = ReadString(binReader);
- String v = ReadString(binReader);
- tile.Properties[p] = v;
- }
- tile.propertyUI.FromProperties(tile.Properties);
- }
- int c3 = t.widthTiles * t.heightTiles;
- for (int m = c2; m < c3;m++ )
- {
- Tile tile = new Tile();
- t.Tiles.Add(tile);
- }
- Tilesets[t.name] = t;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment