mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Made An Older Switch Layer Converter
This commit is contained in:
parent
a3d29d5447
commit
32c8a349f5
|
@ -3219,6 +3219,13 @@ void CEditorMap::MakeSwitchLayer(CLayer *pLayer)
|
|||
m_pSwitchLayer->m_TexId = m_pEditor->ms_SwitchTexture;
|
||||
}
|
||||
|
||||
void CEditorMap::MakeSwitchLayerOlder(CLayer *pLayer)
|
||||
{
|
||||
m_pSwitchLayerOlder = (CLayerSwitchOlder *)pLayer;
|
||||
m_pSwitchLayerOlder->m_pEditor = m_pEditor;
|
||||
m_pSwitchLayerOlder->m_TexId = m_pEditor->ms_SwitchTexture;
|
||||
}
|
||||
|
||||
void CEditorMap::MakeGameGroup(CLayerGroup *pGroup)
|
||||
{
|
||||
m_pGameGroup = pGroup;
|
||||
|
|
|
@ -275,6 +275,7 @@ public:
|
|||
class CLayerSpeedup *m_pSpeedupLayer;
|
||||
class CLayerFront *m_pFrontLayer;
|
||||
class CLayerSwitch *m_pSwitchLayer;
|
||||
class CLayerSwitchOlder *m_pSwitchLayerOlder;
|
||||
CLayerGroup *m_pGameGroup;
|
||||
|
||||
CEnvelope *NewEnvelope(int Channels)
|
||||
|
@ -332,6 +333,7 @@ public:
|
|||
void MakeSpeedupLayer(CLayer *pLayer);
|
||||
void MakeFrontLayer(CLayer *pLayer);
|
||||
void MakeSwitchLayer(CLayer *pLayer);
|
||||
void MakeSwitchLayerOlder(CLayer *pLayer);
|
||||
};
|
||||
|
||||
|
||||
|
@ -497,6 +499,20 @@ public:
|
|||
virtual void FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect);
|
||||
};
|
||||
|
||||
class CLayerSwitchOlder : public CLayerTiles
|
||||
{
|
||||
public:
|
||||
CLayerSwitchOlder(int w, int h);
|
||||
~CLayerSwitchOlder();
|
||||
|
||||
CTeleTile *m_pSwitchTile;
|
||||
|
||||
virtual void Resize(int NewW, int NewH);
|
||||
virtual void Shift(int Direction);
|
||||
virtual void BrushDraw(CLayer *pBrush, float wx, float wy);
|
||||
virtual void FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect);
|
||||
};
|
||||
|
||||
class CEditor : public IEditor
|
||||
{
|
||||
class IInput *m_pInput;
|
||||
|
|
|
@ -539,6 +539,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
|||
{
|
||||
CMapItemLayerTilemap *pTilemapItem = (CMapItemLayerTilemap *)pLayerItem;
|
||||
CLayerTiles *pTiles = 0;
|
||||
CLayerTiles *pTilesTemp = 0;
|
||||
|
||||
if(pTilemapItem->m_Flags&1)
|
||||
{
|
||||
|
@ -565,6 +566,8 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
|||
{
|
||||
pTiles = new CLayerSwitch(pTilemapItem->m_Width, pTilemapItem->m_Height);
|
||||
MakeSwitchLayer(pTiles);
|
||||
pTilesTemp = new CLayerSwitchOlder(pTilemapItem->m_Width, pTilemapItem->m_Height);
|
||||
MakeSwitchLayerOlder(pTilesTemp);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -635,8 +638,23 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
|||
else if(pTiles->m_Switch)
|
||||
{
|
||||
void *pSwitchData = DataFile.GetData(pTilemapItem->m_Switch);
|
||||
mem_copy(((CLayerSwitch*)pTiles)->m_pSwitchTile, pSwitchData, pTiles->m_Width*pTiles->m_Height*sizeof(CSwitchTile));
|
||||
mem_copy(((CLayerSwitchOlder*)pTilesTemp)->m_pSwitchTile, pSwitchData, pTiles->m_Width*pTiles->m_Height*sizeof(CTeleTile));
|
||||
for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
|
||||
{
|
||||
if(((CLayerSwitchOlder*)pTilesTemp)->m_pSwitchTile[i].m_Type)
|
||||
{
|
||||
((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type = ((CLayerSwitchOlder*)pTilesTemp)->m_pSwitchTile[i].m_Type;
|
||||
((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Number = ((CLayerSwitchOlder*)pTilesTemp)->m_pSwitchTile[i].m_Number;
|
||||
}
|
||||
else
|
||||
{
|
||||
((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type = 0;
|
||||
((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Number = 0;
|
||||
}
|
||||
|
||||
((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags = 0;
|
||||
((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Delay = 0;
|
||||
}
|
||||
for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
|
||||
{
|
||||
if((((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type > (ENTITY_CRAZY_SHOTGUN + ENTITY_OFFSET) && ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type < (ENTITY_DRAGGER_WEAK + ENTITY_OFFSET) || ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == (ENTITY_LASER_O_FAST + 1 + ENTITY_OFFSET)))
|
||||
|
|
|
@ -1095,3 +1095,159 @@ void CLayerSwitch::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CLayerSwitchOlder::CLayerSwitchOlder(int w, int h)
|
||||
: CLayerTiles(w, h)
|
||||
{
|
||||
m_pTypeName = "Switch";
|
||||
m_Switch = 1;
|
||||
|
||||
m_pSwitchTile = new CTeleTile[w*h];
|
||||
mem_zero(m_pSwitchTile, w*h*sizeof(CTeleTile));
|
||||
}
|
||||
|
||||
CLayerSwitchOlder::~CLayerSwitchOlder()
|
||||
{
|
||||
delete[] m_pSwitchTile;
|
||||
}
|
||||
|
||||
void CLayerSwitchOlder::Resize(int NewW, int NewH)
|
||||
{
|
||||
// resize switch data
|
||||
CTeleTile *pNewSwitchData = new CTeleTile[NewW*NewH];
|
||||
mem_zero(pNewSwitchData, NewW*NewH*sizeof(CTeleTile));
|
||||
|
||||
// copy old data
|
||||
for(int y = 0; y < min(NewH, m_Height); y++)
|
||||
mem_copy(&pNewSwitchData[y*NewW], &m_pSwitchTile[y*m_Width], min(m_Width, NewW)*sizeof(CTeleTile));
|
||||
|
||||
// replace old
|
||||
delete [] m_pSwitchTile;
|
||||
m_pSwitchTile = pNewSwitchData;
|
||||
|
||||
// resize tile data
|
||||
CLayerTiles::Resize(NewW, NewH);
|
||||
|
||||
// resize gamelayer too
|
||||
if(m_pEditor->m_Map.m_pGameLayer->m_Width != NewW || m_pEditor->m_Map.m_pGameLayer->m_Height != NewH)
|
||||
m_pEditor->m_Map.m_pGameLayer->Resize(NewW, NewH);
|
||||
}
|
||||
|
||||
void CLayerSwitchOlder::Shift(int Direction)
|
||||
{
|
||||
CLayerTiles::Shift(Direction);
|
||||
|
||||
switch(Direction)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
// left
|
||||
for(int y = 0; y < m_Height; ++y)
|
||||
mem_move(&m_pSwitchTile[y*m_Width], &m_pSwitchTile[y*m_Width+1], (m_Width-1)*sizeof(CTeleTile));
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
// right
|
||||
for(int y = 0; y < m_Height; ++y)
|
||||
mem_move(&m_pSwitchTile[y*m_Width+1], &m_pSwitchTile[y*m_Width], (m_Width-1)*sizeof(CTeleTile));
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
// up
|
||||
for(int y = 0; y < m_Height-1; ++y)
|
||||
mem_copy(&m_pSwitchTile[y*m_Width], &m_pSwitchTile[(y+1)*m_Width], m_Width*sizeof(CTeleTile));
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
{
|
||||
// down
|
||||
for(int y = m_Height-1; y > 0; --y)
|
||||
mem_copy(&m_pSwitchTile[y*m_Width], &m_pSwitchTile[(y-1)*m_Width], m_Width*sizeof(CTeleTile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CLayerSwitchOlder::BrushDraw(CLayer *pBrush, float wx, float wy)
|
||||
{
|
||||
CLayerSwitch *l = (CLayerSwitch *)pBrush;
|
||||
int sx = ConvertX(wx);
|
||||
int sy = ConvertY(wy);
|
||||
|
||||
for(int y = 0; y < l->m_Height; y++)
|
||||
for(int x = 0; x < l->m_Width; x++)
|
||||
{
|
||||
int fx = x+sx;
|
||||
int fy = y+sy;
|
||||
if(fx<0 || fx >= m_Width || fy < 0 || fy >= m_Height)
|
||||
continue;
|
||||
|
||||
if(l->m_pTiles[y*l->m_Width+x].m_Index >= (ENTITY_ARMOR_1 + ENTITY_OFFSET) && l->m_pTiles[y*l->m_Width+x].m_Index <= (ENTITY_DOOR + ENTITY_OFFSET) || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_SWITCHOPEN || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_SWITCHCLOSE || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_SWITCHTIMEDOPEN || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_SWITCHTIMEDCLOSE)
|
||||
{
|
||||
/*if(l->m_pSwitchTile[y*l->m_Width+x].m_Number)
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Number = l->m_pSwitchTile[y*l->m_Width+x].m_Number;
|
||||
else*/
|
||||
{
|
||||
if(!m_pEditor->m_SwitchNum)
|
||||
{
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Number = 0;
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Type = 0;
|
||||
m_pTiles[fy*m_Width+fx].m_Index = 0;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Number = m_pEditor->m_SwitchNum;
|
||||
}
|
||||
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Type = l->m_pTiles[y*l->m_Width+x].m_Index;
|
||||
m_pTiles[fy*m_Width+fx].m_Index = l->m_pTiles[y*l->m_Width+x].m_Index;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Number = 0;
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Type = 0;
|
||||
m_pTiles[fy*m_Width+fx].m_Index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CLayerSwitchOlder::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)
|
||||
{
|
||||
if(m_Readonly)
|
||||
return;
|
||||
|
||||
int sx = ConvertX(Rect.x);
|
||||
int sy = ConvertY(Rect.y);
|
||||
int w = ConvertX(Rect.w);
|
||||
int h = ConvertY(Rect.h);
|
||||
|
||||
CLayerSwitch *pLt = static_cast<CLayerSwitch*>(pBrush);
|
||||
|
||||
for(int y = 0; y <= h; y++)
|
||||
{
|
||||
for(int x = 0; x <= w; x++)
|
||||
{
|
||||
int fx = x+sx;
|
||||
int fy = y+sy;
|
||||
|
||||
if(fx < 0 || fx >= m_Width || fy < 0 || fy >= m_Height)
|
||||
continue;
|
||||
|
||||
if(Empty)
|
||||
{
|
||||
m_pTiles[fy*m_Width+fx].m_Index = 0;
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Number = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pTiles[fy*m_Width+fx] = pLt->m_pTiles[(y*pLt->m_Width + x%pLt->m_Width) % (pLt->m_Width*pLt->m_Height)];
|
||||
if(!pLt->m_pSwitchTile[(y*pLt->m_Width + x%pLt->m_Width) % (pLt->m_Width*pLt->m_Height)].m_Number && m_pEditor->m_SwitchNum && m_pTiles[fy*m_Width+fx].m_Index > 0)
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Number = m_pEditor->m_SwitchNum;
|
||||
else
|
||||
m_pSwitchTile[fy*m_Width+fx].m_Number = pLt->m_pSwitchTile[(y*pLt->m_Width + x%pLt->m_Width) % (pLt->m_Width*pLt->m_Height)].m_Number;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue