Example #1
0
		public Managed Parse(TextParser parser, string defaultName)
		{
			ResGroup group = new ResGroup(this.context.Resolve<IResourceManager>(), parser.ResourceFile, this.context)
				{ BasePath = parser.BasePath };
			group.Name = defaultName;
			parser.Consume("CIwResGroup");
			parser.Consume("{");
			for (;;)
			{
				var attribute = parser.Lexem;
				if (attribute == "}")
				{
					parser.Consume();
					break;
				}
				if (attribute == "name")
				{
					parser.Consume();
					group.Name = parser.ConsumeString();
					continue;
				}
				if (attribute == "shared")
				{
					parser.Consume();
					group.IsShared = parser.ConsumeBool();
					continue;
				}
				if (attribute == "useTemplate")
				{
					//TODO: make a template handler
					parser.Consume();
					var ext = parser.ConsumeString();
					var name = parser.ConsumeString();
					continue;
				}

				var relPath = attribute.Replace('/', Path.DirectorySeparatorChar);
				if (relPath.Length > 2 && relPath[0] == '.' && relPath[1] == Path.DirectorySeparatorChar)
				{
					relPath = relPath.Substring(2);
				}
				string fullPath;
				if (relPath[0] == Path.DirectorySeparatorChar)
				{
					var searchPath = parser.BasePath;
					do
					{
						var subpath = relPath.Substring(1);
						fullPath = Path.Combine(searchPath, subpath);
						if (File.Exists(fullPath))
						{
							ParseFileReference(parser, @group, fullPath);
							continue;
						}
						searchPath = Path.GetDirectoryName(searchPath);
					}
					while (!string.IsNullOrEmpty(searchPath));

					//fullPath = Path.Combine(searchPath, parser.BasePath);
					//ParseFileReference(parser, @group, fullPath);
					//continue;
				}
				else
				{
					fullPath = Path.Combine(parser.BasePath, relPath);
					//if (File.Exists(fullPath))
					{
						ParseFileReference(parser, @group, fullPath);
						continue;
					}
				}
				parser.UnknownLexemError();
			}
			return group;
		}
		//public IList<Material> Load(Stream stream)
		//{
		//    IList<Material> materials = new List<Material>();
		//    using (var source = new StreamReader(stream))
		//    {
		//        var parser = new TextParser(source, Directory.GetCurrentDirectory());
		//        materials.Add((Material)this.Parse(parser, TODO));
		//    }
		//    return materials;
		//}

		#region Public Methods and Operators

		public Managed Parse(TextParser parser, string defaultName)
		{
			Material material = this.context.Resolve<Material>();
			material.Name = defaultName;
			material.BasePath = parser.BasePath;
			parser.Consume("CIwMaterial");
			parser.Consume("{");
			for (;;)
			{
				var attribute = parser.Lexem;
				if (attribute == "}")
				{
					parser.Consume();
					break;
				}
				if (attribute == "name")
				{
					parser.Consume();
					material.Name = parser.ConsumeString();
					continue;
				}

				if (attribute == "celW")
				{
					parser.Consume();
					this.EnsureAnim(material).CelW = parser.ConsumeByte();
					continue;
				}
				if (attribute == "celH")
				{
					parser.Consume();

					this.EnsureAnim(material).CelH = parser.ConsumeByte();
					continue;
				}
				if (attribute == "celNumU")
				{
					parser.Consume();
					this.EnsureAnim(material).CelNumU = parser.ConsumeByte();
					continue;
				}

				if (attribute == "clampUV")
				{
					parser.Consume();
					material.ClampUV = parser.ConsumeBool();
					continue;
				}
				if (attribute == "specularPower")
				{
					parser.Consume();
					material.SpecularPower = parser.ConsumeByte();
					continue;
				}
				if (attribute == "celNum")
				{
					parser.Consume();
					this.EnsureAnim(material).CelNum = parser.ConsumeByte();
					continue;
				}
				if (attribute == "celPeriod")
				{
					parser.Consume();
					this.EnsureAnim(material).CelPeriod = parser.ConsumeByte();
					continue;
				}
				if (attribute == "zDepthOfs")
				{
					parser.Consume();
					material.ZDepthOfs = parser.ConsumeShort();
					continue;
				}
				if (attribute == "modulateMode")
				{
					parser.Consume();
					material.ModulateMode = parser.ConsumeEnum<ModulateMode>();
					continue;
				}
				if (attribute == "alphaMode")
				{
					parser.Consume();
					material.AlphaMode = parser.ConsumeEnum<AlphaMode>();
					continue;
				}
				if (attribute == "cullMode")
				{
					parser.Consume();
					material.CullMode = parser.ConsumeEnum<CullMode>();
					continue;
				}

				if (attribute == "colAmbient")
				{
					parser.Consume();
					material.ColAmbient = parser.ConsumeColor();
					continue;
				}
				if (attribute == "colEmissive")
				{
					parser.Consume();
					material.ColEmissive = parser.ConsumeColor();
					continue;
				}
				if (attribute == "colDiffuse")
				{
					parser.Consume();
					material.ColDiffuse = parser.ConsumeColor();
					continue;
				}
				if (attribute == "colSpecular")
				{
					parser.Consume();
					material.ColSpecular = parser.ConsumeColor();
					continue;
				}
				if (attribute == "noFog")
				{
					parser.Consume();
					material.NoFog = parser.ConsumeBool();
					continue;
				}
				if (attribute == "texture0" || attribute == "mapDiffuse")
				{
					parser.Consume();
					parser.ConsumeResourceReference(material.Texture0, "textures");
					continue;
				}
				if (attribute == "texture1")
				{
					parser.Consume();
					parser.ConsumeResourceReference(material.Texture1, "textures");
					continue;
				}
				if (attribute == "texture2")
				{
					parser.Consume();
					parser.ConsumeResourceReference(material.Texture2, "textures");
					continue;
				}
				if (attribute == "texture3")
				{
					parser.Consume();
					parser.ConsumeResourceReference(material.Texture3, "textures");
					continue;
				}
				if (attribute == "effectPreset")
				{
					parser.Consume();
					material.EffectPreset = parser.ConsumeEnum<EffectPreset>();
					continue;
				}
				if (attribute == "shadeMode")
				{
					parser.Consume();
					material.ShadeMode = parser.ConsumeEnum<ShadeMode>();
					continue;
				}
				if (attribute == "blendMode")
				{
					parser.Consume();
					material.BlendMode = parser.ConsumeEnum<BlendMode>();
					continue;
				}
				if (attribute == "shaderTechnique")
				{
					parser.Consume();
					parser.ConsumeResourceReference(material.ShaderTechnique);
					continue;
				}
				if (attribute == "vertexShader")
				{
					parser.Consume();
					material.VertexShader = parser.ConsumeString();
					continue;
				}

				parser.UnknownLexemError();
			}
			return material;
		}