feat: Added Daedalus class
+ sqParseTable moved to nonut::CustomTypes as SqDict + fix: Removed Python constructors for ItemGround and DamageDescription classes (so it's unable to make new objects in the scripts)
This commit is contained in:
@@ -9,5 +9,6 @@ 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 sqg2oconst import *
|
||||
15
g2o/daedalus.py
Normal file
15
g2o/daedalus.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import sqg2o
|
||||
|
||||
class Daedalus:
|
||||
|
||||
@staticmethod
|
||||
def index(value : str) -> int:
|
||||
return sqg2o.Daedalus.index(value)
|
||||
|
||||
@staticmethod
|
||||
def symbol(value : str) -> dict:
|
||||
return sqg2o.Daedalus.symbol(value)
|
||||
|
||||
@staticmethod
|
||||
def instance(value : str) -> dict:
|
||||
return sqg2o.Daedalus.instance(value)
|
||||
@@ -108,4 +108,33 @@ namespace nonut
|
||||
GET_SLOT(y, Float);
|
||||
GET_SLOT(z, Float);
|
||||
}
|
||||
|
||||
void SqDict::convert(SQObject object)
|
||||
{
|
||||
Sqrat::Table tab = Sqrat::Table(object);
|
||||
Sqrat::Object::iterator tabIterator;
|
||||
int i = 0;
|
||||
|
||||
while (tab.Next(tabIterator))
|
||||
{
|
||||
HSQOBJECT key = tabIterator.getKey();
|
||||
HSQOBJECT value = tabIterator.getValue();
|
||||
|
||||
if (key._type != OT_STRING)
|
||||
continue;
|
||||
|
||||
if (value._type == OT_STRING)
|
||||
data[sq_objtostring(&key)] = sq_objtostring(&value);
|
||||
else if (value._type == OT_INTEGER)
|
||||
data[sq_objtostring(&key)] = sq_objtointeger(&value);
|
||||
else if (value._type == OT_FLOAT)
|
||||
data[sq_objtostring(&key)] = sq_objtofloat(&value);
|
||||
else if (value._type == OT_TABLE)
|
||||
{
|
||||
SqDict result = SqDict();
|
||||
result.convert(object);
|
||||
data[sq_objtostring(&key)] = result.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
#define NONUT_G2O_SHARED_CUSTOM_TYPES_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <pybind11/embed.h>
|
||||
#include "Utils.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace nonut
|
||||
{
|
||||
struct GameTime : CustomType
|
||||
@@ -164,5 +166,11 @@ namespace nonut
|
||||
return std::make_tuple(name, x, y, z);
|
||||
}
|
||||
};
|
||||
|
||||
struct SqDict : CustomType
|
||||
{
|
||||
void convert(SQObject object) override;
|
||||
py::dict data{};
|
||||
};
|
||||
}
|
||||
#endif // NONUT_G2O_SHARED_CUSTOM_TYPES_H
|
||||
|
||||
11
src/bind.cpp
11
src/bind.cpp
@@ -2,6 +2,7 @@
|
||||
#include "classes/py/Packet.h"
|
||||
#include "classes/py/DamageDescription.h"
|
||||
#include "classes/py/ItemGround.h"
|
||||
#include "classes/py/Daedalus.h"
|
||||
#include <NoNut/core/Constant.h>
|
||||
|
||||
namespace py = pybind11;
|
||||
@@ -39,8 +40,6 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
py::class_<PyDamageDescription>(m, "DamageDescription")
|
||||
.def(py::init<>())
|
||||
.def("__del__", &PyDamageDescription::del)
|
||||
|
||||
.def_property_readonly("item_instance", &PyDamageDescription::getItemInstance)
|
||||
|
||||
@@ -54,7 +53,6 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
py::class_<PyItemGround>(m, "ItemGround")
|
||||
.def(py::init<>())
|
||||
.def("__del__", &PyItemGround::del)
|
||||
|
||||
.def("getPosition", &PyItemGround::getPosition)
|
||||
@@ -66,4 +64,11 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
|
||||
.def_property_readonly("world", &PyItemGround::getWorld)
|
||||
|
||||
.def_property("virtualWorld", &PyItemGround::getVirtualWorld, &PyItemGround::setVirtualWorld, py::return_value_policy::reference_internal);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
py::class_<PyDaedalus>(m, "Daedalus")
|
||||
.def_static("index", &PyDaedalus::index)
|
||||
.def_static("symbol", &PyDaedalus::symbol)
|
||||
.def_static("instance", &PyDaedalus::instance);
|
||||
}
|
||||
20
src/classes/py/Daedalus.h
Normal file
20
src/classes/py/Daedalus.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef _PYDAEDALUS_H_
|
||||
#define _PYDAEDALUS_H_
|
||||
|
||||
#include <classes/sq/Daedalus.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include <iostream>
|
||||
namespace py = pybind11;
|
||||
|
||||
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 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; }
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,6 @@ private:
|
||||
nonut::DamageDescription *sqobj;
|
||||
|
||||
public:
|
||||
PyDamageDescription() { sqobj = new nonut::DamageDescription(); };
|
||||
PyDamageDescription(SQObject obj) { sqobj = new nonut::DamageDescription(obj); }
|
||||
|
||||
nonut::Int getFlags() { return sqobj->flags; }
|
||||
|
||||
@@ -12,7 +12,6 @@ private:
|
||||
nonut::ItemGround *sqobj;
|
||||
|
||||
public:
|
||||
PyItemGround() { sqobj = new nonut::ItemGround(); };
|
||||
PyItemGround(SQObject obj) { sqobj = new nonut::ItemGround(obj); }
|
||||
|
||||
py::tuple getPosition() { return py::make_tuple(sqobj->getPosition().toTuple()); }
|
||||
|
||||
23
src/classes/sq/Daedalus.cpp
Normal file
23
src/classes/sq/Daedalus.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <NoNut/core/CommonHeader.h>
|
||||
#include "Daedalus.h"
|
||||
|
||||
namespace nonut
|
||||
{
|
||||
Daedalus* Daedalus::get()
|
||||
{
|
||||
if (inst == nullptr)
|
||||
{
|
||||
inst = new Daedalus();
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
Daedalus::Daedalus() :
|
||||
StaticClass("Daedalus"),
|
||||
|
||||
METHOD_CTOR(index),
|
||||
METHOD_CTOR(symbol),
|
||||
METHOD_CTOR(instance)
|
||||
{
|
||||
}
|
||||
}
|
||||
27
src/classes/sq/Daedalus.h
Normal file
27
src/classes/sq/Daedalus.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _DAEDALUS_H_
|
||||
#define _DAEDALUS_H_
|
||||
#include <string>
|
||||
|
||||
#include <NoNut/core/StaticClass.h>
|
||||
#include <NoNut/core/CustomTypes.h>
|
||||
|
||||
namespace nonut
|
||||
{
|
||||
class Daedalus : public StaticClass
|
||||
{
|
||||
public:
|
||||
static Daedalus* get();
|
||||
|
||||
Function<Int, String> index;
|
||||
Function<SqDict, String> symbol;
|
||||
Function<SqDict, String> instance;
|
||||
|
||||
private:
|
||||
|
||||
static inline Daedalus* inst = nullptr;
|
||||
|
||||
Daedalus();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3,20 +3,6 @@
|
||||
|
||||
namespace nonut
|
||||
{
|
||||
DamageDescription::DamageDescription() :
|
||||
Class("DamageDescription"),
|
||||
|
||||
PROPERTY_CTOR(flags),
|
||||
PROPERTY_CTOR(damage),
|
||||
PROPERTY_CTOR(item_instance),
|
||||
PROPERTY_CTOR(distance),
|
||||
PROPERTY_CTOR(spell_id),
|
||||
PROPERTY_CTOR(spell_level),
|
||||
PROPERTY_CTOR(node)
|
||||
{
|
||||
classCtor();
|
||||
}
|
||||
|
||||
DamageDescription::DamageDescription(SQObject object) :
|
||||
Class("DamageDescription", object),
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ namespace nonut
|
||||
class DamageDescription : public Class
|
||||
{
|
||||
public:
|
||||
DamageDescription();
|
||||
explicit DamageDescription(SQObject object);
|
||||
DamageDescription(SQObject object);
|
||||
|
||||
Property<Int> flags;
|
||||
Property<Int> damage;
|
||||
|
||||
@@ -3,21 +3,6 @@
|
||||
|
||||
namespace nonut
|
||||
{
|
||||
ItemGround::ItemGround() :
|
||||
Class("ItemGround"),
|
||||
|
||||
METHOD_CTOR(getPosition),
|
||||
METHOD_CTOR(getRotation),
|
||||
|
||||
PROPERTY_CTOR(id),
|
||||
PROPERTY_CTOR(instance),
|
||||
PROPERTY_CTOR(amount),
|
||||
PROPERTY_CTOR(world),
|
||||
PROPERTY_CTOR(virtualWorld)
|
||||
{
|
||||
classCtor();
|
||||
}
|
||||
|
||||
ItemGround::ItemGround(SQObject object) :
|
||||
Class("ItemGround", object),
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ namespace nonut
|
||||
class ItemGround : public Class
|
||||
{
|
||||
public:
|
||||
ItemGround();
|
||||
explicit ItemGround(SQObject object);
|
||||
ItemGround(SQObject object);
|
||||
|
||||
Function<nonut::Position3d> getPosition;
|
||||
Function<nonut::Position3d> getRotation;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <sqapi.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include "sqevents.h"
|
||||
#include "sqcontainers.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace pybind11::literals;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <sqapi.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include "NoNut/core/Utils.h"
|
||||
#include "sqcontainers.h"
|
||||
#include "sqevents.h"
|
||||
|
||||
SQInteger sq_onPlayerUseCheat(HSQUIRRELVM vm)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <sqapi.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include "NoNut/core/Utils.h"
|
||||
#include "sqcontainers.h"
|
||||
#include "NoNut/core/CustomTypes.h"
|
||||
#include "sqevents.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
@@ -45,10 +45,10 @@ SQInteger sq_onBan(HSQUIRRELVM vm)
|
||||
{
|
||||
HSQOBJECT obj;
|
||||
nonut::sqGetValue(vm, 2, &obj);
|
||||
Sqrat::Table banData = Sqrat::Table(obj, vm);
|
||||
|
||||
py::dict kwargs = sqParseTable(banData);
|
||||
callEvent("onBan", kwargs);
|
||||
nonut::SqDict dictData;
|
||||
dictData.convert(obj);
|
||||
callEvent("onBan", dictData.data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -57,10 +57,10 @@ SQInteger sq_onUnban(HSQUIRRELVM vm)
|
||||
{
|
||||
HSQOBJECT obj;
|
||||
nonut::sqGetValue(vm, 2, &obj);
|
||||
Sqrat::Table banData = Sqrat::Table(obj, vm);
|
||||
|
||||
py::dict kwargs = sqParseTable(banData);
|
||||
callEvent("onUnban", kwargs);
|
||||
nonut::SqDict dictData;
|
||||
dictData.convert(obj);
|
||||
callEvent("onUnban", dictData.data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <sqapi.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include "NoNut/core/Utils.h"
|
||||
#include "sqcontainers.h"
|
||||
#include "sqevents.h"
|
||||
|
||||
SQInteger sq_onNpcActionFinished(HSQUIRRELVM vm)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#include <sqapi.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include "sqcontainers.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace pybind11::literals;
|
||||
|
||||
py::dict sqParseTable(Sqrat::Table tab)
|
||||
{
|
||||
py::dict result;
|
||||
Sqrat::Object::iterator tabIterator;
|
||||
int i = 0;
|
||||
|
||||
while (tab.Next(tabIterator))
|
||||
{
|
||||
HSQOBJECT key = tabIterator.getKey();
|
||||
HSQOBJECT value = tabIterator.getValue();
|
||||
|
||||
if (key._type != OT_STRING)
|
||||
continue;
|
||||
|
||||
switch(value._type)
|
||||
{
|
||||
case OT_STRING:
|
||||
result[sq_objtostring(&key)] = sq_objtostring(&value);
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
result[sq_objtostring(&key)] = sq_objtointeger(&value);
|
||||
break;
|
||||
case OT_FLOAT:
|
||||
result[sq_objtostring(&key)] = sq_objtofloat(&value);
|
||||
break;
|
||||
case OT_TABLE:
|
||||
result[sq_objtostring(&key)] = sqParseTable(Sqrat::Table(value));
|
||||
break;
|
||||
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace pybind11::literals;
|
||||
|
||||
py::dict sqParseTable(Sqrat::Table);
|
||||
Reference in New Issue
Block a user