Skip to content

Commit

Permalink
Reformatted (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlegiantJGC authored Jan 28, 2025
1 parent f0efc57 commit 5860e38
Show file tree
Hide file tree
Showing 73 changed files with 3,934 additions and 4,234 deletions.
51 changes: 26 additions & 25 deletions src/amulet/biome.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
#include <map>
#include <variant>
#include <type_traits>
#include <string>
#include <functional>
#include <map>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <variant>

#include <amulet/dll.hpp>
#include <amulet/biome.hpp>
#include <amulet/dll.hpp>
#include <amulet_nbt/nbt_encoding/binary.hpp>
#include <amulet_nbt/nbt_encoding/string.hpp>

namespace Amulet {
void Biome::serialise(BinaryWriter& writer) const {
writer.writeNumeric<std::uint8_t>(1);
writer.writeSizeAndBytes(get_platform());
get_version()->serialise(writer);
writer.writeSizeAndBytes(namespace_);
writer.writeSizeAndBytes(base_name);
void Biome::serialise(BinaryWriter& writer) const
{
writer.writeNumeric<std::uint8_t>(1);
writer.writeSizeAndBytes(get_platform());
get_version()->serialise(writer);
writer.writeSizeAndBytes(namespace_);
writer.writeSizeAndBytes(base_name);
}
std::shared_ptr<Biome> Biome::deserialise(BinaryReader& reader)
{
auto version_number = reader.readNumeric<std::uint8_t>();
switch (version_number) {
case 1: {
std::string platform = reader.readSizeAndBytes();
std::shared_ptr<VersionNumber> version = VersionNumber::deserialise(reader);
std::string namespace_ = reader.readSizeAndBytes();
std::string base_name = reader.readSizeAndBytes();
return std::make_shared<Biome>(platform, version, namespace_, base_name);
}
std::shared_ptr<Biome> Biome::deserialise(BinaryReader& reader){
auto version_number = reader.readNumeric<std::uint8_t>();
switch (version_number) {
case 1:
{
std::string platform = reader.readSizeAndBytes();
std::shared_ptr<VersionNumber> version = VersionNumber::deserialise(reader);
std::string namespace_ = reader.readSizeAndBytes();
std::string base_name = reader.readSizeAndBytes();
return std::make_shared<Biome>(platform, version, namespace_, base_name);
}
default:
throw std::invalid_argument("Unsupported version " + std::to_string(version_number));
}
default:
throw std::invalid_argument("Unsupported version " + std::to_string(version_number));
}
}

}
69 changes: 38 additions & 31 deletions src/amulet/biome.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,49 @@
#include <string>

#include <amulet/dll.hpp>
#include <amulet/version.hpp>
#include <amulet/io/binary_reader.hpp>
#include <amulet/io/binary_writer.hpp>

#include <amulet/version.hpp>

namespace Amulet {
class Biome: public PlatformVersionContainer {
private:
std::string namespace_;
std::string base_name;
public:
const std::string& get_namespace() const { return namespace_; }
const std::string& get_base_name() const { return base_name; }
class Biome : public PlatformVersionContainer {
private:
std::string namespace_;
std::string base_name;

public:
const std::string& get_namespace() const { return namespace_; }
const std::string& get_base_name() const { return base_name; }

Biome(
const PlatformType& platform,
std::shared_ptr<VersionNumber> version,
const std::string& namespace_,
const std::string& base_name
):
PlatformVersionContainer(platform, version),
namespace_(namespace_),
base_name(base_name) {}
Biome(
const PlatformType& platform,
std::shared_ptr<VersionNumber> version,
const std::string& namespace_,
const std::string& base_name)
: PlatformVersionContainer(platform, version)
, namespace_(namespace_)
, base_name(base_name)
{
}

AMULET_CORE_EXPORT void serialise(BinaryWriter&) const;
AMULET_CORE_EXPORT static std::shared_ptr<Biome> deserialise(BinaryReader&);
AMULET_CORE_EXPORT void serialise(BinaryWriter&) const;
AMULET_CORE_EXPORT static std::shared_ptr<Biome> deserialise(BinaryReader&);

auto operator<=>(const Biome& other) const {
auto cmp = PlatformVersionContainer::operator<=>(other);
if (cmp != 0) { return cmp; }
cmp = namespace_ <=> other.namespace_;
if (cmp != 0) { return cmp; }
return base_name <=> other.base_name;
}
bool operator==(const Biome& other) const {
return (*this <=> other) == 0;
}
};
auto operator<=>(const Biome& other) const
{
auto cmp = PlatformVersionContainer::operator<=>(other);
if (cmp != 0) {
return cmp;
}
cmp = namespace_ <=> other.namespace_;
if (cmp != 0) {
return cmp;
}
return base_name <=> other.base_name;
}
bool operator==(const Biome& other) const
{
return (*this <=> other) == 0;
}
};
}
167 changes: 74 additions & 93 deletions src/amulet/biome.py.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/typing.h>

#include <span>
#include <memory>
#include <span>

#include <amulet/biome.hpp>

namespace py = pybind11;

void init_biome(py::module m_parent) {
void init_biome(py::module m_parent)
{
auto m = m_parent.def_submodule("biome");
py::class_<Amulet::Biome, Amulet::PlatformVersionContainer, std::shared_ptr<Amulet::Biome>> Biome(m, "Biome",
"A class to manage the state of a biome.\n"
Expand All @@ -25,96 +26,76 @@ void init_biome(py::module m_parent) {
"\n"
">>> # Create a plains biome for Bedrock \n"
">>> plains = Biome(\"bedrock\", VersionNumber(1, 21, 0, 3), \"minecraft\", \"plains\")\n"
">>> # The biome version number is unused in Bedrock but it is here for completeness."
);
Biome.def(
py::init<
const Amulet::PlatformType&,
std::shared_ptr<Amulet::VersionNumber>,
const std::string&,
const std::string&
>(),
py::arg("platform"),
py::arg("version"),
py::arg("namespace"),
py::arg("base_name")
);
Biome.def_property_readonly(
"namespaced_name",
[](const Amulet::Biome& self) {
return self.get_namespace() + ":" + self.get_base_name();
">>> # The biome version number is unused in Bedrock but it is here for completeness.");
Biome.def(
py::init<
const Amulet::PlatformType&,
std::shared_ptr<Amulet::VersionNumber>,
const std::string&,
const std::string&>(),
py::arg("platform"),
py::arg("version"),
py::arg("namespace"),
py::arg("base_name"));
Biome.def_property_readonly(
"namespaced_name",
[](const Amulet::Biome& self) {
return self.get_namespace() + ":" + self.get_base_name();
},
py::doc(
"The namespaced id of the :class:`Biome` object.\n"
"\n"
">>> biome: Biome\n"
">>> biome.namespaced_name\n"
"\n"
":return: The \"namespace:base_name\" of the biome"));
Biome.def_property_readonly(
"namespace",
&Amulet::Biome::get_namespace,
py::doc(
"The namespace of the :class:`Biome` object.\n"
"\n"
">>> biome: Biome\n"
">>> water.namespace\n"
"\n"
":return: The namespace of the biome"));
Biome.def_property_readonly(
"base_name",
&Amulet::Biome::get_base_name,
py::doc(
"The base name of the :class:`Biome` object.\n"
"\n"
">>> biome: Biome\n"
">>> biome.base_name\n"
"\n"
":return: The base name of the biome"));
Biome.def(
"__repr__",
[](const Amulet::Biome& self) {
return "Biome(" + py::repr(py::cast(self.get_platform())).cast<std::string>() + ", " + py::repr(py::cast(self.get_version())).cast<std::string>() + ", " + py::repr(py::cast(self.get_namespace())).cast<std::string>() + ", " + py::repr(py::cast(self.get_base_name())).cast<std::string>() + ")";
});
Biome.def(
"__hash__",
[](const Amulet::Biome& self) {
return py::hash(
py::make_tuple(
py::cast(self.get_platform()),
py::cast(self.get_version()),
py::cast(self.get_namespace()),
py::cast(self.get_base_name())));
});
Biome.def(
py::pickle(
[](const Amulet::Biome& self) -> py::bytes {
return py::bytes(Amulet::serialise(self));
},
py::doc(
"The namespaced id of the :class:`Biome` object.\n"
"\n"
">>> biome: Biome\n"
">>> biome.namespaced_name\n"
"\n"
":return: The \"namespace:base_name\" of the biome"
)
);
Biome.def_property_readonly(
"namespace",
&Amulet::Biome::get_namespace,
py::doc(
"The namespace of the :class:`Biome` object.\n"
"\n"
">>> biome: Biome\n"
">>> water.namespace\n"
"\n"
":return: The namespace of the biome"
)
);
Biome.def_property_readonly(
"base_name",
&Amulet::Biome::get_base_name,
py::doc(
"The base name of the :class:`Biome` object.\n"
"\n"
">>> biome: Biome\n"
">>> biome.base_name\n"
"\n"
":return: The base name of the biome"
)
);
Biome.def(
"__repr__",
[](const Amulet::Biome& self){
return "Biome(" +
py::repr(py::cast(self.get_platform())).cast<std::string>() + ", " +
py::repr(py::cast(self.get_version())).cast<std::string>() + ", " +
py::repr(py::cast(self.get_namespace())).cast<std::string>() + ", " +
py::repr(py::cast(self.get_base_name())).cast<std::string>() +
")";
}
);
Biome.def(
"__hash__",
[](const Amulet::Biome& self) {
return py::hash(
py::make_tuple(
py::cast(self.get_platform()),
py::cast(self.get_version()),
py::cast(self.get_namespace()),
py::cast(self.get_base_name())
)
);
}
);
Biome.def(
py::pickle(
[](const Amulet::Biome& self) -> py::bytes {
return py::bytes(Amulet::serialise(self));
},
[](py::bytes state){
return Amulet::deserialise<Amulet::Biome>(state.cast<std::string>());
}
)
);
[](py::bytes state) {
return Amulet::deserialise<Amulet::Biome>(state.cast<std::string>());
}));

Biome.def(py::self == py::self);
Biome.def(py::self > py::self);
Biome.def(py::self < py::self);
Biome.def(py::self >= py::self);
Biome.def(py::self <= py::self);
Biome.def(py::self == py::self);
Biome.def(py::self > py::self);
Biome.def(py::self < py::self);
Biome.def(py::self >= py::self);
Biome.def(py::self <= py::self);
}
Loading

0 comments on commit 5860e38

Please sign in to comment.