diff --git a/docs/classes/waypoint/Way.md b/docs/classes/waypoint/Way.md new file mode 100644 index 0000000..f9573d2 --- /dev/null +++ b/docs/classes/waypoint/Way.md @@ -0,0 +1,3 @@ +# `class` Way +--- +::: g2o.classes.way.Way \ No newline at end of file diff --git a/g2o/__init__.py b/g2o/__init__.py index 6fe1d6b..6b83521 100644 --- a/g2o/__init__.py +++ b/g2o/__init__.py @@ -13,6 +13,7 @@ from g2o.classes.items import ItemsGround from g2o.classes.daedalus import Daedalus from g2o.classes.sky import Sky from g2o.classes.mds import Mds +from g2o.classes.way import Way from g2o.functions.chat import sendMessageToAll from g2o.functions.chat import sendMessageToPlayer diff --git a/g2o/classes/way.py b/g2o/classes/way.py new file mode 100644 index 0000000..733b8a9 --- /dev/null +++ b/g2o/classes/way.py @@ -0,0 +1,48 @@ + +import sqg2o + +class Way(sqg2o.Way): + """ + This class represents Way constructed from waypoints. + Original: [Way](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-classes/waypoint/Way/) + + ## `str` start *(read-only)* + Represents the start waypoint for Way. + + ## `str` end *(read-only)* + Represents the end waypoint for Way. + """ + def __init__(self, world : str, startWp : str, endWp : str): + """ + ## Parameters + `str` **world**: the name of the world from config.xml. + `str` **startWp**: the name of the start waypoint. + `str` **endWp**: the name of the end waypoint. + """ + return super().__init__(world, startWp, endWp) + + def getWaypoints(self) -> list: + """ + This method will get the all waypoints between startWp & endWp. + + ## Returns + `list [str]`: the list containing the names of all of the Way waypoints. + """ + return super().getWaypoints() + + def getCountWaypoints(self): + """ + This method will get the number of waypoints between start waypoint & end waypoint. + + ## Returns + `int`: the number of waypoints. + """ + return super().getCountWaypoints() + + @property + def start(self): + return super().start + + @property + def end(self): + return super().end \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index fc6e403..f32e8c8 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -29,7 +29,9 @@ nav: - Network: - Packet: classes/network/Packet.md - Mds: - - Mds: classes/mds/mds.md + - Mds: classes/mds/Mds.md + - Waypoint: + - Way: classes/waypoint/Way.md - Constants: - AntiCheat: constants/anticheat.md - Context: constants/context.md diff --git a/src/bind.cpp b/src/bind.cpp index c3f089d..b2fef42 100644 --- a/src/bind.cpp +++ b/src/bind.cpp @@ -7,6 +7,7 @@ #include "classes/py/Sky.h" #include "classes/py/ItemsGround.h" #include "classes/py/Mds.h" +#include "classes/py/Way.h" #include "functions/pyfunctions.h" @@ -108,6 +109,18 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) { .def_static("id", [](std::string value){ return PyMds::id(value); }) .def_static("name", [](int value){ return PyMds::name(value); }); +// ------------------------------------------------------------------------- + + py::class_(m, "Way") + + .def(py::init()) + .def("getWaypoints", &PyWay::getWaypoints) + .def("getCountWaypoints", &PyWay::getCountWaypoints) + .def("__del__", &PyWay::del) + + .def_property_readonly("start", &PyWay::getStart) + .def_property_readonly("end", &PyWay::getEnd); + // ------------------------------------------------------------------------- m.def("getHostname", &py_getHostname); diff --git a/src/classes/py/Way.h b/src/classes/py/Way.h new file mode 100644 index 0000000..5ecc7a0 --- /dev/null +++ b/src/classes/py/Way.h @@ -0,0 +1,24 @@ +#ifndef _PYWAY_H_ +#define _PYWAY_H_ + +#include + +class PyWay +{ +private: + nonut::Way *sqway; + +public: + PyWay(std::string world, std::string start, std::string end) { sqway = new nonut::Way(world, start, end); }; + PyWay(SQObject obj) { if (obj._type == OT_NULL) throw py::type_error("Presented Squirrel Object doesn't exist (type: null)"); sqway = new nonut::Way(obj); } + + py::list getWaypoints() { return sqway->getWaypoints().data; } + int getCountWaypoints() { return sqway->getCountWaypoints(); } + + std::string getStart() { return sqway->start; } + std::string getEnd() { return sqway->end; } + + void del() { delete sqway; } +}; + +#endif \ No newline at end of file diff --git a/src/classes/sq/Way.cpp b/src/classes/sq/Way.cpp new file mode 100644 index 0000000..34036d4 --- /dev/null +++ b/src/classes/sq/Way.cpp @@ -0,0 +1,26 @@ +#include +#include "Way.h" + +namespace nonut +{ + Way::Way(String world, String startWp, String endWp) : + Class("Way"), + METHOD_CTOR(getWaypoints), + METHOD_CTOR(getCountWaypoints), + + PROPERTY_CTOR(start), + PROPERTY_CTOR(end) + { + classCtor(world, startWp, endWp); + } + + Way::Way(SQObject object) : + Class("Way", object), + METHOD_CTOR(getWaypoints), + METHOD_CTOR(getCountWaypoints), + + PROPERTY_CTOR(start), + PROPERTY_CTOR(end) + { + } +} diff --git a/src/classes/sq/Way.h b/src/classes/sq/Way.h new file mode 100644 index 0000000..c1624c3 --- /dev/null +++ b/src/classes/sq/Way.h @@ -0,0 +1,24 @@ +#ifndef _WAY_H +#define _WAY_H +#include + +#include +#include + +namespace nonut +{ + class Way : public Class + { + public: + Way(String, String, String); + explicit Way(SQObject object); + + Property start; + Property end; + + Function getWaypoints; + Function getCountWaypoints; + }; +} +#endif +