public static object readPlist(Stream stream, PlistType type) { if (type == PlistType.Auto) { type = getPlistType(stream); stream.Seek(0, SeekOrigin.Begin); } if (type == PlistType.Binary) { using (var reader = new BinaryReader(stream)) { var data = reader.ReadBytes((int)reader.BaseStream.Length); return(readBinary(data)); } } else { var xml = new XmlDocument { XmlResolver = null }; xml.Load(stream); return(readXml(xml)); } }
public KeyAttributes(string keyName, PlistType pType, string defaultsTo, Presence presence = Presence.Optional) { KeyName = keyName; Presence = presence; PType = pType; DefaultsTo = defaultsTo; }
public static PlistType GetPlistType(Stream stream) { var magicHeader = new byte[8]; stream.Read(magicHeader, 0, 8); PlistType plistType = BitConverter.ToInt64(magicHeader, 0) == MagicHeader ? PlistType.Binary : PlistType.Xml; stream.Seek(0, SeekOrigin.Begin); return(plistType); }
public static object ReadStream (Stream stream, PlistType type = PlistType.Auto) { if (type == PlistType.Auto) type = GetPlistType(stream); switch (type) { case PlistType.Binary: using (var reader = new BinaryReader(stream)) return new Plist().ReadBinary(reader.ReadBytes((int)reader.BaseStream.Length)); case PlistType.Xml: var xml = new XmlDocument { XmlResolver = null }; xml.Load(stream); return new Plist().ReadXml(xml); } throw new ArgumentOutOfRangeException("type"); }
public void InitWithStream(Stream stream, CCTexture2D texture) { var document = new PlistDocument(); try { document.LoadFromXmlFile(stream); plistType = GetPlistType(document.Root.AsDictionary); } catch (Exception) { throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the sprite sheet definition file from stream")); } PlistDictionary dict = document.Root.AsDictionary; InitWithDictionary(dict, texture); }
public static object ReadStream(Stream stream, PlistType type = PlistType.Auto) { if (type == PlistType.Auto) { type = GetPlistType(stream); } switch (type) { case PlistType.Binary: using (var reader = new BinaryReader(stream)) return(new Plist().ReadBinary(reader.ReadBytes((int)reader.BaseStream.Length))); case PlistType.Xml: var xml = new XmlDocument { XmlResolver = null }; xml.Load(stream); return(new Plist().ReadXml(xml)); } throw new ArgumentOutOfRangeException("type"); }
public object ReadPlist(Stream stream, PlistType type) { if (type == PlistType.Auto) { type = GetPlistType(stream); stream.Seek(0, SeekOrigin.Begin); } if (type == PlistType.Binary) { using (BinaryReader reader = new BinaryReader(stream)) { byte[] data = reader.ReadBytes((int)reader.BaseStream.Length); return(ReadBinary(data)); } } else { XmlDocument xml = new XmlDocument(); xml.XmlResolver = null; xml.Load(stream); return(ReadXml(xml)); } }
public void InitWithFile(string fileName) { PlistDocument document = CCContentManager.SharedContentManager.Load <PlistDocument>(fileName); var dict = document.Root.AsDictionary; var texturePath = string.Empty; plistFilePath = string.Empty; plistType = GetPlistType(dict); if (plistType == PlistType.SpriteKit) { var images = dict.ContainsKey("images") ? dict ["images"].AsArray : null; var imageDict = images [0].AsDictionary; if (imageDict != null) { // try to read texture file name from meta data if (imageDict.ContainsKey("path")) { texturePath = imageDict ["path"].AsString; } } } else { var metadataDict = dict.ContainsKey("metadata") ? dict ["metadata"].AsDictionary : null; if (metadataDict != null) { // try to read texture file name from meta data if (metadataDict.ContainsKey("textureFileName")) { texturePath = metadataDict ["textureFileName"].AsString; } } } if (!string.IsNullOrEmpty(texturePath)) { // build texture path relative to plist file texturePath = CCFileUtils.FullPathFromRelativeFile(texturePath, fileName); } else { // build texture path by replacing file extension texturePath = fileName; // remove .xxx texturePath = CCFileUtils.RemoveExtension(texturePath); CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", texturePath); } plistFilePath = Path.GetDirectoryName(texturePath); CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(texturePath); if (pTexture != null) { InitWithDictionary(dict, pTexture); } else { CCLog.Log("CCSpriteSheet: Couldn't load texture"); } }
public void InitWithFile(string fileName) { PlistDocument document = CCContentManager.SharedContentManager.Load<PlistDocument>(fileName); var dict = document.Root.AsDictionary; var texturePath = string.Empty; plistFilePath = string.Empty; plistType = GetPlistType (dict); if (plistType == PlistType.SpriteKit) { var images = dict.ContainsKey ("images") ? dict ["images"].AsArray : null; var imageDict = images [0].AsDictionary; if (imageDict != null) { // try to read texture file name from meta data if (imageDict.ContainsKey ("path")) { texturePath = imageDict ["path"].AsString; } } } else { var metadataDict = dict.ContainsKey ("metadata") ? dict ["metadata"].AsDictionary : null; if (metadataDict != null) { // try to read texture file name from meta data if (metadataDict.ContainsKey ("textureFileName")) { texturePath = metadataDict ["textureFileName"].AsString; } } } if (!string.IsNullOrEmpty(texturePath)) { // build texture path relative to plist file texturePath = CCFileUtils.FullPathFromRelativeFile(texturePath, fileName); } else { // build texture path by replacing file extension texturePath = fileName; // remove .xxx texturePath = CCFileUtils.RemoveExtension(texturePath); CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", texturePath); } plistFilePath = Path.GetDirectoryName (texturePath); CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(texturePath); if (pTexture != null) { InitWithDictionary(dict, pTexture); } else { CCLog.Log("CCSpriteSheet: Couldn't load texture"); } }