feat: Added Way class

This commit is contained in:
AURUMVORXX
2024-11-11 11:32:10 +03:00
parent 2e83646914
commit b199563943
8 changed files with 142 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
# `class` Way
---
::: g2o.classes.way.Way

View File

@@ -13,6 +13,7 @@ from g2o.classes.items import ItemsGround
from g2o.classes.daedalus import Daedalus from g2o.classes.daedalus import Daedalus
from g2o.classes.sky import Sky from g2o.classes.sky import Sky
from g2o.classes.mds import Mds from g2o.classes.mds import Mds
from g2o.classes.way import Way
from g2o.functions.chat import sendMessageToAll from g2o.functions.chat import sendMessageToAll
from g2o.functions.chat import sendMessageToPlayer from g2o.functions.chat import sendMessageToPlayer

48
g2o/classes/way.py Normal file
View File

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

View File

@@ -29,7 +29,9 @@ nav:
- Network: - Network:
- Packet: classes/network/Packet.md - Packet: classes/network/Packet.md
- Mds: - Mds:
- Mds: classes/mds/mds.md - Mds: classes/mds/Mds.md
- Waypoint:
- Way: classes/waypoint/Way.md
- Constants: - Constants:
- AntiCheat: constants/anticheat.md - AntiCheat: constants/anticheat.md
- Context: constants/context.md - Context: constants/context.md

View File

@@ -7,6 +7,7 @@
#include "classes/py/Sky.h" #include "classes/py/Sky.h"
#include "classes/py/ItemsGround.h" #include "classes/py/ItemsGround.h"
#include "classes/py/Mds.h" #include "classes/py/Mds.h"
#include "classes/py/Way.h"
#include "functions/pyfunctions.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("id", [](std::string value){ return PyMds::id(value); })
.def_static("name", [](int value){ return PyMds::name(value); }); .def_static("name", [](int value){ return PyMds::name(value); });
// -------------------------------------------------------------------------
py::class_<PyWay>(m, "Way")
.def(py::init<std::string, std::string, std::string>())
.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); m.def("getHostname", &py_getHostname);

24
src/classes/py/Way.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef _PYWAY_H_
#define _PYWAY_H_
#include <classes/sq/Way.h>
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

26
src/classes/sq/Way.cpp Normal file
View File

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

24
src/classes/sq/Way.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef _WAY_H
#define _WAY_H
#include <string>
#include <NoNut/core/Class.h>
#include <NoNut/core/CustomTypes.h>
namespace nonut
{
class Way : public Class
{
public:
Way(String, String, String);
explicit Way(SQObject object);
Property<String> start;
Property<String> end;
Function<SqList> getWaypoints;
Function<Int> getCountWaypoints;
};
}
#endif