Esempio n. 1
0
        private void LoadSpritesInternal()
        {
            Debug.LogWarning("Loading sprites");

            foreach (XmlNode childNode in root)
            {
                if (childNode.Name != "SpriteAtlas")
                {
                    continue;
                }

                var atlasName = XmlUtil.GetStringAttribute(childNode, "name");
                if (spriteAtlases.ContainsKey(atlasName))
                {
                    throw new ParseException(String.Format("Duplicate atlas name \"{0}\"", atlasName), childNode);
                }

                Debug.LogWarningFormat("Generating atlas \"{0}\"", atlasName);

                var atlasPacker = new AtlasPacker();

                int count = 0;
                foreach (XmlNode spriteNode in childNode.ChildNodes)
                {
                    var path = spriteNode.InnerText;
                    if (fileWatcher != null)
                    {
                        fileWatcher.WatchFile(path);
                    }

                    var name = XmlUtil.GetStringAttribute(spriteNode, "name");
                    Debug.LogWarningFormat("Found definition for sprite \"{0}\" in atlas \"{1}\"", name, atlasName);

                    var fullPath = Path.Combine(sapphirePath, path);

                    if (!File.Exists(fullPath))
                    {
                        throw new FileNotFoundException(String.Format("Sprite at path \"{0}\" not found!", fullPath), fullPath);
                    }

                    atlasPacker.AddSprite(name, fullPath);
                    count++;
                }

                Debug.LogWarningFormat("Added {0} sprites to atlas \"{1}\"", count, atlasName);

                try
                {
                    spriteAtlases[atlasName] = atlasPacker.GenerateAtlas(atlasName);
                }
                catch (AtlasPacker.TooManySprites)
                {
                    ErrorLogger.LogError("Too many sprites in atlas \"" + atlasName + "\", move some sprites to a new atlas!");
                    break;
                }

                Debug.LogWarningFormat("Atlas \"{0}\" generated", atlasName);
            }
        }
Esempio n. 2
0
        private void Reload(bool autoReloadOnChange)
        {
            isValid = true;

            Dispose();

            modules[ModuleClass.MainMenu]    = new List <SkinModule>();
            modules[ModuleClass.InGame]      = new List <SkinModule>();
            modules[ModuleClass.MapEditor]   = new List <SkinModule>();
            modules[ModuleClass.AssetEditor] = new List <SkinModule>();

            document = new XmlDocument();
            document.LoadXml(File.ReadAllText(skinXmlPath));

            if (fileWatcher != null)
            {
                fileWatcher.Dispose();
                fileWatcher = null;
            }

            if (autoReloadOnChange)
            {
                fileWatcher = new FileWatcher(sapphirePath);
                fileWatcher.WatchFile("skin.xml");
            }

            root = document.SelectSingleNode("/SapphireSkin");
            if (root == null)
            {
                isValid = false;
                throw new ParseException("Skin missing root SapphireSkin node at " + sapphirePath, null);
            }

            name   = XmlUtil.GetStringAttribute(root, "name");
            author = XmlUtil.GetStringAttribute(root, "author");

            LoadSkinSettings();
            LoadSprites();
            LoadColors();
            LoadModules();
        }