let CAutoMapper inherit CEditorComponent

This commit is contained in:
marmare314 2023-08-28 18:22:01 +02:00
parent c3a07dd977
commit 07fd8e6712
3 changed files with 14 additions and 13 deletions

View file

@ -5,8 +5,10 @@
#include <engine/shared/linereader.h>
#include <engine/storage.h>
#include <game/mapitems.h>
#include "auto_map.h"
#include "editor.h"
#include "editor.h" // TODO: only needs CLayerTiles
// Based on triple32inc from https://github.com/skeeto/hash-prospector/tree/79a6074062a84907df6e45b756134b74e2956760
static uint32_t HashUInt32(uint32_t Num)
@ -39,15 +41,14 @@ static int HashLocation(uint32_t Seed, uint32_t Run, uint32_t Rule, uint32_t X,
CAutoMapper::CAutoMapper(CEditor *pEditor)
{
m_pEditor = pEditor;
m_FileLoaded = false;
Init(pEditor);
}
void CAutoMapper::Load(const char *pTileName)
{
char aPath[IO_MAX_PATH_LENGTH];
str_format(aPath, sizeof(aPath), "editor/%s.rules", pTileName);
IOHANDLE RulesFile = m_pEditor->Storage()->OpenFile(aPath, IOFLAG_READ | IOFLAG_SKIP_BOM, IStorage::TYPE_ALL);
IOHANDLE RulesFile = Storage()->OpenFile(aPath, IOFLAG_READ | IOFLAG_SKIP_BOM, IStorage::TYPE_ALL);
if(!RulesFile)
return;
@ -362,7 +363,7 @@ void CAutoMapper::Load(const char *pTileName)
char aBuf[IO_MAX_PATH_LENGTH + 16];
str_format(aBuf, sizeof(aBuf), "loaded %s", aPath);
m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf);
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf);
m_FileLoaded = true;
}
@ -470,7 +471,7 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO
for(int x = 0; x < pLayer->m_Width; x++)
{
CTile *pTile = &(pLayer->m_pTiles[y * pLayer->m_Width + x]);
m_pEditor->m_Map.OnModify();
Editor()->m_Map.OnModify();
for(size_t i = 0; i < pRun->m_vIndexRules.size(); ++i)
{

View file

@ -3,7 +3,9 @@
#include <vector>
class CAutoMapper
#include "component.h"
class CAutoMapper : public CEditorComponent
{
struct CIndexInfo
{
@ -55,7 +57,7 @@ class CAutoMapper
};
public:
CAutoMapper(class CEditor *pEditor);
explicit CAutoMapper(CEditor *pEditor);
void Load(const char *pTileName);
void ProceedLocalized(class CLayerTiles *pLayer, int ConfigID, int Seed = 0, int X = 0, int Y = 0, int Width = -1, int Height = -1);
@ -67,9 +69,8 @@ public:
bool IsLoaded() const { return m_FileLoaded; }
private:
std::vector<CConfiguration> m_vConfigs;
class CEditor *m_pEditor;
bool m_FileLoaded;
std::vector<CConfiguration> m_vConfigs = {};
bool m_FileLoaded = false;
};
#endif

View file

@ -12,8 +12,7 @@ class CEditorImage : public CImageInfo
public:
CEditor *m_pEditor;
CEditorImage(CEditor *pEditor) :
m_AutoMapper(pEditor)
CEditorImage(CEditor *pEditor): m_AutoMapper(pEditor)
{
m_pEditor = pEditor;
m_aName[0] = 0;