ALERROR WriteModuleImages (CXMLElement *pModule, const CString &sFolder, CSymbolTable &Resources, CDataFile &Out) { ALERROR error; int i; for (i = 0; i < pModule->GetContentElementCount(); i++) { CXMLElement *pItem = pModule->GetContentElement(i); if (strEquals(pItem->GetTag(), TAG_IMAGES)) { CString sSubFolder = pathAddComponent(sFolder, pItem->GetAttribute(ATTRIB_FOLDER)); if (error = WriteModuleImages(pItem, sSubFolder, Resources, Out)) return error; } else if (strEquals(pItem->GetTag(), TAG_IMAGE)) { CString sFilename = pItem->GetAttribute(ATTRIB_BITMAP); if (!sFilename.IsBlank()) { if (error = WriteResource(sFilename, sFolder, Resources, Out)) continue; } sFilename = pItem->GetAttribute(ATTRIB_BITMASK); if (!sFilename.IsBlank()) { if (error = WriteResource(sFilename, sFolder, Resources, Out)) continue; } } } return NOERROR; }
ALERROR WriteModuleImages (CTDBCompiler &Ctx, CXMLElement *pModule, const CString &sFolder, CDataFile &Out) { ALERROR error; int i; for (i = 0; i < pModule->GetContentElementCount(); i++) { CXMLElement *pItem = pModule->GetContentElement(i); if (strEquals(pItem->GetTag(), TAG_IMAGES)) { CString sSubFolder = pathAddComponent(sFolder, pItem->GetAttribute(ATTRIB_FOLDER)); if (error = WriteModuleImages(Ctx, pItem, sSubFolder, Out)) return error; } else if (strEquals(pItem->GetTag(), TAG_IMAGE)) { CString sFilename = pItem->GetAttribute(ATTRIB_BITMAP); if (!sFilename.IsBlank()) { bool bCompress = strEquals(strToLower(pathGetExtension(sFilename)), CONSTLIT("bmp")); if (error = WriteResource(Ctx, sFilename, sFolder, bCompress, Out)) continue; } sFilename = pItem->GetAttribute(ATTRIB_BITMASK); if (!sFilename.IsBlank()) { bool bCompress = strEquals(strToLower(pathGetExtension(sFilename)), CONSTLIT("bmp")); if (error = WriteResource(Ctx, sFilename, sFolder, bCompress, Out)) continue; } sFilename = pItem->GetAttribute(ATTRIB_SHADOW_MASK); if (!sFilename.IsBlank()) { bool bCompress = strEquals(strToLower(pathGetExtension(sFilename)), CONSTLIT("bmp")); if (error = WriteResource(Ctx, sFilename, sFolder, bCompress, Out)) continue; } sFilename = pItem->GetAttribute(ATTRIB_HIT_MASK); if (!sFilename.IsBlank()) { bool bCompress = strEquals(strToLower(pathGetExtension(sFilename)), CONSTLIT("bmp")); if (error = WriteResource(Ctx, sFilename, sFolder, bCompress, Out)) continue; } } } return NOERROR; }
ALERROR WriteModule (CTDBCompiler &Ctx, const CString &sFilename, const CString &sFolder, CDataFile &Out, int *retiModuleEntry, bool bCore) { ALERROR error; int i; // Parse the file CXMLElement *pModule; CExternalEntityTable *pEntityTable = new CExternalEntityTable; CFileReadBlock DataFile(pathAddComponent(Ctx.GetRootPath(), sFilename)); CString sError; printf("Parsing %s...", sFilename.GetASCIIZPointer()); if (error = CXMLElement::ParseXML(&DataFile, Ctx.GetCoreEntities(), &pModule, &sError, pEntityTable)) { printf("\n"); Ctx.ReportError(sError); return error; } // If this is a core module (embedded in the root XML) then we add these // entities to the core. [Ctx takes ownership.] if (bCore) Ctx.AddEntityTable(pEntityTable); // Chain entity tables (so that any modules that we load get the benefit). // This will chain Ctx.pCoreEntities (and restore it in the destructor). // // NOTE: If this is a core module, then we don't do this, since we've // already added the entities to the context block. CSaveEntitiesTable SavedEntities(Ctx, (!bCore ? pEntityTable : NULL)); printf("done.\n"); // Compress if this is NOT the main file. We can't compress the // main file because we sometimes need to read it partially. bool bCompress = (retiModuleEntry == NULL); // Write the module itself int iEntry; if (error = WriteGameFile(Ctx, sFilename, bCompress, Out, &iEntry)) return error; // If the caller doesn't want the module entry, then it means that this is // a module (instead of the main file). If so, add it to the resources table if (retiModuleEntry == NULL) Ctx.AddResource(sFilename, iEntry, bCompress); // Store all the image resources if (error = WriteModuleImages(Ctx, pModule, sFolder, Out)) return error; // Store all the sound resources if (error = WriteModuleSounds(Ctx, pModule, sFolder, Out)) return error; // Store all modules if (error = WriteSubModules(Ctx, pModule, sFolder, Out)) return error; // The root module may have a TranscendenceAdventure tag with modules in it for (i = 0; i < pModule->GetContentElementCount(); i++) { CXMLElement *pItem = pModule->GetContentElement(i); if (strEquals(pItem->GetTag(), TAG_CORE_LIBRARY) || strEquals(pItem->GetTag(), TAG_TRANSCENDENCE_ADVENTURE) || strEquals(pItem->GetTag(), TAG_TRANSCENDENCE_LIBRARY)) { // If we have a filename, then we need to save the target as a // module. CString sFilename; if (pItem->FindAttribute(ATTRIB_FILENAME, &sFilename)) { // Write out the module, making sure to set the core flag. if (error = WriteModule(Ctx, sFilename, sFolder, Out, NULL, true)) return error; // We ignore any other elements. continue; } // Store all the image resources if (error = WriteModuleImages(Ctx, pItem, sFolder, Out)) return error; // Store all the sound resources if (error = WriteModuleSounds(Ctx, pItem, sFolder, Out)) return error; // Modules if (error = WriteSubModules(Ctx, pItem, sFolder, Out)) return error; } } // Done if (retiModuleEntry) *retiModuleEntry = iEntry; return NOERROR; }
ALERROR WriteModule (const CString &sFilename, const CString &sFolder, CExternalEntityTable *pEntityTable, CSymbolTable &Resources, CDataFile &Out, int *retiModuleEntry) { ALERROR error; int i; // Parse the file CXMLElement *pModule; CExternalEntityTable EntityTable; if (pEntityTable) { CFileReadBlock DataFile(sFilename); CString sError; printf("Parsing %s...", sFilename.GetASCIIZPointer()); if (error = CXMLElement::ParseXML(&DataFile, pEntityTable, &pModule, &sError)) { printf("\n%s\n", sError.GetASCIIZPointer()); return error; } printf("done.\n"); } else { CFileReadBlock DataFile(sFilename); CString sError; printf("Parsing %s...", sFilename.GetASCIIZPointer()); if (error = CXMLElement::ParseXML(&DataFile, &pModule, &sError, &EntityTable)) { printf("\n%s\n", sError.GetASCIIZPointer()); return error; } pEntityTable = &EntityTable; printf("done.\n"); } // Write the module itself int iEntry; if (error = WriteGameFile(sFilename, Out, &iEntry)) return error; // If the caller doesn't want the module entry, then it means that this is // a module (instead of the main file). If so, add it to the resources table if (retiModuleEntry == NULL) Resources.AddEntry(sFilename, (CObject *)iEntry); // Store all the image resources if (error = WriteModuleImages(pModule, sFolder, Resources, Out)) return error; // Store all the sound resources if (error = WriteModuleSounds(pModule, sFolder, Resources, Out)) return error; // Store all modules CXMLElement *pModules = pModule->GetContentElementByTag(TAG_MODULES); if (pModules) { for (i = 0; i < pModules->GetContentElementCount(); i++) { CXMLElement *pItem = pModules->GetContentElement(i); CString sFilename = pItem->GetAttribute(ATTRIB_FILENAME); if (error = WriteModule(sFilename, sFolder, pEntityTable, Resources, Out, NULL)) continue; } } // Done if (retiModuleEntry) *retiModuleEntry = iEntry; return NOERROR; }