Ejemplo n.º 1
0
// Parse GFX
int parseGfx(TiXmlElement *zbeXML, FILE *output)
{
	// Total # gfx. Do the same like total number assets
	fpos_t totalGfxPos = tempVal<uint32_t>("Total GFX", output);
	uint32_t totalGfx = 0;

	// For all the graphics in the XML file
	TiXmlElement *graphicsXML = zbeXML->FirstChildElement("bin")->FirstChildElement("graphics");
	if (graphicsXML)
	{
		TiXmlElement *gfxXML = graphicsXML->FirstChildElement("gfx");
		while (gfxXML)
		{
			// Increment total gfx counter
			++totalGfx;

			// Get all the needed attributes
			string thisBin = getStrAttr(gfxXML, "bin");
			int w = getIntAttr(gfxXML, "w");
			int h = getIntAttr(gfxXML, "h");
			int t = getIntAttr(gfxXML, "top");
			int l = getIntAttr(gfxXML, "left");

			// Copy it into the zbe file
			debug("\tGFX: %d x %d at (%d, %d)\n", w, h, t, l);
			fwrite<uint8_t>((uint8_t) w, output);
			fwrite<uint8_t>((uint8_t) h, output);
			fwrite<uint8_t>((uint8_t) t, output);
			fwrite<uint8_t>((uint8_t) l, output);
			// The length is unknown right now, it'll be counted in the copy op and returned
			// so we'll return here after that copy is done
			debug("\t");
			fpos_t lenPos = tempVal<uint16_t>("Tiles Length", output);
			debug("\tAppending GFX's Tiles Data from file %s\n", thisBin.c_str());
			uint16_t len = appendData(output, thisBin);

			// Now we have the length, so go back and write it down
			goWrite<uint16_t>(uint16_t(len), output, &lenPos);
			debug("\tTiles' length: %d B\n", int(len));

			// Get the next sibling
			gfxXML = gfxXML->NextSiblingElement("gfx");
			debug("GFX done\n");
		}
	}
	// Now that the total number of gfx are known, go back and write that down
	goWrite<uint32_t>(totalGfx, output, &totalGfxPos);
	debug("%d GFX processed\n\n", int(totalGfx));
	return totalGfx;
}
Ejemplo n.º 2
0
// Parse Simple binary, like Palette or bgTiles
int parseBins(TiXmlElement *zbeXML, string type, FILE *output)
{
	// Total # Bin.
	fpos_t totalBinPos = tempVal<uint32_t>("Total " + type + "s", output);
	uint32_t totalBin = 0;

	// For all the bins in the XML file
	TiXmlElement *binsXML = zbeXML->FirstChildElement(string(type + "s").c_str());
	if (binsXML)
	{
		TiXmlElement *binXML = binsXML->FirstChildElement(type.c_str());
		while (binXML)
		{
			// Increment total bin counter
			++totalBin;

			// Get all the needed attributes
			string thisBin = getStrAttr(binXML, "bin");

			// The length is unknown right now, it'll be counted in the copy op and returned
			// so we'll return here after that copy is done
			debug("\t");
			fpos_t lenPos = tempVal<uint16_t>(type + " Length", output);
			debug("\tAppending %s Data from file %s\n", type.c_str(), thisBin.c_str());
			uint16_t len = appendData(output, thisBin);

			// Now we have the length, so go back and write it down
			goWrite<uint16_t>(uint16_t(len), output, &lenPos);
			debug("\t%s's Length: %d B\n", type.c_str(), len);

			// Get the next sibling
			binXML = binXML->NextSiblingElement(type.c_str());
			debug("%s Done\n", type.c_str());
		}
	}

	// Now that the total number of bins are known, go back and write that down
	goWrite<uint32_t>(totalBin, output, &totalBinPos);
	debug("%d %s Processed\n\n", int(totalBin), type.c_str());
	return totalBin;
}
Ejemplo n.º 3
0
const std::string& ItemAttributes::getText() const
{
	return getStrAttr(ATTR_ITEM_TEXT);
}
Ejemplo n.º 4
0
const std::string& ItemAttributes::getSpecialDescription() const
{
	return getStrAttr(ATTR_ITEM_DESC);
}
Ejemplo n.º 5
0
const std::string& ItemAttributes::getWriter() const
{
	return getStrAttr(ATTR_ITEM_WRITTENBY);
}
Ejemplo n.º 6
0
// Parse out backgrounds
int parseBackgrounds(TiXmlElement *zbeXML, FILE *output)
{
	// Total # backgrounds.
	fpos_t totalBgPos = tempVal<uint32_t>("Total Backgrounds", output);
	uint32_t totalBg = 0;

	// For all the backgrounds in the XML file
	TiXmlElement *bgsXML = zbeXML->FirstChildElement("backgrounds");
	if (bgsXML)
	{
		TiXmlElement *bgXML = bgsXML->FirstChildElement("background");
		while (bgXML)
		{
			// Increment total bg counter
			++totalBg;

			// Get the palette to use for this background
			uint32_t pal = 0;
			bool defPal = false;
			int palVal;
			if (!getIntAttr(bgXML, "palette", palVal))
				fprintf(stderr, "WARNING: No default palette defined for background #%d.\n", totalBg);
			else
			{
				pal = (uint32_t) palVal;
				defPal = true;
			}

			// See if there's an xml attribute defined
			string extBgXMLfile = getStrAttr(bgXML, "xml");
			string extBgBINfile = getStrAttr(bgXML, "bin");
			if (!extBgXMLfile.empty())
			{
				debug("\tOpening external background map XML file: %s\n", extBgXMLfile.c_str());
				TiXmlDocument extXML(extBgXMLfile.c_str());
				if (!extXML.LoadFile())
				{
					fprintf(stderr, "Failed to parse file %s\n", extBgXMLfile.c_str());
					exit(EXIT_FAILURE);
				}
				TiXmlElement *extBgXML = extXML.RootElement()->FirstChildElement("backgroundmap");

				parseBackground(extBgXML, output, totalBg, pal, defPal);
			}
			// See if the map was added as a grit-generated bin
			else if (!extBgBINfile.empty())
			{
				
				// Get dimensions of the map
				int width, height;
				if (!getIntAttr(bgXML, "w", width))
				{
					fprintf(stderr, "ERROR: no width provided for background %d.\n", totalBg);
					exit(EXIT_FAILURE);
				}
				if (!getIntAttr(bgXML, "h", height))
				{
					fprintf(stderr, "ERROR: no height provided for background %d.\n", totalBg);
					exit(EXIT_FAILURE);
				}
				if (!defPal)
				{
					fprintf(stderr, "ERROR: no palette provided for background %d.\n", totalBg);
				}
				
				debug("\tInserting external %d x %d background map BIN file %s using palette #%d\n", width, height, extBgBINfile.c_str(), pal);
				// dimensions
				fwrite<uint32_t>(uint32_t(width), output);
				fwrite<uint32_t>(uint32_t(height), output);
				
				// palettes
				fwrite<uint8_t>(1, output);
				fwrite<uint32_t>(pal, output);
				
				// temp data length followed by data
				fpos_t dataLenPos = tempVal<uint32_t>("Map Data Length", output);
				uint32_t dataLen = appendData(output, extBgBINfile);
				goWrite<uint32_t>(dataLen, output, &dataLenPos);
				debug("\tWrote %dB of map data.\n", dataLen);
			}
			else
				parseBackground(bgXML, output, totalBg, pal, defPal);

			// Get the next sibling
			bgXML = bgXML->NextSiblingElement("background");
			debug("Background Done\n");
		}
	}
	// Now that the total number of backgrounds are known, go back and write that down
	goWrite<uint32_t>(totalBg, output, &totalBgPos);
	debug("%d Backgrounds Processed\n\n", int(totalBg));
	return totalBg;
}