Skip to content

Commit

Permalink
Merge pull request #201 from JacobDomagala/197-editor-add-groups-of-o…
Browse files Browse the repository at this point in the history
…bjects

[#197]: Add groups in `Editor`
  • Loading branch information
JacobDomagala authored Apr 22, 2024
2 parents 7378ce2 + 8645d9e commit 1c98816
Show file tree
Hide file tree
Showing 27 changed files with 595 additions and 139 deletions.
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm*,-hicpp-uppercase-literal-suffix, -readability-uppercase-literal-suffix, -readability-implicit-bool-conversion,-cppcoreguidelines-avoid-magic-numbers, -readability-magic-numbers, -cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-reinterpret-cast-cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-pro-type-vararg, -hicpp-vararg, -altera-id-dependent-backward-branch, -bugprone-easily-swappable-parameters, -readability-identifier-length, -altera-unroll-loops, -cppcoreguidelines-non-private-member-variables-in-classes, -altera-struct-pack-align, -misc-non-private-member-variables-in-classes, -cppcoreguidelines-pro-type-static-cast-downcast, -readability-convert-member-functions-to-static, -cppcoreguidelines-owning-memory,
-hicpp-signed-bitwise, -readability-redundant-access-specifiers, -readability-avoid-const-params-in-decls,
-cppcoreguidelines-avoid-non-const-global-variables, -readability-function-cognitive-complexity'
-cppcoreguidelines-avoid-non-const-global-variables, -readability-function-cognitive-complexity, -misc-include-cleaner'
WarningsAsErrors: '*'
HeaderFilterRegex: ''
HeaderFilterRegex: '*'
FormatStyle: none
2 changes: 1 addition & 1 deletion .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
clang_tidy_args: |
-extra-arg=-std=c++20
cppcheck_args: |
--enable=all --suppress=missingIncludeSystem --suppress=functionStatic --suppress=unusedFunction --inline-suppr --inconclusive
--enable=all --suppress=missingIncludeSystem --suppress=functionStatic --suppress=unusedFunction --inline-suppr --inconclusive --check-level=exhaustive
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(cmake/util_functions.cmake)

add_subdirectory(engine)
add_subdirectory(game)
add_subdirectory(looper)
add_subdirectory(editor)

include(cmake/compile_shaders.cmake)
Expand Down
2 changes: 1 addition & 1 deletion assets/levels/MediumLevel.dgl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/levels/MediumLevel.editor.dgl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"GROUPS":{"Buildings":[12884918424,12884919103,12884918425,12884918423,12884918360,12884918315,12884918837,12884918560],"Default":[12884918293,12884918294,12884918295,12884918296,12884918297,12884918298,12884918299,12884918300,12884918301,12884918302,12884918303,12884918304,12884918305,12884918306,12884918307,12884918308,12884918309,12884918310,12884918311,12884918312,12884918313,12884918314,12884918316,12884918317,12884918318,12884918319,12884918320,12884918321,12884918322,12884918323,12884918324,12884918325,12884918326,12884918343,12884918344,12884918345,12884918346,12884918347,12884918348,12884918361,12884918362,12884918363,12884918364,12884918365,12884918366,12884918370,12884918371,12884918382,12884918383,12884918384,12884918406,12884918421,12884918422,12884918426,12884918437,12884918438,12884918439,12884918440,12884918441,12884918442,12884918443,12884918444,12884918445,12884918446,12884918447,12884918448,12884918449,12884918450,12884918451,12884918452,12884918453,12884918454,12884918455,12884918456,12884918463,12884918464,12884918465,12884918466,12884918467,12884918468,12884918469,12884918470,12884918471,12884918472,12884918473,12884918474,12884918475,12884918476,12884918477,12884918478,12884918479,12884918480,12884918481,12884918482,12884918483,12884918484,12884918485,12884918486,12884918487,12884918488,12884918489,12884918490,12884918491,12884918492,12884918493,12884918494,12884918495,12884918496,12884918497,12884918498,12884918499,12884918500,12884918501,12884918502,12884918503,12884918504,12884918505,12884918506,12884918507,12884918508,12884918509,12884918510,12884918511,12884918512,12884918513,12884918514,12884918515,12884918516,12884918517,12884918518,12884918519,12884918520,12884918521,12884918522,12884918523,12884918524,12884918525,12884918526,12884918527,12884918528,12884918529,12884918530,12884918531,12884918532,12884918533,12884918534,12884918535,12884918536,12884918537,12884918538,12884918539,12884918540,12884918541,12884918542,12884918543,12884918544,12884918545,12884918546,12884918547,12884918548,12884918549,12884918550,12884918551,12884918552,12884918553,12884918554,12884918555,12884918556,12884918557,12884918558,12884918559,12884918561,12884918562,12884918563,12884918564,12884918565,12884918566,12884918567,12884918568,12884918569,12884918570,12884918571,12884918572,12884918573,12884918574,12884918575,12884918576,12884918577,12884918578,12884918579,12884918580,12884918581,12884918582,12884918583,12884918584,12884918585,12884918586,12884918587,12884918588,12884918589,12884918590,12884918591,12884918592,12884918593,12884918594,12884918595,12884918596,12884918597,12884918598,12884918599,12884918600,12884918601,12884918602,12884918603,12884918604,12884918605,12884918606,12884918607,12884918608,12884918609,12884918610,12884918611,12884918612,12884918613,12884918614,12884918615,12884918616,12884918617,12884918618,12884918619,12884918620,12884918621,12884918622,12884918623,12884918624,12884918625,12884918626,12884918627,12884918628,12884918629,12884918630,12884918631,12884918632,12884918633,12884918634,12884918635,12884918636,12884918637,12884918638,12884918639,12884918640,12884918641,12884918642,12884918643,12884918644,12884918645,12884918646,12884918647,12884918648,12884918649,12884918650,12884918651,12884918652,12884918653,12884918654,12884918655,12884918656,12884918657,12884918658,12884918659,12884918660,12884918661,12884918662,12884918663,12884918664,12884918665,12884918666,12884918667,12884918668,12884918669,12884918670,12884918671,12884918672,12884918673,12884918674,12884918675,12884918676,12884918677,12884918678,12884918679,12884918680,12884918681,12884918682,12884918683,12884918684,12884918685,12884918686,12884918687,12884918688,12884918689,12884918690,12884918691,12884918692,12884918693,12884918694,12884918695,12884918696,12884918697,12884918698,12884918699,12884918700,12884918701,12884918702,12884918703,12884918704,12884918705,12884918706,12884918707,12884918708,12884918709,12884918710,12884918711,12884918712,12884918713,12884918714,12884918715,12884918716,12884918717,12884918718,12884918719,12884918720,12884918721,12884918722,12884918723,12884918724,12884918725,12884918726,12884918727,12884918728,12884918729,12884918730,12884918731,12884918732,12884918733,12884918734,12884918735,12884918736,12884918737,12884918738,12884918739,12884918740,12884918741,12884918742,12884918743,12884918744,12884918745,12884918746,12884918747,12884918748,12884918749,12884918750,12884918751,12884918752,12884918753,12884918754,12884918755,12884918756,12884918757,12884918758,12884918759,12884918760,12884918761,12884918762,12884918763,12884918764,12884918765,12884918766,12884918767,12884918768,12884918769,12884918770,12884918771,12884918772,12884918773,12884918774,12884918775,12884918776,12884918777,12884918778,12884918779,12884918780,12884918781,12884918782,12884918783,12884918784,12884918785,12884918786,12884918787,12884918788,12884918789,12884918790,12884918791,12884918792,12884918793,12884918794,12884918795,12884918796,12884918797,12884918798,12884918799,12884918800,12884918801,12884918802,12884918803,12884918804,12884918805,12884918806,12884918807,12884918808,12884918809,12884918810,12884918811,12884918812,12884918813,12884918814,12884918815,12884918816,12884918817,12884918818,12884918819,12884918820,12884918821,12884918822,12884918823,12884918824,12884918825,12884918826,12884918827,12884918828,12884918829,12884918830,12884918831,12884918832,12884918833,12884918834,12884918835,12884918836,12884918838,12884918839,12884918840,12884918841,12884918842,12884918843,12884918844,12884918845,12884918846,12884918847,12884918848,12884918849,12884918850,12884918851,12884918852,12884918853,12884918854,12884918855,12884918856,12884918857,12884918858,12884918859,12884918860,12884918861,12884918862,12884918863,12884918864,12884918865,12884918866,12884918867,12884918868,12884918869,12884918870,12884918871,12884918872,12884918873,12884918874,12884918875,12884918876,12884918877,12884918878,12884918879,12884918880,12884918881,12884918882,12884918883,12884918884,12884918885,12884918886,12884918887,12884918888,12884918889,12884918890,12884918891,12884918892,12884918893,12884918894,12884918895,12884918896,12884918897,12884918898,12884918899,12884918900,12884918901,12884918902,12884918903,12884918904,12884918905,12884918906,12884918907,12884918908,12884918909,12884918910,12884918911,12884918912,12884918913,12884918914,12884918915,12884918916,12884918917,12884918918,12884918919,12884918920,12884918921,12884918922,12884918923,12884918924,12884918925,12884918926,12884918927,12884918928,12884918929,12884918930,12884918931,12884918932,12884918933,12884918934,12884918935,12884918936,12884918937,12884918938,12884918939,12884918940,12884918941,12884918942,12884918943,12884918944,12884918945,12884918946,12884918947,12884918948,12884918949,12884918950,12884918951,12884918952,12884918953,12884918954,12884918955,12884918956,12884918957,12884918958,12884918959,12884918960,12884918961,12884918962,12884918963,12884918964,12884918965,12884918966,12884918967,12884918968,12884918969,12884918970,12884918971,12884918972,12884918973,12884918974,12884918975,12884918976,12884918977,12884918978,12884918979,12884918980,12884918981,12884918982,12884918983,12884918984,12884918985,12884918986,12884918987,12884918988,12884918989,12884918990,12884918991,12884918992,12884918993,12884918994,12884918995,12884918996,12884918997,12884918998,12884918999,12884919000,12884919001,12884919002,12884919003,12884919004,12884919005,12884919006,12884919007,12884919008,12884919009,12884919010,12884919011,12884919012,12884919013,12884919014,12884919015,12884919016,12884919017,12884919018,12884919019,12884919020,12884919021,12884919022,12884919023,12884919024,12884919025,12884919026,12884919027,12884919028,12884919029,12884919030,12884919031,12884919032,12884919033,12884919034,12884919035,12884919036,12884919037,12884919038,12884919039,12884919040,12884919041,12884919042,12884919043,12884919044,12884919045,12884919046,12884919047,12884919048,12884919049,12884919050,12884919051,12884919052,12884919053,12884919054,12884919055,12884919056,12884919057,12884919058,12884919059,12884919060,12884919061,12884919062,12884919063,12884919064,12884919065,12884919066,12884919067,12884919068,12884919069,12884919070,12884919071,12884919072,12884919073,12884919074,12884919075,12884919076,12884919077,12884919078,12884919079,12884919080,12884919081,12884919082,12884919083,12884919084,12884919085,12884919086,12884919087,12884919088,12884919089,12884919090,12884919091,12884919092,12884919093,12884919095,12884919096,12884919101,12884919102,12884919104,12884919105,12884919106,12884919107,12884919108,12884919109,12884919110,12884919111,12884919112,12884919113,12884919114,12884919115,12884919116,12884919117,12884919118,12884919119,12884919120,12884919121,12884919122,12884919123,12884919124,12884919125,12884919126,12884919127,12884919128,12884919129,12884919130,12884919131,12884919132,12884919133,12884919134,12884919135,12884919136,12884919137,12884919138,12884919139,12884919140,12884919141,12884919142,12884919143,12884919144,12884919145,12884919146,12884919147,12884919148,12884919149,12884919150,12884919151,12884919152,12884919153,12884919154,12884919155,12884919156,12884919157,12884919158,12884919159,12884919160,12884919161,12884919162,12884919163,12884919164,12884919165,12884919166,12884919167,12884919168,12884919169,12884919170,12884919171,12884919172,12884919173,12884919174,12884919175,12884919176,12884919177,12884919178,12884919179,12884919180,12884919181,12884919182,12884919183,12884919184,12884919185,12884919186,12884919187,12884919188,12884919189,12884919190,12884919191,12884919192,12884919193,12884919194,12884919195,12884919196,12884919197,12884919198,12884919199,12884919200,12884919201,12884919202,12884919203,12884919204,12884919205,12884919206,12884919207,12884919208,12884919209,12884919210,12884919211,12884919212,12884919213,12884919214,12884919215,12884919216,12884919217,12884919218,12884919219,12884919220,12884919221,12884919222,12884919223,12884919224,12884919225,12884919226,12884919227,12884919228,12884919229,12884919230,12884919231,12884919232,12884919233,12884919234,12884919235,12884919236,12884919237,12884919238,12884919239,12884919240,12884919241,12884919242,12884919243,12884919244,12884919245,12884919246,12884919247,12884919248,12884919249,12884919250,12884919251,12884919252,12884919253,12884919254,12884919255,12884919256,12884919257,12884919258,12884919259,12884919260,12884919261,12884919262,12884919263,12884919264,12884919265,12884919266,12884919267,12884919268,12884919269,12884919270,12884919271,12884919272,12884919273,12884919274,12884919275,12884919276,12884919277,12884919278,12884919279,12884919280,12884919281,12884919282,12884919283,12884919284,12884919285,12884919286,12884919287,12884919288,12884919289,12884919290,12884919291,12884919292,12884919293,12884919294,12884919295,12884919296,12884919297,12884919298,12884919299,12884919300,12884919301,12884919302,12884919303,12884919304,12884919305,12884919306,12884919307,12884919308,12884919309,12884919310,12884919311,4294983681,4294983690,4294983694,4294983698,8589950976],"Main Road":[12884918327,12884918328,12884918329,12884918330,12884918331,12884918332,12884918333,12884918334,12884918335,12884918336,12884918337,12884918338,12884918339,12884918340,12884918341,12884918342,12884918349,12884918350,12884918351,12884918352,12884918353,12884918354,12884918355,12884918356,12884918357,12884918358,12884918359,12884918367,12884918368,12884918369,12884918372,12884918373,12884918374,12884918375,12884918376,12884918377,12884918378,12884918379,12884918380,12884918381,12884918385,12884918386,12884918387,12884918388,12884918389,12884918390,12884918391,12884918392,12884918393,12884918394,12884918395,12884918396,12884918397,12884918398,12884918399,12884918400,12884918401,12884918402,12884918403,12884918404,12884918405,12884918407,12884918408,12884918409,12884918410,12884918411,12884918412,12884918413,12884918414,12884918415,12884918416,12884918417,12884918418,12884918419,12884918420,12884918427,12884918428,12884918429,12884918430,12884918431,12884918432,12884918433,12884918434,12884918435,12884918436,12884918457,12884918458,12884918459,12884918460,12884918461,12884918462,12884919094,12884919097,12884919098,12884919099,12884919100]}}
42 changes: 36 additions & 6 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Editor::MouseButtonCallback(MouseButtonEvent& event)
gui_.ObjectUnselected(object);
}


