public static void Reload(string locale = "English") { if (_textBase == null) { _textBase = new Dictionary <string, string> (); } TextAsset _localeString = Resources.Load <TextAsset> ("Locales/" + locale + "/text"); if (_localeString == null) { Debug.LogWarning("CAN'T FIND LOCALE '" + locale + "'. LOADING DEFAULT LOCALE '" + CurrentLocale + "'."); _localeString = Resources.Load <TextAsset> ("Locales/" + locale + "/text"); } NanoXMLDocument document = new NanoXMLDocument(_localeString.text); NanoXMLNode RotNode = document.RootNode; foreach (NanoXMLNode node in RotNode.SubNodes) { if (node.Name.Equals("String")) { _textBase.Add(node.GetAttribute("id").Value, NormalizeDataString(node.Value)); } } }
protected Layer(NanoXMLNode node) { //string Type = node.Name; Name = node.GetAttribute("name").Value; if (string.IsNullOrEmpty(Name)) { Name = "Layer"; } if (node.GetAttribute("width") != null) { Width = int.Parse(node.GetAttribute("width").Value, CultureInfo.InvariantCulture); } else { Width = 0; } if (node.GetAttribute("height") != null) { Height = int.Parse(node.GetAttribute("height").Value, CultureInfo.InvariantCulture); } else { Height = 0; } if (node.GetAttribute("opacity") != null) { Opacity = float.Parse(node.GetAttribute("opacity").Value, CultureInfo.InvariantCulture); } else { Opacity = 1; } if (node.GetAttribute("visible") != null) { Visible = int.Parse(node.GetAttribute("visible").Value, CultureInfo.InvariantCulture) == 1; } else { Visible = true; } NanoXMLNode propertiesNode = node["properties"]; if (propertiesNode != null) { Properties = new PropertyCollection(propertiesNode); } LayerGameObject = new GameObject(Name); }
/// <summary> /// Initialize the Window /// </summary> /// <param name="objectLayerNode">NanoXMLNode of the MapObjectLayer from with MapObject will be read</param> public static void Init(NanoXMLNode objectLayerNode) { // Get existing open window or if none, make a new one: TiledMapObjectsWindow window = (TiledMapObjectsWindow)EditorWindow.GetWindow(typeof(TiledMapObjectsWindow)); _objectLayerNode = objectLayerNode; string name = objectLayerNode.GetAttribute("name") != null? objectLayerNode.GetAttribute("name").Value: "ObjectLayer"; window.title = name; window.RebuildObjectsProperties(); }
/// <summary> /// Creates a Tile Layer from node /// </summary> /// <param name="node">XML node to parse</param> /// <param name="map">TileLayer parent Map</param> /// <param name="layerDepth">This Layer's zDepth</param> /// <param name="makeUnique">true to generate Unique Tiles</param> /// <param name="materials">List of Materials containing the TileSet textures</param> public TileLayer(NanoXMLNode node, Map map, int layerDepth, bool makeUnique, List <Material> materials) : base(node) { NanoXMLNode dataNode = node["data"]; Data = new uint[Width * Height]; LayerDepth = layerDepth; MakeUniqueTiles = makeUnique; // figure out what encoding is being used, if any, and process // the data appropriately if (dataNode.GetAttribute("encoding") != null) { string encoding = dataNode.GetAttribute("encoding").Value; if (encoding == "base64") { ReadAsBase64(dataNode); } else if (encoding == "csv") { ReadAsCsv(dataNode); } else { throw new Exception("Unknown encoding: " + encoding); } } else { // XML format simply lays out a lot of <tile gid="X" /> nodes inside of data. int i = 0; foreach (NanoXMLNode tileNode in dataNode.SubNodes) { if (tileNode.Name.Equals("tile")) { Data[i] = uint.Parse(tileNode.GetAttribute("gid").Value, CultureInfo.InvariantCulture); i++; } } if (i != Data.Length) { throw new Exception("Not enough tile nodes to fill data"); } } Initialize(map, Data, materials); }
// internal constructor because games shouldn't make their own PropertyCollections internal PropertyCollection(NanoXMLNode element) { List <Property> properties = new List <Property>(); foreach (NanoXMLNode property in element.SubNodes) { string name = property.GetAttribute("name").Value; string value = property.GetAttribute("value").Value; bool foundCopy = false; /* * A bug in Tiled will sometimes cause the file to contain identical copies of properties. * I would fix it, but I'd have to dig into the Tiled code. instead, we'll detect exact * duplicates here and log some warnings, failing only if the value is actually different. * * To repro the bug, create two maps that use the same tileset. Open the first file in Tiled * and set a property on a tile. Then open the second map and open the first back up. Look * at the propertes on the tile. It will have two or three copies of the same property. * * If you encounter the bug, you can remedy it in Tiled by closing the current file (Ctrl-F4 * or use Close from the File menu) and then reopen it. The tile will no longer have the * copies of the property. */ foreach (var p in properties) { if (p.Name == name) { if (p.RawValue == value) { foundCopy = true; } else { throw new Exception(string.Format("Multiple properties of name {0} exist with different values: {1} and {2}", name, value, p.RawValue)); } } } // we only want to add one copy of any duplicate properties if (!foundCopy) { Property p = new Property(name, value); properties.Add(p); Add(p); } } //foreach (var p in properties) //{ // values.Add(p.Name, p); //} }
/// <summary> /// Creates a MapObject from node /// </summary> /// <param name="node">NanoXMLNode XML to parse</param> /// <param name="parentObjectLayer">This MapObject's MapObjectLayer parent</param> public MapObject(NanoXMLNode node, MapObjectLayer parentObjectLayer) : base(node) { if (node.GetAttribute("name") != null) { Name = node.GetAttribute("name").Value; } else { Name = "Object"; } if (node.GetAttribute("type") != null) { Type = node.GetAttribute("type").Value; } else { Type = string.Empty; } if (node.GetAttribute("visible") != null) { Visible = int.Parse(node.GetAttribute("visible").Value, CultureInfo.InvariantCulture) == 1; } else { Visible = true; } if (node.GetAttribute("gid") != null) { GID = int.Parse(node.GetAttribute("gid").Value, CultureInfo.InvariantCulture); } else { GID = 0; } ParentObjectLayer = parentObjectLayer; NanoXMLNode propertiesNode = node["properties"]; if (propertiesNode != null) { Properties = new PropertyCollection(propertiesNode); } }
private void ReadAsCsv(NanoXMLNode dataNode) { // split the text up into lines string[] lines = dataNode.Value.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); // iterate each line for (int i = 0; i < lines.Length; i++) { // split the line into individual pieces string[] indices = lines[i].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // iterate the indices and store in our data for (int j = 0; j < indices.Length; j++) { Data[i * Width + j] = uint.Parse(indices[j], CultureInfo.InvariantCulture); } } }
/// <summary> /// c = command, c_CmdXmlParser /// </summary> public static void c_CmdXmlParser(string txt, short startIndex = 0, int count = 4) { txt = txt.Remove(startIndex, count); string strData = Encoding.UTF8.GetString(File.ReadAllBytes(txt)); NanoXMLDocument xml = new NanoXMLDocument(strData); NanoXMLNode myAttribute = xml.RootNode["text"]; if (myAttribute == null) { Console.WriteLine("[Error] myAttribute null"); } Console.WriteLine(myAttribute.Name); Console.WriteLine(myAttribute.Value); Console.WriteLine(myAttribute.GetAttribute("size").Value); }
public static void Reload(string locale = "English") { if (_textBase == null) { _textBase = new Dictionary <string, string>(); } #if UNITY_STANDALONE string path = Application.streamingAssetsPath + "/Locales/text/text.xml"; // string path = Application.streamingAssetsPath + "/Locales/" + locale + "/text/text.xml"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); XmlNodeList textsList = xmlDoc.GetElementsByTagName("String"); foreach (XmlNode textInfo in textsList) { _textBase.Add(textInfo.Attributes["id"].Value, NormalizeDataString(textInfo.InnerText)); } #else TextAsset _localeString = Resources.Load <TextAsset>("Data/Locales/" + locale + "/text/text"); if (_localeString == null) { Debug.LogWarning("CAN'T FIND LOCALE '" + locale + "'. LOADING DEFAULT LOCALE '" + _defaultLocale + "'."); _localeString = Resources.Load <TextAsset>("Data/Locales/" + _defaultLocale + "/text/text"); } NanoXMLDocument document = new NanoXMLDocument(_localeString.text); NanoXMLNode RotNode = document.RootNode; foreach (NanoXMLNode node in RotNode.SubNodes) { if (node.Name.Equals("String")) { _textBase.Add(node.GetAttribute("id").Value, NormalizeDataString(node.Value)); } } #endif }
private void ReadAsBase64(NanoXMLNode dataNode) { // get a stream to the decoded Base64 text Stream data = new MemoryStream(Convert.FromBase64String(dataNode.Value), false); // figure out what, if any, compression we're using. the compression determines // if we need to wrap our data stream in a decompression stream if (dataNode.GetAttribute("compression") != null) { string compression = dataNode.GetAttribute("compression").Value; if (compression == "gzip") { data = new Ionic.Zlib.GZipStream(data, Ionic.Zlib.CompressionMode.Decompress, false); } else if (compression == "zlib") { data = new Ionic.Zlib.ZlibStream(data, Ionic.Zlib.CompressionMode.Decompress, false); } else { throw new InvalidOperationException("Unknown compression: " + compression); } } // simply read in all the integers using (data) { using (BinaryReader reader = new BinaryReader(data)) { for (int i = 0; i < Data.Length; i++) { Data[i] = reader.ReadUInt32(); } } } }
/// <summary> /// Creates an Image Layer from node /// </summary> /// <param name="node">XML node to parse</param> /// <param name="map">ImageLayer parent Map</param> /// <param name="mapPath">Map's directory path</param> /// <param name="baseMaterial">Material to use on this SpriteRenderer</param> public ImageLayer(NanoXMLNode node, Map map, string mapPath, Material baseMaterial) : base(node) { NanoXMLNode imageNode = node["image"]; this.Image = imageNode.GetAttribute("source").Value; if (node.GetAttribute("x") != null) { Position.x = float.Parse(node.GetAttribute("x").Value, NumberStyles.Float) / (float)map.TileWidth; } if (node.GetAttribute("y") != null) { Position.y = -float.Parse(node.GetAttribute("y").Value, NumberStyles.Float) / (float)map.TileHeight; } // if the image is in any director up from us, just take the filename //if (this.Image.StartsWith("..")) // this.Image = Path.GetFileName(this.Image); if (imageNode.GetAttribute("trans") != null) { string color = imageNode.GetAttribute("trans").Value; string r = color.Substring(0, 2); string g = color.Substring(2, 2); string b = color.Substring(4, 2); this.ColorKey = new Color((byte)Convert.ToInt32(r, 16), (byte)Convert.ToInt32(g, 16), (byte)Convert.ToInt32(b, 16)); } SortingOrder = map.DefaultSortingOrder - LayerDepth; Parent = map.MapObject.transform; TileWidth = map.TileWidth; string texturePath = mapPath; if (!map.UsingStreamingAssetsPath) { // Parse the path if (Image.StartsWith("../")) { string path = Image; string rootPath = Directory.GetParent(mapPath).FullName; string appPath = Path.GetFullPath(Application.dataPath.Replace("/Assets", "")); while (path.StartsWith("../")) { rootPath = Directory.GetParent(rootPath).FullName; path = path.Remove(0, 3); } rootPath = rootPath.Replace(appPath, ""); path = Path.GetDirectoryName(path) + Path.AltDirectorySeparatorChar + Path.GetFileNameWithoutExtension(path); if (path.StartsWith("/")) { path = path.Remove(0, 1); } rootPath = rootPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (rootPath.Length > 0) { rootPath += Path.AltDirectorySeparatorChar; } texturePath = rootPath + path; } else { if (Path.GetDirectoryName(this.Image).Length > 0) { texturePath += Path.GetDirectoryName(this.Image) + Path.AltDirectorySeparatorChar; } texturePath += Path.GetFileNameWithoutExtension(this.Image); } this.Texture = Resources.Load <Texture2D>(texturePath); BuildGameObject(); } else { if (!texturePath.Contains("://")) { texturePath = "file://" + texturePath + Path.GetFileName(this.Image); } // Run Coroutine for WWW using TaskManager. new X_UniTMX.Utils.Task(LoadImageTexture(texturePath), true); } }
/// <summary> /// Creates a Map Object Layer from node /// </summary> /// <param name="node">XML node to parse</param> /// <param name="tiledMap">MapObjectLayer parent Map</param> /// <param name="layerDepth">This Layer's zDepth</param> /// <param name="materials">List of Materials containing the TileSet textures</param> public MapObjectLayer(NanoXMLNode node, Map tiledMap, int layerDepth, List <Material> materials) : base(node) { if (node.GetAttribute("color") != null) { // get the color string, removing the leading # string color = node.GetAttribute("color").Value.Substring(1); // get the RGB individually string r = color.Substring(0, 2); string g = color.Substring(2, 2); string b = color.Substring(4, 2); // convert to the color Color = new Color( (byte)int.Parse(r, NumberStyles.AllowHexSpecifier), (byte)int.Parse(g, NumberStyles.AllowHexSpecifier), (byte)int.Parse(b, NumberStyles.AllowHexSpecifier)); } LayerGameObject.transform.parent = tiledMap.MapObject.transform; LayerGameObject.transform.localPosition = new Vector3(0, 0, this.LayerDepth); LayerGameObject.isStatic = true; LayerGameObject.SetActive(Visible); Objects = new List <MapObject>(); foreach (NanoXMLNode objectNode in node.SubNodes) { if (!objectNode.Name.Equals("object")) { continue; } MapObject mapObjectContent = new MapObject(objectNode, this); mapObjectContent.ScaleObject(tiledMap.TileWidth, tiledMap.TileHeight, tiledMap.Orientation); mapObjectContent.Name = this.Name + "_" + mapObjectContent.Name; // Object names need to be unique for our lookup system, but Tiled // doesn't require unique names. string objectName = mapObjectContent.Name; int duplicateCount = 2; // if a object already has the same name... if (Objects.Find(o => o.Name.Equals(objectName)) != null) { // figure out a object name that does work do { objectName = string.Format("{0}{1}", mapObjectContent.Name, duplicateCount); duplicateCount++; } while (Objects.Find(o => o.Name.Equals(objectName)) != null); // log a warning for the user to see //Debug.LogWarning("Renaming object \"" + mapObjectContent.Name + "\" to \"" + objectName + "\" in layer \"" + Name + "\" to make a unique name."); // save that name mapObjectContent.Name = objectName; } mapObjectContent.CreateTileObject(tiledMap, Name, layerDepth, materials); AddObject(mapObjectContent); } }
/// <summary> /// Load this TileSet's information from node and builds its tiles /// </summary> /// <param name="node">NanoXMLNode to parse</param> /// <param name="mapPath">Map's directory</param> /// <param name="map">Reference to the Map this TileSet is in</param> /// <param name="isUsingStreamingPath">true if is using StreamingAssets path or HTTP URL (WWW)</param> /// <param name="onFinishedLoadingTileSet">Delegate to call when this TileSet finishes loading</param> /// <param name="firstID">First ID is a per-Map property, so External TileSets won't have this info in the node</param> public TileSet(NanoXMLNode node, string mapPath, Map map, bool isUsingStreamingPath = false, Action <TileSet> onFinishedLoadingTileSet = null, int firstID = 1) : this(node, map, firstID) { // Build tiles from this tileset string texturePath = mapPath; // Parse the path if (Image.StartsWith("../")) { string path = Image; string rootPath = mapPath; string appPath = Path.GetFullPath(Application.dataPath.Replace("/Assets", "")); while (path.StartsWith("../")) { rootPath = Directory.GetParent(rootPath).FullName; path = path.Remove(0, 3); } rootPath = rootPath.Replace(appPath + Path.DirectorySeparatorChar, ""); path = Path.GetDirectoryName(path) + Path.AltDirectorySeparatorChar + Path.GetFileNameWithoutExtension(path); if (path.StartsWith("/")) { path = path.Remove(0, 1); } rootPath = rootPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (rootPath.Length > 0) { rootPath += Path.AltDirectorySeparatorChar; } texturePath = string.Concat(rootPath, path); } else if (!Application.isWebPlayer) { if (!texturePath.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.InvariantCultureIgnoreCase)) { texturePath += Path.AltDirectorySeparatorChar; } if (texturePath.Equals("/")) { texturePath = ""; } if (Path.GetDirectoryName(this.Image).Length > 0) { texturePath += Path.GetDirectoryName(this.Image) + Path.AltDirectorySeparatorChar; } if (texturePath.Equals("/")) { texturePath = ""; } texturePath = string.Concat(texturePath, Path.GetFileNameWithoutExtension(this.Image)); } else { texturePath = Path.Combine(mapPath, Path.GetFileName(this.Image)); } OnFinishedLoadingTileSet = onFinishedLoadingTileSet; //Debug.Log(texturePath); if (!isUsingStreamingPath) { //texturePath = string.Concat(texturePath, Path.GetExtension(this.Image)); this.Texture = Resources.Load <Texture2D>(texturePath); BuildTiles(map.TileWidth); } else { texturePath = string.Concat(texturePath, Path.GetExtension(this.Image)); if (!texturePath.Contains("://")) { texturePath = string.Concat("file://", texturePath); } //Debug.Log(texturePath); // Run Coroutine for WWW using TaskManager. new X_UniTMX.Utils.Task(LoadTileSetTexture(texturePath, map.TileWidth), true); } }
void ShowObjectsWindow(NanoXMLNode objectLayerNode) { TiledMapObjectsWindow.Init(objectLayerNode); }
/// <summary> /// Creates a TileObject from node /// </summary> /// <param name="node">XML node to parse</param> public TileObject(NanoXMLNode node) : base(node) { }
/// <summary> /// Only derived classes should use this constructor. Creates an Object from a XML node /// </summary> /// <param name="node">XML node to parse</param> protected Object(NanoXMLNode node) { if (node.GetAttribute("rotation") != null) { Rotation = 360 - float.Parse(node.GetAttribute("rotation").Value, CultureInfo.InvariantCulture); } else { Rotation = 0; } // values default to 0 if the attribute is missing from the node float x = node.GetAttribute("x") != null?float.Parse(node.GetAttribute("x").Value, CultureInfo.InvariantCulture) : 0; float y = node.GetAttribute("y") != null?float.Parse(node.GetAttribute("y").Value, CultureInfo.InvariantCulture) : 0; float width = node.GetAttribute("width") != null?float.Parse(node.GetAttribute("width").Value, CultureInfo.InvariantCulture) : 1; float height = node.GetAttribute("height") != null?float.Parse(node.GetAttribute("height").Value, CultureInfo.InvariantCulture) : 1; Bounds = new Rect(x, y, width, height); this.ObjectType = ObjectType.Box; // stores a string of points to parse out if this object is a polygon or polyline string pointsAsString = null; if (node["ellipse"] != null) { ObjectType = ObjectType.Ellipse; } // if there's a polygon node, it's a polygon object else if (node["polygon"] != null) { pointsAsString = node["polygon"].GetAttribute("points").Value; ObjectType = ObjectType.Polygon; } // if there's a polyline node, it's a polyline object else if (node["polyline"] != null) { pointsAsString = node["polyline"].GetAttribute("points").Value; ObjectType = ObjectType.Polyline; } // if we have some points to parse, we do that now if (pointsAsString != null) { // points are separated first by spaces Points = new List <Vector2>(); string[] pointPairs = pointsAsString.Split(' '); foreach (string p in pointPairs) { // then we split on commas string[] coords = p.Split(','); // then we parse the X/Y coordinates Points.Add(new Vector2( float.Parse(coords[0], CultureInfo.InvariantCulture), float.Parse(coords[1], CultureInfo.InvariantCulture))); } } }
private void parseXmlData() { TextAsset _xmlString = Resources.Load <TextAsset>("Data/GameFlow"); NanoXMLDocument document = new NanoXMLDocument(_xmlString.text); NanoXMLNode RotNode = document.RootNode; foreach (NanoXMLNode node in RotNode.SubNodes) { if (node.Name.Equals("screens")) { foreach (NanoXMLNode nodeScreens in node.SubNodes) { string sceneName = nodeScreens.GetAttribute("name").Value; SceneData sceneData = new SceneData(sceneName); string preloadNextScene = nodeScreens.GetAttribute("preloadNextScene").Value; if (!String.IsNullOrEmpty(preloadNextScene)) { sceneData.PreloadSceneName = convertSceneNameToID(preloadNextScene); } string designResolutionWidth = nodeScreens.GetAttribute("DesignResolutionWidth").Value; if (!String.IsNullOrEmpty(designResolutionWidth)) { sceneData.DesignResolutionWidth = Int32.Parse(designResolutionWidth); } string designResolutionHeight = nodeScreens.GetAttribute("DesignResolutionHeight").Value; if (!String.IsNullOrEmpty(designResolutionHeight)) { sceneData.DesignResolutionHeight = Int32.Parse(designResolutionHeight); } string designMatchWidthOrHeight = nodeScreens.GetAttribute("DesignMatchWidthOrHeight").Value; if (!String.IsNullOrEmpty(designMatchWidthOrHeight)) { sceneData.DesignMatchWidthOrHeight = float.Parse(designMatchWidthOrHeight); } if (nodeScreens.Name.Equals("screen")) { foreach (NanoXMLNode nodeScreensScreen in nodeScreens.SubNodes) { string formName = nodeScreensScreen.GetAttribute("name").Value.ToString(); UIConsts.FORM_ID formID = (UIConsts.FORM_ID)System.Enum.Parse(typeof(UIConsts.FORM_ID), formName); int formType = int.Parse(nodeScreensScreen.GetAttribute("type").Value); EFormCreationMethod creationMethod = EFormCreationMethod.Static; string path = UIConsts.DEFAULT_UI_PATH + formName; NanoXMLAttribute attrPath = nodeScreensScreen.GetAttribute("path"); if (attrPath != null) { path = attrPath.Value; } int faderType = 1; //show transparrent NanoXMLAttribute attrFader = nodeScreensScreen.GetAttribute("fader"); if (attrFader != null) { faderType = int.Parse(attrFader.Value); } NanoXMLAttribute attr = nodeScreensScreen.GetAttribute("creation"); if (attr != null) { if (!string.IsNullOrEmpty(attr.Value)) { if (attr.Value.ToLower() == "static") { creationMethod = EFormCreationMethod.Static; } else if (attr.Value.ToLower() == "dynamic") { creationMethod = EFormCreationMethod.Dynamic; } } } FormData formData = new FormData(formType, formID, path, faderType, creationMethod); sceneData.Forms.Add(formData); if (formType == 1) { sceneData.Menu = formID; } } } _scenesData.Add(sceneName, sceneData); } } } }
/// <summary> /// Load this TileSet's information from node /// </summary> /// <param name="node">NanoXMLNode to parse</param> /// <param name="map">Reference to the Map this TileSet is in</param> /// <param name="firstGID">First ID is a per-Map property, so External TileSets won't have this info in the node</param> protected TileSet(NanoXMLNode node, Map map, int firstGID = 1) { if (node.GetAttribute("firstgid") == null || !int.TryParse(node.GetAttribute("firstgid").Value, out FirstId)) { FirstId = firstGID; } //this.FirstId = int.Parse(node.GetAttribute("firstgid").Value, CultureInfo.InvariantCulture); this.Name = node.GetAttribute("name").Value; this.TileWidth = int.Parse(node.GetAttribute("tilewidth").Value, CultureInfo.InvariantCulture); this.TileHeight = int.Parse(node.GetAttribute("tileheight").Value, CultureInfo.InvariantCulture); if (node.GetAttribute("spacing") != null) { this.Spacing = int.Parse(node.GetAttribute("spacing").Value, CultureInfo.InvariantCulture); } if (node.GetAttribute("margin") != null) { this.Margin = int.Parse(node.GetAttribute("margin").Value, CultureInfo.InvariantCulture); } NanoXMLNode tileOffset = node["tileoffset"]; if (tileOffset != null) { this.TileOffsetX = int.Parse(tileOffset.GetAttribute("x").Value, CultureInfo.InvariantCulture); this.TileOffsetY = -int.Parse(tileOffset.GetAttribute("y").Value, CultureInfo.InvariantCulture); } NanoXMLNode imageNode = node["image"]; this.Image = imageNode.GetAttribute("source").Value; // if the image is in any director up from us, just take the filename //if (this.Image.StartsWith("..")) // this.Image = Path.GetFileName(this.Image); if (imageNode.GetAttribute("trans") != null) { string color = imageNode.GetAttribute("trans").Value; string r = color.Substring(0, 2); string g = color.Substring(2, 2); string b = color.Substring(4, 2); this.ColorKey = new Color((byte)Convert.ToInt32(r, 16), (byte)Convert.ToInt32(g, 16), (byte)Convert.ToInt32(b, 16)); } foreach (NanoXMLNode subNode in node.SubNodes) { if (subNode.Name.Equals("tile")) { int id = this.FirstId + int.Parse(subNode.GetAttribute("id").Value, CultureInfo.InvariantCulture); // Load Tile Properties, if any NanoXMLNode propertiesNode = subNode["properties"]; if (propertiesNode != null) { PropertyCollection properties = new PropertyCollection(propertiesNode); //Property.ReadProperties(propertiesNode); this.TileProperties.Add(id, properties); } // Load Tile Animation, if any NanoXMLNode animationNode = subNode["animation"]; if (animationNode != null) { TileAnimation _tileAnimation = new TileAnimation(); foreach (NanoXMLNode frame in animationNode.SubNodes) { if (!frame.Name.Equals("frame")) { continue; } int tileid = int.Parse(frame.GetAttribute("tileid").Value, CultureInfo.InvariantCulture) + FirstId; int duration = int.Parse(frame.GetAttribute("duration").Value, CultureInfo.InvariantCulture); _tileAnimation.AddTileFrame(tileid, duration); } this.AnimatedTiles.Add(id, _tileAnimation); } // Load Tile Objects, if any NanoXMLNode objectsNode = subNode["objectgroup"]; if (objectsNode != null) { List <TileObject> tileObjects = new List <TileObject>(); foreach (NanoXMLNode tileObjNode in objectsNode.SubNodes) { TileObject tObj = new TileObject(tileObjNode); tObj.ScaleObject(map.TileWidth, map.TileHeight, map.Orientation); tileObjects.Add(tObj); } // There's a bug in Tiled 0.10.1- where the objectgroup node won't go away even if you delete all objects from a tile's collision group. if (tileObjects.Count > 0) { TilesObjects.Add(id, tileObjects); } } } } }
private void ReadPropertiesAndVariables() { if (_tiledMapComponent.tileLayers != null && _tiledMapComponent.MakeUniqueTiles != null && _tiledMapComponent.tileLayers.Length > _tiledMapComponent.MakeUniqueTiles.Length) { _changedMap = true; } if (_changedMap || _tiledMapComponent.mapProperties == null || _tiledMapComponent.objectLayerNodes == null || _tiledMapComponent.tileLayersProperties == null || _tiledMapComponent.objectLayersProperties == null || _tiledMapComponent.imageLayersProperties == null || _tiledMapComponent.objectLayers == null || _tiledMapComponent.generateCollider == null || _tiledMapComponent.collidersIs2D == null || _tiledMapComponent.collidersWidth == null || _tiledMapComponent.collidersZDepth == null || _tiledMapComponent.collidersIsInner == null || _tiledMapComponent.collidersIsTrigger == null || _tiledMapComponent.tileLayers == null || _tiledMapComponent.imageLayers == null || _tiledMapComponent.tileLayersFoldoutProperties == null || _tiledMapComponent.objectLayersFoldoutProperties == null || _tiledMapComponent.imageLayersFoldoutProperties == null || _tiledMapComponent.MakeUniqueTiles == null ) { NanoXMLDocument document = new NanoXMLDocument(_tiledMapComponent.MapTMX.text); NanoXMLNode mapNode = document.RootNode; List <Property> mapProperties = new List <Property>(); List <NanoXMLNode> objectLayerNodes = new List <NanoXMLNode>(); List <string> objectLayers = new List <string>(); List <bool> generateCollider = new List <bool>(); List <bool> collidersIs2D = new List <bool>(); List <float> collidersWidth = new List <float>(); List <float> collidersZDepth = new List <float>(); List <bool> collidersIsInner = new List <bool>(); List <bool> collidersIsTrigger = new List <bool>(); List <string> tileLayers = new List <string>(); List <string> imageLayers = new List <string>(); List <bool> makeUniqueTiles = new List <bool>(); List <bool> tileLayersFoldoutProperties = new List <bool>(); List <bool> objectLayersFoldoutProperties = new List <bool>(); List <bool> imageLayersFoldoutProperties = new List <bool>(); Dictionary <int, List <Property> > tileLayersProperties = new Dictionary <int, List <Property> >(); Dictionary <int, List <Property> > objectLayersProperties = new Dictionary <int, List <Property> >(); Dictionary <int, List <Property> > imageLayersProperties = new Dictionary <int, List <Property> >(); foreach (NanoXMLNode layerNode in mapNode.SubNodes) { if (layerNode.Name.Equals("properties")) { foreach (var property in layerNode.SubNodes) { mapProperties.Add( new Property( property.GetAttribute("name").Value, property.GetAttribute("value").Value ) ); } } if (layerNode.Name.Equals("objectgroup")) { objectLayerNodes.Add(layerNode); objectLayers.Add(layerNode.GetAttribute("name").Value); generateCollider.Add(false); collidersIs2D.Add(true); collidersWidth.Add(1); collidersZDepth.Add(0); collidersIsInner.Add(false); collidersIsTrigger.Add(false); // properties objectLayersFoldoutProperties.Add(false); objectLayersProperties.Add(objectLayerNodes.Count - 1, new List <Property>()); foreach (var subNodes in layerNode.SubNodes) { if (subNodes.Name.Equals("properties")) { foreach (var property in subNodes.SubNodes) { objectLayersProperties[objectLayerNodes.Count - 1].Add( new Property( property.GetAttribute("name").Value, property.GetAttribute("value").Value ) ); } } } } if (layerNode.Name.Equals("layer")) { tileLayers.Add(layerNode.GetAttribute("name").Value); // Make Unique Tiles makeUniqueTiles.Add(false); // properties tileLayersFoldoutProperties.Add(false); tileLayersProperties.Add(tileLayers.Count - 1, new List <Property>()); foreach (var subNodes in layerNode.SubNodes) { if (subNodes.Name.Equals("properties")) { foreach (var property in subNodes.SubNodes) { tileLayersProperties[tileLayers.Count - 1].Add( new Property( property.GetAttribute("name").Value, property.GetAttribute("value").Value ) ); } } } } if (layerNode.Name.Equals("imagelayer")) { imageLayers.Add(layerNode.GetAttribute("name").Value); // properties imageLayersFoldoutProperties.Add(false); imageLayersProperties.Add(imageLayers.Count - 1, new List <Property>()); foreach (var subNodes in layerNode.SubNodes) { if (subNodes.Name.Equals("properties")) { foreach (var property in subNodes.SubNodes) { imageLayersProperties[imageLayers.Count - 1].Add( new Property( property.GetAttribute("name").Value, property.GetAttribute("value").Value ) ); } } } } } if (_changedMap || _tiledMapComponent.mapProperties == null) { _tiledMapComponent.mapProperties = mapProperties.ToArray(); } if (_changedMap || _tiledMapComponent.objectLayerNodes == null) { _tiledMapComponent.objectLayerNodes = objectLayerNodes.ToArray(); } if (_changedMap || _tiledMapComponent.tileLayersProperties == null) { _tiledMapComponent.tileLayersProperties = new Dictionary <int, List <Property> >(tileLayersProperties); } if (_changedMap || _tiledMapComponent.objectLayersProperties == null) { _tiledMapComponent.objectLayersProperties = objectLayersProperties; } if (_changedMap || _tiledMapComponent.imageLayersProperties == null) { _tiledMapComponent.imageLayersProperties = imageLayersProperties; } if (_changedMap || _tiledMapComponent.objectLayers == null) { _tiledMapComponent.objectLayers = objectLayers.ToArray(); } if (_changedMap || _tiledMapComponent.generateCollider == null) { _tiledMapComponent.generateCollider = generateCollider.ToArray(); } if (_changedMap || _tiledMapComponent.collidersIs2D == null) { _tiledMapComponent.collidersIs2D = collidersIs2D.ToArray(); } if (_changedMap || _tiledMapComponent.collidersWidth == null) { _tiledMapComponent.collidersWidth = collidersWidth.ToArray(); } if (_changedMap || _tiledMapComponent.collidersZDepth == null) { _tiledMapComponent.collidersZDepth = collidersZDepth.ToArray(); } if (_changedMap || _tiledMapComponent.collidersIsInner == null) { _tiledMapComponent.collidersIsInner = collidersIsInner.ToArray(); } if (_changedMap || _tiledMapComponent.collidersIsTrigger == null) { _tiledMapComponent.collidersIsTrigger = collidersIsTrigger.ToArray(); } if (_changedMap || _tiledMapComponent.tileLayers == null) { _tiledMapComponent.tileLayers = tileLayers.ToArray(); } if (_changedMap || _tiledMapComponent.imageLayers == null) { _tiledMapComponent.imageLayers = imageLayers.ToArray(); } if (_changedMap || _tiledMapComponent.tileLayersFoldoutProperties == null) { _tiledMapComponent.tileLayersFoldoutProperties = tileLayersFoldoutProperties.ToArray(); } if (_changedMap || _tiledMapComponent.objectLayersFoldoutProperties == null) { _tiledMapComponent.objectLayersFoldoutProperties = objectLayersFoldoutProperties.ToArray(); } if (_changedMap || _tiledMapComponent.imageLayersFoldoutProperties == null) { _tiledMapComponent.imageLayersFoldoutProperties = imageLayersFoldoutProperties.ToArray(); } if (_changedMap || _tiledMapComponent.MakeUniqueTiles == null) { _tiledMapComponent.MakeUniqueTiles = makeUniqueTiles.ToArray(); } if (_changedMap) { _changedMap = false; } } }