PythonEditorFuncs.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. #include "PythonEditorFuncs.h"
  10. // Qt
  11. #include <QMessageBox>
  12. #include <QFileDialog>
  13. #include <AzCore/Utils/Utils.h>
  14. // AzToolsFramework
  15. #include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
  16. #include <AzToolsFramework/UI/UICore/WidgetHelpers.h>
  17. // Editor
  18. #include "CryEdit.h"
  19. #include "GameEngine.h"
  20. #include "ViewManager.h"
  21. #include "StringDlg.h"
  22. #include "GenericSelectItemDialog.h"
  23. #include "Objects/BaseObject.h"
  24. #include "Commands/CommandManager.h"
  25. namespace
  26. {
  27. //////////////////////////////////////////////////////////////////////////
  28. const char* PyGetCVarAsString(const char* pName)
  29. {
  30. ICVar* pCVar = GetIEditor()->GetSystem()->GetIConsole()->GetCVar(pName);
  31. if (!pCVar)
  32. {
  33. AZ_Warning("editor", false, "PyGetCVar: Attempt to access non-existent CVar '%s'", pName ? pName : "(null)");
  34. return "(missing)";
  35. }
  36. return pCVar->GetString();
  37. }
  38. //////////////////////////////////////////////////////////////////////////
  39. // forward declarations
  40. void PySetCVarFromInt(const char* pName, int pValue);
  41. void PySetCVarFromFloat(const char* pName, float pValue);
  42. //////////////////////////////////////////////////////////////////////////
  43. void PySetCVarFromString(const char* pName, const char* pValue)
  44. {
  45. ICVar* pCVar = GetIEditor()->GetSystem()->GetIConsole()->GetCVar(pName);
  46. if (!pCVar)
  47. {
  48. AZ_Warning("editor", false, "Attempt to set non-existent string CVar '%s'", pName ? pName : "(null)");
  49. }
  50. else if (pCVar->GetType() == CVAR_INT)
  51. {
  52. PySetCVarFromInt(pName, std::stol(pValue));
  53. }
  54. else if (pCVar->GetType() == CVAR_FLOAT)
  55. {
  56. PySetCVarFromFloat(pName, static_cast<float>(std::stod(pValue)));
  57. }
  58. else if (pCVar->GetType() != CVAR_STRING)
  59. {
  60. AZ_Warning("editor", false, "Type mismatch while assigning CVar '%s' as a string.", pName ? pName : "(null)");
  61. }
  62. else
  63. {
  64. pCVar->Set(pValue);
  65. }
  66. }
  67. //////////////////////////////////////////////////////////////////////////
  68. void PySetCVarFromInt(const char* pName, int pValue)
  69. {
  70. ICVar* pCVar = GetIEditor()->GetSystem()->GetIConsole()->GetCVar(pName);
  71. if (!pCVar)
  72. {
  73. AZ_Warning("editor", false, "Attempt to set non-existent integer CVar '%s'", pName ? pName : "(null)");
  74. }
  75. else if (pCVar->GetType() == CVAR_FLOAT)
  76. {
  77. PySetCVarFromFloat(pName, float(pValue));
  78. }
  79. else if (pCVar->GetType() == CVAR_STRING)
  80. {
  81. auto stringValue = AZStd::to_string(pValue);
  82. PySetCVarFromString(pName, stringValue.c_str());
  83. }
  84. else if (pCVar->GetType() != CVAR_INT)
  85. {
  86. AZ_Warning("editor", false, "Type mismatch while assigning CVar '%s' as an integer.", pName ? pName : "(null)");
  87. }
  88. else
  89. {
  90. pCVar->Set(pValue);
  91. }
  92. }
  93. //////////////////////////////////////////////////////////////////////////
  94. void PySetCVarFromFloat(const char* pName, float pValue)
  95. {
  96. ICVar* pCVar = GetIEditor()->GetSystem()->GetIConsole()->GetCVar(pName);
  97. if (!pCVar)
  98. {
  99. AZ_Warning("editor", false, "Attempt to set non-existent float CVar '%s'", pName ? pName : "(null)");
  100. }
  101. else if (pCVar->GetType() == CVAR_INT)
  102. {
  103. PySetCVarFromInt(pName, static_cast<int>(pValue));
  104. }
  105. else if (pCVar->GetType() == CVAR_STRING)
  106. {
  107. auto stringValue = AZStd::to_string(pValue);
  108. PySetCVarFromString(pName, stringValue.c_str());
  109. }
  110. else if (pCVar->GetType() != CVAR_FLOAT)
  111. {
  112. AZ_Warning("editor", false, "Type mismatch while assigning CVar '%s' as a float.", pName ? pName : "(null)");
  113. }
  114. else
  115. {
  116. pCVar->Set(pValue);
  117. }
  118. }
  119. //////////////////////////////////////////////////////////////////////////
  120. void PySetCVarFromAny(const char* pName, const AZStd::any& value)
  121. {
  122. ICVar* pCVar = GetIEditor()->GetSystem()->GetIConsole()->GetCVar(pName);
  123. if (!pCVar)
  124. {
  125. AZ_Warning("editor", false, "Attempt to set non-existent float CVar '%s'", pName ? pName : "(null)");
  126. }
  127. else if (pCVar->GetType() == CVAR_INT)
  128. {
  129. PySetCVarFromInt(pName, static_cast<int>(AZStd::any_cast<AZ::s64>(value)));
  130. }
  131. else if (pCVar->GetType() == CVAR_FLOAT)
  132. {
  133. PySetCVarFromFloat(pName, static_cast<float>(AZStd::any_cast<double>(value)));
  134. }
  135. else if (pCVar->GetType() == CVAR_STRING)
  136. {
  137. PySetCVarFromString(pName, AZStd::any_cast<AZStd::string_view>(value).data());
  138. }
  139. else
  140. {
  141. AZ_Warning("editor", false, "Type mismatch while assigning CVar '%s' as a float.", pName ? pName : "(null)");
  142. }
  143. }
  144. //////////////////////////////////////////////////////////////////////////
  145. void PyEnterGameMode()
  146. {
  147. if (GetIEditor()->GetGameEngine())
  148. {
  149. GetIEditor()->GetGameEngine()->RequestSetGameMode(true);
  150. }
  151. }
  152. void PyExitGameMode()
  153. {
  154. if (GetIEditor()->GetGameEngine())
  155. {
  156. GetIEditor()->GetGameEngine()->RequestSetGameMode(false);
  157. }
  158. }
  159. bool PyIsInGameMode()
  160. {
  161. return GetIEditor()->IsInGameMode();
  162. }
  163. //////////////////////////////////////////////////////////////////////////
  164. void PyEnterSimulationMode()
  165. {
  166. if (!GetIEditor()->IsInSimulationMode())
  167. {
  168. CCryEditApp::instance()->OnSwitchPhysics();
  169. }
  170. }
  171. void PyExitSimulationMode()
  172. {
  173. if (GetIEditor()->IsInSimulationMode())
  174. {
  175. CCryEditApp::instance()->OnSwitchPhysics();
  176. }
  177. }
  178. bool PyIsInSimulationMode()
  179. {
  180. return GetIEditor()->IsInSimulationMode();
  181. }
  182. //////////////////////////////////////////////////////////////////////////
  183. void PyRunConsole(const char* text)
  184. {
  185. GetIEditor()->GetSystem()->GetIConsole()->ExecuteString(text);
  186. }
  187. //////////////////////////////////////////////////////////////////////////
  188. bool GetPythonScriptPath(const char* pFile, QString& path)
  189. {
  190. bool bRelativePath = true;
  191. char drive[_MAX_DRIVE];
  192. char fdir[_MAX_DIR];
  193. char fname[_MAX_FNAME];
  194. char fext[_MAX_EXT];
  195. drive[0] = '\0';
  196. _splitpath_s(pFile, drive, fdir, fname, fext);
  197. if (strlen(drive) != 0)
  198. {
  199. bRelativePath = false;
  200. }
  201. if (bRelativePath)
  202. {
  203. // Try to open from user folder
  204. QString userSandboxFolder = Path::GetResolvedUserSandboxFolder();
  205. Path::ConvertBackSlashToSlash(userSandboxFolder);
  206. path = userSandboxFolder + pFile;
  207. // If not found try editor folder
  208. if (!CFileUtil::FileExists(path))
  209. {
  210. AZ::IO::FixedMaxPathString engineRoot = AZ::Utils::GetEnginePath();
  211. QDir engineDir = !engineRoot.empty() ? QDir(QString(engineRoot.c_str())) : QDir::current();
  212. QString scriptFolder = engineDir.absoluteFilePath("Assets/Editor/Scripts/");
  213. Path::ConvertBackSlashToSlash(scriptFolder);
  214. path = scriptFolder + pFile;
  215. if (!CFileUtil::FileExists(path))
  216. {
  217. QString error = QString("Could not find '%1'\n in '%2'\n or '%3'\n").arg(pFile).arg(userSandboxFolder).arg(scriptFolder);
  218. AZ_Warning("python", false, error.toUtf8().data());
  219. return false;
  220. }
  221. }
  222. }
  223. else
  224. {
  225. path = pFile;
  226. if (!CFileUtil::FileExists(path))
  227. {
  228. QString error = QString("Could not find '") + pFile + "'\n";
  229. AZ_Warning("python", false, error.toUtf8().data());
  230. return false;
  231. }
  232. }
  233. Path::ConvertBackSlashToSlash(path);
  234. return true;
  235. }
  236. //////////////////////////////////////////////////////////////////////////
  237. void GetPythonArgumentsVector(const char* pArguments, QStringList& inputArguments)
  238. {
  239. if (pArguments == nullptr)
  240. {
  241. return;
  242. }
  243. inputArguments = QString(pArguments).split(" ", Qt::SkipEmptyParts);
  244. }
  245. //////////////////////////////////////////////////////////////////////////
  246. void PyRunFileWithParameters(const char* pFile, const char* pArguments)
  247. {
  248. QString path;
  249. QStringList inputArguments;
  250. GetPythonArgumentsVector(pArguments, inputArguments);
  251. if (GetPythonScriptPath(pFile, path))
  252. {
  253. AZStd::vector<AZStd::string_view> argList;
  254. argList.reserve(inputArguments.size() + 1);
  255. QByteArray p = path.toUtf8();
  256. QVector<QByteArray> argData;
  257. argData.reserve(inputArguments.count());
  258. for (auto iter = inputArguments.begin(); iter != inputArguments.end(); ++iter)
  259. {
  260. argData.push_back(iter->toLatin1());
  261. argList.push_back(argData.last().data());
  262. }
  263. using namespace AzToolsFramework;
  264. EditorPythonRunnerRequestBus::Broadcast(&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, p.data(), argList);
  265. }
  266. }
  267. void PyRunFile(const char* pFile)
  268. {
  269. PyRunFileWithParameters(pFile, nullptr);
  270. }
  271. //////////////////////////////////////////////////////////////////////////
  272. void PyExecuteCommand(const char* cmdline)
  273. {
  274. GetIEditor()->GetCommandManager()->Execute(cmdline);
  275. }
  276. //////////////////////////////////////////////////////////////////////////
  277. void PyLog(const char* pMessage)
  278. {
  279. if (strcmp(pMessage, "") != 0)
  280. {
  281. CryLogAlways(pMessage);
  282. }
  283. }
  284. //////////////////////////////////////////////////////////////////////////
  285. bool PyMessageBox(const char* pMessage)
  286. {
  287. return QMessageBox::information(QApplication::activeWindow(), QString(), pMessage, QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok;
  288. }
  289. bool PyMessageBoxYesNo(const char* pMessage)
  290. {
  291. return QMessageBox::question(QApplication::activeWindow(), QString(), pMessage) == QMessageBox::Yes;
  292. }
  293. bool PyMessageBoxOK(const char* pMessage)
  294. {
  295. return QMessageBox::information(QApplication::activeWindow(), QString(), pMessage) == QMessageBox::Ok;
  296. }
  297. AZStd::string PyEditBox(AZStd::string_view pTitle)
  298. {
  299. StringDlg stringDialog(pTitle.data());
  300. if (stringDialog.exec() == QDialog::Accepted)
  301. {
  302. return stringDialog.GetString().toUtf8().constData();
  303. }
  304. return "";
  305. }
  306. AZStd::any PyEditBoxAndCheckProperty(const char* pTitle)
  307. {
  308. StringDlg stringDialog(pTitle);
  309. stringDialog.SetString(QStringLiteral(""));
  310. if (stringDialog.exec() == QDialog::Accepted)
  311. {
  312. const QString stringValue = stringDialog.GetString();
  313. // detect data type
  314. QString tempString = stringValue;
  315. int countComa = 0;
  316. int countOpenRoundBraket = 0;
  317. int countCloseRoundBraket = 0;
  318. int countDots = 0;
  319. int posDots = 0;
  320. int posComa = 0;
  321. int posOpenRoundBraket = 0;
  322. int posCloseRoundBraket = 0;
  323. for (int i = 0; i < 3; i++)
  324. {
  325. if (tempString.indexOf(".", posDots) > -1)
  326. {
  327. posDots = tempString.indexOf(".", posDots) + 1;
  328. countDots++;
  329. }
  330. if (tempString.indexOf(",", posComa) > -1)
  331. {
  332. posComa = tempString.indexOf(",", posComa) + 1;
  333. countComa++;
  334. }
  335. if (tempString.indexOf("(", posOpenRoundBraket) > -1)
  336. {
  337. posOpenRoundBraket = tempString.indexOf("(", posOpenRoundBraket) + 1;
  338. countOpenRoundBraket++;
  339. }
  340. if (tempString.indexOf(")", posCloseRoundBraket) > -1)
  341. {
  342. posCloseRoundBraket = tempString.indexOf(")", posCloseRoundBraket) + 1;
  343. countCloseRoundBraket++;
  344. }
  345. }
  346. if (countDots == 3 && countComa == 2 && countOpenRoundBraket == 1 && countCloseRoundBraket == 1)
  347. {
  348. // for example: (1.95, 2.75, 3.36)
  349. QString valueRed = stringValue;
  350. int iStart = valueRed.indexOf("(");
  351. valueRed.remove(0, iStart + 1);
  352. int iEnd = valueRed.indexOf(",");
  353. valueRed.remove(iEnd, valueRed.length());
  354. float fValueRed = valueRed.toFloat();
  355. QString valueGreen = stringValue;
  356. iStart = valueGreen.indexOf(",");
  357. valueGreen.remove(0, iStart + 1);
  358. iEnd = valueGreen.indexOf(",");
  359. valueGreen.remove(iEnd, valueGreen.length());
  360. float fValueGreen = valueGreen.toFloat();
  361. QString valueBlue = stringValue;
  362. valueBlue.remove(0, valueBlue.indexOf(",") + 1);
  363. valueBlue.remove(0, valueBlue.indexOf(",") + 1);
  364. valueBlue.remove(valueBlue.indexOf(")"), valueBlue.length());
  365. float fValueBlue = valueBlue.toFloat();
  366. return AZStd::make_any<AZ::Vector3>(fValueRed, fValueGreen, fValueBlue);
  367. }
  368. else if (countDots == 0 && countComa == 2 && countOpenRoundBraket == 1 && countCloseRoundBraket == 1)
  369. {
  370. // for example: (128, 32, 240)
  371. const AZ::u8 lowColorValue { 0 };
  372. const AZ::u8 highColorValue { 255 };
  373. QString valueRed = stringValue;
  374. int iStart = valueRed.indexOf("(");
  375. valueRed.remove(0, iStart + 1);
  376. int iEnd = valueRed.indexOf(",");
  377. valueRed.remove(iEnd, valueRed.length());
  378. AZ::u8 iValueRed = AZStd::clamp(aznumeric_cast<AZ::u8>(valueRed.toInt()), lowColorValue, highColorValue);
  379. QString valueGreen = stringValue;
  380. iStart = valueGreen.indexOf(",");
  381. valueGreen.remove(0, iStart + 1);
  382. iEnd = valueGreen.indexOf(",");
  383. valueGreen.remove(iEnd, valueGreen.length());
  384. AZ::u8 iValueGreen = AZStd::clamp(aznumeric_cast<AZ::u8>(valueGreen.toInt()), lowColorValue, highColorValue);
  385. QString valueBlue = stringValue;
  386. valueBlue.remove(0, valueBlue.indexOf(",") + 1);
  387. valueBlue.remove(0, valueBlue.indexOf(",") + 1);
  388. valueBlue.remove(valueBlue.indexOf(")"), valueBlue.length());
  389. AZ::u8 iValueBlue = AZStd::clamp(aznumeric_cast<AZ::u8>(valueBlue.toInt()), lowColorValue, highColorValue);
  390. return AZStd::make_any<AZ::Color>(iValueRed, iValueGreen, iValueBlue, highColorValue);
  391. }
  392. else if (countDots == 1 && countComa == 0 && countOpenRoundBraket == 0 && countCloseRoundBraket == 0)
  393. {
  394. // for example: 2.56
  395. return AZStd::make_any<double>(stringValue.toDouble());
  396. }
  397. else if (countDots == 0 && countComa == 0 && countOpenRoundBraket == 0 && countCloseRoundBraket == 0)
  398. {
  399. if (stringValue == "False" || stringValue == "True")
  400. {
  401. // for example: True
  402. return AZStd::make_any<bool>(stringValue == "True");
  403. }
  404. else
  405. {
  406. const bool anyNotDigits = AZStd::any_of(stringValue.begin(), stringValue.end(), [](const QChar& ch) { return !ch.isDigit(); });
  407. // looks like a string value?
  408. if (stringValue.isEmpty() || anyNotDigits)
  409. {
  410. // for example: Hello
  411. return AZStd::make_any<AZStd::string>(stringValue.toUtf8().data());
  412. }
  413. else // then it looks like an integer
  414. {
  415. // for example: 456
  416. return AZStd::make_any<AZ::s64>(stringValue.toInt());
  417. }
  418. }
  419. }
  420. }
  421. QMessageBox::critical(AzToolsFramework::GetActiveWindow(), QObject::tr("Invalid Data"), QObject::tr("Invalid data type."));
  422. return {};
  423. }
  424. AZStd::string PyOpenFileBox()
  425. {
  426. QString path = QFileDialog::getOpenFileName();
  427. if (!path.isEmpty())
  428. {
  429. Path::ConvertBackSlashToSlash(path);
  430. }
  431. return path.toUtf8().constData();
  432. }
  433. AZStd::string PyComboBox(AZStd::string title, AZStd::vector<AZStd::string> values, int selectedIdx = 0)
  434. {
  435. AZStd::string result;
  436. if (title.empty())
  437. {
  438. throw std::runtime_error("Incorrect title argument passed in. ");
  439. }
  440. if (values.size() == 0)
  441. {
  442. throw std::runtime_error("Empty value list passed in. ");
  443. }
  444. QStringList list;
  445. for (const AZStd::string& str : values)
  446. {
  447. list.push_back(str.c_str());
  448. }
  449. CGenericSelectItemDialog pyDlg;
  450. pyDlg.setWindowTitle(title.c_str());
  451. pyDlg.SetMode(CGenericSelectItemDialog::eMODE_LIST);
  452. pyDlg.SetItems(list);
  453. pyDlg.PreSelectItem(list[selectedIdx]);
  454. if (pyDlg.exec() == QDialog::Accepted)
  455. {
  456. result = pyDlg.GetSelectedItem().toUtf8().constData();
  457. }
  458. return result;
  459. }
  460. void PyCrash()
  461. {
  462. AZ_Crash();
  463. }
  464. static void PyDrawLabel(int x, int y, float size, float r, float g, float b, float a, const char* pLabel)
  465. {
  466. if (!pLabel)
  467. {
  468. throw std::logic_error("No label given.");
  469. return;
  470. }
  471. if (!r || !g || !b || !a)
  472. {
  473. throw std::logic_error("Invalid color parameters given.");
  474. return;
  475. }
  476. if (!x || !y || !size)
  477. {
  478. throw std::logic_error("Invalid position or size parameters given.");
  479. }
  480. else
  481. {
  482. // ToDo: Remove function or update to work with Atom? LYN-3672
  483. // float color[] = {r, g, b, a};
  484. // ???->Draw2dLabel(x, y, size, color, false, pLabel);
  485. }
  486. }
  487. //////////////////////////////////////////////////////////////////////////
  488. // Constrain
  489. //////////////////////////////////////////////////////////////////////////
  490. const char* PyGetAxisConstraint()
  491. {
  492. AxisConstrains actualConstrain = GetIEditor()->GetAxisConstrains();
  493. switch (actualConstrain)
  494. {
  495. case AXIS_X:
  496. return "X";
  497. case AXIS_Y:
  498. return "Y";
  499. case AXIS_Z:
  500. return "Z";
  501. case AXIS_XY:
  502. return "XY";
  503. case AXIS_XZ:
  504. return "XZ";
  505. case AXIS_YZ:
  506. return "YZ";
  507. case AXIS_XYZ:
  508. return "XYZ";
  509. case AXIS_TERRAIN:
  510. return (GetIEditor()->IsTerrainAxisIgnoreObjects()) ? "TERRAIN" : "TERRAINSNAP";
  511. default:
  512. throw std::logic_error("Invalid axes.");
  513. }
  514. }
  515. void PySetAxisConstraint(AZStd::string_view pConstrain)
  516. {
  517. if (pConstrain == "X")
  518. {
  519. GetIEditor()->SetAxisConstraints(AXIS_X);
  520. }
  521. else if (pConstrain == "Y")
  522. {
  523. GetIEditor()->SetAxisConstraints(AXIS_Y);
  524. }
  525. else if (pConstrain == "Z")
  526. {
  527. GetIEditor()->SetAxisConstraints(AXIS_Z);
  528. }
  529. else if (pConstrain == "XY")
  530. {
  531. GetIEditor()->SetAxisConstraints(AXIS_XY);
  532. }
  533. else if (pConstrain == "YZ")
  534. {
  535. GetIEditor()->SetAxisConstraints(AXIS_YZ);
  536. }
  537. else if (pConstrain == "XZ")
  538. {
  539. GetIEditor()->SetAxisConstraints(AXIS_XZ);
  540. }
  541. else if (pConstrain == "XYZ")
  542. {
  543. GetIEditor()->SetAxisConstraints(AXIS_XYZ);
  544. }
  545. else if (pConstrain == "TERRAIN")
  546. {
  547. GetIEditor()->SetAxisConstraints(AXIS_TERRAIN);
  548. GetIEditor()->SetTerrainAxisIgnoreObjects(true);
  549. }
  550. else if (pConstrain == "TERRAINSNAP")
  551. {
  552. GetIEditor()->SetAxisConstraints(AXIS_TERRAIN);
  553. GetIEditor()->SetTerrainAxisIgnoreObjects(false);
  554. }
  555. else
  556. {
  557. throw std::logic_error("Invalid axes.");
  558. }
  559. }
  560. //////////////////////////////////////////////////////////////////////////
  561. const char* PyGetPakFromFile(const char* filename)
  562. {
  563. auto pIPak = GetIEditor()->GetSystem()->GetIPak();
  564. AZ::IO::HandleType fileHandle = pIPak->FOpen(filename, "rb");
  565. if (fileHandle == AZ::IO::InvalidHandle)
  566. {
  567. throw std::logic_error("Invalid file name.");
  568. }
  569. const char* pArchPath = pIPak->GetFileArchivePath(fileHandle);
  570. pIPak->FClose(fileHandle);
  571. return pArchPath;
  572. }
  573. //////////////////////////////////////////////////////////////////////////
  574. void PyUndo()
  575. {
  576. GetIEditor()->Undo();
  577. }
  578. //////////////////////////////////////////////////////////////////////////
  579. void PyRedo()
  580. {
  581. GetIEditor()->Redo();
  582. }
  583. }
  584. //////////////////////////////////////////////////////////////////////////
  585. // Temporal, to be removed by LY-101149
  586. AZ::EntityId PyFindEditorEntity(const char* name)
  587. {
  588. AZ::EntityId foundEntityId;
  589. auto searchFunc = [name, &foundEntityId](AZ::Entity* e)
  590. {
  591. if (!foundEntityId.IsValid() && e->GetName() == name)
  592. {
  593. bool isEditorEntity = false;
  594. AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(isEditorEntity, &AzToolsFramework::EditorEntityContextRequests::IsEditorEntity, e->GetId());
  595. if (isEditorEntity)
  596. {
  597. foundEntityId = e->GetId();
  598. }
  599. }
  600. };
  601. AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationRequests::EnumerateEntities, searchFunc);
  602. return foundEntityId;
  603. }
  604. AZ::EntityId PyFindGameEntity(const char* name)
  605. {
  606. AZ::EntityId foundEntityId;
  607. auto searchFunc = [name, &foundEntityId](AZ::Entity* e)
  608. {
  609. if (!foundEntityId.IsValid() && e->GetName() == name)
  610. {
  611. bool isEditorEntity = true;
  612. AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(isEditorEntity, &AzToolsFramework::EditorEntityContextRequests::IsEditorEntity, e->GetId());
  613. if (!isEditorEntity)
  614. {
  615. foundEntityId = e->GetId();
  616. }
  617. }
  618. };
  619. AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationRequests::EnumerateEntities, searchFunc);
  620. return foundEntityId;
  621. }
  622. struct PyDumpBindings
  623. {
  624. static AZ_INLINE bool IsBehaviorFlaggedForEditor(const AZ::AttributeArray& attributes)
  625. {
  626. // defaults to Launcher
  627. AZ::Script::Attributes::ScopeFlags scopeType = AZ::Script::Attributes::ScopeFlags::Launcher;
  628. AZ::Attribute* scopeAttribute = AZ::FindAttribute(AZ::Script::Attributes::Scope, attributes);
  629. if (scopeAttribute)
  630. {
  631. AZ::AttributeReader scopeAttributeReader(nullptr, scopeAttribute);
  632. scopeAttributeReader.Read<AZ::Script::Attributes::ScopeFlags>(scopeType);
  633. }
  634. return (scopeType == AZ::Script::Attributes::ScopeFlags::Automation || scopeType == AZ::Script::Attributes::ScopeFlags::Common);
  635. }
  636. static AZ_INLINE AZStd::string GetModuleName(const AZ::AttributeArray& attributes)
  637. {
  638. AZStd::string moduleName;
  639. AZ::Attribute* moduleAttribute = AZ::FindAttribute(AZ::Script::Attributes::Module, attributes);
  640. if (moduleAttribute)
  641. {
  642. AZ::AttributeReader scopeAttributeReader(nullptr, moduleAttribute);
  643. scopeAttributeReader.Read<AZStd::string>(moduleName);
  644. }
  645. if (!moduleName.empty())
  646. {
  647. moduleName = "azlmbr." + moduleName;
  648. }
  649. else
  650. {
  651. moduleName = "azlmbr";
  652. }
  653. return moduleName;
  654. }
  655. static AZStd::string ParameterToString(const AZ::BehaviorMethod* method, size_t index)
  656. {
  657. const AZStd::string* argNameStr = method->GetArgumentName(index);
  658. const char* argName = (argNameStr && !argNameStr->empty()) ? argNameStr->c_str() : nullptr;
  659. if (argName)
  660. {
  661. return AZStd::string::format("%s %s", method->GetArgument(index)->m_name, argName);
  662. }
  663. else
  664. {
  665. return method->GetArgument(index)->m_name;
  666. }
  667. }
  668. static AZStd::string MethodArgumentsToString(const AZ::BehaviorMethod* method)
  669. {
  670. AZStd::string ret;
  671. AZStd::string argumentStr;
  672. for (size_t i = 0; i < method->GetNumArguments(); ++i)
  673. {
  674. argumentStr = ParameterToString(method, i);
  675. ret += argumentStr;
  676. if (i < method->GetNumArguments() - 1)
  677. {
  678. ret += ", ";
  679. }
  680. }
  681. return ret;
  682. }
  683. static AZStd::string MethodToString(const AZStd::string& methodName, const AZ::BehaviorMethod* method)
  684. {
  685. AZStd::string methodNameStrip = methodName.data() + methodName.rfind(':') + 1; // remove ClassName:: part as it is redundant
  686. return AZStd::string::format("%s %s(%s)%s", method->GetResult()->m_name, methodNameStrip.c_str(), MethodArgumentsToString(method).c_str(), method->m_isConst ? " const" : "");
  687. }
  688. static AZStd::string GetExposedPythonClasses()
  689. {
  690. AZ::BehaviorContext* behaviorContext(nullptr);
  691. AZ::ComponentApplicationBus::BroadcastResult(behaviorContext, &AZ::ComponentApplicationRequests::GetBehaviorContext);
  692. AZStd::string output = "";
  693. output += "// Classes\n\n";
  694. for (auto elem : behaviorContext->m_classes)
  695. {
  696. AZ::BehaviorClass* cls = elem.second;
  697. bool exposedToPython = IsBehaviorFlaggedForEditor(cls->m_attributes);
  698. if (!exposedToPython)
  699. continue;
  700. output += AZStd::string::format("// Module: %s\n", GetModuleName(cls->m_attributes).c_str());
  701. output += AZStd::string::format("class %s\n", cls->m_name.c_str());
  702. output += "{\n";
  703. if (cls->m_methods.size() > 0)
  704. {
  705. output += " // Methods\n";
  706. for (auto method_elem : cls->m_methods)
  707. {
  708. output += AZStd::string::format(" %s;\n", MethodToString(method_elem.first, method_elem.second).c_str());
  709. }
  710. }
  711. if (cls->m_properties.size() > 0)
  712. {
  713. output += " // Properties\n";
  714. for (auto property_elem : cls->m_properties)
  715. {
  716. AZ::BehaviorProperty* bproperty = property_elem.second;
  717. output += AZStd::string::format(" %s %s;\n", bproperty->m_getter->GetResult()->m_name, bproperty->m_name.c_str());
  718. }
  719. }
  720. output += "}\n";
  721. }
  722. output += "\n\n// Ebuses\n\n";
  723. for (auto elem : behaviorContext->m_ebuses)
  724. {
  725. AZ::BehaviorEBus* ebus = elem.second;
  726. bool exposedToPython = IsBehaviorFlaggedForEditor(ebus->m_attributes);
  727. if (!exposedToPython)
  728. continue;
  729. output += AZStd::string::format("// Module: %s\n", GetModuleName(ebus->m_attributes).c_str());
  730. output += AZStd::string::format("ebus %s\n", ebus->m_name.c_str());
  731. output += "{\n";
  732. for (auto event_elem : ebus->m_events)
  733. {
  734. auto method = event_elem.second.m_event ? event_elem.second.m_event : event_elem.second.m_broadcast;
  735. if (method)
  736. {
  737. const char* comment = event_elem.second.m_event ? "/* event */" : "/* broadcast */";
  738. output += AZStd::string::format(" %s %s\n", comment, MethodToString(event_elem.first, method).c_str());
  739. }
  740. else
  741. {
  742. output += AZStd::string::format(" %s %s\n", "/* unknown */", event_elem.first.c_str());
  743. }
  744. }
  745. if (ebus->m_createHandler)
  746. {
  747. AZ::BehaviorEBusHandler* handler = nullptr;
  748. ebus->m_createHandler->InvokeResult(handler);
  749. if (handler)
  750. {
  751. const auto& notifications = handler->GetEvents();
  752. for (const auto& notification : notifications)
  753. {
  754. AZStd::string argsStr;
  755. const size_t paramCount = notification.m_parameters.size();
  756. for (size_t i = 0; i < notification.m_parameters.size(); ++i)
  757. {
  758. AZStd::string argName = notification.m_parameters[i].m_name;
  759. argsStr += argName;
  760. if (i != paramCount - 1)
  761. {
  762. argsStr += ", ";
  763. }
  764. }
  765. AZStd::string funcName = notification.m_name;
  766. output += AZStd::string::format(" /* notification */ %s(%s);\n", funcName.c_str(), argsStr.c_str());
  767. }
  768. ebus->m_destroyHandler->Invoke(handler);
  769. }
  770. }
  771. output += "}\n";
  772. }
  773. AzFramework::StringFunc::Replace(output, "AZStd::basic_string<char, AZStd::char_traits<char>, allocator>", "AZStd::string");
  774. return output;
  775. }
  776. };
  777. //////////////////////////////////////////////////////////////////////////
  778. namespace AzToolsFramework
  779. {
  780. void PythonEditorComponent::Reflect(AZ::ReflectContext* context)
  781. {
  782. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  783. {
  784. behaviorContext->EBus<EditorLayerPythonRequestBus>("PythonEditorBus")
  785. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  786. ->Attribute(AZ::Script::Attributes::Module, "python_editor_funcs")
  787. ->Event("GetCVar", &EditorLayerPythonRequestBus::Events::GetCVar)
  788. ->Event("SetCVar", &EditorLayerPythonRequestBus::Events::SetCVar)
  789. ->Event("SetCVarFromString", &EditorLayerPythonRequestBus::Events::SetCVarFromString)
  790. ->Event("SetCVarFromInteger", &EditorLayerPythonRequestBus::Events::SetCVarFromInteger)
  791. ->Event("SetCVarFromFloat", &EditorLayerPythonRequestBus::Events::SetCVarFromFloat)
  792. ->Event("RunConsole", &EditorLayerPythonRequestBus::Events::PyRunConsole)
  793. ->Event("EnterGameMode", &EditorLayerPythonRequestBus::Events::EnterGameMode)
  794. ->Event("IsInGameMode", &EditorLayerPythonRequestBus::Events::IsInGameMode)
  795. ->Event("ExitGameMode", &EditorLayerPythonRequestBus::Events::ExitGameMode)
  796. ->Event("EnterSimulationMode", &EditorLayerPythonRequestBus::Events::EnterSimulationMode)
  797. ->Event("IsInSimulationMode", &EditorLayerPythonRequestBus::Events::IsInSimulationMode)
  798. ->Event("ExitSimulationMode", &EditorLayerPythonRequestBus::Events::ExitSimulationMode)
  799. ->Event("RunFile", &EditorLayerPythonRequestBus::Events::RunFile)
  800. ->Event("RunFileParameters", &EditorLayerPythonRequestBus::Events::RunFileParameters)
  801. ->Event("ExecuteCommand", &EditorLayerPythonRequestBus::Events::ExecuteCommand)
  802. ->Event("MessageBoxOkCancel", &EditorLayerPythonRequestBus::Events::MessageBoxOkCancel)
  803. ->Event("MessageBoxYesNo", &EditorLayerPythonRequestBus::Events::MessageBoxYesNo)
  804. ->Event("MessageBoxOk", &EditorLayerPythonRequestBus::Events::MessageBoxOk)
  805. ->Event("EditBox", &EditorLayerPythonRequestBus::Events::EditBox)
  806. ->Event("EditBoxCheckDataType", &EditorLayerPythonRequestBus::Events::EditBoxCheckDataType)
  807. ->Event("OpenFileBox", &EditorLayerPythonRequestBus::Events::OpenFileBox)
  808. ->Event("GetAxisConstraint", &EditorLayerPythonRequestBus::Events::GetAxisConstraint)
  809. ->Event("SetAxisConstraint", &EditorLayerPythonRequestBus::Events::SetAxisConstraint)
  810. ->Event("GetPakFromFile", &EditorLayerPythonRequestBus::Events::GetPakFromFile)
  811. ->Event("Log", &EditorLayerPythonRequestBus::Events::Log)
  812. ->Event("Undo", &EditorLayerPythonRequestBus::Events::Undo)
  813. ->Event("Redo", &EditorLayerPythonRequestBus::Events::Redo)
  814. ->Event("DrawLabel", &EditorLayerPythonRequestBus::Events::DrawLabel)
  815. ->Event("ComboBox", &EditorLayerPythonRequestBus::Events::ComboBox)
  816. ;
  817. }
  818. }
  819. void PythonEditorComponent::Activate()
  820. {
  821. EditorLayerPythonRequestBus::Handler::BusConnect(GetEntityId());
  822. }
  823. void PythonEditorComponent::Deactivate()
  824. {
  825. EditorLayerPythonRequestBus::Handler::BusDisconnect();
  826. }
  827. const char* PythonEditorComponent::GetCVar(const char* pName)
  828. {
  829. return PyGetCVarAsString(pName);
  830. }
  831. void PythonEditorComponent::SetCVar(const char* pName, const AZStd::any& value)
  832. {
  833. return PySetCVarFromAny(pName, value);
  834. }
  835. void PythonEditorComponent::SetCVarFromString(const char* pName, const char* pValue)
  836. {
  837. return PySetCVarFromString(pName, pValue);
  838. }
  839. void PythonEditorComponent::SetCVarFromInteger(const char* pName, int pValue)
  840. {
  841. return PySetCVarFromInt(pName, pValue);
  842. }
  843. void PythonEditorComponent::SetCVarFromFloat(const char* pName, float pValue)
  844. {
  845. return PySetCVarFromFloat(pName, pValue);
  846. }
  847. void PythonEditorComponent::PyRunConsole(const char* text)
  848. {
  849. return ::PyRunConsole(text);
  850. }
  851. void PythonEditorComponent::EnterGameMode()
  852. {
  853. return PyEnterGameMode();
  854. }
  855. bool PythonEditorComponent::IsInGameMode()
  856. {
  857. return PyIsInGameMode();
  858. }
  859. void PythonEditorComponent::ExitGameMode()
  860. {
  861. return PyExitGameMode();
  862. }
  863. void PythonEditorComponent::EnterSimulationMode()
  864. {
  865. return PyEnterSimulationMode();
  866. }
  867. bool PythonEditorComponent::IsInSimulationMode()
  868. {
  869. return PyIsInSimulationMode();
  870. }
  871. void PythonEditorComponent::ExitSimulationMode()
  872. {
  873. return PyExitSimulationMode();
  874. }
  875. void PythonEditorComponent::RunFile(const char *pFile)
  876. {
  877. return PyRunFile(pFile);
  878. }
  879. void PythonEditorComponent::RunFileParameters(const char* pFile, const char* pArguments)
  880. {
  881. return PyRunFileWithParameters(pFile, pArguments);
  882. }
  883. void PythonEditorComponent::ExecuteCommand(const char* cmdline)
  884. {
  885. return PyExecuteCommand(cmdline);
  886. }
  887. bool PythonEditorComponent::MessageBoxOkCancel(const char* pMessage)
  888. {
  889. return PyMessageBox(pMessage);
  890. }
  891. bool PythonEditorComponent::MessageBoxYesNo(const char* pMessage)
  892. {
  893. return PyMessageBoxYesNo(pMessage);
  894. }
  895. bool PythonEditorComponent::MessageBoxOk(const char* pMessage)
  896. {
  897. return PyMessageBoxOK(pMessage);
  898. }
  899. AZStd::string PythonEditorComponent::EditBox(AZStd::string_view pTitle)
  900. {
  901. return PyEditBox(pTitle);
  902. }
  903. AZStd::any PythonEditorComponent::EditBoxCheckDataType(const char* pTitle)
  904. {
  905. return PyEditBoxAndCheckProperty(pTitle);
  906. }
  907. AZStd::string PythonEditorComponent::OpenFileBox()
  908. {
  909. return PyOpenFileBox();
  910. }
  911. const char* PythonEditorComponent::GetAxisConstraint()
  912. {
  913. return PyGetAxisConstraint();
  914. }
  915. void PythonEditorComponent::SetAxisConstraint(AZStd::string_view pConstrain)
  916. {
  917. return PySetAxisConstraint(pConstrain);
  918. }
  919. const char* PythonEditorComponent::GetPakFromFile(const char* filename)
  920. {
  921. return PyGetPakFromFile(filename);
  922. }
  923. void PythonEditorComponent::Log(const char* pMessage)
  924. {
  925. return PyLog(pMessage);
  926. }
  927. void PythonEditorComponent::Undo()
  928. {
  929. return PyUndo();
  930. }
  931. void PythonEditorComponent::Redo()
  932. {
  933. return PyRedo();
  934. }
  935. void PythonEditorComponent::DrawLabel(int x, int y, float size, float r, float g, float b, float a, const char* pLabel)
  936. {
  937. return PyDrawLabel(x, y, size, r, g, b, a, pLabel);
  938. }
  939. AZStd::string PythonEditorComponent::ComboBox(AZStd::string title, AZStd::vector<AZStd::string> values, int selectedIdx)
  940. {
  941. return PyComboBox(title, values, selectedIdx);
  942. }
  943. }
  944. namespace AzToolsFramework
  945. {
  946. void PythonEditorFuncsHandler::Reflect(AZ::ReflectContext* context)
  947. {
  948. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  949. {
  950. // this will put these methods into the 'azlmbr.legacy.general' module
  951. auto addLegacyGeneral = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder)
  952. {
  953. methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  954. ->Attribute(AZ::Script::Attributes::Category, "Legacy/General")
  955. ->Attribute(AZ::Script::Attributes::Module, "legacy.general");
  956. };
  957. addLegacyGeneral(behaviorContext->Method("get_cvar", PyGetCVarAsString, nullptr, "Gets a CVar value as a string."));
  958. addLegacyGeneral(behaviorContext->Method("set_cvar", PySetCVarFromAny, nullptr, "Sets a CVar value from any simple value."));
  959. addLegacyGeneral(behaviorContext->Method("set_cvar_string", PySetCVarFromString, nullptr, "Sets a CVar value from a string."));
  960. addLegacyGeneral(behaviorContext->Method("set_cvar_integer", PySetCVarFromInt, nullptr, "Sets a CVar value from an integer."));
  961. addLegacyGeneral(behaviorContext->Method("set_cvar_float", PySetCVarFromFloat, nullptr, "Sets a CVar value from a float."));
  962. addLegacyGeneral(behaviorContext->Method("run_console", PyRunConsole, nullptr, "Runs a console command."));
  963. addLegacyGeneral(behaviorContext->Method("enter_game_mode", PyEnterGameMode, nullptr, "Enters the editor game mode."));
  964. addLegacyGeneral(behaviorContext->Method("is_in_game_mode", PyIsInGameMode, nullptr, "Queries if it's in the game mode or not."));
  965. addLegacyGeneral(behaviorContext->Method("exit_game_mode", PyExitGameMode, nullptr, "Exits the editor game mode."));
  966. addLegacyGeneral(behaviorContext->Method("enter_simulation_mode", PyEnterSimulationMode, nullptr, "Enters the editor AI/Physics simulation mode."));
  967. addLegacyGeneral(behaviorContext->Method("is_in_simulation_mode", PyIsInSimulationMode, nullptr, "Queries if the editor is currently in the AI/Physics simulation mode or not."));
  968. addLegacyGeneral(behaviorContext->Method("exit_simulation_mode", PyExitSimulationMode, nullptr, "Exits the editor AI/Physics simulation mode."));
  969. addLegacyGeneral(behaviorContext->Method("run_file", PyRunFile, nullptr, "Runs a script file. A relative path from the editor user folder or an absolute path should be given as an argument."));
  970. addLegacyGeneral(behaviorContext->Method("run_file_parameters", PyRunFileWithParameters, nullptr, "Runs a script file with parameters. A relative path from the editor user folder or an absolute path should be given as an argument. The arguments should be separated by whitespace."));
  971. addLegacyGeneral(behaviorContext->Method("execute_command", PyExecuteCommand, nullptr, "Executes a given string as an editor command."));
  972. addLegacyGeneral(behaviorContext->Method("message_box", PyMessageBox, nullptr, "Shows a confirmation message box with ok|cancel and shows a custom message."));
  973. addLegacyGeneral(behaviorContext->Method("message_box_yes_no", PyMessageBoxYesNo, nullptr, "Shows a confirmation message box with yes|no and shows a custom message."));
  974. addLegacyGeneral(behaviorContext->Method("message_box_ok", PyMessageBoxOK, nullptr, "Shows a confirmation message box with only ok and shows a custom message."));
  975. addLegacyGeneral(behaviorContext->Method("edit_box", PyEditBox, nullptr, "Shows an edit box and returns the value as string."));
  976. addLegacyGeneral(behaviorContext->Method("edit_box_check_data_type", PyEditBoxAndCheckProperty, nullptr, "Shows an edit box and checks the custom value to use the return value with other functions correctly."));
  977. addLegacyGeneral(behaviorContext->Method("open_file_box", PyOpenFileBox, nullptr, "Shows an open file box and returns the selected file path and name."));
  978. addLegacyGeneral(behaviorContext->Method("get_axis_constraint", PyGetAxisConstraint, nullptr, "Gets axis."));
  979. addLegacyGeneral(behaviorContext->Method("set_axis_constraint", PySetAxisConstraint, nullptr, "Sets axis."));
  980. addLegacyGeneral(behaviorContext->Method("get_pak_from_file", PyGetPakFromFile, nullptr, "Finds a pak file name for a given file."));
  981. addLegacyGeneral(behaviorContext->Method("log", PyLog, nullptr, "Prints the message to the editor console window."));
  982. addLegacyGeneral(behaviorContext->Method("undo", PyUndo, nullptr, "Undoes the last operation."));
  983. addLegacyGeneral(behaviorContext->Method("redo", PyRedo, nullptr, "Redoes the last undone operation."));
  984. addLegacyGeneral(behaviorContext->Method("draw_label", PyDrawLabel, nullptr, "Shows a 2d label on the screen at the given position and given color."));
  985. addLegacyGeneral(behaviorContext->Method("combo_box", PyComboBox, nullptr, "Shows a combo box listing each value passed in, returns string value selected by the user."));
  986. addLegacyGeneral(behaviorContext->Method("crash", PyCrash, nullptr, "Crashes the application, useful for testing crash reporting and other automation tools."));
  987. /////////////////////////////////////////////////////////////////////////
  988. // Temporal, to be removed by LY-101149
  989. addLegacyGeneral(behaviorContext->Method("find_editor_entity", PyFindEditorEntity, nullptr, "Retrieves a editor entity id by name"));
  990. addLegacyGeneral(behaviorContext->Method("find_game_entity", PyFindGameEntity, nullptr, "Retrieves a game entity id by name"));
  991. //////////////////////////////////////////////////////////////////////////
  992. addLegacyGeneral(behaviorContext->Method("dump_exposed_classes", PyDumpBindings::GetExposedPythonClasses, nullptr, "Retrieves exposed classes"));
  993. }
  994. }
  995. }