Files
metin2-client/tests/port/port_python_ui_modules_test.cpp
T
shenandshen dd71ee5b61 feat: add POINT_GEM (248) player binding and initialization fix (Stage 6)
- Add POINT_GEM = 248 point type constant in Packet.h
- Add player.GetGem() and export POINT_GEM/GEM constants in PythonPlayerModule
- Fix CPythonPlayer constructor to explicitly call Clear() ensuring clean initial player status
- Add test assertions for player.GetGem() and player.POINT_GEM in port_python_ui_modules_test
2026-10-20 04:53:37 -07:00

160 lines
6.1 KiB
C++

#include "EterPythonLib/StdAfx.h"
#include "EterPythonLib/PythonWindowManager.h"
#include "ScriptLib/PythonLauncher.h"
#include "UserInterface/StdAfx.h"
extern void initapp();
extern void initPlayer();
extern void initItem();
extern void initchrmgr();
extern void initnet();
extern void initshop();
extern void initprivateShopSearch();
#include "UserInterface/PythonPlayer.h"
#include "UserInterface/PythonShop.h"
#include "UserInterface/PythonPrivateShopSearch.h"
#include <cassert>
#include "../../src/platform/ScriptLib/PythonHost.h"
#include <cstdio>
#include <string>
int main(int argc, char** argv)
{
const std::string stdlib = argc > 1 ? argv[1] : PythonHost::DefaultStdLibPath();
PythonHost::Configure();
CPythonLauncher launcher;
if (!launcher.Create())
return 1;
std::string error;
if (!PythonHost::InstallStdLib(stdlib.c_str(), &error))
{
std::fprintf(stderr, "InstallStdLib: %s\n", error.c_str());
return 1;
}
{
UI::CWindowManager manager;
initgrp();
initgrpImage();
initgrpText();
initgrpThing();
initwndMgr();
initapp();
initItem();
initchrmgr();
initnet();
CPythonPlayer player;
initPlayer();
CPythonShop shop;
initshop();
CPythonPrivateShopSearch privateShopSearch;
initprivateShopSearch();
CPythonPlayer::Instance().SetGold64(123456789012345LL);
assert(CPythonPlayer::Instance().GetGold64() == 123456789012345LL);
assert(CPythonPlayer::Instance().GetStatus(POINT_GOLD) == 2000000000);
CPythonPlayer::Instance().SetStatus(POINT_GEM, 1234);
assert(CPythonPlayer::Instance().GetStatus(POINT_GEM) == 1234);
if (!launcher.RunLine(
"import player, item, chrmgr, app\n"
"gold = player.GetElk()\n"
"assert gold == 123456789012345L, 'GetElk mismatch: %r' % gold\n"
"assert player.GetGold64() == 123456789012345L\n"
"assert hasattr(player, 'GetGem')\n"
"assert player.GetGem() == 1234\n"
"assert player.POINT_GEM == 248\n"
"def _fmt(v):\n"
" if v >= 1000000000000: return '%.2f T' % (float(v)/1000000000000.0)\n"
" elif v >= 1000000000: return '%.2f B' % (float(v)/1000000000.0)\n"
" return format(int(v), ',')\n"
"assert _fmt(gold) == '123.46 T'\n"
"assert _fmt(5200000000L) == '5.20 B'\n"
"assert _fmt(1234567) == '1,234,567'\n"
"assert item.COSTUME_SLOT_WEAPON == player.COSTUME_SLOT_WEAPON\n"
"assert item.COSTUME_SLOT_NEW_SASH == player.COSTUME_SLOT_NEW_SASH\n"
"assert item.SHINING_SLOT_WEAPON == player.SHINING_SLOT_WEAPON\n"
"assert item.SHINING_SLOT_ARMOR == player.SHINING_SLOT_ARMOR\n"
"assert item.SHINING_SLOT_SPECIAL == player.SHINING_SLOT_SPECIAL\n"
"assert player.IsCostumeSlot(player.COSTUME_SLOT_WEAPON) == 1\n"
"assert player.IsCostumeSlot(player.COSTUME_SLOT_NEW_SASH) == 1\n"
"assert player.IsCostumeSlot(player.SHINING_SLOT_WEAPON) == 1\n"
"assert player.IsCostumeSlot(player.SHINING_SLOT_ARMOR) == 1\n"
"assert player.IsCostumeSlot(player.SHINING_SLOT_SPECIAL) == 1\n"
"assert item.COSTUME_TYPE_WEAPON == 5\n"
"assert item.COSTUME_TYPE_NEW_SASH == 6\n"
"assert item.ITEM_TYPE_SHINING == 35\n"
"assert item.SHINING_WEAPON == 0\n"
"assert chrmgr.EFFECT_SHINING_WEAPON >= 0\n"
"assert app.ENABLE_NEW_PET_SYSTEM == 1\n"
"assert item.ITEM_TYPE_PET == 37\n"
"assert item.EQUIPMENT_OLDPET == item.COSTUME_SLOT_PET\n"
"assert item.EQUIPMENT_PET == item.PET_SLOT\n"
"assert item.PET_LEVELABLE == 0\n"
"assert item.PET_EGG == 1\n"
"assert item.PET_PROTEIN == 3\n"
"assert item.PET_DEW == 5\n"
"assert item.PET_SKILL == 6\n"
"assert item.PET_SKILL_DEL_BOOK == 11\n"
"assert item.PET_SKILL_ALL_DEL_BOOK == 12\n"
"assert app.ENABLE_ATTR_6TH_7TH == 1\n"
"assert app.BL_67_ATTR == 1\n"
"assert player.ON_TOP_WND_ATTR_67 == 7\n"
"assert player.ON_TOP_WND_NONE == 0\n"
"assert app.ENABLE_SPECIAL_STORAGE == 1\n"
"assert player.SWITCHBOT == 7\n"
"assert player.UPGRADE_INVENTORY == 8\n"
"assert player.BOOK_INVENTORY == 9\n"
"assert player.STONE_INVENTORY == 10\n"
"assert player.CHANGE_INVENTORY == 11\n"
"assert player.COSTUME_INVENTORY == 12\n"
"assert player.SLOT_TYPE_UPGRADE_INVENTORY > 0\n"
"assert player.SLOT_TYPE_BOOK_INVENTORY > 0\n"
"assert player.SLOT_TYPE_STONE_INVENTORY > 0\n"
"assert player.SLOT_TYPE_CHANGE_INVENTORY > 0\n"
"assert player.SLOT_TYPE_COSTUME_INVENTORY > 0\n"
"assert player.SPECIAL_PAGE_SIZE == 45\n"
"assert player.SPECIAL_PAGE_COUNT == 4\n"
"assert player.SPECIAL_SLOT_COUNT == 180\n"
"assert hasattr(player, 'GetItemCountByTT')\n"
"import net\n"
"assert hasattr(net, 'Send67AttrPacket')\n"
"assert hasattr(net, 'Send67AttrClosePacket')\n"
"assert app.ENABLE_OFFLINESHOP_SYSTEM == 1\n"
"assert app.ENABLE_SHOP_SEARCH_SYSTEM == 1\n"
"import shop\n"
"assert shop.OFFLINE_SHOP_SLOT_COUNT == 80\n"
"assert hasattr(shop, 'IsOfflineShop')\n"
"assert hasattr(shop, 'GetOfflineShopItemID')\n"
"assert hasattr(shop, 'GetOfflineShopItemCount')\n"
"assert hasattr(shop, 'GetOfflineShopItemPrice')\n"
"assert hasattr(shop, 'GetCurrentOfflineShopMoney')\n"
"assert hasattr(shop, 'HasOfflineShop')\n"
"assert hasattr(shop, 'GetShopFlag')\n"
"import privateShopSearch\n"
"assert hasattr(privateShopSearch, 'GetItemCount')\n"
"assert hasattr(privateShopSearch, 'GetSearchItemPrice')\n"
"assert hasattr(privateShopSearch, 'ClearSearchItems')\n"
"assert privateShopSearch.GetItemCount() == 0\n"
"assert hasattr(net, 'SendOfflineShopEndPacket')\n"
"assert hasattr(net, 'SendOfflineShopBuyPacket')\n"
"assert hasattr(net, 'SendAddOfflineShopItem')\n"
"assert hasattr(net, 'SendRemoveOfflineShopItem')\n"
"assert hasattr(net, 'SendOpenShopSlot')\n"
"assert hasattr(net, 'SendPrivateShopSearchInfo')\n"
))
return 1;
if (!launcher.RunLine("import wndMgr, grp, grpImage, grpText, grpThing, app"))
return 1;
if (!launcher.RunLine(
"class Handler: pass\n"
"window = wndMgr.Register(Handler(), 'UI')\n"
"assert window > 0\n"
"wndMgr.SetName(window, 'roundtrip')\n"
"wndMgr.SetWindowSize(window, 100, 50)\n"
"assert wndMgr.GetWindowWidth(window) == 100\n"
"wndMgr.Destroy(window)\n"))
return 1;
manager.Update();
}
launcher.Clear();
return 0;
}