ScriptManagerBinds.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <iostream>
  16. #include "../modules/worldmap/WorldmapModule.h"
  17. #include "Console.h"
  18. #include "Logger.h"
  19. #include "CameraManager.h"
  20. #include "Entity.h"
  21. #include "EntityManager.h"
  22. #include "BattleManager.h"
  23. #include "AudioManager.h"
  24. #include "SavemapHandler.h"
  25. #include "Timer.h"
  26. #include "UiManager.h"
  27. #include "UiWidget.h"
  28. #include "XmlMapFile.h"
  29. #include "XmlMapsFile.h"
  30. #include "DialogsManager.h"
  31. #include "TextHandler.h"
  32. /*
  33. * TODO:
  34. *
  35. * If I manage to upgrade luabind version (or even better, remove it and use an external one),
  36. * I could pass entire objects to Lua scripts as tables, and this will be waaaaay easier.
  37. */
  38. /**
  39. * Prints to the game console.
  40. *
  41. * @param[in] text The text to be printed.
  42. */
  43. void ScriptPrint(const char* text){
  44. std::cout << "[SCRIPT] " << text << std::endl;
  45. Console::getSingleton().AddTextToOutput(text);
  46. }
  47. /**
  48. * Changes the current map.
  49. *
  50. * Reads the data for the next map, initializes all it's entities, scripts, etc
  51. * and loads it.
  52. *
  53. * @param[in] text The new map name.
  54. */
  55. void ScriptMap(const char* text){
  56. EntityManager::getSingleton().Clear();
  57. XmlMapsFile xml("./data/fields/_fields.xml");
  58. Ogre::String file_name = xml.GetMapFileNameByName(text);
  59. XmlMapFile xml_map("./data/fields/" + file_name);
  60. xml_map.LoadMap();
  61. }
  62. /**
  63. * Executes a script in the game console.
  64. *
  65. * It should not be related to the game itself. The script output will be
  66. * written to the game console.
  67. *
  68. * @param[in] text The script command to execute.
  69. */
  70. void ScriptConsole(const char* text){
  71. Console::getSingleton().ExecuteCommand(text);
  72. }
  73. void ScriptManager::InitBinds(){
  74. // Global functions.
  75. luabind::module(lua_state_)[
  76. luabind::def("print", (void(*)(const char*)) &ScriptPrint),
  77. luabind::def("map", (void(*)(const char*)) &ScriptMap),
  78. luabind::def("console", (void(*)(const char*)) &ScriptConsole)
  79. ];
  80. // Individual entity commands.
  81. luabind::module(lua_state_)[
  82. luabind::class_<Entity>("Entity")
  83. .def(
  84. "set_position",
  85. (void(Entity::*)(const float, const float, const float)) &Entity::ScriptSetPosition
  86. )
  87. // Internally returns 3 values:
  88. .def("get_position", (void(Entity::*)()) &Entity::ScriptGetPosition)
  89. .def("set_rotation", (void(Entity::*)(const float)) &Entity::ScriptSetRotation)
  90. .def("get_rotation", (float(Entity::*)()) &Entity::ScriptGetRotation)
  91. .def("set_solid_radius", (void(Entity::*)(const float)) &Entity::SetSolidRadius)
  92. .def("get_solid_radius", (float(Entity::*)()) &Entity::GetSolidRadius)
  93. .def("set_solid", (void(Entity::*)(const bool)) &Entity::SetSolid)
  94. .def("is_solid", (bool(Entity::*)()) &Entity::IsSolid)
  95. .def("set_talk_radius", (void(Entity::*)(const float)) &Entity::SetTalkRadius)
  96. .def("get_talk_radius", (float(Entity::*)()) &Entity::GetTalkRadius)
  97. // Some old test script use this, its just an alias for SetTalkable:
  98. .def("set_interactable", (void(Entity::*)(const bool)) &Entity::SetTalkable)
  99. .def("set_talkable", (void(Entity::*)(const bool)) &Entity::SetTalkable)
  100. .def("is_talkable", (bool(Entity::*)()) &Entity::IsTalkable)
  101. .def("set_visible", (void(Entity::*)(const bool)) &Entity::SetVisible)
  102. .def("is_visible", (bool(Entity::*)()) &Entity::IsVisible)
  103. .def("set_move_auto_speed", (void(Entity::*)(const float)) &Entity::SetMoveAutoSpeed)
  104. .def("get_move_auto_speed", (float(Entity::*)()) &Entity::GetMoveAutoSpeed)
  105. .def("get_move_triangle_id", (int(Entity::*)()) &Entity::GetMoveTriangleId)
  106. .def("set_move_triangle_id", (void(Entity::*)(const int)) &Entity::SetMoveTriangleId)
  107. .def("move_auto_rotation", (void(Entity::*)(const bool)) &Entity::SetMoveAutoRotation)
  108. .def("move_auto_animation", (void(Entity::*)(const bool)) &Entity::SetMoveAutoAnimation)
  109. .def(
  110. "move_to_position",
  111. (void(Entity::*)(const float, const float)) &Entity::ScriptMoveToPosition
  112. )
  113. .def("move_to_entity", (void(Entity::*)(Entity*)) &Entity::ScriptMoveToEntity)
  114. .def("move_sync", (int(Entity::*)()) &Entity::ScriptMoveSync, luabind::yield)
  115. .def(
  116. "linear_to_position",
  117. (void(Entity::*)(
  118. const float, const float, const float, const LinearMovement,
  119. const char*, const float, const int
  120. )) &Entity::ScriptLinearToPosition
  121. )
  122. .def(
  123. "linear_sync", (int(Entity::*)()) &Entity::ScriptLinearSync, luabind::yield
  124. )
  125. .def(
  126. "jump_to_position",
  127. (void(Entity::*)(const float, const float, const float, const float, const int))
  128. &Entity::ScriptJumpToPosition
  129. )
  130. .def("jump_sync", (int(Entity::*)()) &Entity::ScriptJumpSync, luabind::yield)
  131. .def(
  132. "offset_to_position",
  133. (void(Entity::*)(const float, const float, const float, const ActionType, const float))
  134. &Entity::ScriptOffsetToPosition
  135. )
  136. .def("offset_sync", (int(Entity::*)()) &Entity::ScriptOffsetSync, luabind::yield)
  137. .def(
  138. "turn_to_entity",
  139. (void(Entity::*)(Entity*, const TurnDirection, const float)) &Entity::ScriptTurnToEntity
  140. )
  141. .def(
  142. "turn_to_direction", (
  143. void(Entity::*)(const float, const TurnDirection, const ActionType, const float)
  144. ) &Entity::ScriptTurnToDirection)
  145. .def("turn_sync", (int(Entity::*)()) &Entity::ScriptTurnSync, luabind::yield)
  146. .def(
  147. "set_animation_speed", (void(Entity::*)(const float)) &Entity::ScriptSetAnimationSpeed
  148. )
  149. .def("play_animation", (void(Entity::*)(const char*)) &Entity::ScriptPlayAnimation)
  150. .def(
  151. "play_animation_stop", (void(Entity::*)(const char*)) &Entity::ScriptPlayAnimationStop
  152. )
  153. .def(
  154. "play_animation",
  155. (void(Entity::*)(const char*, const float, const float)) &Entity::ScriptPlayAnimation
  156. )
  157. .def(
  158. "play_animation_stop",
  159. (void(Entity::*)(const char*, const float, const float))
  160. &Entity::ScriptPlayAnimationStop
  161. )
  162. .def(
  163. "set_default_animation",
  164. (void(Entity::*)(const char*)) &Entity::ScriptSetDefaultAnimation
  165. )
  166. .def("animation_sync", (int(Entity::*)()) &Entity::ScriptAnimationSync, luabind::yield)
  167. .enum_("constants")[
  168. luabind::value("NONE", AT_NONE),
  169. luabind::value("LINEAR", AT_LINEAR),
  170. luabind::value("SMOOTH", AT_SMOOTH),
  171. luabind::value("CLOCKWISE", TD_CLOCKWISE),
  172. luabind::value("ANTICLOCKWISE", TD_ANTICLOCKWISE),
  173. luabind::value("CLOSEST", TD_CLOSEST),
  174. luabind::value("UP_TO_DOWN", LM_UP_TO_DOWN),
  175. luabind::value("DOWN_TO_UP", LM_DOWN_TO_UP),
  176. luabind::value("LEFT_TO_RIGHT", LM_LEFT_TO_RIGHT),
  177. luabind::value("RIGHT_TO_LEFT", LM_RIGHT_TO_LEFT)
  178. ]
  179. ];
  180. // Field commands.
  181. // TODO: Duplicated in group EntityManager, this can probably be deleted
  182. luabind::module(lua_state_)[
  183. luabind::class_<EntityManager>("Field")
  184. .def(
  185. "random_encounters_on",
  186. (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters
  187. )
  188. .def("start_battle", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
  189. // TODO: Run? Set battle flags
  190. .def("battle_run", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
  191. ];
  192. // Entity individual point commands
  193. luabind::module(lua_state_)[
  194. luabind::class_<EntityPoint>("EntityPoint")
  195. // Internally returns 3 values:
  196. .def("get_position", (void(EntityPoint::*)()) &EntityPoint::ScriptGetPosition)
  197. .def("get_rotation", (float(EntityPoint::*)()) &EntityPoint::ScriptGetRotation)
  198. ];
  199. // Commands for the entity manager, not related to any particular entity.
  200. luabind::module(lua_state_)[
  201. luabind::class_<EntityManager>("EntityManager")
  202. .def("set_paused", (void(EntityManager::*)(const bool)) &EntityManager::ScriptSetPaused)
  203. .def(
  204. "add_entity",
  205. (void(EntityManager::*)(
  206. const char*, const char*, const float,const float,
  207. const float, const float, const int
  208. )) &EntityManager::ScriptAddEntity
  209. )
  210. .def(
  211. "add_entity_script",
  212. (void(EntityManager::*)(const char*)) &EntityManager::ScriptAddEntityScript
  213. )
  214. .def(
  215. "get_entity", (Entity*(EntityManager::*)(const char*)) &EntityManager::ScriptGetEntity
  216. )
  217. .def(
  218. "get_entity_from_index",
  219. (Entity*(EntityManager::*)(const int)) &EntityManager::GetEntityFromIndex
  220. )
  221. .def(
  222. "get_entity_from_character_id",
  223. (Entity*(EntityManager::*)(const int)) &EntityManager::GetEntityFromCharacterId
  224. )
  225. .def(
  226. "get_entity_point",
  227. (EntityPoint*(EntityManager::*)(const char*)) &EntityManager::ScriptGetEntityPoint
  228. )
  229. .def(
  230. "set_player_entity",
  231. (void(EntityManager::*)(const char*)) &EntityManager::ScriptSetPlayerEntity
  232. )
  233. .def(
  234. "get_player_entity",
  235. (Entity*(EntityManager::*)()) &EntityManager::ScriptGetPlayerEntity
  236. )
  237. .def(
  238. "unset_player_entity",
  239. (void(EntityManager::*)()) &EntityManager::ScriptUnsetPlayerEntity
  240. )
  241. .def(
  242. "player_lock", (void(EntityManager::*)(const bool)) &EntityManager::ScriptPlayerLock
  243. )
  244. .def(
  245. "random_encounters_on",
  246. (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters
  247. )
  248. .def("start_battle", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
  249. // TODO: Run? Set battle flags
  250. .def("battle_run", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
  251. .def("is_key_on", (bool(EntityManager::*)(unsigned int)) &EntityManager::IsKeyOn)
  252. .def("is_key_off", (bool(EntityManager::*)(unsigned int)) &EntityManager::IsKeyOff)
  253. .def(
  254. "set_entity_to_character",
  255. (void(EntityManager::*)(const char*, unsigned int)) &EntityManager::SetEntityToCharacter
  256. )
  257. ];
  258. // Commands for the battle manager.
  259. luabind::module(lua_state_)[
  260. luabind::class_<BattleManager>("BattleManager")
  261. .def(
  262. "start_battle", (void(BattleManager::*)(const unsigned int)) &BattleManager::StartBattle
  263. )
  264. .def("end_battle", (void(BattleManager::*)()) &BattleManager::EndBattle)
  265. ];
  266. // Commands for the audio manager.
  267. luabind::module(lua_state_)[
  268. luabind::class_<AudioManager>("AudioManager")
  269. .def("play_music", (void(AudioManager::*)(const char*)) &AudioManager::ScriptPlayMusic)
  270. .def("play_sound", (void(AudioManager::*)(const char*)) &AudioManager::ScriptPlaySound)
  271. .def(
  272. "play_sound",
  273. (void(AudioManager::*)(const char*, const int)) &AudioManager::ScriptPlaySound
  274. )
  275. .def(
  276. "play_sounds",
  277. (void(AudioManager::*)(const char*, const char*, const char*, const char*))
  278. &AudioManager::ScriptPlaySounds
  279. )
  280. .def("get_track_id", (int(AudioManager::*)(int)) &AudioManager::ScriptGetTrack)
  281. .def("get_battle_track_id", (int(AudioManager::*)()) &AudioManager::ScriptGetBattleTrack)
  282. .def(
  283. "set_battle_track_id", (void(AudioManager::*)(int)) &AudioManager::ScriptSetBattleTrack
  284. )
  285. ];
  286. // Commands for the audio manager.
  287. luabind::module(lua_state_)[
  288. luabind::class_<CameraManager>("CameraManager")
  289. .def("set_camera",
  290. (void(CameraManager::*)(
  291. const int, const int, const int, const int, const int, const int
  292. )) &CameraManager::ScriptSetCamera
  293. )
  294. ];
  295. // Commands for the savemap handelr.
  296. luabind::module(lua_state_)[
  297. luabind::class_<SavemapHandler>("SavemapHandler")
  298. .def(
  299. "release", (void(SavemapHandler::*)()) &SavemapHandler::Release
  300. )
  301. .def(
  302. "get_current_savemap",
  303. (Savemap*(SavemapHandler::*)()) &SavemapHandler::GetCurrentSavemap
  304. )
  305. .def(
  306. "get_savemap",
  307. (Savemap*(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSavemap
  308. )
  309. .def(
  310. "set_data",
  311. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const int))
  312. &SavemapHandler::SetData
  313. )
  314. .def(
  315. "set_control_key", (void(SavemapHandler::*)(const char*)) &SavemapHandler::SetControlKey
  316. )
  317. .def(
  318. "set_window_colours",
  319. (void(SavemapHandler::*)(
  320. const unsigned int, const unsigned int, const unsigned int,
  321. const unsigned int, const unsigned int, const unsigned int,
  322. const unsigned int, const unsigned int, const unsigned int,
  323. const unsigned int, const unsigned int, const unsigned int
  324. )) &SavemapHandler::SetWindowColours
  325. )
  326. .def("set_money", (void(SavemapHandler::*)(const unsigned int)) &SavemapHandler::SetMoney)
  327. .def(
  328. "set_game_time",
  329. (void(SavemapHandler::*)(const unsigned int)) &SavemapHandler::SetGameTime
  330. )
  331. .def(
  332. "set_countdown_time",
  333. (void(SavemapHandler::*)(const unsigned int)) &SavemapHandler::SetCountdownTime
  334. )
  335. .def(
  336. "set_key_item",
  337. (void(SavemapHandler::*)(const unsigned int, const bool)) &SavemapHandler::SetKeyItem
  338. )
  339. .def(
  340. "set_party",
  341. (void(SavemapHandler::*)(const int, const int, const int)) &SavemapHandler::SetParty
  342. )
  343. .def(
  344. "set_item",
  345. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const unsigned int))
  346. &SavemapHandler::SetItem
  347. )
  348. .def(
  349. "set_materia",
  350. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const unsigned int))
  351. &SavemapHandler::SetMateria
  352. )
  353. .def(
  354. "set_e_skill_materia",
  355. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const bool))
  356. &SavemapHandler::SetESkillMateria
  357. )
  358. .def(
  359. "set_materia_stash",
  360. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const unsigned int))
  361. &SavemapHandler::SetMateriaStash
  362. )
  363. .def(
  364. "set_e_skill_materia_stash",
  365. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const bool))
  366. &SavemapHandler::SetESkillMateriaStash
  367. )
  368. .def(
  369. "set_location",
  370. (void(SavemapHandler::*)(
  371. const float, const float, const float, const unsigned int, const int,
  372. const char*, const char*
  373. )) &SavemapHandler::SetLocation
  374. )
  375. .def(
  376. "set_setting",
  377. (void(SavemapHandler::*)(const unsigned int, const unsigned int))
  378. &SavemapHandler::SetSetting
  379. )
  380. .def(
  381. "set_character_info",
  382. (void(SavemapHandler::*)(
  383. const unsigned int, const int, const char*, const bool, const bool, const unsigned int,
  384. const unsigned int, const bool, const unsigned int, const unsigned int,
  385. const unsigned int, const unsigned int, const unsigned int, const unsigned int,
  386. const int
  387. )) &SavemapHandler::SetCharacterInfo
  388. )
  389. .def(
  390. "set_character_stat",
  391. (void(SavemapHandler::*)(
  392. const unsigned int, const unsigned int, const unsigned int, const unsigned int
  393. )) &SavemapHandler::SetCharacterStat
  394. )
  395. .def(
  396. "set_character_limit_learned",
  397. (void(SavemapHandler::*)(
  398. const unsigned int, const unsigned int, const unsigned int,
  399. const bool, const unsigned int
  400. )) &SavemapHandler::SetCharacterLimitLearned
  401. )
  402. .def(
  403. "set_character_materia",
  404. (void(SavemapHandler::*)(
  405. const unsigned int, const bool, const unsigned int,
  406. const unsigned int, const unsigned int
  407. )) &SavemapHandler::SetCharacterMateria
  408. )
  409. .def(
  410. "set_character_e_skill_materia",
  411. (void(SavemapHandler::*)(
  412. const unsigned int, const bool, const unsigned int, const unsigned int, const bool
  413. )) &SavemapHandler::SetCharacterESkillMateria
  414. )
  415. .def(
  416. "set_character_status",
  417. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const bool))
  418. &SavemapHandler::SetCharacterStatus
  419. )
  420. .def(
  421. "save", (bool(SavemapHandler::*)(const unsigned int, const bool)) &SavemapHandler::Save
  422. )
  423. .def(
  424. "is_slot_empty",
  425. (bool(SavemapHandler::*)(const unsigned int)) &SavemapHandler::IsSlotEmpty
  426. )
  427. .def(
  428. "get_slot_control_key",
  429. (std::string(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotControlKey
  430. )
  431. .def(
  432. "get_slot_control_key",
  433. (unsigned int(SavemapHandler::*)(
  434. const unsigned int, const unsigned int, const unsigned int
  435. )) &SavemapHandler::GetSlotWindowCornerColourComponent
  436. )
  437. .def(
  438. "get_slot_money",
  439. (unsigned int(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotMoney
  440. )
  441. .def(
  442. "get_slot_game_time",
  443. (unsigned int(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotGameTime
  444. )
  445. .def(
  446. "get_slot_countdown_time",
  447. (unsigned int(SavemapHandler::*)(const unsigned int))
  448. &SavemapHandler::GetSlotCountdownTime
  449. )
  450. .def(
  451. "get_slot_party_member",
  452. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  453. &SavemapHandler::GetSlotPartyMember
  454. )
  455. .def(
  456. "get_slot_item_at_pos_id",
  457. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  458. &SavemapHandler::GetSlotItemAtPosId
  459. )
  460. .def(
  461. "get_slot_item_at_pos_qty",
  462. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  463. &SavemapHandler::GetSlotItemAtPosQty
  464. )
  465. .def(
  466. "get_slot_key_item",
  467. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  468. &SavemapHandler::GetSlotKeyItem
  469. )
  470. .def(
  471. "get_slot_materia_at_pos_id",
  472. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  473. &SavemapHandler::GetSlotMateriaAtPosId
  474. )
  475. .def(
  476. "get_slot_materia_at_pos_ap",
  477. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  478. &SavemapHandler::GetSlotMateriaAtPosAp
  479. )
  480. .def(
  481. "is_slot_materia_at_pos_e_skill",
  482. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  483. &SavemapHandler::IsSlotMateriaAtPosESkill
  484. )
  485. .def(
  486. "is_slot_materia_at_pos_e_skill_learned",
  487. (bool(SavemapHandler::*)(
  488. const unsigned int, const unsigned int, const unsigned int
  489. )) &SavemapHandler::IsSlotMateriaAtPosESkillLearned
  490. )
  491. .def(
  492. "get_slot_stash_at_pos_id",
  493. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  494. &SavemapHandler::GetSlotStashAtPosId
  495. )
  496. .def(
  497. "get_slot_stash_at_pos_ap",
  498. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  499. &SavemapHandler::GetSlotStashAtPosAp
  500. )
  501. .def(
  502. "is_slot_stash_at_pos_e_skill",
  503. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  504. &SavemapHandler::IsSlotStashAtPosESkill
  505. )
  506. .def(
  507. "is_slot_stash_at_pos_e_skill_learned",
  508. (bool(SavemapHandler::*)(
  509. const unsigned int, const unsigned int, const unsigned int
  510. )) &SavemapHandler::IsSlotStashAtPosESkillLearned
  511. )
  512. .def(
  513. "get_slot_location_x",
  514. (float(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotLocationX
  515. )
  516. .def(
  517. "get_slot_location_y",
  518. (float(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotLocationY
  519. )
  520. .def(
  521. "get_slot_location_z",
  522. (float(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotLocationZ
  523. )
  524. .def(
  525. "get_slot_location_triangle",
  526. (unsigned int(SavemapHandler::*)(const unsigned int))
  527. &SavemapHandler::GetSlotLocationTriangle
  528. )
  529. .def(
  530. "get_slot_location_angle",
  531. (unsigned int(SavemapHandler::*)(const unsigned int))
  532. &SavemapHandler::GetSlotLocationAngle
  533. )
  534. .def(
  535. "get_slot_location_field",
  536. (std::string(SavemapHandler::*)(const unsigned int))
  537. &SavemapHandler::GetSlotLocationField
  538. )
  539. .def(
  540. "get_slot_location_name",
  541. (std::string(SavemapHandler::*)(const unsigned int))
  542. &SavemapHandler::GetSlotLocationName
  543. )
  544. .def(
  545. "get_slot_setting",
  546. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  547. &SavemapHandler::GetSlotSetting
  548. )
  549. .def(
  550. "get_slot_character_char_id",
  551. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  552. &SavemapHandler::GetSlotCharacterCharId
  553. )
  554. .def(
  555. "get_slot_character_name",
  556. (std::string(SavemapHandler::*)(const unsigned int, const unsigned int))
  557. &SavemapHandler::GetSlotCharacterName
  558. )
  559. .def(
  560. "get_slot_character_level",
  561. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  562. &SavemapHandler::GetSlotCharacterLevel
  563. )
  564. .def(
  565. "get_slot_character_kills",
  566. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  567. &SavemapHandler::GetSlotCharacterKills
  568. )
  569. .def(
  570. "is_slot_character_enabled",
  571. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  572. &SavemapHandler::IsSlotCharacterEnabled
  573. )
  574. .def(
  575. "is_slot_character_locked",
  576. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  577. &SavemapHandler::IsSlotCharacterLocked
  578. )
  579. .def(
  580. "is_slot_character_back_row",
  581. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  582. &SavemapHandler::IsSlotCharacterBackRow
  583. )
  584. .def(
  585. "get_slot_character_exp",
  586. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  587. &SavemapHandler::GetSlotCharacterExp
  588. )
  589. .def(
  590. "get_slot_character_exp_to_next",
  591. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  592. &SavemapHandler::GetSlotCharacterExpToNext
  593. )
  594. .def(
  595. "get_slot_character_limit_level",
  596. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  597. &SavemapHandler::GetSlotCharacterLimitLevel
  598. )
  599. .def(
  600. "get_slot_character_limit_bar",
  601. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  602. &SavemapHandler::GetSlotCharacterLimitBar
  603. )
  604. .def(
  605. "get_slot_character_weapon_id",
  606. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  607. &SavemapHandler::GetSlotCharacterWeaponId
  608. )
  609. .def(
  610. "get_slot_character_armor_id",
  611. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  612. &SavemapHandler::GetSlotCharacterArmorId
  613. )
  614. .def(
  615. "get_slot_character_accessory_id",
  616. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  617. &SavemapHandler::GetSlotCharacterAccessoryId
  618. )
  619. .def(
  620. "get_slot_character_stat_base",
  621. (unsigned int(SavemapHandler::*)(
  622. const unsigned int, const unsigned int, const unsigned int
  623. )) &SavemapHandler::GetSlotCharacterStatBase
  624. )
  625. .def(
  626. "get_slot_character_stat_extra",
  627. (unsigned int(SavemapHandler::*)(
  628. const unsigned int, const unsigned int, const unsigned int
  629. )) &SavemapHandler::GetSlotCharacterStatExtra
  630. )
  631. .def(
  632. "get_slot_character_limit_uses",
  633. (unsigned int(SavemapHandler::*)(
  634. const unsigned int, const unsigned int, const unsigned int
  635. )) &SavemapHandler::GetSlotCharacterLimitUses
  636. )
  637. .def(
  638. "is_slot_character_limit_learned",
  639. (unsigned int(SavemapHandler::*)(
  640. const unsigned int, const unsigned int, const unsigned int, const unsigned int
  641. )) &SavemapHandler::IsSlotCharacterLimitLearned
  642. )
  643. .def(
  644. "get_slot_character_materia_id",
  645. (int(SavemapHandler::*)(
  646. const unsigned int, const unsigned int, const bool, const unsigned int
  647. )) &SavemapHandler::GetSlotCharacterMateriaId
  648. )
  649. .def(
  650. "get_slot_character_materia_ap",
  651. (unsigned int(SavemapHandler::*)(
  652. const unsigned int, const unsigned int, const bool, const unsigned int
  653. )) &SavemapHandler::GetSlotCharacterMateriaAp
  654. )
  655. .def(
  656. "get_slot_character_materia_e_skill",
  657. (bool(SavemapHandler::*)(
  658. const unsigned int, const unsigned int, const bool,
  659. const unsigned int, const unsigned int
  660. )) &SavemapHandler::IsSlotCharacterMateriaESkill
  661. )
  662. .def(
  663. "get_slot_character_materia_e_skill_learned",
  664. (bool(SavemapHandler::*)(
  665. const unsigned int, const unsigned int, const bool,
  666. const unsigned int, const unsigned int
  667. )) &SavemapHandler::IsSlotCharacterMateriaESkillLearned
  668. )
  669. .def(
  670. "get_slot_data",
  671. (int(SavemapHandler::*)(const unsigned int, const unsigned int, const unsigned int))
  672. &SavemapHandler::GetSlotData
  673. )
  674. ];
  675. // 2D background and camera commands
  676. luabind::module(lua_state_)[
  677. luabind::class_<Background2D>("Background2D")
  678. .def(
  679. "autoscroll_to_entity",
  680. (void(Background2D::*)(Entity*)) &Background2D::ScriptAutoScrollToEntity
  681. )
  682. .def(
  683. "scroll_to_player",
  684. (void(Background2D::*)(const Background2D::SCROLL_TYPE, const unsigned int))
  685. &Background2D::ScriptScrollToPlayer
  686. )
  687. .def(
  688. "scroll_to_position",
  689. (void(Background2D::*)(
  690. const float, const float, const Background2D::SCROLL_TYPE, const float
  691. )) &Background2D::ScriptScrollToPosition
  692. )
  693. .def(
  694. "scroll_sync", (int(Background2D::*)()) &Background2D::ScriptScrollSync, luabind::yield
  695. )
  696. .def(
  697. "offset", (void(Background2D::*)(const float, const float)) &Background2D::ScriptOffset
  698. )
  699. .def(
  700. "play_animation_looped",
  701. (void(Background2D::*)(const char*)) &Background2D::ScriptPlayAnimationLooped
  702. )
  703. .def(
  704. "play_animation_once",
  705. (void(Background2D::*)(const char*)) &Background2D::ScriptPlayAnimationOnce
  706. )
  707. .def(
  708. "animation_sync",
  709. (int(Background2D::*)(const char*)) &Background2D::ScriptAnimationSync,
  710. luabind::yield
  711. )
  712. .enum_("constants")[
  713. luabind::value("NONE", AT_NONE),
  714. luabind::value("LINEAR", AT_LINEAR),
  715. luabind::value("SMOOTH", AT_SMOOTH)
  716. ]
  717. ];
  718. // Walkmesh commands
  719. luabind::module(lua_state_)[
  720. luabind::class_<Walkmesh>("Walkmesh")
  721. .def("lock_walkmesh", (void(Walkmesh ::*)(unsigned int, bool)) &Walkmesh ::LockWalkmesh)
  722. .def("is_locked", (bool(Walkmesh ::*)(unsigned int)) &Walkmesh ::IsLocked)
  723. ];
  724. // Text handler commands
  725. luabind::module(lua_state_)[
  726. luabind::class_<TextHandler>("TextHandler")
  727. .def(
  728. "set_character_name",
  729. (void(TextHandler ::*)(unsigned int, const char*)) &TextHandler::SetCharacterName
  730. )
  731. .def("set_party", (void(TextHandler ::*)(int, int, int)) &TextHandler::SetParty)
  732. ];
  733. // Dialog commands
  734. luabind::module(lua_state_)[
  735. luabind::class_<DialogsManager>("Dialog")
  736. .def(
  737. "dialog_open",
  738. (void(DialogsManager::*)(const char*, int, int, int, int)) &DialogsManager::OpenDialog
  739. )
  740. .def(
  741. "set_numeric",
  742. (void(DialogsManager::*)(const char*, const bool, const bool))
  743. &DialogsManager::SetNumeric
  744. )
  745. .def(
  746. "update_timer",
  747. (void(DialogsManager::*)(const unsigned int)) &DialogsManager::UpdateTimer
  748. )
  749. .def(
  750. "set_mode",
  751. (void(DialogsManager::*)(const char*, const unsigned int, const bool))
  752. &DialogsManager::SetMode
  753. )
  754. .def(
  755. "dialog_set_text",
  756. (void(DialogsManager::*)(const char*, const char*)) &DialogsManager::SetText
  757. )
  758. .def(
  759. "dialog_wait_for_close",
  760. (int(DialogsManager::*)(const char*)) &DialogsManager::Sync,
  761. luabind::yield
  762. )
  763. .def("dialog_close", (void(DialogsManager::*)(const char*)) &DialogsManager::Hide)
  764. .def(
  765. "set_variable",
  766. (void(DialogsManager::*)(const char*, const char*, const char*))
  767. &DialogsManager::SetVariable
  768. )
  769. .def(
  770. "set_clickable",
  771. (void(DialogsManager::*)(const char*, const bool)) &DialogsManager::SetClickable
  772. )
  773. .def(
  774. "set_cursor",
  775. (void(DialogsManager::*)(const char*, const int, const int)) &DialogsManager::SetCursor
  776. )
  777. .def("get_cursor", (int(DialogsManager::*)(const char*)) &DialogsManager::GetCursor)
  778. .enum_("constants")[
  779. luabind::value("SOLID", MSL_SOLID),
  780. luabind::value("TRANSPARENT", MSL_TRANSPARENT),
  781. luabind::value("NONE", MSL_NONE)
  782. ]
  783. .def(
  784. "set_map_name", (void(DialogsManager::*)(const char*)) &DialogsManager::ScriptSetMapName
  785. )
  786. .def(
  787. "get_map_name", (std::string(DialogsManager::*)()) &DialogsManager::GetMapName
  788. )
  789. ];
  790. // UI widget commands
  791. luabind::module(lua_state_)[
  792. luabind::class_<UiWidget>("UiWidget")
  793. .def("set_visible", (void(UiWidget::*)(const bool)) &UiWidget::SetVisible)
  794. .def("is_visible", (bool(UiWidget::*)()) &UiWidget::IsVisible)
  795. .def("play_animation", (void(UiWidget::*)(const char*)) &UiWidget::ScriptPlayAnimation)
  796. .def(
  797. "play_animation_stop",
  798. (void(UiWidget::*)(const char*)) &UiWidget::ScriptPlayAnimationStop
  799. )
  800. .def(
  801. "play_animation",
  802. (void(UiWidget::*)(const char*, const float, const float))
  803. &UiWidget::ScriptPlayAnimation
  804. )
  805. .def(
  806. "play_animation_stop",
  807. (void(UiWidget::*)(const char*, const float, const float))
  808. &UiWidget::ScriptPlayAnimationStop
  809. )
  810. .def(
  811. "set_default_animation",
  812. (void(UiWidget::*)(const char*)) &UiWidget::ScriptSetDefaultAnimation
  813. )
  814. .def(
  815. "animation_sync", (int(UiWidget::*)()) &UiWidget::ScriptAnimationSync, luabind::yield
  816. )
  817. .def(
  818. "set_colour",
  819. (void(UiWidget::*)(const float, const float, const float)) &UiWidget::SetColour
  820. )
  821. .def("set_alpha", (void(UiWidget::*)(const float)) &UiWidget::SetAlpha)
  822. .def("set_x", (void(UiWidget::*)(const float, const float)) &UiWidget::SetX)
  823. .def("set_y", (void(UiWidget::*)(const float, const float)) &UiWidget::SetY)
  824. .def("set_z", (void(UiWidget::*)(const float)) &UiWidget::SetZ)
  825. .def("get_width", (float(UiWidget::*)()) &UiWidget::ScriptGetWidth)
  826. .def("set_width", (void(UiWidget::*)(const float)) &UiWidget::ScriptSetWidth)
  827. .def("get_height", (float(UiWidget::*)()) &UiWidget::ScriptGetHeight)
  828. .def("set_height", (void(UiWidget::*)(const float)) &UiWidget::ScriptSetHeight)
  829. .def("set_text", (void(UiWidget::*)(const char*)) &UiWidget::SetText)
  830. .def("set_image", (void(UiWidget::*)(const char*)) &UiWidget::SetImage)
  831. ];
  832. // UI manager commands. Use to get a specific widget.
  833. luabind::module(lua_state_)[
  834. luabind::class_<UiManager>("UiManager")
  835. .def("get_widget", (UiWidget*(UiManager::*)(const char*)) &UiManager::ScriptGetWidget)
  836. ];
  837. // Timer command. To show a in-game timer.
  838. luabind::module(lua_state_)[
  839. luabind::class_<Timer>("Timer")
  840. .def("get_game_time_total", (float(Timer::*)()) &Timer::GetGameTimeTotal)
  841. .def("set_timer", (float(Timer::*)(const float)) &Timer::SetGameTimer)
  842. .def("get_timer", (int(Timer::*)()) &Timer::GetGameTimer)
  843. ];
  844. // Commands that control script execution
  845. luabind::module(lua_state_)[
  846. luabind::class_<ScriptManager>("Script")
  847. .def(
  848. "wait", (int(ScriptManager::*)(const float)) &ScriptManager::ScriptWait, luabind::yield
  849. )
  850. .def(
  851. "request",
  852. (void(ScriptManager::*)(const ScriptManager::Type, const char*, const char*, const int))
  853. &ScriptManager::ScriptRequest
  854. )
  855. .def(
  856. "request_start_sync",
  857. (int(ScriptManager::*)(const ScriptManager::Type, const char*, const char*, const int))
  858. &ScriptManager::ScriptRequestStartSync,
  859. luabind::yield
  860. )
  861. .def(
  862. "request_end_sync",
  863. (int(ScriptManager::*) (const ScriptManager::Type, const char*, const char*, const int))
  864. &ScriptManager::ScriptRequestEndSync,
  865. luabind::yield
  866. )
  867. .enum_("constants")[
  868. luabind::value("SYSTEM", ScriptManager::SYSTEM),
  869. luabind::value("ENTITY", ScriptManager::ENTITY),
  870. luabind::value("UI", ScriptManager::UI)
  871. ]
  872. ];
  873. // Commnds to initiate modules
  874. luabind::module(lua_state_)[
  875. luabind::class_<VGears::WorldmapModule>("world_map_module")
  876. .def("init", (void(VGears::WorldmapModule::*)()) &VGears::WorldmapModule::Init)
  877. ];
  878. // Register all command handlers
  879. auto a = boost::ref(*(EntityManager::getSingletonPtr()));
  880. luabind::globals(lua_state_);
  881. //auto b = luabind::globals(lua_state_)["entity_manager"];
  882. luabind::globals(lua_state_)["camera_manager"]
  883. = boost::ref(*(CameraManager::getSingletonPtr()));
  884. luabind::globals(lua_state_)["entity_manager"]
  885. = boost::ref(*(EntityManager::getSingletonPtr()));
  886. luabind::globals(lua_state_)["battle_manager"]
  887. = boost::ref(*(BattleManager::getSingletonPtr()));
  888. luabind::globals(lua_state_)["audio_manager"] = boost::ref(*(AudioManager::getSingletonPtr()));
  889. luabind::globals(lua_state_)["savemap_manager"]
  890. = boost::ref(*(SavemapHandler::getSingletonPtr()));
  891. luabind::globals(lua_state_)["background2d"]
  892. = boost::ref(*(EntityManager::getSingletonPtr()->GetBackground2D()));
  893. luabind::globals(lua_state_)["walkmesh"]
  894. = boost::ref(*(EntityManager::getSingletonPtr()->GetWalkmesh()));
  895. luabind::globals(lua_state_)["text_manager"] = boost::ref(*(TextHandler::getSingletonPtr()));
  896. luabind::globals(lua_state_)["dialog"] = boost::ref(*(DialogsManager::getSingletonPtr()));
  897. luabind::globals(lua_state_)["ui_manager"] = boost::ref(*(UiManager::getSingletonPtr()));
  898. luabind::globals(lua_state_)["world_map_module"]
  899. = boost::ref(*(VGears::WorldmapModule::getSingletonPtr()));
  900. luabind::globals(lua_state_)["timer"] = boost::ref(*(Timer::getSingletonPtr()));
  901. luabind::globals(lua_state_)["script"] = boost::ref(*this);
  902. }