From 31288fafd61433c6c10922d7ac9662a736be4d9a Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 24 Apr 2020 21:47:53 +0700 Subject: [PATCH] remove pivot from samples --- headers/enduro2d/high/components/named.hpp | 4 ++ samples/bin/library/prefabs/ship_prefab.json | 21 +++++-- samples/bin/library/scenes/sample_04.json | 45 +++++++++----- .../library/sprites/background_sprite.json | 1 - .../bin/library/sprites/cube_0_sprite.json | 1 - .../bin/library/sprites/cube_1_sprite.json | 1 - samples/bin/library/sprites/panel_sprite.json | 1 - samples/bin/library/sprites/ship_sprite.json | 1 - samples/bin/library/sprites/ships_atlas.json | 2 - samples/sources/sample_03/sample_03.cpp | 61 ++++++++++++------- untests/bin/library/atlas.json | 2 - untests/bin/library/sprite.json | 1 - untests/bin/library/sprite2.json | 1 - untests/sources/untests_high/library.cpp | 4 -- 14 files changed, 88 insertions(+), 58 deletions(-) diff --git a/headers/enduro2d/high/components/named.hpp b/headers/enduro2d/high/components/named.hpp index 1643796e..4ea45564 100644 --- a/headers/enduro2d/high/components/named.hpp +++ b/headers/enduro2d/high/components/named.hpp @@ -13,6 +13,7 @@ namespace e2d class named final { public: named() = default; + named(str value) noexcept; named& name(str value) noexcept; @@ -53,6 +54,9 @@ namespace e2d namespace e2d { + inline named::named(str value) noexcept + : name_(std::move(value)) {} + inline named& named::name(str value) noexcept { name_ = std::move(value); return *this; diff --git a/samples/bin/library/prefabs/ship_prefab.json b/samples/bin/library/prefabs/ship_prefab.json index 78b4949e..601f0891 100644 --- a/samples/bin/library/prefabs/ship_prefab.json +++ b/samples/bin/library/prefabs/ship_prefab.json @@ -1,11 +1,22 @@ { - "prefab" : "sprite_prefab.json", "components" : { "named" : { "name" : "ship" - }, - "sprite_renderer" : { - "sprite" : "../sprites/ship_sprite.json" } - } + }, + "children" : [{ + "uuid" : "6A3E19C4-840C-40E9-9AB0-5D8DF77F0634", + "prefab" : "sprite_prefab.json", + "components" : { + "named" : { + "name" : "sprite" + }, + "actor" : { + "translation" : [-33,-56.5] + }, + "sprite_renderer" : { + "sprite" : "../sprites/ship_sprite.json" + } + } + }] } diff --git a/samples/bin/library/scenes/sample_04.json b/samples/bin/library/scenes/sample_04.json index 61eb6f04..c5df9f52 100644 --- a/samples/bin/library/scenes/sample_04.json +++ b/samples/bin/library/scenes/sample_04.json @@ -58,37 +58,50 @@ "actor" : { "translation" : [0,0], "scale" : 20 - }, - "named" : { - "name" : "gnome" } } }, { - "prefab" : "../prefabs/ship_prefab.json", "components" : { - "sprite_renderer" : { - "blending" : "additive" - }, - "actor" : { - "translation" : [-50,-50] - }, "named" : { - "name" : "ship(1)" + "name" : "ships" } }, "children" : [{ "prefab" : "../prefabs/ship_prefab.json", "components" : { - "sprite_renderer" : { - "tint" : [255,0,0,255] + "named" : { + "name" : "ship(1)" }, "actor" : { - "translation" : [100,0] - }, + "translation" : [-50,-50] + } + }, + "mod_children" : [{ + "uuid" : "6A3E19C4-840C-40E9-9AB0-5D8DF77F0634", + "components" : { + "sprite_renderer" : { + "tint" : [255,0,0,255] + } + } + }] + }, { + "prefab" : "../prefabs/ship_prefab.json", + "components" : { "named" : { "name" : "ship(2)" + }, + "actor" : { + "translation" : [50,-50] } - } + }, + "mod_children" : [{ + "uuid" : "6A3E19C4-840C-40E9-9AB0-5D8DF77F0634", + "components" : { + "sprite_renderer" : { + "blending" : "additive" + } + } + }] }] }, { "prefab" : "../prefabs/label_bm_prefab.json", diff --git a/samples/bin/library/sprites/background_sprite.json b/samples/bin/library/sprites/background_sprite.json index e57b5343..7d17856d 100644 --- a/samples/bin/library/sprites/background_sprite.json +++ b/samples/bin/library/sprites/background_sprite.json @@ -1,5 +1,4 @@ { "texture" : "background.png", - "pivot" : { "x" : 0, "y" : 0 }, "texrect" : { "x" : 0, "y" : 0, "w" : 256, "h" : 256 } } diff --git a/samples/bin/library/sprites/cube_0_sprite.json b/samples/bin/library/sprites/cube_0_sprite.json index 5ff1c3bd..8ff2dd27 100644 --- a/samples/bin/library/sprites/cube_0_sprite.json +++ b/samples/bin/library/sprites/cube_0_sprite.json @@ -1,5 +1,4 @@ { "texture" : "cube_0.png", - "pivot" : { "x" : 12, "y" : 12 }, "texrect" : { "x" : 0, "y" : 0, "w" : 24, "h" : 24 } } diff --git a/samples/bin/library/sprites/cube_1_sprite.json b/samples/bin/library/sprites/cube_1_sprite.json index 2efec47d..b8e527a5 100644 --- a/samples/bin/library/sprites/cube_1_sprite.json +++ b/samples/bin/library/sprites/cube_1_sprite.json @@ -1,5 +1,4 @@ { "texture" : "cube_1.png", - "pivot" : { "x" : 12, "y" : 12 }, "texrect" : { "x" : 0, "y" : 0, "w" : 24, "h" : 24 } } diff --git a/samples/bin/library/sprites/panel_sprite.json b/samples/bin/library/sprites/panel_sprite.json index 2b0b1cbd..3fb2411b 100644 --- a/samples/bin/library/sprites/panel_sprite.json +++ b/samples/bin/library/sprites/panel_sprite.json @@ -1,6 +1,5 @@ { "texture" : "panel.png", - "pivot" : { "x" : 0, "y" : 0 }, "inner_texrect" : { "x" : 6, "y" : 6, "w" : 88, "h" : 88 }, "outer_texrect" : { "x" : 0, "y" : 0, "w" : 100, "h" : 100 } } diff --git a/samples/bin/library/sprites/ship_sprite.json b/samples/bin/library/sprites/ship_sprite.json index d8d0203e..6ea5b7d0 100644 --- a/samples/bin/library/sprites/ship_sprite.json +++ b/samples/bin/library/sprites/ship_sprite.json @@ -1,5 +1,4 @@ { "texture" : "ships.png", - "pivot" : { "x" : 441, "y" : 340.5 }, "texrect" : { "x" : 408, "y" : 284, "w" : 66, "h" : 113 } } diff --git a/samples/bin/library/sprites/ships_atlas.json b/samples/bin/library/sprites/ships_atlas.json index 4fba5134..0c8f3cdc 100644 --- a/samples/bin/library/sprites/ships_atlas.json +++ b/samples/bin/library/sprites/ships_atlas.json @@ -2,11 +2,9 @@ "texture" : "ships.png", "sprites" : [{ "name" : "ship (1).png", - "pivot" : { "x" : 441, "y" : 455 }, "texrect" : { "x" : 408, "y" : 399, "w" : 66, "h" : 113 } },{ "name" : "ship (2).png", - "pivot" : { "x" : 441, "y" : 340 }, "texrect" : { "x" : 408, "y" : 284, "w" : 66, "h" : 113 } }] } diff --git a/samples/sources/sample_03/sample_03.cpp b/samples/sources/sample_03/sample_03.cpp index 1cd7cf60..cfd8ef00 100644 --- a/samples/sources/sample_03/sample_03.cpp +++ b/samples/sources/sample_03/sample_03.cpp @@ -80,6 +80,7 @@ namespace auto scene_i = the().instantiate(); scene_i.component().assign(); + scene_i.component().assign("scene"); { prefab prefab; @@ -113,14 +114,22 @@ namespace } { + prefab sprite_prefab; + sprite_prefab.prototype() + .component(named() + .name("sprite")) + .component(actor() + .node(node::create(math::make_translation_trs2(v2f{-33.f,-56.5f})))) + .component() + .component(sprite_renderer(sprite_res) + .materials({{"normal", sprite_mat}})); + prefab prefab; prefab.prototype() .component(named() .name("ship")) - .component() - .component() - .component(sprite_renderer(sprite_res) - .materials({{"normal", sprite_mat}})); + .component(); + prefab.set_children({sprite_prefab}); the().instantiate( prefab, @@ -129,11 +138,12 @@ namespace } { - prefab prefab_a; - prefab_a.prototype() + prefab sprite_prefab; + sprite_prefab.prototype() .component(named() - .name("cube")) - .component() + .name("sprite")) + .component(actor() + .node(node::create(math::make_translation_trs2(v2f{-12.f,-12.f})))) .component() .component(sprite_renderer() .filtering(false) @@ -142,28 +152,35 @@ namespace .play("idle") .looped(true)); + prefab child_prefab; + child_prefab.prototype() + .component(named() + .name("child")) + .component(actor() + .node(node::create(make_trs2( + v2f{20.f,0.f}, + 0.f, + v2f{0.3f,0.3f})))) + .component(); + child_prefab.set_children({sprite_prefab}); + + prefab root_prefab; + root_prefab.prototype() + .component(named() + .name("root")) + .component(); + root_prefab.set_children({sprite_prefab, child_prefab}); + for ( std::size_t i = 0; i < 2; ++i ) for ( std::size_t j = 0; j < 5; ++j ) { t2f trans{ {-80.f + j * 40.f, -200.f + i * 40.f}, 0.f, {2.f,2.f}}; - gobject inst = the().instantiate( - prefab_a, + the().instantiate( + root_prefab, scene_i.component()->node(), trans); - - prefab prefab_b = prefab_a; - prefab_b.prototype() - .component() - .component(node::create(make_trs2( - v2f{20.f,0.f}, - 0.f, - v2f{0.3f,0.3f}))); - - the().instantiate( - prefab_b, - inst.component()->node()); } } diff --git a/untests/bin/library/atlas.json b/untests/bin/library/atlas.json index 478f2ba9..bd84bdb6 100644 --- a/untests/bin/library/atlas.json +++ b/untests/bin/library/atlas.json @@ -2,11 +2,9 @@ "texture" : "image.png", "sprites" : [{ "name" : "sprite", - "pivot" : { "x" : 1, "y" : 2 }, "texrect" : { "x" : 5, "y" : 6, "w" : 7, "h" : 8 } },{ "name" : "sprite2", - "pivot" : { "x" : 1, "y" : 2 }, "inner_texrect" : { "x" : 1, "y" : 2, "w" : 3, "h" : 4 }, "outer_texrect" : { "x" : 5, "y" : 6, "w" : 7, "h" : 8 } }] diff --git a/untests/bin/library/sprite.json b/untests/bin/library/sprite.json index 28abe14a..7e8defb3 100644 --- a/untests/bin/library/sprite.json +++ b/untests/bin/library/sprite.json @@ -1,5 +1,4 @@ { "texture" : "image.png", - "pivot" : { "x" : 1, "y" : 2 }, "texrect" : { "x" : 5, "y" : 6, "w" : 7, "h" : 8 } } diff --git a/untests/bin/library/sprite2.json b/untests/bin/library/sprite2.json index 876d5416..f238ea3f 100644 --- a/untests/bin/library/sprite2.json +++ b/untests/bin/library/sprite2.json @@ -1,6 +1,5 @@ { "texture" : "image.png", - "pivot" : { "x" : 1, "y" : 2 }, "inner_texrect" : { "x" : 1, "y" : 2, "w" : 3, "h" : 4 }, "outer_texrect" : { "x" : 5, "y" : 6, "w" : 7, "h" : 8 } } diff --git a/untests/sources/untests_high/library.cpp b/untests/sources/untests_high/library.cpp index f67a1625..8ea1fbf9 100644 --- a/untests/sources/untests_high/library.cpp +++ b/untests/sources/untests_high/library.cpp @@ -192,14 +192,12 @@ TEST_CASE("library"){ sprite_asset::ptr spr = atlas_res->find_nested_asset("sprite"); REQUIRE(spr); - REQUIRE(spr->content().pivot() == v2f(1.f,2.f)); REQUIRE(spr->content().inner_texrect() == b2f(5.f,6.f,7.f,8.f)); REQUIRE(spr->content().outer_texrect() == b2f(5.f,6.f,7.f,8.f)); REQUIRE(spr->content().texture()== texture_res); sprite_asset::ptr spr2 = atlas_res->find_nested_asset("sprite2"); REQUIRE(spr2); - REQUIRE(spr2->content().pivot() == v2f(1.f,2.f)); REQUIRE(spr2->content().inner_texrect() == b2f(1.f,2.f,3.f,4.f)); REQUIRE(spr2->content().outer_texrect() == b2f(5.f,6.f,7.f,8.f)); REQUIRE(spr2->content().texture()== texture_res); @@ -208,14 +206,12 @@ TEST_CASE("library"){ { auto sprite_res = l.load_asset("sprite.json"); REQUIRE(sprite_res); - REQUIRE(sprite_res->content().pivot() == v2f(1.f, 2.f)); REQUIRE(sprite_res->content().inner_texrect() == b2f(5.f, 6.f, 7.f, 8.f)); REQUIRE(sprite_res->content().outer_texrect() == b2f(5.f, 6.f, 7.f, 8.f)); REQUIRE(sprite_res->content().texture() == texture_res); auto sprite2_res = l.load_asset("sprite2.json"); REQUIRE(sprite2_res); - REQUIRE(sprite2_res->content().pivot() == v2f(1.f, 2.f)); REQUIRE(sprite2_res->content().inner_texrect() == b2f(1.f, 2.f, 3.f, 4.f)); REQUIRE(sprite2_res->content().outer_texrect() == b2f(5.f, 6.f, 7.f, 8.f)); REQUIRE(sprite2_res->content().texture() == texture_res);