pawsFrameDrawable::pawsFrameDrawable(csRef<iDocumentNode> node) : scfImplementationType (this) { defaultTransparentColourBlue = -1; defaultTransparentColourGreen = -1; defaultTransparentColourRed = -1; defaultAlphaValue = 0; // Read off the image and file vars imageFileLocation = node->GetAttributeValue("file"); resourceName = node->GetAttributeValue("resource"); csString typeStr(node->GetAttributeValue("type")); type = FDT_FULL; if (typeStr == "horizontal") type = FDT_HORIZONTAL; else if (typeStr == "vertical") type = FDT_VERTICAL; csRef<iDocumentNodeIterator> iter = node->GetNodes(); while ( iter->HasNext() ) { csRef<iDocumentNode> childNode = iter->Next(); // Read the default alpha value. if (strcmp(childNode->GetValue(), "alpha") == 0) defaultAlphaValue = childNode->GetAttributeValueAsInt("level"); // Read the default transparent colour. else if (strcmp(childNode->GetValue(), "trans") == 0) { defaultTransparentColourRed = childNode->GetAttributeValueAsInt("r"); defaultTransparentColourGreen = childNode->GetAttributeValueAsInt("g"); defaultTransparentColourBlue = childNode->GetAttributeValueAsInt("b"); } else if (strcmp(childNode->GetValue(), "top_left") == 0) LoadPiece(childNode, FDP_TOP_LEFT); else if (strcmp(childNode->GetValue(), "top") == 0) LoadPiece(childNode, FDP_TOP); else if (strcmp(childNode->GetValue(), "top_right") == 0) LoadPiece(childNode, FDP_TOP_RIGHT); else if (strcmp(childNode->GetValue(), "left") == 0) LoadPiece(childNode, FDP_LEFT); else if (strcmp(childNode->GetValue(), "middle") == 0) LoadPiece(childNode, FDP_MIDDLE); else if (strcmp(childNode->GetValue(), "right") == 0) LoadPiece(childNode, FDP_RIGHT); else if (strcmp(childNode->GetValue(), "bottom_left") == 0) LoadPiece(childNode, FDP_BOTTOM_LEFT); else if (strcmp(childNode->GetValue(), "bottom") == 0) LoadPiece(childNode, FDP_BOTTOM); else if (strcmp(childNode->GetValue(), "bottom_right") == 0) LoadPiece(childNode, FDP_BOTTOM_RIGHT); } }
pawsImageDrawable::pawsImageDrawable(csRef<iDocumentNode> node) : scfImplementationType (this) { debugImageErrors = true; defaultTransparentColourBlue = -1; defaultTransparentColourGreen = -1; defaultTransparentColourRed = -1; defaultAlphaValue = 0; // Read off the image and file vars imageFileLocation = node->GetAttributeValue( "file" ); resourceName = node->GetAttributeValue( "resource" ); tiled = node->GetAttributeValueAsBool("tiled"); csRef<iDocumentNodeIterator> iter = node->GetNodes(); while ( iter->HasNext() ) { csRef<iDocumentNode> childNode = iter->Next(); // Read the texture rectangle for this image. if ( strcmp( childNode->GetValue(), "texturerect" ) == 0 ) { textureRectangle.xmin = childNode->GetAttributeValueAsInt("x"); textureRectangle.ymin = childNode->GetAttributeValueAsInt("y"); int width = childNode->GetAttributeValueAsInt("width"); int height = childNode->GetAttributeValueAsInt("height"); textureRectangle.SetSize(width, height); } // Read the default alpha value. if ( strcmp( childNode->GetValue(), "alpha" ) == 0 ) { defaultAlphaValue = childNode->GetAttributeValueAsInt("level"); } // Read the default transparent colour. if ( strcmp( childNode->GetValue(), "trans" ) == 0 ) { defaultTransparentColourRed = childNode->GetAttributeValueAsInt("r"); defaultTransparentColourGreen = childNode->GetAttributeValueAsInt("g"); defaultTransparentColourBlue = childNode->GetAttributeValueAsInt("b"); } } PreparePixmap(); }
void OptimiseData::ParseMeshObj(csArray<csString>& libsNeeded, csArray<csString>& materialsNeeded, csString& mapInPath, csRef<iDocumentNode> meshobj) { csRef<iDocumentNodeIterator> meshobjs = meshobj->GetNodes("meshobj"); while(meshobjs->HasNext()) { ParseMeshObj(libsNeeded, materialsNeeded, mapInPath, meshobjs->Next()); } if(meshobj->GetNode("params")) { meshobj = meshobj->GetNode("params"); if(meshobj->GetNode("factory")) { bool found = false; for(size_t i=0; i<meshFactsOut.GetSize(); i++) { if(csString(meshFactsOut[i]->GetRoot()->GetNode("library")->GetNode("meshfact")->GetAttributeValue("name")).Compare(meshobj->GetNode("factory")->GetContentsValue())) { libsNeeded.PushSmart(meshobj->GetNode("factory")->GetContentsValue()); found = true; } } if(!found) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Mesh object %s uses mesh factory %s but there is no factory data!\n", meshobj->GetAttributeValue("name"), meshobj->GetNode("factory")->GetContentsValue()); } } if(meshobj->GetNode("material")) { bool found = false; for(size_t i=0; i<materials.GetSize(); i++) { if(csString(materials[i]->GetAttributeValue("name")).Compare(meshobj->GetNode("material")->GetContentsValue())) { materialsNeeded.PushSmart(meshobj->GetNode("material")->GetContentsValue()); found = true; } } if(!found) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Mesh object %s uses material %s but there is no such material declaration!\n", meshobj->GetAttributeValue("name"), meshobj->GetNode("material")->GetContentsValue()); } } } else if(meshobj->GetNode("paramsfile")) { csString paramsPath = mapInPath + "/" + meshobj->GetNode("paramsfile")->GetContentsValue(); csRef<iFile> file = vfs->Open(paramsPath, VFS_FILE_READ); csRef<iDocument> paramsDoc = docSys->CreateDocument(); paramsDoc->Parse(file); meshobj = paramsDoc->GetRoot()->GetNode("params"); if(meshobj->GetNode("factory")) { bool found = false; for(size_t i=0; i<meshFactsOut.GetSize(); i++) { if(csString(meshFactsOut[i]->GetRoot()->GetNode("library")->GetNode("meshfact")->GetAttributeValue("name")).Compare(meshobj->GetNode("factory")->GetContentsValue())) { libsNeeded.PushSmart(meshobj->GetNode("factory")->GetContentsValue()); found = true; } } if(!found) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Mesh object %s uses mesh factory %s but there is no factory data!\n", meshobj->GetParent()->GetAttributeValue("name"), meshobj->GetNode("factory")->GetContentsValue()); } } if(meshobj->GetNode("material")) { bool found = false; for(size_t i=0; i<materials.GetSize(); i++) { if(csString(materials[i]->GetAttributeValue("name")).Compare(meshobj->GetNode("material")->GetContentsValue())) { materialsNeeded.PushSmart(meshobj->GetNode("material")->GetContentsValue()); found = true; } } if(!found) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Mesh object %s uses material %s but there is no such material declaration!\n", meshobj->GetParent()->GetAttributeValue("name"), meshobj->GetNode("material")->GetContentsValue()); } } } }
void OptimiseData::ParseMeshFact(csRef<iDocumentNode>& meshFact, csRef<iDocumentNode>& tempDocRoot, csRefArray<iDocumentNode>& tempMats) { csRef<iDocumentNode> params = meshFact->GetNode("params"); if(params.IsValid()) { bool first = true; csRef<iDocumentNodeIterator> submeshes = params->GetNodes("submesh"); if(!submeshes->HasNext()) { submeshes = params->GetNodes("curve"); } while((first && params->GetNode("material")) || submeshes->HasNext()) { csString materialName; if(first && params->GetNode("material")) { materialName = params->GetNode("material")->GetContentsValue(); first = false; } else if(submeshes->HasNext()) { csRef<iDocumentNode> submesh = submeshes->Next(); if(submesh->GetNode("material")) { materialName = submesh->GetNode("material")->GetContentsValue(); } else { continue; } } bool hasMaterialDecl = false; csRef<iDocumentNode> material; for(size_t j=0; j<materials.GetSize(); j++) { material = materials[j]; if(materialName.Compare(material->GetAttributeValue("name"))) { hasMaterialDecl = true; break; } } if(!hasMaterialDecl) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Meshfact %s uses material %s but there is no material declaration!\n", meshFact->GetAttributeValue("name"), materialName.GetData()); } tempMats.PushSmart(material); } } csRef<iDocumentNodeIterator> undermeshes = meshFact->GetNodes("meshfact"); while(undermeshes->HasNext()) { csRef<iDocumentNode> next = undermeshes->Next(); ParseMeshFact(next, tempDocRoot, tempMats); } }