feat: add play / editor mode
This commit is contained in:
@@ -83,7 +83,7 @@ void LightKeeper::updateViewMode()
|
||||
auto& input = InputManager::GetInstance();
|
||||
FirstPersonController* player = mainScene.playerController;
|
||||
|
||||
if (player != nullptr && input.WasKeyPressed(SDL_SCANCODE_F5))
|
||||
if (isPlaying() && player != nullptr && input.WasKeyPressed(SDL_SCANCODE_F6))
|
||||
{
|
||||
player->SetPossessed(!player->IsPossessed());
|
||||
}
|
||||
@@ -100,13 +100,13 @@ void LightKeeper::updateViewMode()
|
||||
|
||||
bool LightKeeper::isPlayerViewActive() const
|
||||
{
|
||||
return mainScene.playerController != nullptr && mainScene.playerController->IsPossessed();
|
||||
return isPlaying() && mainScene.playerController != nullptr && mainScene.playerController->IsPossessed();
|
||||
}
|
||||
|
||||
CameraComponent* LightKeeper::getSceneCamera() const
|
||||
{
|
||||
const auto& activeScenes = SceneManager::GetInstance().GetActiveScenes();
|
||||
if (useFreeCamera || activeScenes.empty()) {
|
||||
if (!isPlaying() || useFreeCamera || activeScenes.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return activeScenes.front()->GetCurrentCamera();
|
||||
@@ -187,6 +187,23 @@ void LightKeeper::customFixedUpdate(float dt)
|
||||
SceneManager::GetInstance().FixedUpdate(dt);
|
||||
}
|
||||
|
||||
void LightKeeper::onPlayModeChanged(bool nowPlaying)
|
||||
{
|
||||
findPlayer();
|
||||
if (nowPlaying) {
|
||||
// The player view moves the free camera, put it back where the editor left it on Stop
|
||||
editorCamera = camera;
|
||||
if (mainScene.playerController != nullptr) {
|
||||
mainScene.playerController->SetPossessed(true);
|
||||
}
|
||||
} else if (editorCamera) {
|
||||
const float aspectRatio = camera.GetAspectRatio();
|
||||
camera = *editorCamera;
|
||||
camera.setAspectRatio(aspectRatio);
|
||||
editorCamera.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void LightKeeper::onWindowResize(int newWidth, int newHeight)
|
||||
{
|
||||
renderer.resize(gfxDevice, glm::ivec2{newWidth, newHeight});
|
||||
|
||||
Reference in New Issue
Block a user