From 07fd8e6712c74ea5dd3ff7d3dc7ec4045a4abce3 Mon Sep 17 00:00:00 2001 From: marmare314 <49279081+Marmare314@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:22:01 +0200 Subject: [PATCH] let `CAutoMapper` inherit `CEditorComponent` --- src/game/editor/auto_map.cpp | 13 +++++++------ src/game/editor/auto_map.h | 11 ++++++----- src/game/editor/mapitems/image.h | 3 +-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/game/editor/auto_map.cpp b/src/game/editor/auto_map.cpp index d339a2601..bca98c498 100644 --- a/src/game/editor/auto_map.cpp +++ b/src/game/editor/auto_map.cpp @@ -5,8 +5,10 @@ #include #include +#include + #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) { diff --git a/src/game/editor/auto_map.h b/src/game/editor/auto_map.h index b5fd6cc4d..4e998af72 100644 --- a/src/game/editor/auto_map.h +++ b/src/game/editor/auto_map.h @@ -3,7 +3,9 @@ #include -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 m_vConfigs; - class CEditor *m_pEditor; - bool m_FileLoaded; + std::vector m_vConfigs = {}; + bool m_FileLoaded = false; }; #endif diff --git a/src/game/editor/mapitems/image.h b/src/game/editor/mapitems/image.h index 77a845a87..b34edba79 100644 --- a/src/game/editor/mapitems/image.h +++ b/src/game/editor/mapitems/image.h @@ -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;