public static bloResourceFinder setFinder(bloResourceFinder finder) { bloResourceFinder old = sInstance; sInstance = finder; return(old); }
static void loadCornerXml(TextureSlot slot, bloResourceFinder finder, xElement element, bloMirror defMirror) { slot.texture = finder.find <bloTexture>(element.Element("texture"), "timg"); slot.color = bloXml.loadColor(element.Element("color"), new bloColor(bloColor.cWhite)); if (!Enum.TryParse <bloMirror>(element.Element("mirror"), out slot.mirror)) { slot.mirror = 0; } }
public bloResourceFinder(bloResourceFinder finder) { if (finder == null) { throw new ArgumentNullException("finder"); } mLocalPath = finder.mLocalPath; mGlobalPaths = new List <string>(finder.mGlobalPaths.Capacity); mGlobalPaths.AddRange(finder.mGlobalPaths); mCache = new Dictionary <string, bloResource>(100, new EqualityComparer()); }
static bloResourceFinder createFinder(string localPath, IEnumerable <string> globalPaths) { var finder = new bloResourceFinder(localPath); if (globalPaths != null) { foreach (var globalPath in globalPaths) { finder.addGlobalPath(globalPath); } } bloResourceFinder.setFinder(finder); return(finder); }
public static bloScreen loadXml(Stream stream) { var settings = new XmlReaderSettings() { CheckCharacters = false }; var reader = XmlReader.Create(stream, settings); var document = new xDocument(reader); bloScreen scrn = new bloScreen(); var oldFinder = bloResourceFinder.getFinder(); var newFinder = new bloResourceFinder(oldFinder); bloResourceFinder.setFinder(newFinder); var root = document.Root; if (root == null || root.Name != "screen") { return(null); } var info = root.Element("info"); var width = (info.Element("width") | 640); var height = (info.Element("height") | 480); scrn.mRect.set(0, 0, width, height); scrn.mTintColor = bloXml.loadColor(info.Element("tint-color"), new bloColor(bloColor.cZero)); var searchPaths = root.Element("search-paths"); foreach (var searchPath in searchPaths.Elements("path")) { newFinder.addGlobalPath(searchPath); } loadXml(scrn, root); bloResourceFinder.setFinder(oldFinder); return(scrn); }
static int doCommandLine(aCommandLine cmd) { bool inputSet = false; string input = null; bloFormat inputFormat = bloFormat.Blo1; bool outputSet = false; string output = null; bloFormat outputFormat = bloFormat.Blo1; var searchPaths = new List <string>(5); foreach (var param in cmd) { switch (param.Name.ToLowerInvariant()) { case "-input": { if (param.Count < 1) { break; } inputSet = true; input = param[0]; inputFormat = (param.Count >= 2 ? parseFormat(param[1]) : bloFormat.Blo1); break; } case "-output": { if (param.Count < 1) { break; } outputSet = true; output = param[0]; outputFormat = (param.Count >= 2 ? parseFormat(param[1]) : bloFormat.Blo1); break; } case "-search-paths": { foreach (var arg in param) { searchPaths.Add(arg); } break; } } } if (!inputSet || !outputSet) { return(doUsage()); } var inputFile = Path.GetFullPath(input); var outputFile = Path.GetFullPath(output); var inputPath = Path.GetDirectoryName(inputFile); var outputPath = Path.GetDirectoryName(outputFile); var finder = new bloResourceFinder(inputPath); foreach (var searchPath in searchPaths) { finder.addGlobalPath(searchPath); } bloResourceFinder.setFinder(finder); if (!File.Exists(inputFile)) { Console.WriteLine("Could not find input file '{0}'", inputFile); return(1); } if (inputFile == outputFile) { Console.WriteLine("Input and output files cannot be the same."); return(1); } if (inputFormat == outputFormat) { File.Copy(inputFile, outputFile); return(0); } bloScreen screen = null; using (var stream = File.OpenRead(inputFile)) { switch (inputFormat) { case bloFormat.Compact: screen = bloScreen.loadCompact(stream); break; case bloFormat.Blo1: screen = bloScreen.loadBlo1(stream); break; case bloFormat.Xml: screen = bloScreen.loadXml(stream); break; default: { Console.WriteLine("Unimplemented input format {0}", inputFormat); return(1); } } } if (screen == null) { Console.WriteLine("Failed to input file '{0}'", inputFile); return(1); } using (var stream = File.Create(outputFile)) { switch (outputFormat) { case bloFormat.Compact: screen.saveCompact(stream); break; case bloFormat.Blo1: screen.saveBlo1(stream); break; case bloFormat.Xml: screen.saveXml(stream); break; default: { Console.WriteLine("Unimplemented output format {0}", outputFormat); return(1); } } } return(0); }