From 29b1f04ae8bbc1eaae85fd02c55cc805de4ab54e Mon Sep 17 00:00:00 2001 From: Fleeym <61891787+Fleeym@users.noreply.github.com> Date: Sat, 14 Oct 2023 00:28:08 +0300 Subject: [PATCH] RobTopGames called release() on my start position And it made me very angry >:( --- .../StartPosSwitcher/StartPosSwitcher.cpp | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/features/StartPosSwitcher/StartPosSwitcher.cpp b/src/features/StartPosSwitcher/StartPosSwitcher.cpp index 09c17139..264c1e8a 100644 --- a/src/features/StartPosSwitcher/StartPosSwitcher.cpp +++ b/src/features/StartPosSwitcher/StartPosSwitcher.cpp @@ -22,31 +22,37 @@ using namespace editor_api; bool g_enteringLevel = false; class $modify(PlayLayer) { - StartPosObject* activeStartPos = nullptr; - bool fromLevelStart = false; + StartPosObject* customStart = nullptr; + void addObject(GameObject* obj) { g_enteringLevel = false; PlayLayer::addObject(obj); - if (obj->m_objectID != 31) { + if (StartPosManager::get()->isDefault()) { return; } - if (StartPosManager::get()->isDefault() && !m_fields->activeStartPos) { - return; - } - if (StartPosManager::get()->isLevelStart() && !m_fields->activeStartPos) { + if (StartPosManager::get()->isLevelStart()) { m_startPos = nullptr; - m_playerStartPosition = CCPointZero; - return; + m_playerStartPosition = ccp(0, 105.f); } - auto active = StartPosManager::get()->getActive(); - if (obj->getPosition() == StartPosManager::get()->getActive() && !m_fields->activeStartPos) { - m_fields->activeStartPos = static_cast(obj); + if ( + obj->m_objectID == 31 && + obj->getPosition() == StartPosManager::get()->getActive() + ) { + m_fields->customStart = static_cast(obj); } - if (m_fields->activeStartPos) { - m_startPos = m_fields->activeStartPos; - m_playerStartPosition = m_fields->activeStartPos->getPosition(); + if (m_fields->customStart) { + if (m_startPos != m_fields->customStart) { + if (m_fields->customStart) { + m_fields->customStart->retain(); + } + if (m_startPos) { + m_startPos->release(); + } + m_startPos = m_fields->customStart; + m_playerStartPosition = m_fields->customStart->getPosition(); + } } } };