mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #114 from cinaera/pr_compatibility
Add editor compatibility with sound layers from older maps
This commit is contained in:
commit
58214e0cc3
|
@ -198,6 +198,19 @@ void editor_load_old(DATAFILE *df, MAP *map)
|
|||
}
|
||||
}*/
|
||||
|
||||
// compatibility with old sound layers
|
||||
struct CSoundSource_DEPRECATED
|
||||
{
|
||||
CPoint m_Position;
|
||||
int m_Loop;
|
||||
int m_TimeDelay; // in s
|
||||
int m_FalloffDistance;
|
||||
int m_PosEnv;
|
||||
int m_PosEnvOffset;
|
||||
int m_SoundEnv;
|
||||
int m_SoundEnvOffset;
|
||||
};
|
||||
|
||||
int CEditor::Save(const char *pFilename)
|
||||
{
|
||||
return m_Map.Save(Kernel()->RequestInterface<IStorage>(), pFilename);
|
||||
|
@ -1019,6 +1032,53 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
|||
mem_copy(pSounds->m_lSources.base_ptr(), pData, sizeof(CSoundSource)*pSoundsItem->m_NumSources);
|
||||
DataFile.UnloadData(pSoundsItem->m_Data);
|
||||
}
|
||||
else if(pLayerItem->m_Type == LAYERTYPE_SOUNDS_DEPRECATED)
|
||||
{
|
||||
// compatibility with old sound layers
|
||||
CMapItemLayerSounds *pSoundsItem = (CMapItemLayerSounds *)pLayerItem;
|
||||
if(pSoundsItem->m_Version < 1 || pSoundsItem->m_Version > CMapItemLayerSounds::CURRENT_VERSION)
|
||||
continue;
|
||||
|
||||
CLayerSounds *pSounds = new CLayerSounds;
|
||||
pSounds->m_pEditor = m_pEditor;
|
||||
pLayer = pSounds;
|
||||
pSounds->m_Sound = pSoundsItem->m_Sound;
|
||||
|
||||
// validate m_Sound
|
||||
if(pSounds->m_Sound < -1 || pSounds->m_Sound >= m_lSounds.size())
|
||||
pSounds->m_Sound = -1;
|
||||
|
||||
// load layer name
|
||||
if(pSoundsItem->m_Version >= 1)
|
||||
IntsToStr(pSoundsItem->m_aName, sizeof(pSounds->m_aName)/sizeof(int), pSounds->m_aName);
|
||||
|
||||
// load data
|
||||
CSoundSource_DEPRECATED *pData = (CSoundSource_DEPRECATED *)DataFile.GetDataSwapped(pSoundsItem->m_Data);
|
||||
pGroup->AddLayer(pSounds);
|
||||
pSounds->m_lSources.set_size(pSoundsItem->m_NumSources);
|
||||
|
||||
for(int i = 0; i < pSoundsItem->m_NumSources; i++)
|
||||
{
|
||||
CSoundSource_DEPRECATED *pOldSource = &pData[i];
|
||||
|
||||
CSoundSource &Source = pSounds->m_lSources[i];
|
||||
Source.m_Position = pOldSource->m_Position;
|
||||
Source.m_Loop = pOldSource->m_Loop;
|
||||
Source.m_Pan = true;
|
||||
Source.m_TimeDelay = pOldSource->m_TimeDelay;
|
||||
Source.m_Falloff = 0;
|
||||
|
||||
Source.m_PosEnv = pOldSource->m_PosEnv;
|
||||
Source.m_PosEnvOffset = pOldSource->m_PosEnvOffset;
|
||||
Source.m_SoundEnv = pOldSource->m_SoundEnv;
|
||||
Source.m_SoundEnvOffset = pOldSource->m_SoundEnvOffset;
|
||||
|
||||
Source.m_Shape.m_Type = CSoundShape::SHAPE_CIRCLE;
|
||||
Source.m_Shape.m_Circle.m_Radius = pOldSource->m_FalloffDistance;
|
||||
}
|
||||
|
||||
DataFile.UnloadData(pSoundsItem->m_Data);
|
||||
}
|
||||
|
||||
if(pLayer)
|
||||
pLayer->m_Flags = pLayerItem->m_Flags;
|
||||
|
|
Loading…
Reference in a new issue