/* * GroupTextureManager.cs * Authors: Karl Orosz * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using System.IO; using System.Text; namespace StarJack { class GroupTextureManager { private static String mRootDirectory; public static String RootDirectory{ get{return mRootDirectory;} set{mRootDirectory = value;} } private static Dictionary> mGroupList; static GroupTextureManager (){ mGroupList = new Dictionary>(); mRootDirectory = Entity.RootDirectory; } public static Dictionary GetGroupTexture(string name) { if (mGroupList.ContainsKey(name)) { return mGroupList[name]; } else { if (LoadGroup(name)) { return mGroupList[name]; } else { return null; } } } private static bool LoadGroup(string name) { if (name == null || name.Equals("")) { return false; } else { if (Directory.Exists(mRootDirectory + @"\Content\Texture\" + name)) { Dictionary mGroupTextures = new Dictionary(); string[] assets = Directory.GetFiles(mRootDirectory + @"\Content\Texture\" + name); foreach (string s in assets) { if (s.Contains(".xnb")) { int last = s.LastIndexOf(@"\"); string assetName = s.Substring(last + 1, s.Length - 4 - last - 1); mGroupTextures.Add(assetName, new TextureInfo(assetName, name)); } } mGroupList.Add(name, mGroupTextures); } else { #if DEBUG throw new Exception("Missing Group Folder" + mRootDirectory + @"\Content\Texture\" + name); #else return false; #endif } } return true; } } }