feat: Added Sky class

+ changed file structure in the python module
+ fixed static method binding for PyDaedalus class
This commit is contained in:
AURUMVORXX
2024-11-07 02:29:19 +03:00
parent 6e76960158
commit 15b34c3f40
11 changed files with 185 additions and 16 deletions

View File

@@ -6,9 +6,10 @@ 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 *

61
g2o/classes/sky.py Normal file
View File

@@ -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()

View File

@@ -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 <NoNut/core/Constant.h>
namespace py = pybind11;
@@ -68,7 +69,21 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
// -------------------------------------------------------------------------
py::class_<PyDaedalus>(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_<PySky>(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(); });
}

View File

@@ -3,7 +3,6 @@
#include <classes/sq/Daedalus.h>
#include <pybind11/embed.h>
#include <iostream>
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; }
};

30
src/classes/py/Sky.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef _PYSKY_H_
#define _PYSKY_H_
#include <classes/sq/Sky.h>
#include <pybind11/embed.h>
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

30
src/classes/sq/Sky.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <NoNut/core/CommonHeader.h>
#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)
{
}
}

34
src/classes/sq/Sky.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef _SKY_H_
#define _SKY_H_
#include <string>
#include <NoNut/core/StaticClass.h>
#include <NoNut/core/CustomTypes.h>
namespace nonut
{
class Sky : public StaticClass
{
public:
static Sky* get();
Function<void, Int, Int> setRainStartTime;
Function<SqDict> getRainStartTime;
Function<void, Int, Int> setRainStopTime;
Function<SqDict> getRainStopTime;
Property<Int> weather;
Property<Bool> raining;
Property<Bool> renderLightning;
Property<Float> windScale;
Property<Bool> dontRain;
private:
static inline Sky* inst = nullptr;
Sky();
};
}
#endif