Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
angle.hpp
Go to the documentation of this file.
1
12#ifndef MINESERVER_ANGLE_H
13#define MINESERVER_ANGLE_H
14
15#include <cstddef>
16#include <plugins/luaheaders.h>
17
24class Angle
25{
26private:
27 std::byte value;
28
29public:
35 Angle() : value((std::byte)0) {}
41 Angle(float degrees) : value((std::byte)(degrees * 256.f / 360.f)) {}
47 Angle(std::byte value) : value(value) {}
52 ~Angle() = default;
53
59 float getDegrees() const
60 {
61 return ((float)value) * 360.f / 256.f;
62 }
63
69 std::byte getByte() const
70 {
71 return value;
72 }
73
80 static void loadLua(lua_State *state, const char *namespaceName)
81 {
82 luabridge::getGlobalNamespace(state)
83 .beginNamespace(namespaceName)
84 .beginClass<Angle>("Angle")
85 .addConstructor<void(float), void(std::byte)>()
86 .addFunction("getDegrees", &Angle::getDegrees)
87 .addFunction("getByte", &Angle::getByte)
88 .endClass()
89 .endNamespace();
90 }
91};
92
93#endif // MINESERVER_ANGLE_H
Angle class holder.
Definition angle.hpp:25
Angle(std::byte value)
Construct a new Angle object from byte.
Definition angle.hpp:47
std::byte getByte() const
Get the Byte representation.
Definition angle.hpp:69
float getDegrees() const
Get the Degrees of the Angle.
Definition angle.hpp:59
static void loadLua(lua_State *state, const char *namespaceName)
Loads Angle to lua state.
Definition angle.hpp:80
Angle(float degrees)
Construct a new Angle object from degrees.
Definition angle.hpp:41
~Angle()=default
Destroy the Angle object.
Angle()
Construct a new Angle object.
Definition angle.hpp:35
constexpr std::string_view type_name()
Gets the name of the type paramater.
Definition event.h:56
Utility header file for lua things.