1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.IO;
|
---|
4 | using System.Xml;
|
---|
5 |
|
---|
6 | namespace Oni.Level
|
---|
7 | {
|
---|
8 | using Oni.Akira;
|
---|
9 | using Oni.Metadata;
|
---|
10 | using Oni.Motoko;
|
---|
11 | using Oni.Xml;
|
---|
12 |
|
---|
13 | partial class LevelImporter
|
---|
14 | {
|
---|
15 | private Motoko.TextureImporter3 textureImporter;
|
---|
16 | private TextureFormat defaultTextureFormat = TextureFormat.BGR;
|
---|
17 | private TextureFormat defaultAlphaTextureFormat = TextureFormat.RGBA;
|
---|
18 | private int maxTextureSize = 512;
|
---|
19 |
|
---|
20 | private void ReadTextures(XmlReader xml, string basePath)
|
---|
21 | {
|
---|
22 | if (xml.SkipEmpty())
|
---|
23 | return;
|
---|
24 |
|
---|
25 | string format = xml.GetAttribute("Format");
|
---|
26 | string alphaFormat = xml.GetAttribute("AlphaFormat");
|
---|
27 | string size = xml.GetAttribute("MaxSize");
|
---|
28 |
|
---|
29 | if (format != null)
|
---|
30 | defaultTextureFormat = TextureImporter.ParseTextureFormat(format);
|
---|
31 |
|
---|
32 | if (alphaFormat != null)
|
---|
33 | defaultAlphaTextureFormat = TextureImporter.ParseTextureFormat(alphaFormat);
|
---|
34 |
|
---|
35 | if (size != null)
|
---|
36 | maxTextureSize = int.Parse(size);
|
---|
37 |
|
---|
38 | xml.ReadStartElement("Textures");
|
---|
39 |
|
---|
40 | while (xml.IsStartElement())
|
---|
41 | {
|
---|
42 | if (xml.LocalName == "Import")
|
---|
43 | {
|
---|
44 | var importPath = Path.Combine(basePath, xml.ReadElementContentAsString());
|
---|
45 |
|
---|
46 | var settings = new XmlReaderSettings {
|
---|
47 | IgnoreWhitespace = true,
|
---|
48 | IgnoreProcessingInstructions = true,
|
---|
49 | IgnoreComments = true
|
---|
50 | };
|
---|
51 |
|
---|
52 | using (var importXml = XmlReader.Create(importPath, settings))
|
---|
53 | {
|
---|
54 | importXml.ReadStartElement("Oni");
|
---|
55 | ReadTextures(importXml, Path.GetDirectoryName(importPath));
|
---|
56 | importXml.ReadEndElement();
|
---|
57 | }
|
---|
58 | }
|
---|
59 | else
|
---|
60 | {
|
---|
61 | textureImporter.ReadOptions(xml, basePath);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | xml.ReadEndElement();
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|