selectedObjects_ = selectedObjects;
auto& firstObject = currentLevel_->GetGameObjectRef(selectedObjects_.front());
auto gizmoPos = firstObject.GetCenteredPosition();
Expand All @@ -197,7 +197,6 @@ Editor::MouseButtonCallback(MouseButtonEvent& event)
};
}



gizmoActive_ = true;
gizmo_.Show();
Expand Down Expand Up @@ -565,6 +564,17 @@ Editor::GetSelectedObjects() const
return selectedObjects_;
}

void
Editor::ChangeSelectedObjects(const std::vector< Object::ID >& newObjects)
{
selectedObjects_ = newObjects;
gizmoActive_ = true;
gizmo_.Show();
RecalculateGizmoPos();

camera_.SetCameraAtPosition(gizmo_.Position());
}

void
Editor::SelectGameObject(Object::ID newSelectedGameObject)
{
Expand Down Expand Up @@ -624,9 +634,10 @@ Editor::RecalculateGizmoPos()
glm::vec2 min = gizmoPos;
glm::vec2 max = gizmoPos;

for (const auto object : selectedObjects_)
for (uint32_t idx = 1; idx < selectedObjects_.size(); ++idx)
{
const auto& objectPos = currentLevel_->GetGameObjectRef(object).GetCenteredPosition();
const auto& objectPos =
currentLevel_->GetGameObjectRef(selectedObjects_.at(idx)).GetCenteredPosition();
min = glm::vec2{
glm::min(min.x, objectPos.x),
glm::min(min.y, objectPos.y),
Expand Down Expand Up @@ -754,6 +765,12 @@ Editor::GetEditorObjectRefByLinkedID(Object::ID linkedObjID)
return *animationPointIt;
}

const std::string&
Editor::GetLevelFileName() const
{
return levelFileName_;
}

void
Editor::UnselectEditorObject(Object::ID object)
{
Expand Down Expand Up @@ -1258,6 +1275,16 @@ Editor::LoadLevel(const std::string& levelPath)

levelLoaded_ = true;

// for (const auto obj : currentLevel_->GetObjects())
//{
// gui_.ObjectAdded(obj.GetID());
// }
// for (const auto enemy : currentLevel_->GetEnemies())
//{
// gui_.ObjectAdded(enemy.GetID());
// }
// gui_.ObjectAdded(currentLevel_->GetPlayer().GetID());

gui_.LevelLoaded(currentLevel_);

currentLevel_->GenerateTextureForCollision();
Expand All @@ -1275,14 +1302,17 @@ Editor::SaveLevel(const std::string& levelPath)
{
levelFileName_ = levelPath;
currentLevel_->Save(levelFileName_);
gui_.SaveConfigFile();
}

void
Editor::AddGameObject(ObjectType objectType, const glm::vec2& position)
{
HandleGameObjectClicked(currentLevel_->AddGameObject(objectType, position), false, false);
const auto ID = currentLevel_->AddGameObject(objectType, position);
HandleGameObjectClicked(ID, false, false);

shouldUpdateRenderer_ = true;
gui_.ObjectAdded(ID);
}

void
Expand Down Expand Up @@ -1477,7 +1507,7 @@ void
Editor::UpdateAnimationData(Object::ID object)
{
auto& baseObject = currentLevel_->GetObjectRef(object);
auto& gameObject = dynamic_cast< GameObject& >(baseObject);
const auto& gameObject = dynamic_cast< GameObject& >(baseObject);

auto* animatable = dynamic_cast< Animatable* >(&baseObject);
if (animatable)
Expand Down
18 changes: 12 additions & 6 deletions editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class Editor : public Application
GetRenderOffsets() const;

void
HandleGameObjectClicked(Object::ID newSelectedGameObject, bool groupSelect, bool fromGUI = false);
HandleGameObjectClicked(Object::ID newSelectedGameObject, bool groupSelect,
bool fromGUI = false);

void
HandleObjectSelected(Object::ID objectID, bool fromGUI);
Expand All @@ -158,8 +159,10 @@ class Editor : public Application
GetSelectedObjects() const;

void
HandleEditorObjectSelected(EditorObject& newSelectedEditorObject,
bool fromGUI = false);
ChangeSelectedObjects(const std::vector< Object::ID >& newObjects);

void
HandleEditorObjectSelected(EditorObject& newSelectedEditorObject, bool fromGUI = false);

void
ActionOnObject(ACTION action, Object::ID object);
Expand Down Expand Up @@ -192,6 +195,12 @@ class Editor : public Application
EditorObject&
GetEditorObjectRefByLinkedID(Object::ID linkedObjID);

const std::string&
GetLevelFileName() const;

void
UnselectAll();

private:
// [[nodiscard]] std::shared_ptr< EditorObject >
// GetEditorObjectByID(Object::ID ID);
Expand Down Expand Up @@ -238,9 +247,6 @@ class Editor : public Application
void
UnselectGameObject(Object::ID object, bool groupSelect);

void
UnselectAll();

void
ShowCursor(bool choice);

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ EditorObject::SetName(const std::string& name)
name_ = name;
}

std::string
const std::string&
EditorObject::GetName() const
{
return name_;
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class EditorObject : public Object
renderer::Sprite&
GetSprite();

[[nodiscard]] std::string
[[nodiscard]] const std::string&
GetName() const;

[[nodiscard]] Object::ID
Expand Down
6 changes: 6 additions & 0 deletions editor/gizmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Gizmo::Update(const glm::vec2& centeredPos, float rotation)
AdjustSize();
}

glm::vec2
Gizmo::Position() const
{
return gizmoCenter_.GetPosition();
}

void
Gizmo::Move(const glm::vec2& moveBy)
{
Expand Down
3 changes: 3 additions & 0 deletions editor/gizmo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Gizmo
void
SwitchToTranslate();

glm::vec2
Position() const;

private:
void
AdjustSize();
Expand Down
Loading

0 comments on commit 1c98816

Please sign in to comment.