diff --git a/include/bedrock/core/math/int_range.h b/include/bedrock/common/util/int_range.h similarity index 94% rename from include/bedrock/core/math/int_range.h rename to include/bedrock/common/util/int_range.h index cccb71513..d1438b950 100644 --- a/include/bedrock/core/math/int_range.h +++ b/include/bedrock/common/util/int_range.h @@ -15,6 +15,6 @@ #pragma once struct IntRange { - int min; - int max; + int range_min; + int range_max; }; diff --git a/include/bedrock/core/math/color.h b/include/bedrock/core/math/color.h index 3c3eccfa3..36763cb3a 100644 --- a/include/bedrock/core/math/color.h +++ b/include/bedrock/core/math/color.h @@ -22,31 +22,8 @@ namespace mce { class Color { public: - [[nodiscard]] std::string toHexString() const - { - std::stringstream stream; - stream << "#" << std::setfill('0') << std::hex // - << std::setw(2) << static_cast(r * 255) // - << std::setw(2) << static_cast(g * 255) // - << std::setw(2) << static_cast(b * 255) // - << std::setw(2) << static_cast(a * 255); - return stream.str(); - } - - static Color fromHexString(const std::string &hex_string) - { - Color color = {0}; - if (hex_string.length() != 8) { - return color; - } - - auto value = std::strtoul(hex_string.c_str(), nullptr, 16); - color.r = static_cast(((value >> 24) & 0xFF)) / 255.0F; - color.g = static_cast(((value >> 16) & 0xFF)) / 255.0F; - color.b = static_cast(((value >> 8) & 0xFF)) / 255.0F; - color.a = static_cast((value & 0xFF)) / 255.0F; - return color; - } + [[nodiscard]] std::string toHexString() const; + static Color fromHexString(const std::string &hex_string); float r; float g; diff --git a/include/bedrock/world/level/block/block_legacy.h b/include/bedrock/world/level/block/block_legacy.h index 894b58f84..ff056b5fe 100644 --- a/include/bedrock/world/level/block/block_legacy.h +++ b/include/bedrock/world/level/block/block_legacy.h @@ -17,9 +17,9 @@ #include #include "bedrock/common/resources/base_game_version.h" +#include "bedrock/common/util/int_range.h" #include "bedrock/core/hashed_string.h" #include "bedrock/core/math/color.h" -#include "bedrock/core/math/int_range.h" #include "bedrock/entity/entity_context.h" #include "bedrock/forward.h" #include "bedrock/world/direction.h" diff --git a/src/endstone_runtime/bedrock/core/math/color.cpp b/src/endstone_runtime/bedrock/core/math/color.cpp new file mode 100644 index 000000000..26756371a --- /dev/null +++ b/src/endstone_runtime/bedrock/core/math/color.cpp @@ -0,0 +1,41 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bedrock/core/math/color.h" + +std::string mce::Color::toHexString() const +{ + std::stringstream stream; + stream << "#" << std::setfill('0') << std::hex // + << std::setw(2) << static_cast(r * 255) // + << std::setw(2) << static_cast(g * 255) // + << std::setw(2) << static_cast(b * 255) // + << std::setw(2) << static_cast(a * 255); + return stream.str(); +} + +mce::Color mce::Color::fromHexString(const std::string &hex_string) +{ + Color color{}; + if (hex_string.length() != 8) { + return color; + } + + const auto value = std::strtoul(hex_string.c_str(), nullptr, 16); + color.r = static_cast((value >> 24) & 0xFF) / 255.0F; + color.g = static_cast((value >> 16) & 0xFF) / 255.0F; + color.b = static_cast((value >> 8) & 0xFF) / 255.0F; + color.a = static_cast(value & 0xFF) / 255.0F; + return color; +}