mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 12:04:55 +02:00
rename item data to count, add function to get current class name in lua
This commit is contained in:
@@ -48,7 +48,8 @@ void LuaInterface::init()
|
||||
|
||||
// register LuaObject, the base of all other objects
|
||||
registerClass<LuaObject>();
|
||||
bindClassMemberGetField<LuaObject>("use_count", &LuaObject::getUseCount);
|
||||
bindClassMemberFunction<LuaObject>("getUseCount", &LuaObject::getUseCount);
|
||||
bindClassMemberFunction<LuaObject>("getClassName", &LuaObject::getClassName);
|
||||
}
|
||||
|
||||
void LuaInterface::terminate()
|
||||
@@ -958,7 +959,7 @@ void LuaInterface::pushObject(const LuaObjectPtr& obj)
|
||||
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
|
||||
|
||||
// set the userdata metatable
|
||||
getGlobal(Fw::mkstr(obj->getLuaObjectName(), "_mt"));
|
||||
getGlobal(Fw::mkstr(obj->getClassName(), "_mt"));
|
||||
assert(!isNil());
|
||||
setMetatable();
|
||||
}
|
||||
|
@@ -61,8 +61,8 @@ public:
|
||||
/// @note each userdata of this object on lua counts as a reference
|
||||
int getUseCount();
|
||||
|
||||
/// Returns the class name used in Lua
|
||||
virtual std::string getLuaObjectName() const {
|
||||
/// Returns the derived class name, its the same name used in Lua
|
||||
virtual std::string getClassName() const {
|
||||
// TODO: this could be cached for more performance
|
||||
return Fw::demangleName(typeid(*this).name());
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
Item::Item() : Thing()
|
||||
{
|
||||
m_data = 1;
|
||||
m_count = 1;
|
||||
}
|
||||
|
||||
ItemPtr Item::create(int id)
|
||||
@@ -77,26 +77,26 @@ void Item::setPosition(const Position& position)
|
||||
Thing::setPosition(position);
|
||||
}
|
||||
|
||||
void Item::setData(uint8 data)
|
||||
void Item::setCount(uint8 count)
|
||||
{
|
||||
if(isStackable() && getNumPatternsX() == 4 && getNumPatternsY() == 2) {
|
||||
if(data < 5) {
|
||||
m_xPattern = data-1;
|
||||
if(count < 5) {
|
||||
m_xPattern = count-1;
|
||||
m_yPattern = 0;
|
||||
}
|
||||
else if(data < 10) {
|
||||
else if(count < 10) {
|
||||
m_xPattern = 0;
|
||||
m_yPattern = 1;
|
||||
}
|
||||
else if(data < 25) {
|
||||
else if(count < 25) {
|
||||
m_xPattern = 1;
|
||||
m_yPattern = 1;
|
||||
}
|
||||
else if(data < 50) {
|
||||
else if(count < 50) {
|
||||
m_xPattern = 2;
|
||||
m_yPattern = 1;
|
||||
}
|
||||
else if(data <= 100) {
|
||||
else if(count <= 100) {
|
||||
m_xPattern = 3;
|
||||
m_yPattern = 1;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ void Item::setData(uint8 data)
|
||||
}
|
||||
else if(isFluid() || isFluidContainer()) {
|
||||
int color = Otc::FluidTransparent;
|
||||
switch(data) {
|
||||
switch(count) {
|
||||
case Otc::FluidNone:
|
||||
color = Otc::FluidTransparent;
|
||||
break;
|
||||
@@ -175,5 +175,5 @@ void Item::setData(uint8 data)
|
||||
m_yPattern = (color / 4) % getNumPatternsY();
|
||||
}
|
||||
|
||||
m_data = data;
|
||||
m_count = count;
|
||||
}
|
||||
|
@@ -36,14 +36,14 @@ public:
|
||||
void draw(const Point& dest, float scaleFactor);
|
||||
|
||||
void setPosition(const Position &position);
|
||||
void setData(uint8 data);
|
||||
void setCount(uint8 data);
|
||||
|
||||
uint8 getData() { return m_data; }
|
||||
uint8 getCount() { return m_count; }
|
||||
|
||||
ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); }
|
||||
|
||||
private:
|
||||
uint8 m_data;
|
||||
uint8 m_count;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -71,7 +71,7 @@ void Map::load()
|
||||
if(item->isStackable() || item->isFluidContainer() || item->isFluid()) {
|
||||
uint8 data;
|
||||
in.read((char*)&data, sizeof(data));
|
||||
item->setData(data);
|
||||
item->setCount(data);
|
||||
}
|
||||
addThing(item, pos, 255);
|
||||
in.read((char*)&id, sizeof(id));
|
||||
@@ -95,7 +95,7 @@ void Map::save()
|
||||
id = item->getId();
|
||||
out.write((char*)&id, sizeof(id));
|
||||
if(item->isStackable() || item->isFluidContainer() || item->isFluid()) {
|
||||
uint8 data = item->getData();
|
||||
uint8 data = item->getCount();
|
||||
out.write((char*)&data, sizeof(data));
|
||||
}
|
||||
}
|
||||
|
@@ -108,9 +108,9 @@ protected:
|
||||
void internalDraw(const Point& dest, float scaleFactor, int layer);
|
||||
void updateType();
|
||||
|
||||
uint32 m_id;
|
||||
uint32 m_id; //TODO: move to derived class to use less memory
|
||||
Position m_position;
|
||||
uint8 m_xPattern, m_yPattern, m_zPattern, m_animation;
|
||||
uint8 m_xPattern, m_yPattern, m_zPattern, m_animation; //TODO: remove this variables to use less memory
|
||||
|
||||
private:
|
||||
ThingType *m_type;
|
||||
|
@@ -129,7 +129,7 @@ void OTClient::registerLuaFunctions()
|
||||
|
||||
g_lua.registerClass<Item, Thing>();
|
||||
g_lua.bindClassStaticFunction<Item>("create", &Item::create);
|
||||
g_lua.bindClassMemberFunction<Item>("getData", &Item::getData);
|
||||
g_lua.bindClassMemberFunction<Item>("getCount", &Item::getCount);
|
||||
|
||||
g_lua.registerClass<Effect, Thing>();
|
||||
g_lua.registerClass<Missile, Thing>();
|
||||
|
@@ -1125,7 +1125,7 @@ ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id)
|
||||
|
||||
ItemPtr item = Item::create(id);
|
||||
if(item->isStackable() || item->isFluidContainer() || item->isFluid())
|
||||
item->setData(msg.getU8());
|
||||
item->setCount(msg.getU8());
|
||||
|
||||
return item;
|
||||
}
|
||||
|
@@ -40,8 +40,8 @@ void UIItem::draw()
|
||||
g_painter.setColor(Fw::white);
|
||||
m_item->draw(topLeft, 1);
|
||||
|
||||
if(m_font && m_item->isStackable() && m_item->getData() > 1) {
|
||||
std::string count = Fw::tostring(m_item->getData());
|
||||
if(m_font && m_item->isStackable() && m_item->getCount() > 1) {
|
||||
std::string count = Fw::tostring(m_item->getCount());
|
||||
m_font->renderText(count, Rect(m_rect.topLeft(), m_rect.bottomRight() - Point(3, 0)), Fw::AlignBottomRight, Color(231, 231, 231));
|
||||
}
|
||||
|
||||
@@ -56,14 +56,19 @@ void UIItem::setItemId(int id)
|
||||
{
|
||||
if(!m_item)
|
||||
m_item = Item::create(id);
|
||||
else
|
||||
m_item->setId(id);
|
||||
else {
|
||||
// remove item
|
||||
if(id == 0)
|
||||
m_item = nullptr;
|
||||
else
|
||||
m_item->setId(id);
|
||||
}
|
||||
}
|
||||
|
||||
void UIItem::setItemCount(int count)
|
||||
{
|
||||
if(m_item)
|
||||
m_item->setData(count);
|
||||
m_item->setCount(count);
|
||||
}
|
||||
|
||||
void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||
|
@@ -37,9 +37,10 @@ public:
|
||||
void setItemCount(int count);
|
||||
void setItem(const ItemPtr& item) { m_item = item; }
|
||||
void setVirtual(bool virt) { m_virtual = virt; }
|
||||
void clearItem() { setItemId(0); }
|
||||
|
||||
int getItemId() { return m_item->getId(); }
|
||||
int getItemCount() { return m_item->getData(); }
|
||||
int getItemId() { return m_item ? m_item->getId() : 0; }
|
||||
int getItemCount() { return m_item ? m_item->getCount() : 0; }
|
||||
ItemPtr getItem() { return m_item; }
|
||||
bool isVirtual() { return m_virtual; }
|
||||
|
||||
|
Reference in New Issue
Block a user