mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Save automapper config as external-typed mapitem
This commit is contained in:
parent
351fee2666
commit
823e4ee0f3
|
@ -9,6 +9,7 @@
|
|||
#include <engine/serverbrowser.h>
|
||||
#include <engine/storage.h>
|
||||
#include <game/gamecore.h>
|
||||
#include <game/mapitems_ex.h>
|
||||
#include "editor.h"
|
||||
|
||||
template<typename T>
|
||||
|
@ -352,6 +353,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
|||
|
||||
// save layers
|
||||
int LayerCount = 0, GroupCount = 0;
|
||||
int AutomapperCount = 0;
|
||||
for(int g = 0; g < m_lGroups.size(); g++)
|
||||
{
|
||||
CLayerGroup *pGroup = m_lGroups[g];
|
||||
|
@ -442,6 +444,17 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
|||
|
||||
df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item);
|
||||
|
||||
CMapItemAutoMapperConfig ItemAutomapper;
|
||||
ItemAutomapper.m_GroupId = GroupCount;
|
||||
ItemAutomapper.m_LayerId = GItem.m_NumLayers;
|
||||
ItemAutomapper.m_AutomapperConfig = pLayer->m_AutoMapperConfig;
|
||||
ItemAutomapper.m_AutomapperSeed = pLayer->m_Seed;
|
||||
ItemAutomapper.m_Flags = 0;
|
||||
if (pLayer->m_AutoAutoMap) ItemAutomapper.m_Flags |= CMapItemAutoMapperConfig::FLAG_AUTOMATIC;
|
||||
|
||||
df.AddItem(MAPITEMTYPE_AUTOMAPPER_CONFIG, AutomapperCount, sizeof(ItemAutomapper), &ItemAutomapper);
|
||||
AutomapperCount++;
|
||||
|
||||
GItem.m_NumLayers++;
|
||||
LayerCount++;
|
||||
}
|
||||
|
@ -1261,6 +1274,26 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
|||
pEnv->m_Synchronized = pItem->m_Synchronized;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int Start, Num;
|
||||
DataFile.GetType(MAPITEMTYPE_AUTOMAPPER_CONFIG, &Start, &Num);
|
||||
for(int i = 0; i < Num; i++)
|
||||
{
|
||||
CMapItemAutoMapperConfig *pItem = (CMapItemAutoMapperConfig *)DataFile.GetItem(Start+i, 0, 0);
|
||||
if (pItem->m_Version == CMapItemAutoMapperConfig::CURRENT_VERSION) {
|
||||
if (pItem->m_GroupId >= 0 && pItem->m_GroupId < m_lGroups.size() &&
|
||||
pItem->m_LayerId >= 0 && pItem->m_LayerId < m_lGroups[pItem->m_GroupId]->m_lLayers.size() &&
|
||||
m_lGroups[pItem->m_GroupId]->m_lLayers[pItem->m_LayerId]->m_Type == LAYERTYPE_TILES) {
|
||||
|
||||
CLayerTiles *pLayer = (CLayerTiles *)m_lGroups[pItem->m_GroupId]->m_lLayers[pItem->m_LayerId];
|
||||
pLayer->m_AutoMapperConfig = pItem->m_AutomapperConfig;
|
||||
pLayer->m_Seed = pItem->m_AutomapperSeed;
|
||||
pLayer->m_AutoAutoMap = !!(pItem->m_Flags & CMapItemAutoMapperConfig::FLAG_AUTOMATIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
|
|
@ -821,12 +821,10 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox)
|
|||
if(Prop == PROP_COLOR_ENV_OFFSET)
|
||||
m_ColorEnvOffset = NewVal;
|
||||
else if(Prop == PROP_SEED)
|
||||
{
|
||||
m_Seed = NewVal;
|
||||
}
|
||||
else if(Prop == PROP_AUTOMAPPER)
|
||||
{
|
||||
if (m_Image >= 0 && m_pEditor->m_Map.m_lImages[m_Image]->m_AutoMapper.ConfigNamesNum() > 0)
|
||||
if (m_Image >= 0 && m_pEditor->m_Map.m_lImages[m_Image]->m_AutoMapper.ConfigNamesNum() > 0 && NewVal >= 0)
|
||||
m_AutoMapperConfig = NewVal%m_pEditor->m_Map.m_lImages[m_Image]->m_AutoMapper.ConfigNamesNum();
|
||||
else
|
||||
m_AutoMapperConfig = -1;
|
||||
|
|
|
@ -1352,8 +1352,8 @@ int CEditor::PopupSelectGameTileOpResult()
|
|||
return Result;
|
||||
}
|
||||
|
||||
static int s_AutoMapConfigSelected = -1;
|
||||
static int s_AutoMapConfigCurrent = -1;
|
||||
static int s_AutoMapConfigSelected = -100;
|
||||
static int s_AutoMapConfigCurrent = -100;
|
||||
|
||||
int CEditor::PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,20 @@ struct CMapItemTest
|
|||
int m_Field4;
|
||||
} ;
|
||||
|
||||
struct CMapItemAutoMapperConfig
|
||||
{
|
||||
enum { CURRENT_VERSION=1 };
|
||||
enum { FLAG_AUTOMATIC=1 };
|
||||
|
||||
int m_Version;
|
||||
int m_GroupId;
|
||||
int m_LayerId;
|
||||
int m_AutomapperConfig;
|
||||
int m_AutomapperSeed;
|
||||
int m_Flags;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
void RegisterMapItemTypeUuids(class CUuidManager *pManager);
|
||||
#endif // GAME_MAPITEMS_EX_H
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// This file can be included several times.
|
||||
|
||||
UUID(MAPITEMTYPE_TEST, "mapitemtype-test@ddnet.tw")
|
||||
UUID(MAPITEMTYPE_TEST, "mapitemtype-test@ddnet.tw")
|
||||
UUID(MAPITEMTYPE_AUTOMAPPER_CONFIG, "mapitemtype-automapper-config@ddnet.tw")
|
||||
|
|
Loading…
Reference in a new issue