Save automapper config as external-typed mapitem

This commit is contained in:
Bojidar Marinov 2018-10-08 23:44:49 +03:00
parent 351fee2666
commit 823e4ee0f3
No known key found for this signature in database
GPG key ID: 4D546A8F1E091856
5 changed files with 52 additions and 6 deletions

View file

@ -9,6 +9,7 @@
#include <engine/serverbrowser.h> #include <engine/serverbrowser.h>
#include <engine/storage.h> #include <engine/storage.h>
#include <game/gamecore.h> #include <game/gamecore.h>
#include <game/mapitems_ex.h>
#include "editor.h" #include "editor.h"
template<typename T> template<typename T>
@ -352,6 +353,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
// save layers // save layers
int LayerCount = 0, GroupCount = 0; int LayerCount = 0, GroupCount = 0;
int AutomapperCount = 0;
for(int g = 0; g < m_lGroups.size(); g++) for(int g = 0; g < m_lGroups.size(); g++)
{ {
CLayerGroup *pGroup = m_lGroups[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); 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++; GItem.m_NumLayers++;
LayerCount++; LayerCount++;
} }
@ -1261,6 +1274,26 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
pEnv->m_Synchronized = pItem->m_Synchronized; 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 else
return 0; return 0;

View file

@ -821,12 +821,10 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox)
if(Prop == PROP_COLOR_ENV_OFFSET) if(Prop == PROP_COLOR_ENV_OFFSET)
m_ColorEnvOffset = NewVal; m_ColorEnvOffset = NewVal;
else if(Prop == PROP_SEED) else if(Prop == PROP_SEED)
{
m_Seed = NewVal; m_Seed = NewVal;
}
else if(Prop == PROP_AUTOMAPPER) 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(); m_AutoMapperConfig = NewVal%m_pEditor->m_Map.m_lImages[m_Image]->m_AutoMapper.ConfigNamesNum();
else else
m_AutoMapperConfig = -1; m_AutoMapperConfig = -1;

View file

@ -1352,8 +1352,8 @@ int CEditor::PopupSelectGameTileOpResult()
return Result; return Result;
} }
static int s_AutoMapConfigSelected = -1; static int s_AutoMapConfigSelected = -100;
static int s_AutoMapConfigCurrent = -1; static int s_AutoMapConfigCurrent = -100;
int CEditor::PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View) int CEditor::PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View)
{ {

View file

@ -21,6 +21,20 @@ struct CMapItemTest
int m_Field4; 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); void RegisterMapItemTypeUuids(class CUuidManager *pManager);
#endif // GAME_MAPITEMS_EX_H #endif // GAME_MAPITEMS_EX_H

View file

@ -1,3 +1,4 @@
// This file can be included several times. // 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")