Skip to content

Commit

Permalink
set the first cam in menu and do nothing else
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSapps committed Feb 18, 2018
1 parent 3fe5fc9 commit 36130c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 39 deletions.
13 changes: 10 additions & 3 deletions include/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

class AbstractRenderer;
class EntityManager;
class ResourceLocator;

class Menu
{
public:
Menu(EntityManager& /*em*/);
Menu(EntityManager& em, ResourceLocator& locator);

void ToBootSequnce();
void ToIntroSequnce();
Expand All @@ -31,6 +32,12 @@ class Menu
void Render(AbstractRenderer& rend);

private:

//EntityManager& mEm;
enum class States
{
eSetFirstScreen,
eRunning
};
States mState = States::eSetFirstScreen;
EntityManager& mEm;
ResourceLocator& mLocator;
};
30 changes: 2 additions & 28 deletions src/core/systems/gridmapsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ void GridmapSystem::OnResolveDependencies()
mGridMap = std::make_unique<GridMap>(mCoords, *mManager);
}

void GridmapSystem::MoveToCamera(ResourceLocator& locator, const char* cameraName)
{

void GridmapSystem::MoveToCamera(ResourceLocator& locator, const char* cameraName)
{
std::pair<u32, u32> GridmapSystem::MoveToCamera(ResourceLocator& locator, const char* cameraName)
{
for (u32 x = 0; x < mGridMap->XSize(); x++)
Expand All @@ -32,7 +27,7 @@ std::pair<u32, u32> GridmapSystem::MoveToCamera(ResourceLocator& locator, const
if (mGridMap->GetGridScreen(x, y)->mCameraAndObjects.mName == cameraName)
{
MoveToCamera(locator, x, y);
return std::make_pair(x,y);
return std::make_pair(x, y);
}
}
}
Expand Down Expand Up @@ -95,30 +90,9 @@ void GridmapSystem::UnloadAllGridScreens()

u32 GridmapSystem::GetCurrentGridScreenX() const
{
GridScreenData* pData = mGridMap->GetGridScreen(xIndex, yIndex);
assert(pData);
if (xIndex < mGridMap->XSize() && yIndex < mGridMap->YSize())
{
GridScreenData* pData = mGridMap->GetGridScreen(xIndex, yIndex);
assert(pData);
return mCurrentGridScreenX;
}

Entity entity = mManager->CreateEntityWith<GridMapScreenComponent, TransformComponent>();

GridMapScreenComponent* gridMapScreen = entity.GetComponent<GridMapScreenComponent>();
gridMapScreen->LoadCamera(locator, pData->mCameraAndObjects.mName);

TransformComponent* pTransform = entity.GetComponent<TransformComponent>();
pTransform->Set(xIndex * cameraSystem->mCameraBlockSize.x, yIndex * cameraSystem->mCameraBlockSize.y);
Entity entity = mManager->CreateEntityWith<GridMapScreenComponent, TransformComponent>();

GridMapScreenComponent* gridMapScreen = entity.GetComponent<GridMapScreenComponent>();
gridMapScreen->LoadCamera(locator, pData->mCameraAndObjects.mName);

TransformComponent* pTransform = entity.GetComponent<TransformComponent>();
pTransform->Set(xIndex * cameraSystem->mCameraBlockSize.x, yIndex * cameraSystem->mCameraBlockSize.y);
}
u32 GridmapSystem::GetCurrentGridScreenY() const
{
return mCurrentGridScreenY;
Expand Down Expand Up @@ -167,4 +141,4 @@ void GridMapScreenComponent::Render(AbstractRenderer& rend, float x, float y, fl
void GridMapScreenComponent::LoadCamera(ResourceLocator& locator, const std::string& name)
{
mBits = locator.LocateCamera(name).get();
}
}
15 changes: 11 additions & 4 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include "core/systems/camerasystem.hpp"
#include "core/systems/gridmapsystem.hpp"

Menu::Menu(EntityManager& /*em*/) //: mEm(em)
Menu::Menu(EntityManager& em, ResourceLocator& locator)
: mEm(em), mLocator(locator)
{

}
Expand Down Expand Up @@ -85,10 +86,16 @@ void Menu::ToQuit()

void Menu::Update()
{
//mEm.GetSystem<GridmapSystem>()->MoveToCamera( "STP01C25.CAM");
if (mState == States::eSetFirstScreen)
{
auto camPos = mEm.GetSystem<GridmapSystem>()->MoveToCamera(mLocator, "STP01C25.CAM");

const auto cameraSystem = mEm.GetSystem<CameraSystem>();
cameraSystem->SetGameCameraToCameraAt(camPos.first, camPos.second);

mState = States::eRunning;
}

//const auto cameraSystem = mEm.GetSystem<CameraSystem>();
//cameraSystem->SetGameCameraToCameraAt(cameraSystem->CurrentCameraX(), cameraSystem->CurrentCameraY());
}

void Menu::Render(AbstractRenderer& /*rend*/)
Expand Down
8 changes: 4 additions & 4 deletions src/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ World::World(
{
LoadSystems();

mMenu = std::make_unique<Menu>(mEntityManager);
mMenu = std::make_unique<Menu>(mEntityManager, locator);

mGameMode = std::make_unique<GameMode>(*this);
mEditorMode = std::make_unique<EditorMode>(*this);
Expand Down Expand Up @@ -163,6 +163,9 @@ void World::SetState(World::States state)
static_cast<u32>(mPathBeingLoaded->mPath->AbeSpawnY() / cameraSystem->mVirtualScreenSize.y));
mLoadingIcon.SetEnabled(false);
mSound.HandleMusicEvent("BASE_LINE");

// HACK: - to test menu
//mState = States::eFrontEndMenu;
}
}
}
Expand Down Expand Up @@ -296,9 +299,6 @@ EngineStates World::Update(const InputReader& input, CoordinateSpace& coords)
// TODO: Throw ?
LOG_ERROR("LVL or file in LVL not found");

// HACK: Force to menu
//mState = States::eFrontEndMenu;

SetState(States::eInGame);
}
}
Expand Down

0 comments on commit 36130c0

Please sign in to comment.