SBSPSS/Utils/MapEdit/Export.cpp

148 lines
3.5 KiB
C++
Raw Normal View History

2000-11-24 23:34:20 +01:00
/**************/
/*** Export ***/
/**************/
#include "stdafx.h"
#include <Vector>
#include "Core.h"
#include "TileSet.h"
#include "Map.h"
#include "Export.h"
#include "utils.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CExport::CExport(char *Filename)
{
2000-11-28 00:07:07 +01:00
_splitpath(Filename,Drive,Path,Name,Ext);
2000-11-24 23:34:20 +01:00
}
/*****************************************************************************/
CExport::~CExport()
{
fclose(File);
}
/*****************************************************************************/
void CExport::ExportAll(CCore *Core)
{
ExportTiles(Core);
}
2000-11-28 00:07:07 +01:00
2000-11-24 23:34:20 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2000-11-28 00:07:07 +01:00
void CExport::ExportLayerTile(char *LayerName,CMap &Map)
2000-11-24 23:34:20 +01:00
{
2000-11-28 00:07:07 +01:00
int MapWidth=Map.GetWidth();
int MapHeight=Map.GetHeight();
int MinWidth=GetMinLayerTileWidth();
int MinHeight=GetMinLayerTileHeight();
int ExpWidth=max(MapWidth,MinWidth);
int ExpHeight=max(MapHeight,MinHeight);
sMapElem BlankElem={0,0,0};
2000-11-24 23:34:20 +01:00
2000-11-28 00:07:07 +01:00
ExportLayerTileStart(LayerName,ExpWidth,ExpHeight);
for (int Y=0; Y<ExpHeight; Y++)
2000-11-24 23:34:20 +01:00
{
2000-11-28 00:07:07 +01:00
for (int X=0; X<ExpWidth; X++)
2000-11-24 23:34:20 +01:00
{
2000-11-28 00:07:07 +01:00
if (X<MapWidth && Y<MapHeight)
{
sMapElem &ThisElem=Map.Get(X,Y);
int Idx=AddTileToList(ThisElem);
ExportLayerTile(ThisElem,Idx);
}
else
{
ExportLayerTile(BlankElem,0);
}
2000-11-24 23:34:20 +01:00
}
}
2000-11-28 00:07:07 +01:00
ExportLayerTileEnd(LayerName);
2000-11-24 23:34:20 +01:00
}
/*****************************************************************************/
void CExport::PrintTileList()
{
int ListSize=UsedTileList.size();
for (int i=0; i<ListSize; i++)
{
// TRACE3("%02d: %i %i\n",i,UsedTileList[i].Set,UsedTileList[i].Tile);
}
}
/*****************************************************************************/
int CExport::FindTileInList(sMapElem &Tile)
{
int ListSize=UsedTileList.size();
for (int Idx=0; Idx<ListSize; Idx++)
{
sMapElem &ListTile=UsedTileList[Idx];
if (ListTile.Set==Tile.Set && ListTile.Tile==Tile.Tile) return(Idx);
}
return(-1);
}
/*****************************************************************************/
int CExport::AddTileToList(sMapElem &Tile)
{
int Idx=FindTileInList(Tile);
if (Idx==-1)
{ // New tile!!
Idx=UsedTileList.size();
UsedTileList.push_back(Tile);
}
return(Idx);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CExport::ExportTiles(CCore *Core)
{
CTileBank &TileBank=Core->GetTileBank();
int ListSize=UsedTileList.size(),i;
PrintTileList();
for (i=0; i<ListSize; i++)
{
sMapElem &ThisElem=UsedTileList[i];
CTile &ThisTile=Core->GetTile(ThisElem.Set,ThisElem.Tile);
ParseTile(ThisTile);
}
CreateTilePalette();
2000-11-28 00:07:07 +01:00
ExportTileStart(ListSize);
2000-11-24 23:34:20 +01:00
for (i=0; i<ListSize; i++)
{
sMapElem &ThisElem=UsedTileList[i];
CTile &ThisTile=Core->GetTile(ThisElem.Set,ThisElem.Tile);
ExportTile(ThisTile);
}
ExportTileEnd();
// Palette
ExportPaletteStart();
ExportPalette();
ExportPaletteEnd();
}
/*****************************************************************************/