//-----------------------------------------------------------------------------------------------
void ResourceStream::WriteBlockBegin( const char* optionalLabel )
{
	if( m_internalFormat == RESOURCE_STREAM_FORMAT_BINARY )
		return; // absent in compact binary format

	if( !m_justWroteBlockBegin )
	{
		if( m_consecutiveNewLineCount == 0 )
		{
			WriteNewLine(); // end the previous line (if we were in the middle of one)
		}

		if( m_consecutiveNewLineCount <= 1 )
		{
			WriteNewLine(); // make sure there's a blank line before each block
		}
	}

	if( optionalLabel )
	{
		WriteStringIndentedIfNeeded( Stringf( ENDLINE_LABEL_FORMAT_STRING, optionalLabel ) );
		WriteNewLine();
	}

	WriteStringIndentedIfNeeded( "{" );

	m_currentIndentationDepth ++;
	WriteNewLine();
	m_justWroteBlockBegin = true;
}
Beispiel #2
0
void JsonExpressFormater::WriteSubDictionary(stringx name, ref<JsonNode> node, ref<StringBuilder> sb, int level)
{
	WriteValue(name, __X("{"), sb, level);
	WriteNewLine(sb);

	ref<JsonNode::JsonNodeDictionary> dict = node->NodeDictionary();
	int count = dict->Count();
	foreach (ref<JsonNode>, subnode, dict)
	{
		ASSERT(subnode->GetName() != NULL);
		WriteExpression(subnode->GetName(), subnode, sb, level + 1);
		if (--count > 0)
			sb->Append(',');
		WriteNewLine(sb);
	}
Beispiel #3
0
int main(int argc, char* argv[]) {
    if (!ParseParams(argc, argv))
        return 1;

    if (FILE* f_src = fopen(params.srcFile, "rb")) {
        FILE* f_dest = stdout;
        //if (f_dest) {
        if (params.header) {
            fprintf(f_dest, "unsigned char %s[] = {", params.hArrName);
            WriteNewLine(f_dest);
        }
        int c = fgetc(f_src);
        if (!feof(f_src)) {
            unsigned int n = 0;
            while (true) {
                WriteChar(f_dest, c);
                c = fgetc(f_src);
                if (feof(f_src))
                    break;
                WriteLineTerm(f_dest, n++);
            }
            while(params.nul--) {
                WriteLineTerm(f_dest, n++);
                WriteChar(f_dest, 0);
            }
        } else {
            fprintf(stderr,"Warning: The input file was empty. Empty file generated.\n");
        }
        if (params.header) {
            WriteNewLine(f_dest);
            fputs("};", f_dest);
        }
        while(params.line--) {
            WriteNewLine(f_dest);
        }
        //fclose(f_dest);
        fclose(f_src);
        return 0;
        //} else {
        //fclose(f_src);
        //fprintf(stderr,"Error: Can't create file '%s'\n",params.dstFile);
        //return 3;
        //}
    } else {
        fprintf(stderr,"Error: Can't open file '%s'\n",params.srcFile);
        return 2;
    }
}
//-----------------------------------------------------------------------------------------------
void ResourceStream::WriteBlockEnd()
{
	if( m_internalFormat == RESOURCE_STREAM_FORMAT_BINARY )
		return; // absent in compact binary format

	m_currentIndentationDepth --;

	if( m_consecutiveNewLineCount == 0 )
	{
		WriteNewLine(); // end the previous line (if we were in the middle of one)
	}

	m_justWroteBlockEnd = false;
	WriteStringIndentedIfNeeded( "}" );
	WriteNewLine(); // end the closing-brace line
	m_justWroteBlockBegin = false;
	m_justWroteBlockEnd = true;
}
Beispiel #5
0
void Tileset::WriteExport(std::ostream& file) const
{
    if (export_shared_data)
    {
        if (bpp == 8)
            palette->WriteExport(file);
        else
            paletteBanks.WriteExport(file);
    }

    WriteDefine(file, name, "_PALETTE_TYPE", (bpp == 8), 7);
    WriteNewLine(file);

    WriteExtern(file, "const unsigned short", name, "_tiles", Size());
    WriteDefine(file, name, "_TILES", tiles.size());
    WriteDefine(file, name, "_TILES_SIZE", Size() * 2);
    WriteDefine(file, name, "_TILES_LENGTH", Size());
    WriteNewLine(file);
}
//-----------------------------------------------------------------------------------------------
void ResourceStream::WriteLineEndIfVerbose( const char* optionalLabel )
{
	if( m_internalFormat != RESOURCE_STREAM_FORMAT_TEXT_VERBOSE )
		return;

	if( optionalLabel )
	{
		WriteStringDirectly( Stringf( ENDLINE_LABEL_FORMAT_STRING, optionalLabel ) );
	}

	WriteNewLine();
}
Beispiel #7
0
void WriteLineTerm(FILE* f, int n) {
    fputc(',', f);
    if ((n+1)%params.width == 0) {
        WriteNewLine(f);
    } else {
        if (params.tabs) {
            fputc('\t', f);
        } else {
            fputc(' ', f);
        }
    }
}
//-----------------------------------------------------------------------------------------------
void ResourceStream::WriteStringIndentedIfNeeded( const std::string& data )
{
	if( m_justWroteBlockEnd )
	{
		WriteNewLine();
	}

	if( IsAtLineStart() )
	{
		for( int i = 0; i < m_currentIndentationDepth; ++ i )
		{
			WriteStringDirectly( "\t" );
		}
	}

	WriteStringDirectly( data );
}
Beispiel #9
0
void Map::WriteExport(std::ostream& file) const
{
    // Sole owner of tileset.
    if (export_shared_info)
        tileset->WriteExport(file);

    unsigned int size = data.size() / (affine ? 2 : 1);
    WriteExtern(file, "const unsigned short", export_name, "", size);
    if (!animated)
    {
        WriteDefine(file, export_name, "_MAP_WIDTH", width);
        WriteDefine(file, export_name, "_MAP_HEIGHT", height);
        WriteDefine(file, export_name, "_MAP_SIZE", size * 2);
        WriteDefine(file, export_name, "_MAP_LENGTH", size);
        if (affine)
            WriteDefine(file, export_name, "_MAP_TYPE", log2(width) - 4, 14);
        else
            WriteDefine(file, export_name, "_MAP_TYPE", (width > 32 ? 1 : 0) | (height > 32 ? 1 : 0) << 1, 14);
        }
    WriteNewLine(file);
}
Beispiel #10
0
void Tileset::WriteData(std::ostream& file) const
{
    if (export_shared_data)
    {
        if (bpp == 8)
            palette->WriteData(file);
        else
            paletteBanks.WriteData(file);
    }

    WriteBeginArray(file, "const unsigned short", name, "_tiles", Size());
    std::vector<Tile>::const_iterator tile_ptr = tilesExport.begin();
    for (unsigned int i = 0; i < tilesExport.size(); i++)
    {
        file << *tile_ptr;
        if (i != tilesExport.size() - 1)
            file << ",\n\t";
        ++tile_ptr;
    }
    WriteEndArray(file);
    WriteNewLine(file);
}
Beispiel #11
0
void Map::WriteSbbData(std::ostream& file) const
{
    char buffer[7];
    int type = (width > 32 ? 1 : 0) | (height > 32 ? 1 : 0) << 1;
    int num_blocks = (type == 0 ? 1 : (type < 3 ? 2 : 4));

    WriteBeginArray(file, "const unsigned short", export_name, "", num_blocks * 32 * 32);
    for (int i = 0; i < num_blocks; i++)
    {
        // Case for each possible value of num_blocks
        // 1: 0
        // 2: type is 1 - 0, 1
        //    type is 2 - 0, 2
        // 4: 0, 1, 2, 3
        int sbb = (i == 0 ? 0 : (i == 1 && type == 2 ? 2 : i));
        unsigned int sx, sy;
        sx = ((sbb & 1) != 0) * 32;
        sy = ((sbb & 2) != 0) * 32;
        for (unsigned int y = 0; y < 32; y++)
        {
            for (unsigned int x = 0; x < 32; x++)
            {
                // Read tile if outside bounds replace with null tile
                unsigned short tile_id;
                if (x + sx > width || y + sy > height)
                    tile_id = 0;
                else
                    tile_id = data[(y + sy) * width + (x + sx)];

                snprintf(buffer, 7, "0x%04x", tile_id);
                // Write it.
                WriteElement(file, buffer, num_blocks * 32 * 32, (y + sy) * width + (x + sx), 8);
            }
        }
    }
    WriteEndArray(file);
    WriteNewLine(file);
}
Beispiel #12
0
void Map::WriteAffineData(std::ostream& file) const
{
    WriteShortArrayAsChars(file, export_name, "", data, 16);
    WriteNewLine(file);
}