From 15b34c3f40fe6ef5152de60acd2feb2fd209873d Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Thu, 7 Nov 2024 02:29:19 +0300 Subject: [PATCH] feat: Added Sky class + changed file structure in the python module + fixed static method binding for PyDaedalus class --- g2o/__init__.py | 21 ++++++------ g2o/{ => classes}/daedalus.py | 0 g2o/{ => classes}/damage.py | 0 g2o/{ => classes}/items.py | 0 g2o/{ => classes}/packets.py | 0 g2o/classes/sky.py | 61 +++++++++++++++++++++++++++++++++++ src/bind.cpp | 21 ++++++++++-- src/classes/py/Daedalus.h | 4 +-- src/classes/py/Sky.h | 30 +++++++++++++++++ src/classes/sq/Sky.cpp | 30 +++++++++++++++++ src/classes/sq/Sky.h | 34 +++++++++++++++++++ 11 files changed, 185 insertions(+), 16 deletions(-) rename g2o/{ => classes}/daedalus.py (100%) rename g2o/{ => classes}/damage.py (100%) rename g2o/{ => classes}/items.py (100%) rename g2o/{ => classes}/packets.py (100%) create mode 100644 g2o/classes/sky.py create mode 100644 src/classes/py/Sky.h create mode 100644 src/classes/sq/Sky.cpp create mode 100644 src/classes/sq/Sky.h diff --git a/g2o/__init__.py b/g2o/__init__.py index abaf0ad..4fbe286 100644 --- a/g2o/__init__.py +++ b/g2o/__init__.py @@ -1,14 +1,15 @@ -from g2o.events import addEvent -from g2o.events import callEvent -from g2o.events import event -from g2o.events import removeEventHandler -from g2o.events import toggleEvent -from g2o.events import removeEvent +from g2o.events import addEvent +from g2o.events import callEvent +from g2o.events import event +from g2o.events import removeEventHandler +from g2o.events import toggleEvent +from g2o.events import removeEvent -from g2o.packets import Packet -from g2o.damage import DamageDescription -from g2o.items import ItemGround -from g2o.daedalus import Daedalus +from g2o.classes.packets import Packet +from g2o.classes.damage import DamageDescription +from g2o.classes.items import ItemGround +from g2o.classes.daedalus import Daedalus +from g2o.classes.sky import Sky from sqg2oconst import * \ No newline at end of file diff --git a/g2o/daedalus.py b/g2o/classes/daedalus.py similarity index 100% rename from g2o/daedalus.py rename to g2o/classes/daedalus.py diff --git a/g2o/damage.py b/g2o/classes/damage.py similarity index 100% rename from g2o/damage.py rename to g2o/classes/damage.py diff --git a/g2o/items.py b/g2o/classes/items.py similarity index 100% rename from g2o/items.py rename to g2o/classes/items.py diff --git a/g2o/packets.py b/g2o/classes/packets.py similarity index 100% rename from g2o/packets.py rename to g2o/classes/packets.py diff --git a/g2o/classes/sky.py b/g2o/classes/sky.py new file mode 100644 index 0000000..c839fba --- /dev/null +++ b/g2o/classes/sky.py @@ -0,0 +1,61 @@ +import sqg2o + +class SkyMeta(type): + @property + def weather(self): + return sqg2o.Sky.weather + + @weather.setter + def weather(self, value): + sqg2o.Sky.weather + + @property + def raining(self): + return sqg2o.Sky.raining + + @raining.setter + def raining(self, value): + sqg2o.Sky.raining = value + + @property + def renderLightning(self): + return sqg2o.Sky.renderLightning + + @renderLightning.setter + def renderLightning(self, value): + sqg2o.Sky.renderLightning = value + + @property + def windScale(self): + return sqg2o.Sky.windScale + + @windScale.setter + def windScale(self, value): + sqg2o.Sky.windScale = value + + @property + def dontRain(self): + return sqg2o.Sky.dontRain + + @dontRain.setter + def dontRain(self, value): + sqg2o.Sky.dontRain = value + +class Sky(metaclass=SkyMeta): + + @staticmethod + def setRainStartTime(hour : int, minute : int): + sqg2o.Sky.setRainStartTime(hour, minute) + + @staticmethod + def setRainStopTime(hour : int, minute : int): + sqg2o.Sky.setRainStopTime(hour, minute) + + @staticmethod + def getRainStartTime() -> dict: + return sqg2o.Sky.getRainStartTime() + + @staticmethod + def getRainStopTime() -> dict: + return sqg2o.Sky.getRainStopTime() + \ No newline at end of file diff --git a/src/bind.cpp b/src/bind.cpp index 8add2b1..d4e5c27 100644 --- a/src/bind.cpp +++ b/src/bind.cpp @@ -3,6 +3,7 @@ #include "classes/py/DamageDescription.h" #include "classes/py/ItemGround.h" #include "classes/py/Daedalus.h" +#include "classes/py/Sky.h" #include namespace py = pybind11; @@ -68,7 +69,21 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) { // ------------------------------------------------------------------------- py::class_(m, "Daedalus") - .def_static("index", &PyDaedalus::index) - .def_static("symbol", &PyDaedalus::symbol) - .def_static("instance", &PyDaedalus::instance); + .def_static("index", [](std::string value){ return PyDaedalus::index(value); }) + .def_static("symbol", [](std::string value){ return PyDaedalus::symbol(value); }) + .def_static("instance", [](std::string value){ return PyDaedalus::instance(value); }); + +// ------------------------------------------------------------------------- + + py::class_(m, "Sky") + .def_property_static("weather", [](py::object){ return PySky::getWeather(); }, [](py::object, int value) { PySky::setWeather(value); }) + .def_property_static("raining", [](py::object){ return PySky::getRaining(); }, [](py::object, int value) { PySky::setRaining(value); }) + .def_property_static("renderLightning", [](py::object){ return PySky::getRenderLightning(); }, [](py::object, int value) { PySky::setRenderLightning(value); }) + .def_property_static("windScale", [](py::object){ return PySky::getWindScale(); }, [](py::object, int value) { PySky::setWindScale(value); }) + .def_property_static("dontRain", [](py::object){ return PySky::getDontRain(); }, [](py::object, int value) { PySky::setDontRain(value); }) + + .def_static("setRainStartTime", [](int hour, int min){ return PySky::setRainStartTime(hour, min); }) + .def_static("setRainStopTime", [](int hour, int min){ return PySky::setRainStopTime(hour, min); }) + .def_static("getRainStartTime", [](){ return PySky::getRainStartTime(); }) + .def_static("getRainStopTime", [](){ return PySky::getRainStopTime(); }); } \ No newline at end of file diff --git a/src/classes/py/Daedalus.h b/src/classes/py/Daedalus.h index e4cc1df..5682fac 100644 --- a/src/classes/py/Daedalus.h +++ b/src/classes/py/Daedalus.h @@ -3,7 +3,6 @@ #include #include -#include namespace py = pybind11; class PyDaedalus @@ -11,8 +10,7 @@ class PyDaedalus public: - //static nonut::Int index(nonut::String value) { return nonut::Daedalus::get()->index(value); } - static nonut::Int index(nonut::String value) { std::cout << nonut::Daedalus::get()->index(value) << std::endl;return 5; } + static nonut::Int index(nonut::String value) { return nonut::Daedalus::get()->index(value); } static py::dict symbol(nonut::String value) { return nonut::Daedalus::get()->symbol(value).data; } static py::dict instance(nonut::String value) { return nonut::Daedalus::get()->instance(value).data; } }; diff --git a/src/classes/py/Sky.h b/src/classes/py/Sky.h new file mode 100644 index 0000000..94dc030 --- /dev/null +++ b/src/classes/py/Sky.h @@ -0,0 +1,30 @@ +#ifndef _PYSKY_H_ +#define _PYSKY_H_ + +#include +#include +namespace py = pybind11; + +class PySky +{ + +public: + + static void setWeather(nonut::Int value) { nonut::Sky::get()->weather = value; } + static nonut::Int getWeather() { return nonut::Sky::get()->weather; } + static void setRaining(nonut::Bool value) { nonut::Sky::get()->raining = value; } + static nonut::Bool getRaining() { return nonut::Sky::get()->raining; } + static void setRenderLightning(nonut::Bool value) { nonut::Sky::get()->renderLightning = value; } + static nonut::Bool getRenderLightning() { return nonut::Sky::get()->renderLightning; } + static void setWindScale(nonut::Float value) { nonut::Sky::get()->windScale = value; } + static nonut::Float getWindScale() { return nonut::Sky::get()->windScale; } + static void setDontRain(nonut::Bool value) { nonut::Sky::get()->dontRain = value; } + static nonut::Bool getDontRain() { return nonut::Sky::get()->dontRain; } + + static void setRainStartTime(nonut::Int h, nonut::Int m) { nonut::Sky::get()->setRainStartTime(h, m); } + static void setRainStopTime(nonut::Int h, nonut::Int m) { nonut::Sky::get()->setRainStopTime(h, m); } + static py::dict getRainStartTime() { return nonut::Sky::get()->getRainStartTime().data; } + static py::dict getRainStopTime() { return nonut::Sky::get()->getRainStopTime().data; } +}; + +#endif \ No newline at end of file diff --git a/src/classes/sq/Sky.cpp b/src/classes/sq/Sky.cpp new file mode 100644 index 0000000..18d5381 --- /dev/null +++ b/src/classes/sq/Sky.cpp @@ -0,0 +1,30 @@ +#include +#include "Sky.h" + +namespace nonut +{ + Sky* Sky::get() + { + if (inst == nullptr) + { + inst = new Sky(); + } + return inst; + } + + Sky::Sky() : + StaticClass("Sky"), + + PROPERTY_CTOR(weather), + PROPERTY_CTOR(raining), + PROPERTY_CTOR(renderLightning), + PROPERTY_CTOR(windScale), + PROPERTY_CTOR(dontRain), + + METHOD_CTOR(getRainStartTime), + METHOD_CTOR(getRainStopTime), + METHOD_CTOR(setRainStartTime), + METHOD_CTOR(setRainStopTime) + { + } +} diff --git a/src/classes/sq/Sky.h b/src/classes/sq/Sky.h new file mode 100644 index 0000000..9f0bfbb --- /dev/null +++ b/src/classes/sq/Sky.h @@ -0,0 +1,34 @@ +#ifndef _SKY_H_ +#define _SKY_H_ +#include + +#include +#include + +namespace nonut +{ + class Sky : public StaticClass + { + public: + static Sky* get(); + + Function setRainStartTime; + Function getRainStartTime; + Function setRainStopTime; + Function getRainStopTime; + + Property weather; + Property raining; + Property renderLightning; + Property windScale; + Property dontRain; + + private: + + static inline Sky* inst = nullptr; + + Sky(); + }; +} +#endif +