Skip to content

Commit

Permalink
[#172]: Fix removal of AnimationPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Feb 9, 2024
1 parent a0dd2c3 commit 970bf9d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 30 deletions.
45 changes: 33 additions & 12 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ Editor::UnselectGameObject(Object::ID object, bool groupSelect)
currentLevel_->GetGameObjectRef(object).SetColor({1.0f, 1.0f, 1.0f, 1.0f});
currentSelectedGameObject_ = Object::INVALID_ID;

// If main selected object was the only one
// If main selected object was the only one
if (selectedObjects_.size() == 1)
{
selectedObjects_.clear();
Expand Down Expand Up @@ -739,6 +739,16 @@ Editor::GetEditorObjectRef(Object::ID object)
return *animationPointIt;
}

EditorObject&
Editor::GetEditorObjectRefByLinkedID(Object::ID linkedObjID)
{
auto animationPointIt = stl::find_if(animationPoints_, [linkedObjID](const auto& editorObject) {
return editorObject.GetLinkedObjectID() == linkedObjID;
});

return *animationPointIt;
}

void
Editor::UnselectEditorObject(Object::ID object)
{
Expand All @@ -747,6 +757,7 @@ Editor::UnselectEditorObject(Object::ID object)

auto& editorObject = GetEditorObjectRef(object);
editorObject.SetObjectUnselected();

currentSelectedEditorObject_ = Object::INVALID_ID;

gizmo_.Hide();
Expand Down Expand Up @@ -892,23 +903,32 @@ Editor::ActionOnObject(Editor::ACTION action, Object::ID object)
}
break;

case ACTION::REMOVE:

if (Object::GetTypeFromID(object) == ObjectType::EDITOR_OBJECT)
{
case ACTION::REMOVE: {
auto removeEditorObject = [this](Object::ID object) {
UnselectEditorObject(object);
auto& currentySelectedObj = GetEditorObjectRef(currentSelectedEditorObject_);

auto& currentySelectedObj = GetEditorObjectRef(object);
gui_.ObjectDeleted(currentySelectedObj.GetLinkedObjectID());
currentySelectedObj.DeleteLinkedObject();

if (Object::GetTypeFromID(currentySelectedObj.GetLinkedObjectID())
== ObjectType::ANIMATION_POINT)
{
animationPoints_.erase(
stl::find_if(animationPoints_, [this](const auto& animationPoint) {
return animationPoint.GetID() == currentSelectedEditorObject_;
}));
auto animationIt =
stl::find_if(animationPoints_, [this, object](const auto& animationPoint) {
return animationPoint.GetID() == object;
});
animationIt->GetSprite().ClearData();
animationPoints_.erase(animationIt);
}
};
if (Object::GetTypeFromID(object) == ObjectType::EDITOR_OBJECT)
{
removeEditorObject(object);
}
else if (Object::GetTypeFromID(object) == ObjectType::ANIMATION_POINT)
{
removeEditorObject(GetEditorObjectRefByLinkedID(object).GetID());
}
else
{
Expand All @@ -917,7 +937,8 @@ Editor::ActionOnObject(Editor::ACTION action, Object::ID object)

currentLevel_->DeleteObject(object);
}
break;
}
break;
default: {
}
}
Expand Down Expand Up @@ -963,7 +984,7 @@ Editor::Render(VkCommandBuffer cmdBuffer)
{
const auto idx = static_cast< size_t >(layer);
const auto& numObjects = renderData.numMeshes.at(idx);

const auto renderThisLayer =
(renderAllLayers or layer == 0) ? true : renderLayerToDraw_ == layer;

Expand Down
3 changes: 3 additions & 0 deletions editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class Editor : public Application
EditorObject&
GetEditorObjectRef(Object::ID object);

EditorObject&
GetEditorObjectRefByLinkedID(Object::ID linkedObjID);

private:
// [[nodiscard]] std::shared_ptr< EditorObject >
// GetEditorObjectByID(Object::ID ID);
Expand Down
9 changes: 1 addition & 8 deletions engine/game/enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace looper {

Enemy::Enemy(Application* context, const glm::vec3& pos, const glm::ivec2& size,
Enemy::Enemy(Application* context, const glm::vec2& pos, const glm::ivec2& size,
const std::string& textureName, const std::vector< AnimationPoint >& keypoints,
Animatable::ANIMATION_TYPE animationType)
: GameObject(context, pos, size, textureName, ObjectType::ENEMY),
Expand All @@ -28,13 +28,6 @@ Enemy::Enemy(Application* context, const glm::vec3& pos, const glm::ivec2& size,
ResetAnimation();
}

Enemy::Enemy(Application* context, const glm::vec2& pos, const glm::ivec2& size,
const std::string& textureName, const std::vector< AnimationPoint >& keypoints,
Animatable::ANIMATION_TYPE animationType)
: Enemy(context, glm::vec3{pos, renderer::LAYER_1}, size, textureName, keypoints, animationType)
{
}

void
Enemy::Setup(Application* context, const glm::vec2& pos, const glm::ivec2& size,
const std::string& textureName, const std::vector< AnimationPoint >& keypoints,
Expand Down
4 changes: 0 additions & 4 deletions engine/game/enemy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class Application;
class Enemy : public GameObject, public Animatable
{
public:
Enemy(Application* context, const glm::vec3& pos, const glm::ivec2& size,
const std::string& textureName, const std::vector< AnimationPoint >& keypoints = {},
Animatable::ANIMATION_TYPE animationType = Animatable::ANIMATION_TYPE::REVERSABLE);

Enemy(Application* context, const glm::vec2& pos, const glm::ivec2& size,
const std::string& textureName, const std::vector< AnimationPoint >& keypoints = {},
Animatable::ANIMATION_TYPE animationType = Animatable::ANIMATION_TYPE::REVERSABLE);
Expand Down
6 changes: 3 additions & 3 deletions engine/game/game_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GameObject::GameObject(Application* application, const glm::vec2& position, cons
const std::string& sprite, ObjectType type)
: Object(type), appHandle_(application)
{
int32_t renderLayer = 2;
uint32_t renderLayer = 2;
switch (type)
{
case ObjectType::ENEMY:
Expand Down Expand Up @@ -44,7 +44,7 @@ GameObject::Setup(Application* application, const glm::vec2& position, const glm
Object::Setup(type);

appHandle_ = application;
int32_t renderLayer = 2;
uint32_t renderLayer = 2;
switch (type)
{
case ObjectType::ENEMY:
Expand All @@ -58,7 +58,7 @@ GameObject::Setup(Application* application, const glm::vec2& position, const glm

sprite_.SetSpriteTextured(position, size, sprite, renderLayer);
currentGameObjectState_.visible_ = true;
currentGameObjectState_.previousPosition_ = glm::vec2(position);
currentGameObjectState_.previousPosition_ = position;


currentGameObjectState_.nodes_ =
Expand Down
2 changes: 1 addition & 1 deletion engine/renderer/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Sprite::ChangeRenderLayer(int32_t newLayer)

void
Sprite::SetSpriteTextured(const glm::vec2& position, const glm::vec2& size,
const std::string& fileName, int32_t renderLayer)
const std::string& fileName, uint32_t renderLayer)
{
changed_ = true;

Expand Down
3 changes: 1 addition & 2 deletions engine/renderer/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Sprite
void
SetSpriteTextured(const glm::vec2& position = glm::vec2(0.0f, 0.0f),
const glm::vec2& size = glm::vec2(128, 128),
const std::string& fileName = "Default128.png", int32_t renderLayer = 2);
const std::string& fileName = "Default128.png", uint32_t renderLayer = 2);

void
SetColor(const glm::vec4& color);
Expand Down Expand Up @@ -178,7 +178,6 @@ class Sprite

StateList< State > statesQueue_ = {};
State currentState_ = {};
SpriteType type_ = SpriteType::regular;

// sprite's texture
TextureIDs textures_ = {};
Expand Down

0 comments on commit 970bf9d

Please sign in to comment.