remove atlas per pixels per unit property

This commit is contained in:
2019-03-26 10:32:02 +07:00
parent cdb15dd58d
commit 37fb586e27
5 changed files with 1 additions and 30 deletions

View File

@@ -44,9 +44,6 @@ namespace e2d
atlas& set_texture(const texture_asset::ptr& texture) noexcept;
const texture_asset::ptr& texture() const noexcept;
atlas& set_pixels_per_unit(f32 pixels_per_unit) noexcept;
f32 pixels_per_unit() const noexcept;
atlas& set_regions(vector<region>&& regions) noexcept;
atlas& set_regions(const vector<region>& regions);
const vector<region>& regions() const noexcept;
@@ -58,7 +55,6 @@ namespace e2d
const shape_region* find_shape_region(str_hash name) const noexcept;
private:
texture_asset::ptr texture_;
f32 pixels_per_unit_{1.f};
vector<region> regions_;
vector<shape_region> shape_regions_;
};

View File

@@ -21,11 +21,10 @@ namespace
const char* atlas_asset_schema_source = R"json(
{
"type" : "object",
"required" : [ "texture", "pixels_per_unit" ],
"required" : [ "texture" ],
"additionalProperties" : false,
"properties" : {
"texture" : { "$ref": "#/common_definitions/address" },
"pixels_per_unit" : { "type" : "number" },
"regions" : { "$ref": "#/definitions/regions" },
"shape_regions" : { "$ref": "#/definitions/shape_regions" }
},
@@ -154,13 +153,6 @@ namespace
auto texture_p = library.load_asset_async<texture_asset>(
path::combine(parent_address, root["texture"].GetString()));
f32 pixels_per_unit = 1.f;
E2D_ASSERT(root.HasMember("pixels_per_unit"));
if ( !json_utils::try_parse_value(root["pixels_per_unit"], pixels_per_unit) ) {
return stdex::make_rejected_promise<atlas>(
atlas_asset_loading_exception());
}
vector<atlas::region> regions;
if ( root.HasMember("regions") ) {
E2D_ASSERT(root["regions"].IsArray());
@@ -182,13 +174,11 @@ namespace
}
return texture_p.then([
pixels_per_unit,
regions = std::move(regions),
shape_regions = std::move(shape_regions)
](const texture_asset::load_result& texture) mutable {
atlas content;
content.set_texture(texture);
content.set_pixels_per_unit(pixels_per_unit);
content.set_regions(std::move(regions));
content.set_shape_regions(std::move(shape_regions));
return content;

View File

@@ -29,7 +29,6 @@ namespace e2d
void atlas::clear() noexcept {
texture_.reset();
pixels_per_unit_ = 1.f;
regions_.clear();
shape_regions_.clear();
}
@@ -37,7 +36,6 @@ namespace e2d
void atlas::swap(atlas& other) noexcept {
using std::swap;
swap(texture_, other.texture_);
swap(pixels_per_unit_, other.pixels_per_unit_);
swap(regions_, other.regions_);
swap(shape_regions_, other.shape_regions_);
}
@@ -54,7 +52,6 @@ namespace e2d
if ( this != &other ) {
atlas s;
s.texture_ = other.texture_;
s.pixels_per_unit_ = other.pixels_per_unit_;
s.regions_ = other.regions_;
s.shape_regions_ = other.shape_regions_;
swap(s);
@@ -71,15 +68,6 @@ namespace e2d
return texture_;
}
atlas& atlas::set_pixels_per_unit(f32 pixels_per_unit) noexcept {
pixels_per_unit_ = pixels_per_unit;
return *this;
}
f32 atlas::pixels_per_unit() const noexcept {
return pixels_per_unit_;
}
atlas& atlas::set_regions(vector<region>&& regions) noexcept {
regions_ = std::move(regions);
std::sort(
@@ -147,7 +135,6 @@ namespace e2d
bool operator==(const atlas& l, const atlas& r) noexcept {
return l.texture() == r.texture()
&& math::approximately(l.pixels_per_unit(), r.pixels_per_unit())
&& l.regions() == r.regions()
&& l.shape_regions() == r.shape_regions();
}

View File

@@ -1,6 +1,5 @@
{
"texture" : "image.png",
"pixels_per_unit" : 2,
"regions" : [{
"name" : "sprite",
"pivot" : { "x" : 1, "y" : 2 },

View File

@@ -99,7 +99,6 @@ TEST_CASE("library"){
auto atlas_res = l.load_asset<atlas_asset>("atlas.json");
REQUIRE(atlas_res);
REQUIRE(atlas_res->content().texture() == texture_res);
REQUIRE(math::approximately(atlas_res->content().pixels_per_unit(), 2.f));
REQUIRE(atlas_res->content().regions().size() == 1);
REQUIRE(atlas_res->content().find_region("sprite"));
REQUIRE(atlas_res->content().find_region("sprite")->name == make_hash("sprite"));